[vlc-commits] vlc_bits: remove bs_remain

Francois Cartegnie git at videolan.org
Fri Jul 24 11:23:16 CEST 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 23 16:29:18 2020 +0200| [4314526b999ef59f245ec47de722e8cd2ba82ff7] | committer: Francois Cartegnie

vlc_bits: remove bs_remain

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4314526b999ef59f245ec47de722e8cd2ba82ff7
---

 include/vlc_bits.h             | 17 +----------------
 modules/packetizer/hxxx_ep3b.h | 27 ---------------------------
 test/src/misc/bits.c           | 36 ------------------------------------
 3 files changed, 1 insertion(+), 79 deletions(-)

diff --git a/include/vlc_bits.h b/include/vlc_bits.h
index f22b97c410..8d3ae8f098 100644
--- a/include/vlc_bits.h
+++ b/include/vlc_bits.h
@@ -35,10 +35,9 @@ typedef struct bs_s bs_t;
 
 typedef struct
 {
-    /* forward read modifier (p_start, p_end, p_fwpriv, count, pos, remain) */
+    /* forward read modifier (p_start, p_end, p_fwpriv, count, pos) */
     size_t (*pf_byte_forward)(bs_t *, size_t);
     size_t (*pf_byte_pos)(const bs_t *);
-    size_t (*pf_byte_remain)(const bs_t *);
 } bs_byte_callbacks_t;
 
 typedef struct bs_s
@@ -72,14 +71,6 @@ static size_t bs_impl_bytes_forward( bs_t *s, size_t i_count )
     return i_count;
 }
 
-static size_t bs_impl_bytes_remain( const bs_t *s )
-{
-    if( s->p )
-        return s->p < s->p_end ? s->p_end - s->p - 1: 0;
-    else
-        return s->p_end - s->p_start;
-}
-
 static size_t bs_impl_bytes_pos( const bs_t *s )
 {
     if( s->p )
@@ -106,7 +97,6 @@ static inline void bs_init( bs_t *s, const void *p_data, size_t i_data )
     bs_byte_callbacks_t cb = {
         bs_impl_bytes_forward,
         bs_impl_bytes_pos,
-        bs_impl_bytes_remain,
     };
     bs_init_custom( s, p_data, i_data, &cb, NULL );
 }
@@ -145,11 +135,6 @@ static inline size_t bs_pos( const bs_t *s )
     return 8 * s->cb.pf_byte_pos( s ) - s->i_left;
 }
 
