From: Ramiro Polla via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Ramiro Polla <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/mjpegdec: speed up find_marker() (PR #21313)
Date: Mon, 29 Dec 2025 18:42:34 -0000
Message-ID: <176703375463.25.10211214697437099362@4457048688e7> (raw)
PR #21313 opened by Ramiro Polla (ramiro)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21313
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21313.patch
Minimize number of reads and simplify conditionals.
Also use memchr(), as suggested by Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>From ab28b728b8a337f5f74e6b42239bdd1c8257dcba Mon Sep 17 00:00:00 2001
From: Ramiro Polla <ramiro.polla@gmail.com>
Date: Tue, 23 Sep 2025 17:11:40 +0200
Subject: [PATCH] avcodec/mjpegdec: speed up find_marker()
Minimize number of reads and simplify conditionals.
Also use memchr(), as suggested by Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegdec.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 05150e982c..cc05e87898 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2193,17 +2193,19 @@ static int mjpeg_decode_com(MJpegDecodeContext *s)
static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
{
const uint8_t *buf_ptr;
- unsigned int v, v2;
int val;
int skipped = 0;
buf_ptr = *pbuf_ptr;
- while (buf_end - buf_ptr > 1) {
- v = *buf_ptr++;
- v2 = *buf_ptr;
- if ((v == 0xff) && (v2 >= SOF0) && (v2 <= COM) && buf_ptr < buf_end) {
+ while ((buf_ptr = memchr(buf_ptr, 0xff, buf_end - buf_ptr))) {
+ buf_ptr++;
+ while (buf_ptr < buf_end) {
val = *buf_ptr++;
- goto found;
+ if (val != 0xff) {
+ if ((val >= SOF0) && (val <= COM))
+ goto found;
+ break;
+ }
}
skipped++;
}
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-12-29 18:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176703375463.25.10211214697437099362@4457048688e7 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git