[FFmpeg-devel] [PATCH 35/38] avcodec/mjpegdec: use ff_frame_new_side_data

Anton Khirnov anton at khirnov.net
Fri Feb 23 15:58:57 EET 2024


From: Niklas Haas <git at haasn.dev>

For consistency, even though this can't (yet) be overriden at the packet
level.
---
 libavcodec/mjpegdec.c | 66 ++++++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 43b36d0a8f..4ef565fe2d 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2865,42 +2865,44 @@ the_end:
             if (orientation >= 2 && orientation <= 8) {
                 int32_t *matrix;
 
-                sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
-                if (!sd) {
+                ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9, &sd);
+                if (ret < 0) {
                     av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
-                    return AVERROR(ENOMEM);
+                    return ret;
                 }
 
-                matrix = (int32_t *)sd->data;
+                if (sd) {
+                    matrix = (int32_t *)sd->data;
 
-                switch (orientation) {
-                case 2:
-                    av_display_rotation_set(matrix, 0.0);
-                    av_display_matrix_flip(matrix, 1, 0);
-                    break;
-                case 3:
-                    av_display_rotation_set(matrix, 180.0);
-                    break;
-                case 4:
-                    av_display_rotation_set(matrix, 180.0);
-                    av_display_matrix_flip(matrix, 1, 0);
-                    break;
-                case 5:
-                    av_display_rotation_set(matrix, 90.0);
-                    av_display_matrix_flip(matrix, 1, 0);
-                    break;
-                case 6:
-                    av_display_rotation_set(matrix, 90.0);
-                    break;
-                case 7:
-                    av_display_rotation_set(matrix, -90.0);
-                    av_display_matrix_flip(matrix, 1, 0);
-                    break;
-                case 8:
-                    av_display_rotation_set(matrix, -90.0);
-                    break;
-                default:
-                    av_assert0(0);
+                    switch (orientation) {
+                    case 2:
+                        av_display_rotation_set(matrix, 0.0);
+                        av_display_matrix_flip(matrix, 1, 0);
+                        break;
+                    case 3:
+                        av_display_rotation_set(matrix, 180.0);
+                        break;
+                    case 4:
+                        av_display_rotation_set(matrix, 180.0);
+                        av_display_matrix_flip(matrix, 1, 0);
+                        break;
+                    case 5:
+                        av_display_rotation_set(matrix, 90.0);
+                        av_display_matrix_flip(matrix, 1, 0);
+                        break;
+                    case 6:
+                        av_display_rotation_set(matrix, 90.0);
+                        break;
+                    case 7:
+                        av_display_rotation_set(matrix, -90.0);
+                        av_display_matrix_flip(matrix, 1, 0);
+                        break;
+                    case 8:
+                        av_display_rotation_set(matrix, -90.0);
+                        break;
+                    default:
+                        av_assert0(0);
+                    }
                 }
             }
         }
-- 
2.42.0



More information about the ffmpeg-devel mailing list