[FFmpeg-cvslog] cbs_av1: Don't reject unknown metadata

Mark Thompson git at videolan.org
Wed May 17 23:48:42 EEST 2023


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Tue Jan 24 22:46:21 2023 +0000| [dce6cf2c368edae76cd78f3cbfedb8187c3cb4b7] | committer: Mark Thompson

cbs_av1: Don't reject unknown metadata

Accept it and pass it through unchanged.

The standard requires that decoders ignore unknown metadata, and indeed
this is tested by some of the Argon coverage streams.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dce6cf2c368edae76cd78f3cbfedb8187c3cb4b7
---

 libavcodec/cbs_av1.c                 |  7 +++++++
 libavcodec/cbs_av1.h                 |  7 +++++++
 libavcodec/cbs_av1_syntax_template.c | 26 ++++++++++++++++++++++++--
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 45e1288a51..8788fee099 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -1306,9 +1306,16 @@ static void cbs_av1_free_metadata(void *unit, uint8_t *content)
     md = &obu->obu.metadata;
 
     switch (md->metadata_type) {
+    case AV1_METADATA_TYPE_HDR_CLL:
+    case AV1_METADATA_TYPE_HDR_MDCV:
+    case AV1_METADATA_TYPE_SCALABILITY:
+    case AV1_METADATA_TYPE_TIMECODE:
+        break;
     case AV1_METADATA_TYPE_ITUT_T35:
         av_buffer_unref(&md->metadata.itut_t35.payload_ref);
         break;
+    default:
+        av_buffer_unref(&md->metadata.unknown.payload_ref);
     }
     av_free(content);
 }
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 1fc80dcfa0..36848d4410 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -370,6 +370,12 @@ typedef struct AV1RawMetadataTimecode {
     uint32_t time_offset_value;
 } AV1RawMetadataTimecode;
 
+typedef struct AV1RawMetadataUnknown {
+    uint8_t     *payload;
+    AVBufferRef *payload_ref;
+    size_t       payload_size;
+} AV1RawMetadataUnknown;
+
 typedef struct AV1RawMetadata {
     uint64_t metadata_type;
     union {
@@ -378,6 +384,7 @@ typedef struct AV1RawMetadata {
         AV1RawMetadataScalability scalability;
         AV1RawMetadataITUTT35     itut_t35;
         AV1RawMetadataTimecode    timecode;
+        AV1RawMetadataUnknown     unknown;
     } metadata;
 } AV1RawMetadata;
 
diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
index 67a0dddd70..8f4640d1af 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -2004,6 +2004,29 @@ static int FUNC(metadata_timecode)(CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(metadata_unknown)(CodedBitstreamContext *ctx, RWContext *rw,
+                                  AV1RawMetadataUnknown *current)
+{
+    int err;
+    size_t i;
+
+    HEADER("Unknown Metadata");
+
+#ifdef READ
+    current->payload_size = cbs_av1_get_payload_bytes_left(rw);
+
+    current->payload_ref = av_buffer_alloc(current->payload_size);
+    if (!current->payload_ref)
+        return AVERROR(ENOMEM);
+    current->payload = current->payload_ref->data;
+#endif
+
+    for (i = 0; i < current->payload_size; i++)
+        fbs(8, payload[i], 1, i);
+
+    return 0;
+}
+
 static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
                               AV1RawMetadata *current)
 {
@@ -2028,8 +2051,7 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
         CHECK(FUNC(metadata_timecode)(ctx, rw, &current->metadata.timecode));
         break;
     default:
-        // Unknown metadata type.
-        return AVERROR_PATCHWELCOME;
+        CHECK(FUNC(metadata_unknown)(ctx, rw, &current->metadata.unknown));
     }
 
     return 0;



More information about the ffmpeg-cvslog mailing list