Mercurial > libavformat.hg
comparison mxfenc.c @ 4439:4bc3b8687ec2 libavformat
compute index byte count in mxf_write_partition
author | bcoudurier |
---|---|
date | Tue, 10 Feb 2009 08:46:04 +0000 |
parents | f70863323853 |
children | 64f62c9643c3 |
comparison
equal
deleted
inserted
replaced
4438:f70863323853 | 4439:4bc3b8687ec2 |
---|---|
999 assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); | 999 assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); |
1000 } | 1000 } |
1001 } | 1001 } |
1002 | 1002 |
1003 static void mxf_write_partition(AVFormatContext *s, int bodysid, | 1003 static void mxf_write_partition(AVFormatContext *s, int bodysid, |
1004 int indexsid, unsigned index_byte_count, | 1004 int indexsid, |
1005 const uint8_t *key, int write_metadata) | 1005 const uint8_t *key, int write_metadata) |
1006 { | 1006 { |
1007 MXFContext *mxf = s->priv_data; | 1007 MXFContext *mxf = s->priv_data; |
1008 ByteIOContext *pb = s->pb; | 1008 ByteIOContext *pb = s->pb; |
1009 int64_t header_byte_count_offset; | 1009 int64_t header_byte_count_offset; |
1010 unsigned index_byte_count = 0; | |
1011 | |
1012 if (mxf->edit_units_count) { | |
1013 index_byte_count = 109 + (s->nb_streams+1)*6 + | |
1014 mxf->edit_units_count*(11+mxf->slice_count*4); | |
1015 // add encoded ber length | |
1016 index_byte_count += 16 + klv_ber_length(index_byte_count); | |
1017 index_byte_count += klv_fill_size(index_byte_count); | |
1018 } | |
1010 | 1019 |
1011 // write klv | 1020 // write klv |
1012 put_buffer(pb, key, 16); | 1021 put_buffer(pb, key, 16); |
1013 | 1022 |
1014 klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count); | 1023 klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count); |
1027 header_byte_count_offset = url_ftell(pb); | 1036 header_byte_count_offset = url_ftell(pb); |
1028 put_be64(pb, 0); // headerByteCount, update later | 1037 put_be64(pb, 0); // headerByteCount, update later |
1029 | 1038 |
1030 // indexTable | 1039 // indexTable |
1031 put_be64(pb, index_byte_count); // indexByteCount | 1040 put_be64(pb, index_byte_count); // indexByteCount |
1032 put_be32(pb, indexsid); // indexSID | 1041 put_be32(pb, index_byte_count ? indexsid : 0); // indexSID |
1033 put_be64(pb, 0); // bodyOffset | 1042 put_be64(pb, 0); // bodyOffset |
1034 | 1043 |
1035 put_be32(pb, bodysid); // bodySID | 1044 put_be32(pb, bodysid); // bodySID |
1036 | 1045 |
1037 // operational pattern | 1046 // operational pattern |
1318 return -1; | 1327 return -1; |
1319 } | 1328 } |
1320 } | 1329 } |
1321 | 1330 |
1322 if (!mxf->header_written) { | 1331 if (!mxf->header_written) { |
1323 mxf_write_partition(s, 1, 0, 0, header_open_partition_key, 1); | 1332 mxf_write_partition(s, 1, 0, header_open_partition_key, 1); |
1324 mxf->header_written = 1; | 1333 mxf->header_written = 1; |
1325 } | 1334 } |
1326 | 1335 |
1327 if (st->index == 0) { | 1336 if (st->index == 0) { |
1328 mxf_write_klv_fill(s); | 1337 mxf_write_klv_fill(s); |
1367 | 1376 |
1368 static int mxf_write_footer(AVFormatContext *s) | 1377 static int mxf_write_footer(AVFormatContext *s) |
1369 { | 1378 { |
1370 MXFContext *mxf = s->priv_data; | 1379 MXFContext *mxf = s->priv_data; |
1371 ByteIOContext *pb = s->pb; | 1380 ByteIOContext *pb = s->pb; |
1372 unsigned index_byte_count = | |
1373 109 + (s->nb_streams+1)*6 + | |
1374 mxf->edit_units_count*(11+mxf->slice_count*4); | |
1375 | |
1376 // add encoded ber length | |
1377 index_byte_count += 16 + klv_ber_length(index_byte_count); | |
1378 index_byte_count += klv_fill_size(index_byte_count); | |
1379 | 1381 |
1380 mxf_write_klv_fill(s); | 1382 mxf_write_klv_fill(s); |
1381 mxf->footer_partition_offset = url_ftell(pb); | 1383 mxf->footer_partition_offset = url_ftell(pb); |
1382 mxf_write_partition(s, 0, 2, index_byte_count, footer_partition_key, 0); | 1384 mxf_write_partition(s, 0, 2, footer_partition_key, 0); |
1383 | 1385 |
1384 mxf_write_klv_fill(s); | 1386 mxf_write_klv_fill(s); |
1385 mxf_write_index_table_segment(s); | 1387 mxf_write_index_table_segment(s); |
1386 | 1388 |
1387 mxf_write_klv_fill(s); | 1389 mxf_write_klv_fill(s); |
1388 mxf_write_random_index_pack(s); | 1390 mxf_write_random_index_pack(s); |
1389 | 1391 |
1390 if (!url_is_streamed(s->pb)) { | 1392 if (!url_is_streamed(s->pb)) { |
1391 url_fseek(pb, 0, SEEK_SET); | 1393 url_fseek(pb, 0, SEEK_SET); |
1392 mxf_write_partition(s, 1, 0, 0, header_closed_partition_key, 1); | 1394 mxf_write_partition(s, 1, 0, header_closed_partition_key, 1); |
1393 } | 1395 } |
1394 | 1396 |
1395 ff_audio_interleave_close(s); | 1397 ff_audio_interleave_close(s); |
1396 | 1398 |
1397 av_freep(&mxf->index_entries); | 1399 av_freep(&mxf->index_entries); |