[Ffmpeg-cvslog] r5871 - trunk/libavformat/mxf.c

bcoudurier subversion
Mon Jul 31 17:26:33 CEST 2006


Author: bcoudurier
Date: Mon Jul 31 17:26:33 2006
New Revision: 5871

Modified:
   trunk/libavformat/mxf.c

Log:
simplify using function table

Modified: trunk/libavformat/mxf.c
==============================================================================
--- trunk/libavformat/mxf.c	(original)
+++ trunk/libavformat/mxf.c	Mon Jul 31 17:26:33 2006
@@ -143,21 +143,10 @@
     enum CodecID id;
 } MXFCodecUL;
 
-static const UID mxf_metadata_preface_key                  = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 };
-static const UID mxf_metadata_content_storage_key          = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 };
-static const UID mxf_metadata_source_package_key           = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 };
-static const UID mxf_metadata_material_package_key         = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 };
-static const UID mxf_metadata_sequence_key                 = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 };
-static const UID mxf_metadata_source_clip_key              = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 };
-static const UID mxf_metadata_multiple_descriptor_key      = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 };
-static const UID mxf_metadata_generic_sound_descriptor_key = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 };
-static const UID mxf_metadata_cdci_descriptor_key          = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 };
-static const UID mxf_metadata_rgba_descriptor_key          = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 };
-static const UID mxf_metadata_mpegvideo_descriptor_key     = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 };
-static const UID mxf_metadata_wave_descriptor_key          = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 };
-static const UID mxf_metadata_aes3_descriptor_key          = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 };
-static const UID mxf_metadata_static_track_key             = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 };
-static const UID mxf_metadata_track_key                    = { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3b,0x00 };
+typedef struct MXFMetadataReadTableEntry {
+    const UID key;
+    int (*read)(MXFContext *mxf, KLVPacket *klv);
+} MXFMetadataReadTableEntry;
 
 /* partial keys to match */
 static const uint8_t mxf_header_partition_pack_key[]       = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 };
@@ -838,14 +827,34 @@
     return 0;
 }
 
+static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x2F,0x00 }, mxf_read_metadata_preface },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_multiple_descriptor },
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor }, /* Generic Sound */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor }, /* CDCI */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor }, /* RGBA */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor }, /* MPEG 2 Video */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor }, /* Wave */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor }, /* AES3 */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track }, /* Static Track */
+    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track }, /* Generic Track */
+    { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL },
+};
+
 static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
     MXFContext *mxf = s->priv_data;
     KLVPacket klv;
-    int ret = 0;
 
     mxf->fc = s;
     while (!url_feof(&s->pb)) {
+        const MXFMetadataReadTableEntry *function;
+
         if (klv_read_packet(&klv, &s->pb) < 0) {
             av_log(s, AV_LOG_ERROR, "error reading KLV packet\n");
             return -1;
@@ -853,46 +862,23 @@
 #ifdef DEBUG
         PRINT_KEY(klv.key);
 #endif
-        if (IS_KLV_KEY(klv.key, mxf_metadata_track_key))
-            ret = mxf_read_metadata_track(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_static_track_key))
-            ret = mxf_read_metadata_track(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_source_package_key))
-            ret = mxf_read_metadata_source_package(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_sequence_key))
-            ret = mxf_read_metadata_sequence(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_material_package_key))
-            ret = mxf_read_metadata_material_package(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_source_clip_key))
-            ret = mxf_read_metadata_source_clip(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_multiple_descriptor_key))
-            ret = mxf_read_metadata_multiple_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_wave_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_mpegvideo_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_cdci_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_rgba_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_generic_sound_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_aes3_descriptor_key))
-            ret = mxf_read_metadata_generic_descriptor(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_preface_key))
-            ret = mxf_read_metadata_preface(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_metadata_content_storage_key))
-            ret = mxf_read_metadata_content_storage(mxf, &klv);
-        else if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
+        if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {
             /* FIXME avoid seek */
             url_fseek(&s->pb, klv.offset, SEEK_SET);
             break;
-        } else
-            url_fskip(&s->pb, klv.length);
-        if (ret < 0) {
-            av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
-            return ret;
         }
+
+        for (function = mxf_metadata_read_table; function->read; function++) {
+            if (IS_KLV_KEY(klv.key, function->key)) {
+                if (function->read(mxf, &klv) < 0) {
+                    av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
+                    return -1;
+                }
+                break;
+            }
+        }
+        if (!function->read)
+            url_fskip(&s->pb, klv.length);
     }
     return mxf_parse_structural_metadata(mxf);
 }




More information about the ffmpeg-cvslog mailing list