diff mbox series

[FFmpeg-devel,26/38] avcodec/mpeg12dec: respect side data preference

Message ID 20240223143115.16521-27-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/38] lavu/opt: cosmetics, change option flags to (1 << N) style | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Feb. 23, 2024, 1:58 p.m. UTC
From: Niklas Haas <git@haasn.dev>

We only need to consider side data types that may possibly come from the
packet.
---
 libavcodec/mpeg12dec.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index d07eed8744..96987f5a8e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1306,16 +1306,17 @@  static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
             }
         }
 
-        pan_scan = av_frame_new_side_data(s->current_picture_ptr->f,
-                                          AV_FRAME_DATA_PANSCAN,
-                                          sizeof(s1->pan_scan));
-        if (!pan_scan)
-            return AVERROR(ENOMEM);
-        memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
+        ret = ff_frame_new_side_data(s->avctx, s->current_picture_ptr->f,
+                                     AV_FRAME_DATA_PANSCAN, sizeof(s1->pan_scan),
+                                     &pan_scan);
+        if (ret < 0)
+            return ret;
+        if (pan_scan)
+            memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
 
         if (s1->a53_buf_ref) {
-            AVFrameSideData *sd = av_frame_new_side_data_from_buf(
-                s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
+            AVFrameSideData *sd = ff_frame_new_side_data_from_buf(
+                s->avctx, s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
                 s1->a53_buf_ref);
             if (!sd)
                 av_buffer_unref(&s1->a53_buf_ref);
@@ -1332,13 +1333,13 @@  static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
         }
 
         if (s1->has_afd) {
-            AVFrameSideData *sd =
-                av_frame_new_side_data(s->current_picture_ptr->f,
-                                       AV_FRAME_DATA_AFD, 1);
-            if (!sd)
-                return AVERROR(ENOMEM);
-
-            *sd->data   = s1->afd;
+            AVFrameSideData *sd;
+            ret = ff_frame_new_side_data(s->avctx, s->current_picture_ptr->f,
+                                         AV_FRAME_DATA_AFD, 1, &sd);
+            if (ret < 0)
+                return ret;
+            if (sd)
+                *sd->data = s1->afd;
             s1->has_afd = 0;
         }