This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 0ddb3e6af233ccdf846a83a96de9ffd01bfe8cb6
Author:     Ramiro Polla <[email protected]>
AuthorDate: Thu Sep 11 22:14:43 2025 +0200
Commit:     Ramiro Polla <[email protected]>
CommitDate: Fri Feb 20 16:32:10 2026 +0100

    avcodec/mjpegdec: improve ff_mjpeg_find_marker() for non-SOS and for THP
    
    There is no need to unescape the buffer for non-SOS fields and for THP.
---
 libavcodec/mjpegdec.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 1dab0eaca6..d79e4ecadc 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2241,12 +2241,19 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s,
     int start_code;
     start_code = find_marker(buf_ptr, buf_end);
 
+    if (start_code != SOS ||
+        s->avctx->codec_id == AV_CODEC_ID_THP) {
+        *unescaped_buf_ptr  = *buf_ptr;
+        *unescaped_buf_size = buf_end - *buf_ptr;
+        return start_code;
+    }
+
     av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr);
     if (!s->buffer)
         return AVERROR(ENOMEM);
 
     /* unescape buffer of SOS, use special treatment for JPEG-LS */
-    if (start_code == SOS && !s->ls) {
+    if (!s->ls) {
         const uint8_t *src = *buf_ptr;
         const uint8_t *ptr = src;
         uint8_t *dst = s->buffer;
@@ -2260,10 +2267,6 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s,
             }                                         \
         } while (0)
 
-        if (s->avctx->codec_id == AV_CODEC_ID_THP) {
-            ptr = buf_end;
-            copy_data_segment(0);
-        } else {
             while (ptr < buf_end) {
                 uint8_t x = *(ptr++);
 
@@ -2293,7 +2296,6 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s,
             }
             if (src < ptr)
                 copy_data_segment(0);
-        }
         #undef copy_data_segment
 
         *unescaped_buf_ptr  = s->buffer;
@@ -2303,7 +2305,7 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s,
 
         av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
                (buf_end - *buf_ptr) - (dst - s->buffer));
-    } else if (start_code == SOS && s->ls) {
+    } else {
         const uint8_t *src = *buf_ptr;
         uint8_t *dst  = s->buffer;
         int bit_count = 0;
@@ -2345,9 +2347,6 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s,
         *unescaped_buf_size = (bit_count + 7) >> 3;
         memset(s->buffer + *unescaped_buf_size, 0,
                AV_INPUT_BUFFER_PADDING_SIZE);
-    } else {
-        *unescaped_buf_ptr  = *buf_ptr;
-        *unescaped_buf_size = buf_end - *buf_ptr;
     }
 
     return start_code;

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

Reply via email to