Write a Seek entry for each Cluster if vlc_compat is on.
[libmkv.git] / src / matroska.h
blobf162b47c70a74939b90f0791558f5463eb033c8f
1 /*****************************************************************************
2 * matroska.h:
3 *****************************************************************************
4 * Copyright (C) 2005 x264 project
5 * $Id: $
7 * Authors: Mike Matsnev
8 * Nathan Caldwell
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
24 #ifndef _MATROSKA_H
25 #define _MATROSKA_H 1
27 #define _LARGEFILE_SOURCE
28 #define _FILE_OFFSET_BITS 64
30 #define CLSIZE 1048576
31 #define CHECK(x) do { if ((x) < 0) return -1; } while (0)
33 typedef struct mk_Context_s mk_Context;
34 typedef struct mk_Seek_s mk_Seek;
35 typedef struct mk_Chapter_s mk_Chapter;
37 struct mk_Context_s {
38 mk_Context *next, **prev, *parent;
39 mk_Writer *owner;
40 unsigned id;
42 void *data;
43 unsigned d_cur, d_max;
46 struct mk_Writer_s {
47 FILE *fp;
48 uint64_t f_pos;
49 uint64_t f_eof;
52 int64_t duration_ptr;
53 int64_t seekhead_ptr;
54 int64_t segment_ptr;
56 mk_Context *root;
57 mk_Context *freelist;
58 mk_Context *actlist;
59 mk_Context *chapters;
60 mk_Context *edition_entry;
61 mk_Context *tracks;
62 mk_Context *cues;
64 uint64_t def_duration;
65 uint64_t timescale;
67 uint8_t wrote_header;
69 uint8_t num_tracks;
70 mk_Track **tracks_arr;
72 struct {
73 int64_t segmentinfo;
74 int64_t seekhead;
75 int64_t tracks;
76 int64_t cues;
77 int64_t chapters;
78 int64_t attachments;
79 int64_t tags;
80 } seek_data;
82 struct {
83 mk_Context *context;
84 mk_Context *seekhead;
85 uint64_t block_count;
86 uint64_t count;
87 uint64_t pointer;
88 int64_t tc_scaled;
89 } cluster;
91 int chapter_uid;
92 uint8_t vlc_compat;
95 struct mk_Track_s {
96 uint8_t track_id;
98 int64_t prev_frame_tc_scaled;
99 int64_t max_frame_tc;
100 uint8_t in_frame;
101 uint64_t default_duration;
102 uint8_t track_type;
103 int64_t prev_cue_pos;
105 struct {
106 mk_Context *data;
107 int64_t timecode;
108 uint8_t keyframe;
109 uint8_t lacing;
110 uint8_t lacing_num_frames;
111 uint64_t *lacing_sizes;
112 } frame;
115 /* EBML */
116 mk_Context *mk_createContext(mk_Writer *w, mk_Context *parent, unsigned id);
117 int mk_appendContextData(mk_Context *c, const void *data, uint64_t size);
118 int mk_writeID(mk_Context *c, unsigned id);
119 int mk_writeSize(mk_Context *c, uint64_t size);
120 int mk_writeSSize(mk_Context *c, int64_t size);
121 int mk_flushContextID(mk_Context *c);
122 int mk_flushContextData(mk_Context *c);
123 int mk_closeContext(mk_Context *c, int64_t *off);
124 void mk_destroyContexts(mk_Writer *w);
125 int mk_writeStr(mk_Context *c, unsigned id, const char *str);
126 int mk_writeBin(mk_Context *c, unsigned id, const void *data, unsigned size);
127 int mk_writeUInt(mk_Context *c, unsigned id, uint64_t ui);
128 int mk_writeSInt(mk_Context *c, unsigned id, int64_t si);
129 int mk_writeFloatRaw(mk_Context *c, float f);
130 int mk_writeFloat(mk_Context *c, unsigned id, float f);
131 int mk_writeVoid(mk_Context *c, uint64_t length);
132 unsigned mk_ebmlSizeSize(uint64_t s);
133 unsigned mk_ebmlSIntSize(int64_t si);
134 /* EBML */
136 mk_Context *mk_createContext(mk_Writer *w, mk_Context *parent, unsigned id);
137 int mk_writeUInt(mk_Context *c, unsigned id, uint64_t ui);
138 int mk_writeFloat(mk_Context *c, unsigned id, float f);
139 int mk_writeStr(mk_Context *c, unsigned id, const char *str);
140 int mk_writeBin(mk_Context *c, unsigned id, const void *data, unsigned size);
141 int mk_flushContextData(mk_Context *c);
142 int mk_closeContext(mk_Context *c, int64_t *off);
143 int mk_writeSeek(mk_Writer *w, mk_Context *c, unsigned seek_id, uint64_t seek_pos);
144 int mk_writeSeekHead(mk_Writer *w, int64_t *pointer);
145 int mk_writeTracks(mk_Writer *w, mk_Context *tracks);
146 int mk_writeChapters(mk_Writer *w);
147 int mk_seekFile(mk_Writer *w, uint64_t pos);
149 #endif