diff mbox series

[FFmpeg-devel,22/30] lavc/adxenc: support AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE

Message ID 20221127170351.11477-22-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/30] lavc/libx264: factor out setting up the input frame | 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

Anton Khirnov Nov. 27, 2022, 5:03 p.m. UTC
---
 libavcodec/adxenc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt Jan. 4, 2023, 4:26 p.m. UTC | #1
Anton Khirnov:
> ---
>  libavcodec/adxenc.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
> index e1bf344b01..9e0ceb61eb 100644
> --- a/libavcodec/adxenc.c
> +++ b/libavcodec/adxenc.c
> @@ -185,6 +185,18 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>  
>      avpkt->pts = frame->pts;
>      avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
> +
> +    if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
> +        avpkt->opaque = frame->opaque;
> +        if (frame->opaque_ref) {
> +            avpkt->opaque_ref = av_buffer_ref(frame->opaque_ref);
> +            if (!avpkt->opaque_ref)
> +                return AVERROR(ENOMEM);
> +        }
> +    }
> +
> +    avctx->reordered_opaque = frame->reordered_opaque;

I don't like that you are adding this piece of code both here, in
encode.c, in ffv1enc.c, in pngenc.c and libtheoraenc.c. Why don't you
factor this out?

> +
>      *got_packet_ptr = 1;
>      return 0;
>  }
> @@ -194,7 +206,8 @@ const FFCodec ff_adpcm_adx_encoder = {
>      CODEC_LONG_NAME("SEGA CRI ADX ADPCM"),
>      .p.type         = AVMEDIA_TYPE_AUDIO,
>      .p.id           = AV_CODEC_ID_ADPCM_ADX,
> -    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
> +    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
> +                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
>      .priv_data_size = sizeof(ADXContext),
>      .init           = adx_encode_init,
>      FF_CODEC_ENCODE_CB(adx_encode_frame),
diff mbox series

Patch

diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index e1bf344b01..9e0ceb61eb 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -185,6 +185,18 @@  static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     avpkt->pts = frame->pts;
     avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
+
+    if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
+        avpkt->opaque = frame->opaque;
+        if (frame->opaque_ref) {
+            avpkt->opaque_ref = av_buffer_ref(frame->opaque_ref);
+            if (!avpkt->opaque_ref)
+                return AVERROR(ENOMEM);
+        }
+    }
+
+    avctx->reordered_opaque = frame->reordered_opaque;
+
     *got_packet_ptr = 1;
     return 0;
 }
@@ -194,7 +206,8 @@  const FFCodec ff_adpcm_adx_encoder = {
     CODEC_LONG_NAME("SEGA CRI ADX ADPCM"),
     .p.type         = AVMEDIA_TYPE_AUDIO,
     .p.id           = AV_CODEC_ID_ADPCM_ADX,
-    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
+    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_data_size = sizeof(ADXContext),
     .init           = adx_encode_init,
     FF_CODEC_ENCODE_CB(adx_encode_frame),