Mercurial > libavformat.hg
comparison matroskaenc.c @ 3973:549a09cf23fe libavformat
Remove offset_t typedef and use int64_t directly instead.
The name offset_t is easily confused with the standard off_t type and
*_t is POSIX reserved namespace if any POSIX header is included.
author | diego |
---|---|
date | Fri, 03 Oct 2008 10:16:29 +0000 |
parents | 8f1928b41f45 |
children | acb0ad37d372 |
comparison
equal
deleted
inserted
replaced
3972:c7a831579a13 | 3973:549a09cf23fe |
---|---|
27 #include "libavutil/md5.h" | 27 #include "libavutil/md5.h" |
28 #include "libavcodec/xiph.h" | 28 #include "libavcodec/xiph.h" |
29 #include "libavcodec/mpeg4audio.h" | 29 #include "libavcodec/mpeg4audio.h" |
30 | 30 |
31 typedef struct ebml_master { | 31 typedef struct ebml_master { |
32 offset_t pos; ///< absolute offset in the file where the master's elements start | 32 int64_t pos; ///< absolute offset in the file where the master's elements start |
33 int sizebytes; ///< how many bytes were reserved for the size | 33 int sizebytes; ///< how many bytes were reserved for the size |
34 } ebml_master; | 34 } ebml_master; |
35 | 35 |
36 typedef struct mkv_seekhead_entry { | 36 typedef struct mkv_seekhead_entry { |
37 unsigned int elementid; | 37 unsigned int elementid; |
38 uint64_t segmentpos; | 38 uint64_t segmentpos; |
39 } mkv_seekhead_entry; | 39 } mkv_seekhead_entry; |
40 | 40 |
41 typedef struct mkv_seekhead { | 41 typedef struct mkv_seekhead { |
42 offset_t filepos; | 42 int64_t filepos; |
43 offset_t segment_offset; ///< the file offset to the beginning of the segment | 43 int64_t segment_offset; ///< the file offset to the beginning of the segment |
44 int reserved_size; ///< -1 if appending to file | 44 int reserved_size; ///< -1 if appending to file |
45 int max_entries; | 45 int max_entries; |
46 mkv_seekhead_entry *entries; | 46 mkv_seekhead_entry *entries; |
47 int num_entries; | 47 int num_entries; |
48 } mkv_seekhead; | 48 } mkv_seekhead; |
49 | 49 |
50 typedef struct { | 50 typedef struct { |
51 uint64_t pts; | 51 uint64_t pts; |
52 int tracknum; | 52 int tracknum; |
53 offset_t cluster_pos; ///< file offset of the cluster containing the block | 53 int64_t cluster_pos; ///< file offset of the cluster containing the block |
54 } mkv_cuepoint; | 54 } mkv_cuepoint; |
55 | 55 |
56 typedef struct { | 56 typedef struct { |
57 offset_t segment_offset; | 57 int64_t segment_offset; |
58 mkv_cuepoint *entries; | 58 mkv_cuepoint *entries; |
59 int num_entries; | 59 int num_entries; |
60 } mkv_cues; | 60 } mkv_cues; |
61 | 61 |
62 typedef struct MatroskaMuxContext { | 62 typedef struct MatroskaMuxContext { |
63 ebml_master segment; | 63 ebml_master segment; |
64 offset_t segment_offset; | 64 int64_t segment_offset; |
65 offset_t segment_uid; | 65 int64_t segment_uid; |
66 ebml_master cluster; | 66 ebml_master cluster; |
67 offset_t cluster_pos; ///< file offset of the current cluster | 67 int64_t cluster_pos; ///< file offset of the current cluster |
68 uint64_t cluster_pts; | 68 uint64_t cluster_pts; |
69 offset_t duration_offset; | 69 int64_t duration_offset; |
70 uint64_t duration; | 70 uint64_t duration; |
71 mkv_seekhead *main_seekhead; | 71 mkv_seekhead *main_seekhead; |
72 mkv_seekhead *cluster_seekhead; | 72 mkv_seekhead *cluster_seekhead; |
73 mkv_cues *cues; | 73 mkv_cues *cues; |
74 | 74 |
186 * | 186 * |
187 * @param size The number of bytes to reserve, which must be at least 2. | 187 * @param size The number of bytes to reserve, which must be at least 2. |
188 */ | 188 */ |
189 static void put_ebml_void(ByteIOContext *pb, uint64_t size) | 189 static void put_ebml_void(ByteIOContext *pb, uint64_t size) |
190 { | 190 { |
191 offset_t currentpos = url_ftell(pb); | 191 int64_t currentpos = url_ftell(pb); |
192 | 192 |
193 assert(size >= 2); | 193 assert(size >= 2); |
194 | 194 |
195 put_ebml_id(pb, EBML_ID_VOID); | 195 put_ebml_id(pb, EBML_ID_VOID); |
196 // we need to subtract the length needed to store the size from the | 196 // we need to subtract the length needed to store the size from the |
212 return (ebml_master){ url_ftell(pb), bytes }; | 212 return (ebml_master){ url_ftell(pb), bytes }; |
213 } | 213 } |
214 | 214 |
215 static void end_ebml_master(ByteIOContext *pb, ebml_master master) | 215 static void end_ebml_master(ByteIOContext *pb, ebml_master master) |
216 { | 216 { |
217 offset_t pos = url_ftell(pb); | 217 int64_t pos = url_ftell(pb); |
218 | 218 |
219 // leave the unknown size for masters when streaming | 219 // leave the unknown size for masters when streaming |
220 if (url_is_streamed(pb)) | 220 if (url_is_streamed(pb)) |
221 return; | 221 return; |
222 | 222 |
242 * @param segment_offset The absolute offset to the position in the file | 242 * @param segment_offset The absolute offset to the position in the file |
243 * where the segment begins. | 243 * where the segment begins. |
244 * @param numelements The maximum number of elements that will be indexed | 244 * @param numelements The maximum number of elements that will be indexed |
245 * by this seek head, 0 if unlimited. | 245 * by this seek head, 0 if unlimited. |
246 */ | 246 */ |
247 static mkv_seekhead * mkv_start_seekhead(ByteIOContext *pb, offset_t segment_offset, int numelements) | 247 static mkv_seekhead * mkv_start_seekhead(ByteIOContext *pb, int64_t segment_offset, int numelements) |
248 { | 248 { |
249 mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead)); | 249 mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead)); |
250 if (new_seekhead == NULL) | 250 if (new_seekhead == NULL) |
251 return NULL; | 251 return NULL; |
252 | 252 |
289 * be written at the location reserved for it. Otherwise, it is written | 289 * be written at the location reserved for it. Otherwise, it is written |
290 * at the current location in the file. | 290 * at the current location in the file. |
291 * | 291 * |
292 * @return The file offset where the seekhead was written. | 292 * @return The file offset where the seekhead was written. |
293 */ | 293 */ |
294 static offset_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) | 294 static int64_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) |
295 { | 295 { |
296 ebml_master metaseek, seekentry; | 296 ebml_master metaseek, seekentry; |
297 offset_t currentpos; | 297 int64_t currentpos; |
298 int i; | 298 int i; |
299 | 299 |
300 currentpos = url_ftell(pb); | 300 currentpos = url_ftell(pb); |
301 | 301 |
302 if (seekhead->reserved_size > 0) | 302 if (seekhead->reserved_size > 0) |
328 av_free(seekhead); | 328 av_free(seekhead); |
329 | 329 |
330 return currentpos; | 330 return currentpos; |
331 } | 331 } |
332 | 332 |
333 static mkv_cues * mkv_start_cues(offset_t segment_offset) | 333 static mkv_cues * mkv_start_cues(int64_t segment_offset) |
334 { | 334 { |
335 mkv_cues *cues = av_mallocz(sizeof(mkv_cues)); | 335 mkv_cues *cues = av_mallocz(sizeof(mkv_cues)); |
336 if (cues == NULL) | 336 if (cues == NULL) |
337 return NULL; | 337 return NULL; |
338 | 338 |
339 cues->segment_offset = segment_offset; | 339 cues->segment_offset = segment_offset; |
340 return cues; | 340 return cues; |
341 } | 341 } |
342 | 342 |
343 static int mkv_add_cuepoint(mkv_cues *cues, AVPacket *pkt, offset_t cluster_pos) | 343 static int mkv_add_cuepoint(mkv_cues *cues, AVPacket *pkt, int64_t cluster_pos) |
344 { | 344 { |
345 mkv_cuepoint *entries = cues->entries; | 345 mkv_cuepoint *entries = cues->entries; |
346 | 346 |
347 entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint)); | 347 entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint)); |
348 if (entries == NULL) | 348 if (entries == NULL) |
354 | 354 |
355 cues->entries = entries; | 355 cues->entries = entries; |
356 return 0; | 356 return 0; |
357 } | 357 } |
358 | 358 |
359 static offset_t mkv_write_cues(ByteIOContext *pb, mkv_cues *cues, int num_tracks) | 359 static int64_t mkv_write_cues(ByteIOContext *pb, mkv_cues *cues, int num_tracks) |
360 { | 360 { |
361 ebml_master cues_element; | 361 ebml_master cues_element; |
362 offset_t currentpos; | 362 int64_t currentpos; |
363 int i, j; | 363 int i, j; |
364 | 364 |
365 currentpos = url_ftell(pb); | 365 currentpos = url_ftell(pb); |
366 cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0); | 366 cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0); |
367 | 367 |
799 | 799 |
800 static int mkv_write_trailer(AVFormatContext *s) | 800 static int mkv_write_trailer(AVFormatContext *s) |
801 { | 801 { |
802 MatroskaMuxContext *mkv = s->priv_data; | 802 MatroskaMuxContext *mkv = s->priv_data; |
803 ByteIOContext *pb = s->pb; | 803 ByteIOContext *pb = s->pb; |
804 offset_t currentpos, second_seekhead, cuespos; | 804 int64_t currentpos, second_seekhead, cuespos; |
805 int ret; | 805 int ret; |
806 | 806 |
807 end_ebml_master(pb, mkv->cluster); | 807 end_ebml_master(pb, mkv->cluster); |
808 | 808 |
809 if (!url_is_streamed(pb)) { | 809 if (!url_is_streamed(pb)) { |