diff options
author | Roman Shaposhnik <roman@shaposhnik.org> | 2004-03-12 23:39:38 +0000 |
---|---|---|
committer | Roman Shaposhnik <roman@shaposhnik.org> | 2004-03-12 23:39:38 +0000 |
commit | e7a18d5debc40d39e842d7b7bd1f57ab886c47b9 (patch) | |
tree | 55d544d8ff5e4fe6750b9d0c967672adca007fbe /libavcodec/common.h | |
parent | 6e046750d8aee9010ac923602c4cd6bc6acda78e (diff) | |
download | ffmpeg-e7a18d5debc40d39e842d7b7bd1f57ab886c47b9.tar.gz |
* moving some of the commonly used bit reading/writing functions
from common.c -> common.h so that they can be inlined.
+ performace gain ~1% (measured with DV decoding)
+ code bloat 0.05%
Looks like a win-win solution.
Originally committed as revision 2874 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/common.h')
-rw-r--r-- | libavcodec/common.h | 105 |
1 files changed, 98 insertions, 7 deletions
diff --git a/libavcodec/common.h b/libavcodec/common.h index e3d952eca7..cdbe0f0ba3 100644 --- a/libavcodec/common.h +++ b/libavcodec/common.h @@ -292,11 +292,55 @@ typedef struct PutBitContext { #endif } PutBitContext; -void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size); +static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) +{ + s->buf = buffer; + s->buf_end = s->buf + buffer_size; +#ifdef ALT_BITSTREAM_WRITER + s->index=0; + ((uint32_t*)(s->buf))[0]=0; +// memset(buffer, 0, buffer_size); +#else + s->buf_ptr = s->buf; + s->bit_left=32; + s->bit_buf=0; +#endif +} + +/* return the number of bits output */ +static inline int put_bits_count(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + return s->index; +#else + return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; +#endif +} + +static inline int put_bits_left(PutBitContext* s) +{ + return (s->buf_end - s->buf) * 8 - put_bits_count(s); +} + +/* pad the end of the output stream with zeros */ +static inline void flush_put_bits(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + align_put_bits(s); +#else + s->bit_buf<<= s->bit_left; + while (s->bit_left < 32) { + /* XXX: should test end of buffer */ + *s->buf_ptr++=s->bit_buf >> 24; + s->bit_buf<<=8; + s->bit_left+=8; + } + s->bit_left=32; + s->bit_buf=0; +#endif +} -int put_bits_count(PutBitContext *s); void align_put_bits(PutBitContext *s); -void flush_put_bits(PutBitContext *s); void put_string(PutBitContext * pbc, char *s, int put_zero); /* bit input */ @@ -318,8 +362,6 @@ typedef struct GetBitContext { int size_in_bits; } GetBitContext; -static inline int get_bits_count(GetBitContext *s); - #define VLC_TYPE int16_t typedef struct VLC { @@ -825,8 +867,57 @@ static inline void skip_bits1(GetBitContext *s){ skip_bits(s, 1); } -void init_get_bits(GetBitContext *s, - const uint8_t *buffer, int buffer_size); +/** + * init GetBitContext. + * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits + * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end + * @param bit_size the size of the buffer in bits + */ +static inline void init_get_bits(GetBitContext *s, + const uint8_t *buffer, int bit_size) +{ + const int buffer_size= (bit_size+7)>>3; + + s->buffer= buffer; + s->size_in_bits= bit_size; + s->buffer_end= buffer + buffer_size; +#ifdef ALT_BITSTREAM_READER + s->index=0; +#elif defined LIBMPEG2_BITSTREAM_READER +#ifdef LIBMPEG2_BITSTREAM_READER_HACK + if ((int)buffer&1) { + /* word alignment */ + s->cache = (*buffer++)<<24; + s->buffer_ptr = buffer; + s->bit_count = 16-8; + } else +#endif + { + s->buffer_ptr = buffer; + s->bit_count = 16; + s->cache = 0; + } +#elif defined A32_BITSTREAM_READER + s->buffer_ptr = (uint32_t*)buffer; + s->bit_count = 32; + s->cache0 = 0; + s->cache1 = 0; +#endif + { + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + UPDATE_CACHE(re, s) + CLOSE_READER(re, s) + } +#ifdef A32_BITSTREAM_READER + s->cache1 = 0; +#endif +} + +static inline int get_bits_left(GetBitContext *s) +{ + return s->size_in_bits - get_bits_count(s); +} int check_marker(GetBitContext *s, const char *msg); void align_get_bits(GetBitContext *s); |