On 07/05/16 06:07, Alexandra Hájková wrote: > --- > libavcodec/bitstream.h | 465 > +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 465 insertions(+) > create mode 100644 libavcodec/bitstream.h > > diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h > new file mode 100644 > index 0000000..0b16059 > --- /dev/null > +++ b/libavcodec/bitstream.h > @@ -0,0 +1,465 @@ > +/* > + * copyright (c) 2016 Alexandra Hájková > + * > + * This file is part of Libav. > + * > + * Libav is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * Libav is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with Libav; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > +/** > + * @file > + * bitstream reader API header. > + */ > + > +#ifndef AVCODEC_BITSTREAM_H > +#define AVCODEC_BITSTREAM_H > + > +#include <stdint.h> > + > +#include "libavutil/common.h" > +#include "libavutil/intreadwrite.h" > +#include "libavutil/log.h" > + > +#include "mathops.h" > +#include "vlc.h" > + > +typedef struct BitstreamContext { > + uint64_t bits; // stores bits read from the buffer > + const uint8_t *buffer, *buffer_end; > + const uint8_t *ptr; // pointer to the position inside a buffer > + unsigned bits_left; // number of bits left in bits field > + unsigned size_in_bits; > +} BitstreamContext; > + > +/** > + * Return number of bits already read. > + */ > +static inline int bitstream_tell(const BitstreamContext *s) > +{ > + return (s->ptr - s->buffer) * 8 - s->bits_left; > +} > + > +static inline void refill_64(BitstreamContext *s) > +{ > + if (av_unlikely(s->ptr >= s->buffer_end || !s->buffer)) > + return; > + > +#ifdef BITSTREAM_READER_LE > + s->bits = AV_RL64(s->ptr); > +#else > + s->bits = AV_RB64(s->ptr); > +#endif > + s->ptr += 8; > + s->bits_left = 64; > +} > + > +static inline uint64_t get_val(BitstreamContext *s, int n) > +{ > + uint64_t ret; > + > +#ifdef BITSTREAM_READER_LE > + ret = s->bits & ((UINT64_C(1) << n) - 1); > + s->bits >>= n; > +#else > + ret = s->bits >> (64 - n); > + s->bits <<= n; > +#endif > + s->bits_left -= n; > + > + return ret; > +} > + > +/** > + * Return one bit from the buffer. > + */ > +static inline unsigned int bitstream_read_bit(BitstreamContext *s) > +{ > + if (av_unlikely(!s->bits_left)) > + refill_64(s); > + > + return (uint8_t)get_val(s, 1);
I'd use !!get_val(s, 1) The rest is sort of ok for me. lu _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel