changeset 6207:ab29c8ff40d9 libavformat

Change all functions referenced in the mxf_metadata_read_table to use the same prototype and also always call them with exactly those arguments. The previous way seems to have worked on all supported platforms, however it was not strictly valid C and would crash e.g. with a compiler that uses stdcall by default. Also avoids warnings if -Wstrict-prototypes is used.
author reimar
date Thu, 01 Jul 2010 17:10:31 +0000
parents 8515b7b4fe87
children 209c43ef17af
files mxfdec.c
diffstat 1 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mxfdec.c	Thu Jul 01 15:03:21 2010 +0000
+++ b/mxfdec.c	Thu Jul 01 17:10:31 2010 +0000
@@ -140,9 +140,11 @@
     Clip,
 };
 
+typedef int MXFMetadataReadFunc(void *arg, ByteIOContext *pb, int tag, int size, UID uid);
+
 typedef struct {
     const UID key;
-    int (*read)();
+    MXFMetadataReadFunc *read;
     int ctx_size;
     enum MXFMetadataSetType type;
 } MXFMetadataReadTableEntry;
@@ -342,9 +344,9 @@
     return AVERROR_EOF;
 }
 
-static int mxf_read_primer_pack(MXFContext *mxf)
+static int mxf_read_primer_pack(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
-    ByteIOContext *pb = mxf->fc->pb;
+    MXFContext *mxf = arg;
     int item_num = get_be32(pb);
     int item_len = get_be32(pb);
 
@@ -374,8 +376,9 @@
     return 0;
 }
 
-static int mxf_read_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag, int size, UID uid)
+static int mxf_read_cryptographic_context(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFCryptoContext *cryptocontext = arg;
     if (size != 16)
         return -1;
     if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul))
@@ -383,8 +386,9 @@
     return 0;
 }
 
-static int mxf_read_content_storage(MXFContext *mxf, ByteIOContext *pb, int tag)
+static int mxf_read_content_storage(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFContext *mxf = arg;
     switch (tag) {
     case 0x1901:
         mxf->packages_count = get_be32(pb);
@@ -400,8 +404,9 @@
     return 0;
 }
 
-static int mxf_read_source_clip(MXFStructuralComponent *source_clip, ByteIOContext *pb, int tag)
+static int mxf_read_source_clip(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFStructuralComponent *source_clip = arg;
     switch(tag) {
     case 0x0202:
         source_clip->duration = get_be64(pb);
@@ -421,8 +426,9 @@
     return 0;
 }
 
-static int mxf_read_material_package(MXFPackage *package, ByteIOContext *pb, int tag)
+static int mxf_read_material_package(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFPackage *package = arg;
     switch(tag) {
     case 0x4403:
         package->tracks_count = get_be32(pb);
@@ -438,8 +444,9 @@
     return 0;
 }
 
-static int mxf_read_track(MXFTrack *track, ByteIOContext *pb, int tag)
+static int mxf_read_track(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFTrack *track = arg;
     switch(tag) {
     case 0x4801:
         track->track_id = get_be32(pb);
@@ -458,8 +465,9 @@
     return 0;
 }
 
-static int mxf_read_sequence(MXFSequence *sequence, ByteIOContext *pb, int tag)
+static int mxf_read_sequence(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFSequence *sequence = arg;
     switch(tag) {
     case 0x0202:
         sequence->duration = get_be64(pb);
@@ -481,8 +489,9 @@
     return 0;
 }
 
-static int mxf_read_source_package(MXFPackage *package, ByteIOContext *pb, int tag)
+static int mxf_read_source_package(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFPackage *package = arg;
     switch(tag) {
     case 0x4403:
         package->tracks_count = get_be32(pb);
@@ -506,7 +515,7 @@
     return 0;
 }
 
-static int mxf_read_index_table_segment(MXFIndexTableSegment *segment, ByteIOContext *pb, int tag)
+static int mxf_read_index_table_segment(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
     switch(tag) {
     case 0x3F05: dprintf(NULL, "EditUnitByteCount %d\n", get_be32(pb)); break;
@@ -538,8 +547,9 @@
     ff_mxf_decode_pixel_layout(layout, &descriptor->pix_fmt);
 }
 
-static int mxf_read_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size, UID uid)
+static int mxf_read_generic_descriptor(void *arg, ByteIOContext *pb, int tag, int size, UID uid)
 {
+    MXFDescriptor *descriptor = arg;
     switch(tag) {
     case 0x3F01:
         descriptor->sub_descriptors_count = get_be32(pb);
@@ -852,7 +862,7 @@
     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, 0, AnyType },
 };
 
-static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, int (*read_child)(), int ctx_size, enum MXFMetadataSetType type)
+static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadFunc *read_child, int ctx_size, enum MXFMetadataSetType type)
 {
     ByteIOContext *pb = mxf->fc->pb;
     MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf;
@@ -920,8 +930,12 @@
 
         for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {
             if (IS_KLV_KEY(klv.key, metadata->key)) {
-                int (*read)() = klv.key[5] == 0x53 ? mxf_read_local_tags : metadata->read;
-                if (read(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) {
+                int res;
+                if (klv.key[5] == 0x53) {
+                    res = mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type);
+                } else
+                    res = metadata->read(mxf, s->pb, 0, 0, NULL);
+                if (res < 0) {
                     av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
                     return -1;
                 }