changeset 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
files mxfenc.c
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mxfenc.c	Tue Feb 10 08:35:14 2009 +0000
+++ b/mxfenc.c	Tue Feb 10 08:46:04 2009 +0000
@@ -1001,12 +1001,21 @@
 }
 
 static void mxf_write_partition(AVFormatContext *s, int bodysid,
-                                int indexsid, unsigned index_byte_count,
+                                int indexsid,
                                 const uint8_t *key, int write_metadata)
 {
     MXFContext *mxf = s->priv_data;
     ByteIOContext *pb = s->pb;
     int64_t header_byte_count_offset;
+    unsigned index_byte_count = 0;
+
+    if (mxf->edit_units_count) {
+        index_byte_count = 109 + (s->nb_streams+1)*6 +
+            mxf->edit_units_count*(11+mxf->slice_count*4);
+        // add encoded ber length
+        index_byte_count += 16 + klv_ber_length(index_byte_count);
+        index_byte_count += klv_fill_size(index_byte_count);
+    }
 
     // write klv
     put_buffer(pb, key, 16);
@@ -1029,7 +1038,7 @@
 
     // indexTable
     put_be64(pb, index_byte_count); // indexByteCount
-    put_be32(pb, indexsid); // indexSID
+    put_be32(pb, index_byte_count ? indexsid : 0); // indexSID
     put_be64(pb, 0); // bodyOffset
 
     put_be32(pb, bodysid); // bodySID
@@ -1320,7 +1329,7 @@
     }
 
     if (!mxf->header_written) {
-        mxf_write_partition(s, 1, 0, 0, header_open_partition_key, 1);
+        mxf_write_partition(s, 1, 0, header_open_partition_key, 1);
         mxf->header_written = 1;
     }
 
@@ -1369,17 +1378,10 @@
 {
     MXFContext *mxf = s->priv_data;
     ByteIOContext *pb = s->pb;
-    unsigned index_byte_count =
-        109 + (s->nb_streams+1)*6 +
-        mxf->edit_units_count*(11+mxf->slice_count*4);
-
-    // 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_partition(s, 0, 2, footer_partition_key, 0);
 
     mxf_write_klv_fill(s);
     mxf_write_index_table_segment(s);
@@ -1389,7 +1391,7 @@
 
     if (!url_is_streamed(s->pb)) {
         url_fseek(pb, 0, SEEK_SET);
-        mxf_write_partition(s, 1, 0, 0, header_closed_partition_key, 1);
+        mxf_write_partition(s, 1, 0, header_closed_partition_key, 1);
     }
 
     ff_audio_interleave_close(s);