comparison gxfenc.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 7a0230981402
children 10d52cda08dd
comparison
equal deleted inserted replaced
3972:c7a831579a13 3973:549a09cf23fe
118 } 118 }
119 } 119 }
120 return -1; 120 return -1;
121 } 121 }
122 122
123 static void gxf_write_padding(ByteIOContext *pb, offset_t to_pad) 123 static void gxf_write_padding(ByteIOContext *pb, int64_t to_pad)
124 { 124 {
125 for (; to_pad > 0; to_pad--) { 125 for (; to_pad > 0; to_pad--) {
126 put_byte(pb, 0); 126 put_byte(pb, 0);
127 } 127 }
128 } 128 }
129 129
130 static offset_t updatePacketSize(ByteIOContext *pb, offset_t pos) 130 static int64_t updatePacketSize(ByteIOContext *pb, int64_t pos)
131 { 131 {
132 offset_t curpos; 132 int64_t curpos;
133 int size; 133 int size;
134 134
135 size = url_ftell(pb) - pos; 135 size = url_ftell(pb) - pos;
136 if (size % 4) { 136 if (size % 4) {
137 gxf_write_padding(pb, 4 - size % 4); 137 gxf_write_padding(pb, 4 - size % 4);
142 put_be32(pb, size); 142 put_be32(pb, size);
143 url_fseek(pb, curpos, SEEK_SET); 143 url_fseek(pb, curpos, SEEK_SET);
144 return curpos - pos; 144 return curpos - pos;
145 } 145 }
146 146
147 static offset_t updateSize(ByteIOContext *pb, offset_t pos) 147 static int64_t updateSize(ByteIOContext *pb, int64_t pos)
148 { 148 {
149 offset_t curpos; 149 int64_t curpos;
150 150
151 curpos = url_ftell(pb); 151 curpos = url_ftell(pb);
152 url_fseek(pb, pos, SEEK_SET); 152 url_fseek(pb, pos, SEEK_SET);
153 put_be16(pb, curpos - pos - 2); 153 put_be16(pb, curpos - pos - 2);
154 url_fseek(pb, curpos, SEEK_SET); 154 url_fseek(pb, curpos, SEEK_SET);
205 return 8; 205 return 8;
206 } 206 }
207 207
208 static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stream) 208 static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stream)
209 { 209 {
210 offset_t pos; 210 int64_t pos;
211 211
212 /* track description section */ 212 /* track description section */
213 put_byte(pb, stream->media_type + 0x80); 213 put_byte(pb, stream->media_type + 0x80);
214 put_byte(pb, stream->index + 0xC0); 214 put_byte(pb, stream->index + 0xC0);
215 215
259 return updateSize(pb, pos); 259 return updateSize(pb, pos);
260 } 260 }
261 261
262 static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx) 262 static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx)
263 { 263 {
264 offset_t pos; 264 int64_t pos;
265 const char *filename = strrchr(ctx->fc->filename, '/'); 265 const char *filename = strrchr(ctx->fc->filename, '/');
266 266
267 pos = url_ftell(pb); 267 pos = url_ftell(pb);
268 put_be16(pb, 0); /* size */ 268 put_be16(pb, 0); /* size */
269 269
305 return updateSize(pb, pos); 305 return updateSize(pb, pos);
306 } 306 }
307 307
308 static int gxf_write_track_description_section(ByteIOContext *pb, GXFContext *ctx) 308 static int gxf_write_track_description_section(ByteIOContext *pb, GXFContext *ctx)
309 { 309 {
310 offset_t pos; 310 int64_t pos;
311 int i; 311 int i;
312 312
313 pos = url_ftell(pb); 313 pos = url_ftell(pb);
314 put_be16(pb, 0); /* size */ 314 put_be16(pb, 0); /* size */
315 for (i = 0; i < ctx->fc->nb_streams; ++i) 315 for (i = 0; i < ctx->fc->nb_streams; ++i)
317 return updateSize(pb, pos); 317 return updateSize(pb, pos);
318 } 318 }
319 319
320 static int gxf_write_map_packet(ByteIOContext *pb, GXFContext *ctx) 320 static int gxf_write_map_packet(ByteIOContext *pb, GXFContext *ctx)
321 { 321 {
322 offset_t pos = url_ftell(pb); 322 int64_t pos = url_ftell(pb);
323 323
324 gxf_write_packet_header(pb, PKT_MAP); 324 gxf_write_packet_header(pb, PKT_MAP);
325 325
326 /* preamble */ 326 /* preamble */
327 put_byte(pb, 0xE0); /* version */ 327 put_byte(pb, 0xE0); /* version */
334 } 334 }
335 335
336 #if 0 336 #if 0
337 static int gxf_write_flt_packet(ByteIOContext *pb, GXFContext *ctx) 337 static int gxf_write_flt_packet(ByteIOContext *pb, GXFContext *ctx)
338 { 338 {
339 offset_t pos = url_ftell(pb); 339 int64_t pos = url_ftell(pb);
340 int i; 340 int i;
341 341
342 gxf_write_packet_header(pb, PKT_FLT); 342 gxf_write_packet_header(pb, PKT_FLT);
343 343
344 put_le32(pb, 1000); /* number of fields */ 344 put_le32(pb, 1000); /* number of fields */
388 return 48; 388 return 48;
389 } 389 }
390 390
391 static int gxf_write_umf_track_description(ByteIOContext *pb, GXFContext *ctx) 391 static int gxf_write_umf_track_description(ByteIOContext *pb, GXFContext *ctx)
392 { 392 {
393 offset_t pos = url_ftell(pb); 393 int64_t pos = url_ftell(pb);
394 int tracks[255]={0}; 394 int tracks[255]={0};
395 int i; 395 int i;
396 396
397 ctx->umf_track_offset = pos - ctx->umf_start_offset; 397 ctx->umf_track_offset = pos - ctx->umf_start_offset;
398 for (i = 0; i < ctx->fc->nb_streams; ++i) { 398 for (i = 0; i < ctx->fc->nb_streams; ++i) {
484 } 484 }
485 #endif 485 #endif
486 486
487 static int gxf_write_umf_media_description(ByteIOContext *pb, GXFContext *ctx) 487 static int gxf_write_umf_media_description(ByteIOContext *pb, GXFContext *ctx)
488 { 488 {
489 offset_t pos; 489 int64_t pos;
490 int i; 490 int i;
491 491
492 pos = url_ftell(pb); 492 pos = url_ftell(pb);
493 ctx->umf_media_offset = pos - ctx->umf_start_offset; 493 ctx->umf_media_offset = pos - ctx->umf_start_offset;
494 for (i = 0; i < ctx->fc->nb_streams; ++i) { 494 for (i = 0; i < ctx->fc->nb_streams; ++i) {
495 GXFStreamContext *sc = &ctx->streams[i]; 495 GXFStreamContext *sc = &ctx->streams[i];
496 char buffer[88]; 496 char buffer[88];
497 offset_t startpos, curpos; 497 int64_t startpos, curpos;
498 int path_size = strlen(ES_NAME_PATTERN); 498 int path_size = strlen(ES_NAME_PATTERN);
499 499
500 memset(buffer, 0, 88); 500 memset(buffer, 0, 88);
501 startpos = url_ftell(pb); 501 startpos = url_ftell(pb);
502 put_le16(pb, 0); /* length */ 502 put_le16(pb, 0); /* length */
536 return url_ftell(pb) - pos; 536 return url_ftell(pb) - pos;
537 } 537 }
538 538
539 static int gxf_write_umf_user_data(ByteIOContext *pb, GXFContext *ctx) 539 static int gxf_write_umf_user_data(ByteIOContext *pb, GXFContext *ctx)
540 { 540 {
541 offset_t pos = url_ftell(pb); 541 int64_t pos = url_ftell(pb);
542 ctx->umf_user_data_offset = pos - ctx->umf_start_offset; 542 ctx->umf_user_data_offset = pos - ctx->umf_start_offset;
543 put_le32(pb, 20); 543 put_le32(pb, 20);
544 put_le32(pb, 0); 544 put_le32(pb, 0);
545 put_le16(pb, 0); 545 put_le16(pb, 0);
546 put_le16(pb, 0); 546 put_le16(pb, 0);
552 return 20; 552 return 20;
553 } 553 }
554 554
555 static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx) 555 static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx)
556 { 556 {
557 offset_t pos = url_ftell(pb); 557 int64_t pos = url_ftell(pb);
558 558
559 gxf_write_packet_header(pb, PKT_UMF); 559 gxf_write_packet_header(pb, PKT_UMF);
560 560
561 /* preamble */ 561 /* preamble */
562 put_byte(pb, 3); /* first and last (only) packet */ 562 put_byte(pb, 3); /* first and last (only) packet */
661 return 0; 661 return 0;
662 } 662 }
663 663
664 static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx) 664 static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx)
665 { 665 {
666 offset_t pos = url_ftell(pb); 666 int64_t pos = url_ftell(pb);
667 667
668 gxf_write_packet_header(pb, PKT_EOS); 668 gxf_write_packet_header(pb, PKT_EOS);
669 return updatePacketSize(pb, pos); 669 return updatePacketSize(pb, pos);
670 } 670 }
671 671
672 static int gxf_write_trailer(AVFormatContext *s) 672 static int gxf_write_trailer(AVFormatContext *s)
673 { 673 {
674 ByteIOContext *pb = s->pb; 674 ByteIOContext *pb = s->pb;
675 GXFContext *gxf = s->priv_data; 675 GXFContext *gxf = s->priv_data;
676 offset_t end; 676 int64_t end;
677 int i; 677 int i;
678 678
679 for (i = 0; i < s->nb_streams; ++i) { 679 for (i = 0; i < s->nb_streams; ++i) {
680 if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) { 680 if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) {
681 av_fifo_free(&gxf->streams[i].audio_buffer); 681 av_fifo_free(&gxf->streams[i].audio_buffer);
743 } 743 }
744 744
745 static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt) 745 static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt)
746 { 746 {
747 GXFStreamContext *sc = &ctx->streams[pkt->stream_index]; 747 GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
748 offset_t pos = url_ftell(pb); 748 int64_t pos = url_ftell(pb);
749 int padding = 0; 749 int padding = 0;
750 750
751 gxf_write_packet_header(pb, PKT_MEDIA); 751 gxf_write_packet_header(pb, PKT_MEDIA);
752 if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ 752 if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */
753 padding = 4 - pkt->size % 4; 753 padding = 4 - pkt->size % 4;