This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit e519d13bc72534d120df44ddf60d08d0123fb238 Author: Thierry Foucu <[email protected]> AuthorDate: Wed Aug 26 04:59:48 2026 +0200 Commit: michaelni <[email protected]> CommitDate: Wed Sep 16 18:56:45 2026 +0000 avformat/aviobuf: read multi-byte values directly from the buffer The readers fetch their input through nested avio_r8() calls, paying a buffer bounds check per byte. Read the value with a single load when it is fully contained in the buffer and keep the byte-wise code as the refill fallback. Demuxing a fragmented MP4 with -c copy, where moof/trun parsing is dominated by these readers, drops from 2.703 +/- 0.036 to 2.426 +/- 0.040 seconds of user time (-10%, n=30, p < 1e-4). --- libavformat/aviobuf.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 7012b182f6..edbbc5ffd6 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -714,22 +714,28 @@ int avio_read_partial(AVIOContext *s, unsigned char *buf, int size) return len; } -#define AVIO_READER(name, type, read1, shift1, read2, shift2) \ +#define AVIO_READER(name, type, bytes, load, read1, shift1, read2, shift2) \ type name(AVIOContext *s) \ { \ - type val = (type)read1(s) << shift1; \ - val |= (type)read2(s) << shift2; \ + type val; \ + if (s->buf_end - s->buf_ptr >= bytes) { \ + val = load(s->buf_ptr); \ + s->buf_ptr += bytes; \ + } else { \ + val = (type)read1(s) << shift1; \ + val |= (type)read2(s) << shift2; \ + } \ return val; \ } -AVIO_READER(avio_rl16, unsigned int, avio_r8, 0, avio_r8, 8) -AVIO_READER(avio_rl24, unsigned int, avio_rl16, 0, avio_r8, 16) -AVIO_READER(avio_rl32, unsigned int, avio_rl16, 0, avio_rl16, 16) -AVIO_READER(avio_rl64, uint64_t, avio_rl32, 0, avio_rl32, 32) -AVIO_READER(avio_rb16, unsigned int, avio_r8, 8, avio_r8, 0) -AVIO_READER(avio_rb24, unsigned int, avio_rb16, 8, avio_r8, 0) -AVIO_READER(avio_rb32, unsigned int, avio_rb16, 16, avio_rb16, 0) -AVIO_READER(avio_rb64, uint64_t, avio_rb32, 32, avio_rb32, 0) +AVIO_READER(avio_rl16, unsigned int, 2, AV_RL16, avio_r8, 0, avio_r8, 8) +AVIO_READER(avio_rl24, unsigned int, 3, AV_RL24, avio_rl16, 0, avio_r8, 16) +AVIO_READER(avio_rl32, unsigned int, 4, AV_RL32, avio_rl16, 0, avio_rl16, 16) +AVIO_READER(avio_rl64, uint64_t, 8, AV_RL64, avio_rl32, 0, avio_rl32, 32) +AVIO_READER(avio_rb16, unsigned int, 2, AV_RB16, avio_r8, 8, avio_r8, 0) +AVIO_READER(avio_rb24, unsigned int, 3, AV_RB24, avio_rb16, 8, avio_r8, 0) +AVIO_READER(avio_rb32, unsigned int, 4, AV_RB32, avio_rb16, 16, avio_rb16, 0) +AVIO_READER(avio_rb64, uint64_t, 8, AV_RB64, avio_rb32, 32, avio_rb32, 0) int ff_get_line(AVIOContext *s, char *buf, int maxlen) { int i = 0; -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
