diff mbox series

[FFmpeg-devel,1/2] lavf/mxfdec: Switch to mxf_metadata_read_table loop to FF_ARRAY_ELEMS, skip if read == NULL

Message ID 3ef5c36436349cd5957d0f200b6c64d5750673a1.camel@haerdin.se
State New
Headers show
Series [FFmpeg-devel,1/2] lavf/mxfdec: Switch to mxf_metadata_read_table loop to FF_ARRAY_ELEMS, skip if read == NULL | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Tomas Härdin Sept. 13, 2024, 12:16 p.m. UTC
Passes fate-mxf

/Tomas

Comments

Tomas Härdin Sept. 16, 2024, 8 a.m. UTC | #1
Will push in a day or two

/Tomas
Tomas Härdin Sept. 18, 2024, 7:48 p.m. UTC | #2
mån 2024-09-16 klockan 10:00 +0200 skrev Tomas Härdin:
> Will push in a day or two

Pushed

/Tomas
diff mbox series

Patch

From c96a96dc1f245210997a7d21b158ce504bdf4c73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 13 Sep 2024 14:09:56 +0200
Subject: [PATCH 1/2] lavf/mxfdec: Switch to mxf_metadata_read_table loop to
 FF_ARRAY_ELEMS, skip if read == NULL

---
 libavformat/mxfdec.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index ac63c0d5ad..65ffa0d6b8 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -328,7 +328,7 @@  typedef int MXFMetadataReadFunc(void *arg, AVIOContext *pb, int tag, int size, U
 
 typedef struct MXFMetadataReadTableEntry {
     const UID key;
-    MXFMetadataReadFunc *read;
+    MXFMetadataReadFunc *read; /* if NULL then skip KLV */
     int ctx_size;
     enum MXFMetadataSetType type;
 } MXFMetadataReadTableEntry;
@@ -3235,7 +3235,6 @@  static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 }, mxf_read_cryptographic_context, sizeof(MXFCryptoContext), CryptoContext },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x10,0x01,0x00 }, mxf_read_index_table_segment, sizeof(MXFIndexTableSegment), IndexTableSegment },
     { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x23,0x00 }, mxf_read_essence_container_data, sizeof(MXFEssenceContainerData), EssenceContainerData },
-    { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL },
 };
 
 static int mxf_metadataset_init(MXFMetadataSet *ctx, enum MXFMetadataSetType type, MXFPartition *partition)
@@ -3716,7 +3715,7 @@  static int mxf_read_header(AVFormatContext *s)
     mxf_read_random_index_pack(s);
 
     while (!avio_feof(s->pb)) {
-        const MXFMetadataReadTableEntry *metadata;
+        size_t x;
 
         ret = klv_read_packet(mxf, &klv, s->pb);
         if (ret < 0 || IS_KLV_KEY(klv.key, ff_mxf_random_index_pack_key)) {
@@ -3762,14 +3761,19 @@  static int mxf_read_header(AVFormatContext *s)
             /* we're still parsing forward. proceed to parsing this partition pack */
         }
 
-        for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {
+        for (x = 0; x < FF_ARRAY_ELEMS(mxf_metadata_read_table); x++) {
+            const MXFMetadataReadTableEntry *metadata = &mxf_metadata_read_table[x];
             if (IS_KLV_KEY(klv.key, metadata->key)) {
-                if ((ret = mxf_parse_klv(mxf, klv, metadata->read, metadata->ctx_size, metadata->type)) < 0)
-                    return ret;
+                if (metadata->read) {
+                    if ((ret = mxf_parse_klv(mxf, klv, metadata->read, metadata->ctx_size, metadata->type)) < 0)
+                        return ret;
+                } else {
+                    avio_skip(s->pb, klv.length);
+                }
                 break;
             }
         }
-        if (!metadata->read) {
+        if (x >= FF_ARRAY_ELEMS(mxf_metadata_read_table)) {
             av_log(s, AV_LOG_VERBOSE, "Dark key " PRIxUID "\n",
                             UID_ARG(klv.key));
             avio_skip(s->pb, klv.length);
-- 
2.39.2