History

avcodec/dovi_rpuenc: make encapsulation optional

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).

Niklas Haas committed 2 years ago

Commit b3bc8f81 parent 1e6fdb85 files · +25 −21Browse files

Unified · Split

5 files
  1. libavcodec/dovi_rpu.h +10 −6
  2. libavcodec/dovi_rpuenc.c +10 −12
  3. libavcodec/libaomenc.c +2 −1
  4. libavcodec/libsvtav1.c +2 −1
  5. libavcodec/libx265.c +1 −1
libavcodec/dovi_rpu.h+10−6
@@ -123,16 +123,20 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame); · 122 unmodified lines
123123 */
124124 int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx);
125125
126+enum {
127+ FF_DOVI_WRAP_NAL = 1 << 0, ///< wrap inside NAL RBSP
128+ FF_DOVI_WRAP_T35 = 1 << 1, ///< wrap inside T.35+EMDF
129+};
130+
126131 /**
127− * Synthesize a Dolby Vision RPU reflecting the current state. Note that this
128− * assumes all previous calls to `ff_dovi_rpu_generate` have been appropriately
129− * signalled, i.e. it will not re-send already transmitted redundant data.
132+ * Synthesize a Dolby Vision RPU reflecting the current state. By default, the
133+ * RPU is not encapsulated (see `flags` for more options). Note that this
134+ * assumes all previous calls to `ff_dovi_rpu_generate` have been
135+ * appropriately signalled, i.e. it will not re-send already transmitted
136+ * redundant data.
130137 *
131138 * Mutates the internal state of DOVIContext to reflect the change.
132139 * Returns 0 or a negative error code.
133− *
134− * This generates a fully formed RPU ready for inclusion in the bitstream,
135− * including the EMDF header (profile 10) or NAL encapsulation (otherwise).
136140 */
137141 int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
138142 int flags, uint8_t **out_rpu, int *out_size);
libavcodec/dovi_rpuenc.c+10−12
@@ -713,9 +713,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 712 unmodified lines
713713 flush_put_bits(pb);
714714
715715 rpu_size = put_bytes_output(pb);
716− switch (s->cfg.dv_profile) {
717− case 10:
718− /* AV1 uses T.35 OBU with EMDF header */
716+ if (flags & FF_DOVI_WRAP_T35) {
719717 *out_rpu = av_malloc(rpu_size + 15);
720718 if (!*out_rpu)
721719 return AVERROR(ENOMEM);
@@ -742,10 +740,8 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 20 unmodified lines
742740 flush_put_bits(pb);
743741 *out_size = put_bytes_output(pb);
744742 return 0;
745−
746− case 5:
747− case 8:
748− *out_rpu = dst = av_malloc(1 + rpu_size * 3 / 2); /* worst case */
743+ } else if (flags & FF_DOVI_WRAP_NAL) {
744+ *out_rpu = dst = av_malloc(4 + rpu_size * 3 / 2); /* worst case */
749745 if (!*out_rpu)
750746 return AVERROR(ENOMEM);
751747 *dst++ = 25; /* NAL prefix */
@@ -768,10 +764,12 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 16 unmodified lines
768764 }
769765 *out_size = dst - *out_rpu;
770766 return 0;
771−
772− default:
773− /* Should be unreachable */
774− av_assert0(0);
775− return AVERROR_BUG;
767+ } else {
768+ /* Return intermediate buffer directly */
769+ *out_rpu = s->rpu_buf;
770+ *out_size = rpu_size;
771+ s->rpu_buf = NULL;
772+ s->rpu_buf_sz = 0;
773+ return 0;
776774 }
777775 }
libavcodec/libaomenc.c+2−1
@@ -1294,7 +1294,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1293 unmodified lines
12941294 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
12951295 uint8_t *t35;
12961296 int size;
1297− if ((res = ff_dovi_rpu_generate(&ctx->dovi, metadata, 0, &t35, &size)) < 0)
1297+ if ((res = ff_dovi_rpu_generate(&ctx->dovi, metadata, FF_DOVI_WRAP_T35,
1298+ &t35, &size)) < 0)
12981299 return res;
12991300 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
13001301 t35, size, AOM_MIF_ANY_FRAME);
libavcodec/libsvtav1.c+2−1
@@ -541,7 +541,8 @@ static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 540 unmodified lines
541541 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
542542 uint8_t *t35;
543543 int size;
544− if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, 0, &t35, &size)) < 0)
544+ if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, FF_DOVI_WRAP_T35,
545+ &t35, &size)) < 0)
545546 return ret;
546547 ret = svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, t35, size);
547548 av_free(t35);
libavcodec/libx265.c+1−1
@@ -789,7 +789,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 788 unmodified lines
789789 sd = av_frame_get_side_data(pic, AV_FRAME_DATA_DOVI_METADATA);
790790 if (ctx->dovi.cfg.dv_profile && sd) {
791791 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
792− ret = ff_dovi_rpu_generate(&ctx->dovi, metadata, 0,
792+ ret = ff_dovi_rpu_generate(&ctx->dovi, metadata, FF_DOVI_WRAP_NAL,
793793 &x265pic.rpu.payload,
794794 &x265pic.rpu.payloadSize);
795795 if (ret < 0) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t