Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/dovi_rpuenc: make encapsulation optional
Date: Mon, 24 Jun 2024 19:20:41 +0200
Message-ID: <20240624172044.101722-6-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240624172044.101722-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

And move the choice of desired container to `flags`. This is needed to
handle differing API requirements (e.g. libx265 requires the NAL RBSP,
but CBS BSF requires the unescaped bytes).
---
 libavcodec/dovi_rpu.h    | 16 ++++++++++------
 libavcodec/dovi_rpuenc.c | 22 ++++++++++------------
 libavcodec/libaomenc.c   |  3 ++-
 libavcodec/libsvtav1.c   |  3 ++-
 libavcodec/libx265.c     |  2 +-
 5 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 65a4529106..226a769bff 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -123,16 +123,20 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame);
  */
 int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx);
 
+enum {
+    FF_DOVI_WRAP_NAL        = 1 << 0, ///< wrap inside NAL RBSP
+    FF_DOVI_WRAP_T35        = 1 << 1, ///< wrap inside T.35+EMDF
+};
+
 /**
- * Synthesize a Dolby Vision RPU reflecting the current state. Note that this
- * assumes all previous calls to `ff_dovi_rpu_generate` have been appropriately
- * signalled, i.e. it will not re-send already transmitted redundant data.
+ * Synthesize a Dolby Vision RPU reflecting the current state. By default, the
+ * RPU is not encapsulated (see `flags` for more options). Note that this
+ * assumes all previous calls to `ff_dovi_rpu_generate` have been
+ * appropriately signalled, i.e. it will not re-send already transmitted
+ * redundant data.
  *
  * Mutates the internal state of DOVIContext to reflect the change.
  * Returns 0 or a negative error code.
- *
- * This generates a fully formed RPU ready for inclusion in the bitstream,
- * including the EMDF header (profile 10) or NAL encapsulation (otherwise).
  */
 int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
                          int flags, uint8_t **out_rpu, int *out_size);
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index 6bfb39a7ea..41080521e1 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -710,9 +710,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
     flush_put_bits(pb);
 
     rpu_size = put_bytes_output(pb);
-    switch (s->cfg.dv_profile) {
-    case 10:
-        /* AV1 uses T.35 OBU with EMDF header */
+    if (flags & FF_DOVI_WRAP_T35) {
         *out_rpu = av_malloc(rpu_size + 15);
         if (!*out_rpu)
             return AVERROR(ENOMEM);
@@ -739,10 +737,8 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
         flush_put_bits(pb);
         *out_size = put_bytes_output(pb);
         return 0;
-
-    case 5:
-    case 8:
-        *out_rpu = dst = av_malloc(1 + rpu_size * 3 / 2); /* worst case */
+    } else if (flags & FF_DOVI_WRAP_NAL) {
+        *out_rpu = dst = av_malloc(4 + rpu_size * 3 / 2); /* worst case */
         if (!*out_rpu)
             return AVERROR(ENOMEM);
         *dst++ = 25; /* NAL prefix */
@@ -765,10 +761,12 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
         }
         *out_size = dst - *out_rpu;
         return 0;
-
-    default:
-        /* Should be unreachable */
-        av_assert0(0);
-        return AVERROR_BUG;
+    } else {
+        /* Return intermediate buffer directly */
+        *out_rpu = s->rpu_buf;
+        *out_size = rpu_size;
+        s->rpu_buf = NULL;
+        s->rpu_buf_sz = 0;
+        return 0;
     }
 }
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index aa51c89e29..fd9bea2505 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1294,7 +1294,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
             const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
             uint8_t *t35;
             int size;
-            if ((res = ff_dovi_rpu_generate(&ctx->dovi, metadata, 0, &t35, &size)) < 0)
+            if ((res = ff_dovi_rpu_generate(&ctx->dovi, metadata, FF_DOVI_WRAP_T35,
+                                            &t35, &size)) < 0)
                 return res;
             res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
                                        t35, size, AOM_MIF_ANY_FRAME);
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index b6db63fd7a..e7b12fb488 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -541,7 +541,8 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
         const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
         uint8_t *t35;
         int size;
-        if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, 0, &t35, &size)) < 0)
+        if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, FF_DOVI_WRAP_T35,
+                                        &t35, &size)) < 0)
             return ret;
         ret = svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, t35, size);
         av_free(t35);
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 4302c3d587..718bd21b20 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -783,7 +783,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         sd = av_frame_get_side_data(pic, AV_FRAME_DATA_DOVI_METADATA);
         if (ctx->dovi.cfg.dv_profile && sd) {
             const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
-            ret = ff_dovi_rpu_generate(&ctx->dovi, metadata, 0,
+            ret = ff_dovi_rpu_generate(&ctx->dovi, metadata, FF_DOVI_WRAP_NAL,
                                        &x265pic.rpu.payload,
                                        &x265pic.rpu.payloadSize);
             if (ret < 0) {
-- 
2.45.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-06-24 17:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 17:20 [FFmpeg-devel] [PATCH 1/9] avcodec/dovi_rpudec: clarify semantics Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 2/9] avcodec/dovi_rpuenc: also copy ext blocks to dovi ctx Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 3/9] avcodec/dovi_rpuenc: try to re-use existing vdr_rpu_id Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 4/9] avcodec/dovi_rpuenc: allow changing vdr_rpu_id Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 5/9] avcodec/dovi_rpuenc: add `flags` to ff_dovi_rpu_generate() Niklas Haas
2024-06-24 17:20 ` Niklas Haas [this message]
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 7/9] avcodec/dovi_rpuenc: disable metadata compression by default Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 8/9] avcodec/dovi_rpu: add ff_dovi_get_metadata() Niklas Haas
2024-06-24 17:20 ` [FFmpeg-devel] [PATCH 9/9] avcodec/bsf/dovi_rpu: add new bitstream filter Niklas Haas
2024-07-12 11:40 ` [FFmpeg-devel] [PATCH 1/9] avcodec/dovi_rpudec: clarify semantics Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240624172044.101722-6-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git