From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/4] lavc: add standalone cached bitstream reader
Date: Fri, 24 Jun 2022 14:08:24 +0200
Message-ID: <DB6PR0101MB221416ED8A1084ED7AB074B58FB49@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <DB6PR0101MB22146A81980DEFBFD54CD9998FB59@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>
Andreas Rheinhardt:
> Anton Khirnov:
>> +/* Unwind the cache so a refill_32 can fill it again. */
>> +static inline void bitstream_unwind(BitstreamContext *bc)
>> +{
>> + int unwind = 4;
>> + int unwind_bits = unwind * 8;
>
> I'm surprised that you used signed types here.
>
>> +
>> + if (bc->bits_left < unwind_bits)
>> + return;
>> +
>> + bc->bits >>= unwind_bits;
>> + bc->bits <<= unwind_bits;
>
> The above won't work in LE. Best to call skip_remaining here. And you
> need to templatize this function in 3/4.
Calling skip_remaining is wrong either. Both the above (for BE) as well
as skip_remaining would skip the oldest 32 bits in the cache, but we
need to skip the newest 32 bits in the cache. So the following should do it:
bc->bits_left -= unwind_bits;
bc->ptr -= unwind;
#ifdef BITSTREAM_READER_LE
bc->bits &= ((UINT64_C(1) << bc->bits_left) - 1);
#else
bc->bits &= ~(UINT64_T_MAX >> bc->bits_left);
#endif
(Given that bc->bits_left can be 0 one can't simply shift by 64 -
bits_left. I also don't know whether there should be any check before
decrementing ptr.)
>
>> + bc->bits_left -= unwind_bits;
>> + bc->ptr -= unwind;
>> +}
>> +
>> +/* Unget up to 32 bits. */
>> +static inline void bitstream_unget(BitstreamContext *bc, uint64_t value,
>> + size_t amount)
>
> size_t is the natural type for the bytesize of objects, but not for
> bitsizes. A plane unsigned would be more natural here.
>
>> +{
>> + size_t cache_size = sizeof(bc->bits) * 8;
>> +
>> + if (bc->bits_left + amount > cache_size)
>> + bitstream_unwind(bc);
>> +
>> + bc->bits = (bc->bits >> amount) | (value << (cache_size - amount));
>
> This is big-endian only, too.
>
>> + bc->bits_left += amount;
>> +}
>> +
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-06-24 12:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 12:26 [FFmpeg-devel] [PATCH 1/4] get_bits: move check_marker() to mpegvideodec.h Anton Khirnov
2022-06-23 12:26 ` [FFmpeg-devel] [PATCH 2/4] lavc: add standalone cached bitstream reader Anton Khirnov
2022-06-23 18:56 ` Andreas Rheinhardt
2022-06-24 12:08 ` Andreas Rheinhardt [this message]
2022-06-24 10:18 ` Andreas Rheinhardt
2022-06-24 12:30 ` Andreas Rheinhardt
2022-06-30 9:18 ` Anton Khirnov
2022-06-30 12:16 ` Anton Khirnov
2022-06-23 12:26 ` [FFmpeg-devel] [PATCH 3/4] lavc/bitstream: templatize for BE/LE Anton Khirnov
2022-06-23 17:43 ` Andreas Rheinhardt
2022-06-25 7:53 ` Andreas Rheinhardt
2022-06-23 12:26 ` [FFmpeg-devel] [PATCH 4/4] lavc/get_bits: add a compat wrapper for the cached bitstream reader Anton Khirnov
2022-06-23 18:04 ` Andreas Rheinhardt
2022-06-23 17:07 ` [FFmpeg-devel] [PATCH 1/4] get_bits: move check_marker() to mpegvideodec.h Andreas Rheinhardt
2022-06-25 4:43 ` Andreas Rheinhardt
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=DB6PR0101MB221416ED8A1084ED7AB074B58FB49@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@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