[FFmpeg-devel] [PATCH 5/7] get_bits: improve and fix get_bits_long for 32b
Michael Niedermayer
michael at niedermayer.cc
Tue Apr 14 23:17:40 EEST 2020
On Tue, Apr 14, 2020 at 10:25:01AM +0000, Christophe Gisquet wrote:
> The new code is guaranteed to read at least 32bits, which is likely ok with
> the usual case that get_bits without cache can read up to 25.
> ---
> libavcodec/get_bits.h | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
> index 4f75f9dd84..da054ebfcb 100644
> --- a/libavcodec/get_bits.h
> +++ b/libavcodec/get_bits.h
> @@ -608,21 +608,44 @@ static inline void skip_bits1(GetBitContext *s)
> */
> static inline unsigned int get_bits_long(GetBitContext *s, int n)
> {
> + unsigned ret = 0;
Dead assignment if CACHED_BITSTREAM_READER is not used
> av_assert2(n>=0 && n<=32);
> if (!n) {
> return 0;
> #if CACHED_BITSTREAM_READER
> }
> - return get_bits(s, n);
> +
> +# ifdef BITSTREAM_READER_LE
> + unsigned left = 0;
> +# endif
> + if (n > s->bits_left) {
> + n -= s->bits_left;
> +# ifdef BITSTREAM_READER_LE
> + left = s->bits_left;
> + ret = get_val(s, s->bits_left, 1);
> + refill_all(s, 1);
> +# else
> + ret = get_val(s, s->bits_left, 0);
> + refill_all(s, 0);
> +# endif
Its a pitty one cannot write the following
+# ifdef BITSTREAM_READER_LE
+ left = s->bits_left;
+# endif
+ ret = get_val(s, s->bits_left, BITSTREAM_READER_LE);
+ refill_all(s, BITSTREAM_READER_LE);
that would be nicer looking if it worked
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200414/21e6a8b5/attachment.sig>
More information about the ffmpeg-devel
mailing list