vlc | branch: master | Francois Cartegnie <[email protected]> | Mon Dec 14 17:15:43 2015 +0100| [66f3469f18ff81052a82095c01d9f479ebc4862b] | committer: Francois Cartegnie
vlc_bits: add bs_remain() > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=66f3469f18ff81052a82095c01d9f479ebc4862b --- include/vlc_bits.h | 8 +++++ test/Makefile.am | 3 ++ test/src/misc/bits.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/include/vlc_bits.h b/include/vlc_bits.h index d7a9689..379cf38 100644 --- a/include/vlc_bits.h +++ b/include/vlc_bits.h @@ -62,6 +62,14 @@ static inline int bs_pos( const bs_t *s ) return( 8 * ( s->p - s->p_start ) + 8 - s->i_left ); } +static inline int bs_remain( const bs_t *s ) +{ + if( s->p >= s->p_end ) + return 0; + else + return( 8 * ( s->p_end - s->p ) - 8 + s->i_left ); +} + static inline int bs_eof( const bs_t *s ) { return( s->p >= s->p_end ? 1: 0 ); diff --git a/test/Makefile.am b/test/Makefile.am index b732acf..ad4a049 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -22,6 +22,7 @@ check_PROGRAMS = \ test_src_misc_variables \ test_src_crypto_update \ test_src_input_stream \ + test_src_misc_bits \ $(NULL) check_SCRIPTS = \ @@ -86,6 +87,8 @@ test_src_input_stream_LDADD = $(LIBVLCCORE) $(LIBVLC) test_src_input_stream_net_SOURCES = src/input/stream.c test_src_input_stream_net_CFLAGS = $(AM_CFLAGS) -DTEST_NET test_src_input_stream_net_LDADD = $(LIBVLCCORE) $(LIBVLC) +test_src_misc_bits_SOURCES = src/misc/bits.c +test_src_misc_bits_LDADD = $(LIBVLC) checkall: $(MAKE) check_PROGRAMS="$(check_PROGRAMS) $(EXTRA_PROGRAMS)" check diff --git a/test/src/misc/bits.c b/test/src/misc/bits.c new file mode 100644 index 0000000..de13b73 --- /dev/null +++ b/test/src/misc/bits.c @@ -0,0 +1,89 @@ +/***************************************************************************** + * bits.c test bitstream reader + ***************************************************************************** + * Copyright (C) 2015 VLC authors and VideoLAN + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include "../../libvlc/test.h" + +#include <vlc_bits.h> +#include <assert.h> + +int main( void ) +{ + test_init(); + + uint8_t z[2]; + bs_t bs; + + bs_init( &bs, NULL, 0 ); + assert( bs_remain(&bs) == 0 ); + assert( bs_pos(&bs) == 0 ); + + bs_init( &bs, &z, 0 ); + assert( bs_remain(&bs) == 0 ); + assert( bs_pos(&bs) == 0 ); + + bs_init( &bs, &z, 1 ); + assert( bs_remain(&bs) == 8 ); + assert( bs_pos(&bs) == 0 ); + + bs_skip( &bs, 3 ); + assert( bs_remain(&bs) == 5 ); + assert( bs_pos(&bs) == 3 ); + + bs_init( &bs, &z, 2 ); + assert( bs_remain(&bs) == 16 ); + + bs_write( &bs, 1, 0 ); + assert( bs_remain(&bs) == 16 ); + + bs_read1( &bs ); + assert( bs_remain(&bs) == 15 ); + assert( bs_pos(&bs) == 1 ); + + bs_read( &bs, 7 ); + assert( bs_remain(&bs) == 8 ); + assert( bs_pos(&bs) == 8 ); + + bs_read1( &bs ); + assert( bs_remain(&bs) == 7 ); + assert( bs_pos(&bs) == 9 ); + + bs_align( &bs ); + assert( bs_remain(&bs) == 0 ); + assert( bs_pos(&bs) == 16 ); + + z[0] = 0xAA; + z[1] = 0x55; + bs_init( &bs, &z, 2 ); + assert( bs_read(&bs, 4) == 0x0A ); + assert( bs_read(&bs, 12) == ((0x0A << 8) | 0x55) ); + + z[0] = 0x15; + z[1] = 0x23; + bs_init( &bs, &z, 2 ); + assert( bs_read_ue(&bs) == 0x09 ); + assert( bs_remain(&bs) == 9 ); + assert( bs_read1(&bs) == 1 ); + assert( bs_read_se(&bs) == 2 ); + assert( bs_remain(&bs) == 3 ); + assert( bs_read_se(&bs) == -1 ); + assert( bs_eof(&bs) ); + + return 0; +} _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
