diff mbox series

[FFmpeg-devel,v3,04/13] avcodec/dovi_rpu: expose guess_profile(), clarify semantics

Message ID 20240412113620.84013-5-ffmpeg@haasn.xyz
State Accepted
Commit 2a99d3527bb5c9195292ea3b9496ca1bfb5d066b
Headers show
Series avcodec: add Dolby Vision encoding | 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

Niklas Haas April 12, 2024, 11:35 a.m. UTC
From: Niklas Haas <git@haasn.dev>

To allow internally re-using it for both the encoder and decoder.

This is based on HEVC only, H.264/AV1 use their own (hopefully correctly
signalled) profiles (and in particular, the AV1 decoders implicitly
default the correct profile in the absence of a configuration record).
---
 libavcodec/dovi_rpu.c |  4 ++--
 libavcodec/dovi_rpu.h | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 267e52ceb6..77fef8c496 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -121,7 +121,7 @@  int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
     return 0;
 }
 
-static int guess_profile(const AVDOVIRpuDataHeader *hdr)
+int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
 {
     switch (hdr->vdr_rpu_profile) {
     case 0:
@@ -510,7 +510,7 @@  int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
     use_prev_vdr_rpu = get_bits1(gb);
     use_nlq = (hdr->rpu_format & 0x700) == 0 && !hdr->disable_residual_flag;
 
-    profile = s->cfg.dv_profile ? s->cfg.dv_profile : guess_profile(hdr);
+    profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
     if (profile == 5 && use_nlq) {
         av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n");
         goto fail;
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 9a68e45bf1..a866bbfebe 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -87,6 +87,10 @@  void ff_dovi_ctx_flush(DOVIContext *s);
  * DOVIContext struct.
  *
  * Returns 0 or an error code.
+ *
+ * Note: `DOVIContext.cfg` should be initialized before calling into this
+ * function. If not done, the profile will be guessed according to HEVC
+ * semantics.
  */
 int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
                       int err_recognition);
@@ -96,4 +100,11 @@  int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
  */
 int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame);
 
+/**
+ * Internal helper function to guess the correct DV profile for HEVC.
+ *
+ * Returns the profile number or 0 if unknown.
+ */
+int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr);
+
 #endif /* AVCODEC_DOVI_RPU_H */