[PATCH 7/7] Clip wrapped code

Maksym Veremeyenko verem
Tue Jan 25 12:28:51 CET 2011


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

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 98b65ef..9bc35f9 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -145,6 +145,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;
 
 typedef int MXFMetadataReadFunc(void *arg, ByteIOContext *pb, int tag, int size, UID uid);
@@ -318,8 +321,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);
@@ -333,13 +354,47 @@ 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 */
+            if (((MXFTrack*)s->streams[index]->priv_data)->wrapping == Clip) {
+                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 == 1)
+                    mxf->current_klv_bsize = 1024 * 64;
+                else if (mxf->current_klv_bsize < 32)
+                    mxf->current_klv_bsize *= 1024;
+
+                dprintf(s, "Clip-wrapped reading. mxf->current_klv_bsize=%d, klv.length=%"PRId64"\n",
+                        mxf->current_klv_bsize, klv.length);
+
+                return mxf_read_packet(s, pkt);
+            }
+read_data:
+            PRINT_KEY(s, "read packet data", klv.key);
+            dprintf(s, "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.7.3.5


--------------000507070501090305030800--



More information about the ffmpeg-devel mailing list