-static inline size_t bs_remain( const bs_t *s )
-{
-    return 8 * s->cb.pf_byte_remain( s ) + s->i_left;
-}
-
 static inline void bs_skip( bs_t *s, size_t i_count )
 {
     if( i_count == 0 )
diff --git a/modules/packetizer/hxxx_ep3b.h b/modules/packetizer/hxxx_ep3b.h
index 765092e5b2..337fa7ee7c 100644
--- a/modules/packetizer/hxxx_ep3b.h
+++ b/modules/packetizer/hxxx_ep3b.h
@@ -71,29 +71,12 @@ struct hxxx_bsfw_ep3b_ctx_s
 {
     unsigned i_prev;
     size_t i_bytepos;
-    size_t i_bytesize;
 };
 
 static void hxxx_bsfw_ep3b_ctx_init( struct hxxx_bsfw_ep3b_ctx_s *ctx )
 {
     ctx->i_prev = 0;
     ctx->i_bytepos = 0;
-    ctx->i_bytesize = 0;
-}
-
-static size_t hxxx_ep3b_total_size( const uint8_t *p, const uint8_t *p_end )
-{
-    /* compute final size */
-    unsigned i_prev = 0;
-    size_t i = 0;
-    while( p < p_end )
-    {
-        uint8_t *n = hxxx_ep3b_to_rbsp( (uint8_t *)p, (uint8_t *)p_end, &i_prev, 1 );
-        if( n > p )
-            ++i;
-        p = n;
-    }
-    return i;
 }
 
 static size_t hxxx_bsfw_byte_forward_ep3b( bs_t *s, size_t i_count )
@@ -101,7 +84,6 @@ static size_t hxxx_bsfw_byte_forward_ep3b( bs_t *s, size_t i_count )
     struct hxxx_bsfw_ep3b_ctx_s *ctx = (struct hxxx_bsfw_ep3b_ctx_s *) s->p_priv;
     if( s->p == NULL )
     {
-        ctx->i_bytesize = hxxx_ep3b_total_size( s->p_start, s->p_end );
         s->p = s->p_start;
         ctx->i_bytepos = 1;
         return 1;
@@ -121,17 +103,8 @@ static size_t hxxx_bsfw_byte_pos_ep3b( const bs_t *s )
     return ctx->i_bytepos;
 }
 
-static size_t hxxx_bsfw_byte_remain_ep3b( const bs_t *s )
-{
-    struct hxxx_bsfw_ep3b_ctx_s *ctx = (struct hxxx_bsfw_ep3b_ctx_s *) s->p_priv;
-    if( ctx->i_bytesize == 0 && s->p_start != s->p_end )
-        ctx->i_bytesize = hxxx_ep3b_total_size( s->p_start, s->p_end );
-    return (ctx->i_bytesize > ctx->i_bytepos) ? ctx->i_bytesize - ctx->i_bytepos : 0;
-}
-
 static const bs_byte_callbacks_t hxxx_bsfw_ep3b_callbacks =
 {
     hxxx_bsfw_byte_forward_ep3b,
     hxxx_bsfw_byte_pos_ep3b,
-    hxxx_bsfw_byte_remain_ep3b,
 };
diff --git a/test/src/misc/bits.c b/test/src/misc/bits.c
index f593a4dcca..8171d7535f 100644
--- a/test/src/misc/bits.c
+++ b/test/src/misc/bits.c
@@ -58,56 +58,46 @@ static int run_tests( const struct testset *p_testsets,
     bs_t bs;
 
     bs_init( &bs, NULL, 0 );
-    test_assert( bs_remain(&bs), 0 );
     test_assert( bs_pos(&bs), 0 );
     test_assert( bs_eof(&bs), true );
     test_assert( bs_error(&bs), false );
 
     bs_init( &bs, p_testsets[TESTSET0].data, 0 );
-    test_assert( bs_remain(&bs), 0 );
     test_assert( bs_pos(&bs), 0 );
     bs_skip( &bs, 3 );
     test_assert( bs_error(&bs), true );
 
     bs_init( &bs, p_testsets[TESTSET0].data,
                   p_testsets[TESTSET0].count );
-    test_assert( bs_remain(&bs), 8 );
     test_assert( bs_pos(&bs), 0 );
     test_assert( bs_eof(&bs), false );
     test_assert( bs_error(&bs), false );
 
     bs_skip( &bs, 3 );
-    test_assert( bs_remain(&bs), 5 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_pos(&bs), 3 );
 
     bs_init( &bs, p_testsets[TESTSET1].data,
                   p_testsets[TESTSET1].count );
-    test_assert( bs_remain(&bs), 16 );
     test_assert( bs_error(&bs), false );
 
     bs_write( &bs, 1, 0 );
-    test_assert( bs_remain(&bs), 16 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_eof(&bs), false );
 
     bs_read1( &bs );
-    test_assert( bs_remain(&bs), 15 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_eof(&bs), false );
     test_assert( bs_pos(&bs), 1 );
 
     bs_read( &bs, 7 );
-    test_assert( bs_remain(&bs), 8 );
     test_assert( bs_pos(&bs), 8 );
 
     bs_read1( &bs );
-    test_assert( bs_remain(&bs), 7 );
     test_assert( bs_pos(&bs), 9 );
     test_assert( bs_error(&bs), false );
 
     bs_align( &bs );
-    test_assert( bs_remain(&bs), 0 );
     test_assert( bs_pos(&bs), 16 );
     test_assert( bs_error(&bs), false );
 
@@ -119,11 +109,9 @@ static int run_tests( const struct testset *p_testsets,
     bs_init( &bs, p_testsets[TESTSET_EXPGOLOMB].data,
                   p_testsets[TESTSET_EXPGOLOMB].count );
     test_assert( bs_read_ue(&bs), 0x09 );
-    test_assert( bs_remain(&bs), 9 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_read1(&bs), 1 );
     test_assert( bs_read_se(&bs), 2 );
-    test_assert( bs_remain(&bs), 3 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_read_se(&bs), -1 );
     test_assert( bs_eof(&bs), !0 );
@@ -134,7 +122,6 @@ static int run_tests( const struct testset *p_testsets,
     test_assert( bs_read( &bs, 8 ), 0xDD );
     test_assert( bs_read( &bs, 4 ), 0x0E );
     test_assert( bs_read( &bs, 8 ), 0xEF );
-    test_assert( bs_remain( &bs ), 4 );
     test_assert( bs_error(&bs), false );
 
     bs_init( &bs, p_testsets[TESTSET2].data,
@@ -148,7 +135,6 @@ static int run_tests( const struct testset *p_testsets,
     test_assert( bs_read( &bs, 8 ), 0xCD );
     test_assert( bs_read( &bs, 4 ), 0x0D );
     test_assert( bs_read( &bs, 8 ), 0xEE );
-    test_assert( bs_remain( &bs ), 8 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_eof(&bs), false );
 
@@ -158,7 +144,6 @@ static int run_tests( const struct testset *p_testsets,
     for( size_t i=0; i<6*8; i++ )
     {
         test_assert(bs_aligned( &bs ), !!(i%8 == 0));
-        test_assert(bs_remain( &bs ), 6*8 - i);
         test_assert( bs_eof(&bs), false );
         test_assert(bs_pos( &bs ), i);
         bs_read( &bs, 1 );
@@ -181,7 +166,6 @@ static int run_tests( const struct testset *p_testsets,
     for( size_t i=0, j=0; i<5*8; j++ )
     {
         test_assert(bs_aligned( &bs ), !!(i%8 == 0));
-        test_assert(bs_remain( &bs ), 5*8 - i);
         test_assert( bs_eof(&bs), false );
         test_assert(bs_pos( &bs ), i);
         bs_write(&bs, j % 4, (i % 2) ? 0xFF >> (8 - (j % 4)) : 0 );
@@ -206,14 +190,11 @@ static int run_tests( const struct testset *p_testsets,
     /* overflows */
     bs_init( &bs, p_testsets[TESTSET1].data, p_testsets[TESTSET1].count );
     bs_read( &bs, 42 );
-    test_assert(bs_remain( &bs ), 0);
     test_assert( bs_error(&bs), true );
     test_assert( bs_eof(&bs), true );
     test_assert(bs_pos( &bs ), 16);
 
     bs_init( &bs, p_testsets[TESTSET1].data, p_testsets[TESTSET1].count );
-    bs_skip( &bs, 42 );
-    test_assert(bs_remain( &bs ), 0);
     bs_skip( &bs, 2 );
     test_assert( bs_error(&bs), false );
     test_assert( bs_eof(&bs), false );
@@ -224,11 +205,8 @@ static int run_tests( const struct testset *p_testsets,
 
     bs_init( &bs, p_testsets[TESTSET1].data, p_testsets[TESTSET1].count );
     bs_skip( &bs, 8 );
-    test_assert(bs_remain( &bs ), 8);
     test_assert( bs_error(&bs), false );
     test_assert(bs_pos( &bs ), 8);
-    test_assert(bs_read( &bs, 8 + 2 ), 0x55 << 2);
-    test_assert(bs_remain( &bs ), 0);
     test_assert(bs_read( &bs, 8 + 2 ), 0x55 << 2); /* truncated read */
     test_assert( bs_error(&bs), true );
     test_assert( bs_eof(&bs), true );
@@ -261,14 +239,6 @@ static size_t bs_skipeven_bytes_forward( bs_t *s, size_t i_count )
     }
 }
 
-static size_t bs_skipeven_bytes_remain( const bs_t *s )
-{
-    if( s->p )
-        return s->p < s->p_end ? (s->p_end - s->p + 1) / 2 - 1: 0;
-    else
-        return (s->p_end - s->p_start) / 2;
-}
-
 static size_t bs_skipeven_bytes_pos( const bs_t *s )
 {
     if( s->p )
@@ -280,7 +250,6 @@ static size_t bs_skipeven_bytes_pos( const bs_t *s )
 bs_byte_callbacks_t skipeven_cb = {
     bs_skipeven_bytes_forward,
     bs_skipeven_bytes_pos,
-    bs_skipeven_bytes_remain,
 };
 
 static int test_annexb( const char *psz_tag )
@@ -299,7 +268,6 @@ static int test_annexb( const char *psz_tag )
     for( size_t i=0; i<ARRAY_SIZE(unesc)*8; i++ )
     {
         test_assert(bs_aligned( &bs ), !!(i%8 == 0));
-        test_assert(bs_remain( &bs ), ARRAY_SIZE(unesc)*8 - i);
         test_assert(bs_pos( &bs ), i);
         bs_read( &bs, 1 );
     }
@@ -311,7 +279,6 @@ static int test_annexb( const char *psz_tag )
     bs.p_priv = &bsctx;
     for( size_t i=0; i<ARRAY_SIZE(unesc)*4; i++ )
     {
-        test_assert(bs_remain( &bs ), ARRAY_SIZE(unesc)*8 - i*2);
         test_assert(bs_pos( &bs ), i*2);
         bs_read( &bs, 2 );
     }
@@ -320,7 +287,6 @@ static int test_annexb( const char *psz_tag )
     /* overflows */
     bs_init( &bs, &annexb, ARRAY_SIZE(annexb) );
     bs_skip( &bs, (ARRAY_SIZE(annexb) + 1) * 8 );
-    test_assert(bs_remain( &bs ), 0);
     test_assert(bs_pos( &bs ), ARRAY_SIZE(annexb) * 8);
 
     /* real world vps */
@@ -335,7 +301,6 @@ static int test_annexb( const char *psz_tag )
     hxxx_bsfw_ep3b_ctx_init( &bsctx );
     bs.cb = hxxx_bsfw_ep3b_callbacks;
     bs.p_priv = &bsctx;
-    test_assert(bs_remain( &bs ), ARRAY_SIZE(vpsnalunesc) * 8);
     for(size_t i=0; i<ARRAY_SIZE(vpsnalunesc); i++)
         test_assert(bs_read(&bs, 8), vpsnalunesc[i]);
 
@@ -367,7 +332,6 @@ static int test_annexb( const char *psz_tag )
     hxxx_bsfw_ep3b_ctx_init( &bsctx );
     bs.cb = hxxx_bsfw_ep3b_callbacks;
     bs.p_priv = &bsctx;
-    test_assert(bs_remain( &bs ), ARRAY_SIZE(seinalunesc) * 8);
     for(size_t i=0; i<ARRAY_SIZE(seinalunesc); i++)
         test_assert(bs_read(&bs, 8), seinalunesc[i]);
 



More information about the vlc-commits mailing list