diff mbox series

[FFmpeg-devel,1/6] avcodec/libvpxenc: Only search for side data when intending to use it

Message ID GV1P250MB0737AF727708D511EFFE9DC38F342@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 1093b402183c17c51678bcbed900e19bc5a9b838
Headers show
Series [FFmpeg-devel,1/6] avcodec/libvpxenc: Only search for side data when intending to use it | 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

Andreas Rheinhardt March 27, 2024, 1:36 a.m. UTC
Also rewrite the code so that a variable that is only used
depending upon CONFIG_LIBVPX_VP9_ENCODER is not declared
outside of the #if block.
(The variable was declared with av_uninit, but it should have been
av_unused, as the former does not work for all compilers.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libvpxenc.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

James Zern March 27, 2024, 5:29 p.m. UTC | #1
On Tue, Mar 26, 2024 at 6:36 PM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> Also rewrite the code so that a variable that is only used
> depending upon CONFIG_LIBVPX_VP9_ENCODER is not declared
> outside of the #if block.
> (The variable was declared with av_uninit, but it should have been
> av_unused, as the former does not work for all compilers.)
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/libvpxenc.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>

lgtm.

> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 4b89e47e83..ee903a4e5c 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -357,19 +357,20 @@ static int frame_data_submit(AVCodecContext *avctx, AVFifo *fifo,
>      const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
>
>      FrameData fd = { .pts = frame->pts };
> -
> -    AVFrameSideData *av_uninit(sd);
>      int ret;
>
>  #if CONFIG_LIBVPX_VP9_ENCODER
> -    // Keep HDR10+ if it has bit depth higher than 8 and
> -    // it has PQ trc (SMPTE2084).
> -    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> -    if (avctx->codec_id == AV_CODEC_ID_VP9 && sd &&
> +    if (avctx->codec_id == AV_CODEC_ID_VP9 &&
> +        // Keep HDR10+ if it has bit depth higher than 8 and
> +        // it has PQ trc (SMPTE2084).
>          enccfg->g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) {
> -        fd.hdr10_plus = av_buffer_ref(sd->buf);
> -        if (!fd.hdr10_plus)
> -            return AVERROR(ENOMEM);
> +        const AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> +
> +        if (sd) {
> +            fd.hdr10_plus = av_buffer_ref(sd->buf);
> +            if (!fd.hdr10_plus)
> +                return AVERROR(ENOMEM);
> +        }
>      }
>  #endif
>
> --
> 2.40.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".
diff mbox series

Patch

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 4b89e47e83..ee903a4e5c 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -357,19 +357,20 @@  static int frame_data_submit(AVCodecContext *avctx, AVFifo *fifo,
     const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
 
     FrameData fd = { .pts = frame->pts };
-
-    AVFrameSideData *av_uninit(sd);
     int ret;
 
 #if CONFIG_LIBVPX_VP9_ENCODER
-    // Keep HDR10+ if it has bit depth higher than 8 and
-    // it has PQ trc (SMPTE2084).
-    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
-    if (avctx->codec_id == AV_CODEC_ID_VP9 && sd &&
+    if (avctx->codec_id == AV_CODEC_ID_VP9 &&
+        // Keep HDR10+ if it has bit depth higher than 8 and
+        // it has PQ trc (SMPTE2084).
         enccfg->g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) {
-        fd.hdr10_plus = av_buffer_ref(sd->buf);
-        if (!fd.hdr10_plus)
-            return AVERROR(ENOMEM);
+        const AVFrameSideData *sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
+
+        if (sd) {
+            fd.hdr10_plus = av_buffer_ref(sd->buf);
+            if (!fd.hdr10_plus)
+                return AVERROR(ENOMEM);
+        }
     }
 #endif