diff mbox series

[FFmpeg-devel,11/22] avcodec/dovi_rpuenc: add configuration for compression

Message ID 20240728102527.17991-11-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,01/22] avutil/dovi_meta: document static vs dynamic ext blocks | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas July 28, 2024, 10:25 a.m. UTC
From: Niklas Haas <git@haasn.dev>

In particular, validate that the chosen compression level is compatible
with the chosen profile.
---
 libavcodec/dovi_rpu.h    |  1 +
 libavcodec/dovi_rpuenc.c | 29 ++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 1bbc6ef02c..24a8353bdc 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -138,6 +138,7 @@  int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame);
  */
 int ff_dovi_configure_ext(DOVIContext *s, AVCodecParameters *codecpar,
                           const AVDOVIMetadata *metadata,
+                          enum AVDOVICompression compression,
                           int strict_std_compliance);
 
 /**
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index ad161809a9..25e520dd92 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -54,6 +54,7 @@  static struct {
 
 int ff_dovi_configure_ext(DOVIContext *s, AVCodecParameters *codecpar,
                           const AVDOVIMetadata *metadata,
+                          enum AVDOVICompression compression,
                           int strict_std_compliance)
 {
     AVDOVIDecoderConfigurationRecord *cfg;
@@ -71,6 +72,10 @@  int ff_dovi_configure_ext(DOVIContext *s, AVCodecParameters *codecpar,
     if (s->enable == FF_DOVI_AUTOMATIC && !hdr)
         goto skip;
 
+    if (compression == AV_DOVI_COMPRESSION_RESERVED ||
+        compression > AV_DOVI_COMPRESSION_EXTENDED)
+        return AVERROR(EINVAL);
+
     switch (codecpar->codec_id) {
     case AV_CODEC_ID_AV1:  dv_profile = 10; break;
     case AV_CODEC_ID_H264: dv_profile = 9;  break;
@@ -138,6 +143,25 @@  int ff_dovi_configure_ext(DOVIContext *s, AVCodecParameters *codecpar,
         goto skip;
     }
 
+    if (compression != AV_DOVI_COMPRESSION_NONE) {
+        if (dv_profile < 8 && strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
+            av_log(s->logctx, AV_LOG_ERROR, "Dolby Vision metadata compression "
+                   "is not permitted for profiles 7 and earlier. (dv_profile: %d, "
+                   "compression: %d)\n", dv_profile, compression);
+            return AVERROR(EINVAL);
+        } else if (compression == AV_DOVI_COMPRESSION_EXTENDED &&
+                   strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+            av_log(s->logctx, AV_LOG_ERROR, "Dolby Vision extended metadata "
+                   "compression is experimental and not supported by "
+                   "devices.");
+            return AVERROR(EINVAL);
+        } else if (dv_profile == 8) {
+            av_log(s->logctx, AV_LOG_WARNING, "Dolby Vision metadata compression "
+                   "for profile 8 is known to be unsupported by many devices, "
+                   "use with caution.\n");
+        }
+    }
+
     pps = codecpar->width * codecpar->height;
     if (codecpar->framerate.num) {
         pps = pps * codecpar->framerate.num / codecpar->framerate.den;
@@ -191,6 +215,7 @@  int ff_dovi_configure_ext(DOVIContext *s, AVCodecParameters *codecpar,
     cfg->el_present_flag = 0;
     cfg->bl_present_flag = 1;
     cfg->dv_bl_signal_compatibility_id = bl_compat_id;
+    cfg->dv_md_compression = compression;
 
     s->cfg = *cfg;
     return 0;
@@ -219,7 +244,9 @@  int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx)
     if (sd)
         metadata = (const AVDOVIMetadata *) sd->data;
 
-    ret = ff_dovi_configure_ext(s, codecpar, metadata, avctx->strict_std_compliance);
+    /* Current encoders cannot handle metadata compression during encoding */
+    ret = ff_dovi_configure_ext(s, codecpar, metadata, AV_DOVI_COMPRESSION_NONE,
+                                avctx->strict_std_compliance);
     if (ret < 0)
         goto fail;