[PATCH 6/6] clip-wrapped support added for single track file

Maksym Veremeyenko verem
Sat Jul 3 13:06:58 CEST 2010


---
 libavformat/mxfdec.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index ce88959..f408b96 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -139,6 +139,9 @@ typedef struct {
     struct AVAES *aesc;
     uint8_t *local_tags;
     int local_tags_count;
+    KLVPacket current_klv_data;
+    int current_klv_index;
+    int current_klv_bsize;
 } MXFContext;
 
 enum MXFWrappingScheme {
@@ -317,8 +320,26 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv
 static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     KLVPacket klv;
+    int index;
+    MXFContext* mxf = s->priv_data;
 
     while (!url_feof(s->pb)) {
+        if (mxf->current_klv_data.length) {
+            /* store */
+            klv = mxf->current_klv_data;
+            index = mxf->current_klv_index;
+
+            /* setup length */
+            klv.length = FFMIN(mxf->current_klv_bsize, mxf->current_klv_data.length);
+
+            /* modify size, length */
+            mxf->current_klv_data.offset += klv.length;
+            mxf->current_klv_data.length -= klv.length;
+
+            /* read packet */
+            goto read_data;
+        };
+
         if (klv_read_packet(&klv, s->pb) < 0)
             return -1;
         PRINT_KEY(s, "read packet", klv.key);
@@ -332,13 +353,49 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
             return 0;
         }
         if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
-            int index = mxf_get_stream_index(s, &klv);
+            index = mxf_get_stream_index(s, &klv);
             if (index < 0) {
                 av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", AV_RB32(klv.key+12));
                 goto skip;
             }
             if (s->streams[index]->discard == AVDISCARD_ALL)
                 goto skip;
+
+            /* check for clip wrapped and single track */
+            if (AVSTREAM_PARSE_FULL == s->streams[index]->need_parsing &&
+                1 == s->nb_streams) {
+
+                int k;
+
+                /* store current klv information */
+                mxf->current_klv_data = klv;
+                mxf->current_klv_index = index;
+                mxf->current_klv_bsize = 0;
+
+                /* find block size */
+                for (k = 0; k < mxf->metadata_sets_count; k++) {
+                    MXFMetadataSet *metadata = mxf->metadata_sets[k];
+                    if (IndexTableSegment == metadata->type) {
+                        mxf->current_klv_bsize = ((MXFIndexTableSegment *)metadata)->edit_unit_byte_count;
+                        break;
+                    }
+                }
+
+                /* check small EditUnitByteCount for audio */
+                if (!mxf->current_klv_bsize)
+                    mxf->current_klv_bsize = 1024;
+                else if (mxf->current_klv_bsize < 32)
+                    mxf->current_klv_bsize *= 1024;
+
+                av_log(s, AV_LOG_DEBUG, "Clip-wrapped reading. mxf->current_klv_bsize=%d\n",
+                       mxf->current_klv_bsize);
+
+                return mxf_read_packet(s, pkt);
+            }
+read_data:
+            PRINT_KEY(s, "read packet data", klv.key);
+            av_log(s, AV_LOG_DEBUG, "data size %lld offset %#llx\n", klv.length, klv.offset);
+
             /* check for 8 channels AES3 element */
             if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {
                 if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) {
-- 
1.6.6.1


--------------020603010806020102000208--



More information about the ffmpeg-devel mailing list