# HG changeset patch # User bcoudurier # Date 1234244128 0 # Node ID f8ba6cf226e7fb6d0e2c99119ae9db30f9a2407b # Parent 723d05287ae9daf89923a61b0615f5cdc92c9492 move up mxf_write_klv_fill and align index, rip and primer pack diff -r 723d05287ae9 -r f8ba6cf226e7 mxfenc.c --- a/mxfenc.c Tue Feb 10 05:22:38 2009 +0000 +++ b/mxfenc.c Tue Feb 10 05:35:28 2009 +0000 @@ -973,6 +973,22 @@ } } +static void mxf_write_klv_fill(AVFormatContext *s) +{ + unsigned pad = klv_fill_size(url_ftell(s->pb)); + if (pad) { + put_buffer(s->pb, klv_fill_key, 16); + pad -= 16; + pad -= klv_ber_length(pad); + klv_encode_ber_length(s->pb, pad); + for (; pad > 7; pad -= 8) + put_be64(s->pb, 0); + for (; pad; pad--) + put_byte(s->pb, 0); + assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); + } +} + static void mxf_write_partition(AVFormatContext *s, int bodysid, int indexsid, unsigned index_byte_count, const uint8_t *key, int write_metadata) @@ -1023,6 +1039,8 @@ int64_t pos, start = url_ftell(s->pb); unsigned header_byte_count; + mxf_write_klv_fill(s); + mxf_write_primer_pack(s); mxf_write_header_metadata_sets(s); pos = url_ftell(s->pb); @@ -1207,22 +1225,6 @@ return 0; } -static void mxf_write_klv_fill(AVFormatContext *s) -{ - unsigned pad = klv_fill_size(url_ftell(s->pb)); - if (pad) { - put_buffer(s->pb, klv_fill_key, 16); - pad -= 16; - pad -= klv_ber_length(pad); - klv_encode_ber_length(s->pb, pad); - for (; pad > 7; pad -= 8) - put_be64(s->pb, 0); - for (; pad; pad--) - put_byte(s->pb, 0); - assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); - } -} - static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 }; static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 }; @@ -1368,14 +1370,19 @@ // add encoded ber length index_byte_count += 16 + klv_ber_length(index_byte_count); + index_byte_count += klv_fill_size(index_byte_count); mxf_write_klv_fill(s); mxf->footer_partition_offset = url_ftell(pb); mxf_write_partition(s, 0, 2, index_byte_count, footer_partition_key, 0); + mxf_write_klv_fill(s); + mxf_write_index_table_segment(s); + mxf_write_klv_fill(s); + mxf_write_random_index_pack(s); if (!url_is_streamed(s->pb)) {