PR #21405 opened by Ramiro Polla (ramiro)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21405
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21405.patch

Instead, pass it as a parameter to the only function that uses it.


>From 40593b5a3c81b580cbd6de1819473e6375a18952 Mon Sep 17 00:00:00 2001
From: Ramiro Polla <[email protected]>
Date: Thu, 11 Sep 2025 17:45:47 +0200
Subject: [PATCH] avcodec/mjpegdec: remove start_code field from
 MJpegDecodeContext

Instead, pass it as a parameter to the only function that uses it.
---
 libavcodec/mjpegbdec.c |  4 ----
 libavcodec/mjpegdec.c  | 14 ++++++--------
 libavcodec/mjpegdec.h  |  1 -
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c
index 79eed6eaa6..5a21ea47fc 100644
--- a/libavcodec/mjpegbdec.c
+++ b/libavcodec/mjpegbdec.c
@@ -85,7 +85,6 @@ read_header:
     av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%"PRIx32"\n", dqt_offs);
     if (dqt_offs) {
         bytestream2_init(&s->gB, buf_ptr+dqt_offs, buf_end - 
(buf_ptr+dqt_offs));
-        s->start_code = DQT;
         ret = ff_mjpeg_decode_dqt(s);
         if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
             return ret;
@@ -95,7 +94,6 @@ read_header:
     av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%"PRIx32"\n", dht_offs);
     if (dht_offs) {
         bytestream2_init(&s->gB, buf_ptr+dht_offs, buf_end - 
(buf_ptr+dht_offs));
-        s->start_code = DHT;
         ff_mjpeg_decode_dht(s);
     }
 
@@ -103,7 +101,6 @@ read_header:
     av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%"PRIx32"\n", sof_offs);
     if (sof_offs) {
         bytestream2_init(&s->gB, buf_ptr+sof_offs, buf_end - 
(buf_ptr+sof_offs));
-        s->start_code = SOF0;
         if ((ret = ff_mjpeg_decode_sof(s)) < 0)
             return ret;
     }
@@ -116,7 +113,6 @@ read_header:
         bytestream2_init(&s->gB, buf_ptr+sos_offs,
                          FFMIN(field_size, buf_end - buf_ptr - sos_offs));
         s->mjpb_skiptosod = (sod_offs - sos_offs - 
bytestream2_peek_be16(&s->gB));
-        s->start_code = SOS;
         if (avctx->skip_frame == AVDISCARD_ALL) {
             bytestream2_skipu(&s->gB, bytestream2_get_bytes_left(&s->gB));
         } else {
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 417cedae4a..ada98b0174 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -135,7 +135,6 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
     init_idct(avctx);
     s->buffer_size   = 0;
     s->buffer        = NULL;
-    s->start_code    = -1;
     s->first_picture = 1;
     s->got_picture   = 0;
     s->orig_height    = avctx->coded_height;
@@ -1871,7 +1870,7 @@ static int mjpeg_decode_dri(MJpegDecodeContext *s)
     return 0;
 }
 
-static int mjpeg_decode_app(MJpegDecodeContext *s)
+static int mjpeg_decode_app(MJpegDecodeContext *s, int start_code)
 {
     int len, id, i;
 
@@ -2016,7 +2015,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
     }
 
     /* JPS extension by VRex */
-    if (s->start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) {
+    if (start_code == APP3 && id == AV_RB32("_JPS") && len >= 10) {
         int flags, layout, type;
         if (s->avctx->debug & FF_DEBUG_PICT_INFO)
             av_log(s->avctx, AV_LOG_INFO, "_JPSJPS_\n");
@@ -2056,7 +2055,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
     }
 
     /* EXIF metadata */
-    if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) {
+    if (start_code == APP1 && id == AV_RB32("Exif") && len >= 2) {
         int ret;
 
         bytestream2_skipu(&s->gB, 2); // skip padding
@@ -2075,7 +2074,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
     }
 
     /* Apple MJPEG-A */
-    if ((s->start_code == APP1) && (len > (0x28 - 8))) {
+    if ((start_code == APP1) && (len > (0x28 - 8))) {
         id   = bytestream2_get_be32u(&s->gB);
         len -= 4;
         /* Apple MJPEG-A */
@@ -2095,7 +2094,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
         }
     }
 
-    if (s->start_code == APP2 && id == AV_RB32("ICC_") && len >= 10) {
+    if (start_code == APP2 && id == AV_RB32("ICC_") && len >= 10) {
         int id2;
         unsigned seqno;
         unsigned nummarkers;
@@ -2421,7 +2420,6 @@ redo_for_pal8:
 
         bytestream2_init(&s->gB, unescaped_buf_ptr, unescaped_buf_size);
 
-        s->start_code = start_code;
         if (avctx->debug & FF_DEBUG_STARTCODE)
             av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
 
@@ -2431,7 +2429,7 @@ redo_for_pal8:
                    "restart marker: %d\n", start_code & 0x0f);
             /* APP fields */
         } else if (start_code >= APP0 && start_code <= APP15) {
-            if ((ret = mjpeg_decode_app(s)) < 0)
+            if ((ret = mjpeg_decode_app(s, start_code)) < 0)
                 av_log(avctx, AV_LOG_ERROR, "unable to decode APP fields: 
%s\n",
                        av_err2str(ret));
             /* Comment */
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h
index 4f4139dcc4..4d391ff9f9 100644
--- a/libavcodec/mjpegdec.h
+++ b/libavcodec/mjpegdec.h
@@ -60,7 +60,6 @@ typedef struct MJpegDecodeContext {
     GetByteContext gB;
     int buf_size;
 
-    int start_code; /* current start code */
     int buffer_size;
     uint8_t *buffer;
 
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to