[vlc-commits] packetizer: a52: use dedicated struct for bitstream values

Francois Cartegnie git at videolan.org
Fri Dec 21 16:13:25 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Dec 21 12:37:42 2018 +0100| [430fbebc494c734e8b18e8b01d125beb9e2cecec] | committer: Francois Cartegnie

packetizer: a52: use dedicated struct for bitstream values

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

 modules/audio_filter/converter/tospdif.c |  2 +-
 modules/packetizer/a52.c                 |  4 +-
 modules/packetizer/a52.h                 | 94 +++++++++++++++++++-------------
 3 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/modules/audio_filter/converter/tospdif.c b/modules/audio_filter/converter/tospdif.c
index 21ffb1c2ac..57f1c12391 100644
--- a/modules/audio_filter/converter/tospdif.c
+++ b/modules/audio_filter/converter/tospdif.c
@@ -280,7 +280,7 @@ static int write_buffer_eac3( filter_t *p_filter, block_t *p_in_buf )
 
         if( vlc_a52_header_Parse( &a52_dep, dep_buf, dep_size ) != VLC_SUCCESS
          || a52_dep.i_size > dep_size
-         || !a52_dep.b_eac3 || a52_dep.eac3.strmtyp != EAC3_STRMTYP_DEPENDENT
+         || !a52_dep.b_eac3 || a52_dep.bs.eac3.strmtyp != EAC3_STRMTYP_DEPENDENT
          || p_in_buf->i_buffer > a52.i_size + a52_dep.i_size )
             return SPDIF_ERROR;
     }
diff --git a/modules/packetizer/a52.c b/modules/packetizer/a52.c
index f2d88798e8..c8209f3966 100644
--- a/modules/packetizer/a52.c
+++ b/modules/packetizer/a52.c
@@ -211,7 +211,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
                 break;
             }
 
-            if( p_sys->frame.b_eac3 && p_sys->frame.eac3.strmtyp == EAC3_STRMTYP_DEPENDENT )
+            if( p_sys->frame.b_eac3 && p_sys->frame.bs.eac3.strmtyp == EAC3_STRMTYP_DEPENDENT )
             {
                 msg_Warn( p_dec, "starting with dependent stream, skip it" );
                 p_sys->i_state = STATE_NOSYNC;
@@ -258,7 +258,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
 
             vlc_a52_header_t a52;
             if( !vlc_a52_header_Parse( &a52, p_header, VLC_A52_HEADER_SIZE )
-             && a52.b_eac3 && a52.eac3.strmtyp == EAC3_STRMTYP_DEPENDENT )
+             && a52.b_eac3 && a52.bs.eac3.strmtyp == EAC3_STRMTYP_DEPENDENT )
                 p_sys->i_input_size += a52.i_size;
 
             p_sys->i_state = STATE_GET_DATA;
diff --git a/modules/packetizer/a52.h b/modules/packetizer/a52.h
index 0965710d6f..4a25ef25e3 100644
--- a/modules/packetizer/a52.h
+++ b/modules/packetizer/a52.h
@@ -38,6 +38,28 @@
 /**
  * AC3 header information.
  */
+struct vlc_a52_bitstream_info
+{
+    uint8_t i_fscod;
+    uint8_t i_frmsizcod;
+    uint8_t i_bsid;
+    uint8_t i_bsmod;
+    uint8_t i_acmod;
+    uint8_t i_lfeon;
+    union
+    {
+        struct {
+            enum {
+                EAC3_STRMTYP_INDEPENDENT    = 0,
+                EAC3_STRMTYP_DEPENDENT      = 1,
+                EAC3_STRMTYP_AC3_CONVERT    = 2,
+                EAC3_STRMTYP_RESERVED,
+            } strmtyp;
+            uint8_t i_substreamid;
+        } eac3;
+    };
+};
+
 typedef struct
 {
     bool b_eac3;
@@ -51,17 +73,8 @@ typedef struct
     unsigned int i_size;
     unsigned int i_samples;
 
-    union {
-        struct {
-            enum {
-                EAC3_STRMTYP_INDEPENDENT    = 0,
-                EAC3_STRMTYP_DEPENDENT      = 1,
-                EAC3_STRMTYP_AC3_CONVERT    = 2,
-                EAC3_STRMTYP_RESERVED,
-            } strmtyp;
-            uint8_t i_substreamid;
-        } eac3;
-    };
+    struct vlc_a52_bitstream_info bs;
+
     uint8_t i_blocks_per_sync_frame;
 } vlc_a52_header_t;
 
@@ -125,52 +138,55 @@ static inline int vlc_a52_header_ParseAc3( vlc_a52_header_t *p_header,
         512, 576, 640
     };
 
+    struct vlc_a52_bitstream_info *bs = &p_header->bs;
+
     bs_t s;
     bs_init( &s, (void*)p_buf, VLC_A52_HEADER_SIZE );
     bs_skip( &s, 32 );  /* start code + CRC */
 
     /* cf. 5.3.2 */
-    const uint8_t i_fscod = bs_read( &s, 2 );
-    if( i_fscod == 3 )
+    bs->i_fscod = bs_read( &s, 2 );
+    if( bs->i_fscod == 3 )
         return VLC_EGENERIC;
-    const uint8_t i_frmsizcod = bs_read( &s, 6 );
-    if( i_frmsizcod >= 38 )
+    bs->i_frmsizcod = bs_read( &s, 6 );
+    if( bs->i_frmsizcod >= 38 )
         return VLC_EGENERIC;
-    const uint8_t i_bsid = bs_read( &s, 5 );
+    bs->i_bsid = bs_read( &s, 5 );
     bs_skip( &s, 3 ); /* i_bsmod */
-    const uint8_t i_acmod = bs_read( &s, 3 );
-    if( ( i_acmod & 0x1 ) && ( i_acmod != 0x1 ) )
+    bs->i_acmod = bs_read( &s, 3 );
+    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
     {
         /* if 3 front channels */
         bs_skip( &s, 2 ); /* i_cmixlev */
     }
-    if( i_acmod & 0x4 )
+    if( bs->i_acmod & 0x4 )
     {
         /* if a surround channel exists */
         bs_skip( &s, 2 ); /* i_surmixlev */
     }
     /* if in 2/0 mode */
-    const uint8_t i_dsurmod = i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
-    const uint8_t i_lfeon = bs_read( &s, 1 );
+    const uint8_t i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
+    bs->i_lfeon = bs_read( &s, 1 );
 
-    p_header->i_channels_conf = p_acmod[i_acmod];
+    p_header->i_channels_conf = p_acmod[bs->i_acmod];
     p_header->i_chan_mode = 0;
     if( i_dsurmod == 2 )
         p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
-    if( i_acmod == 0 )
+    if( bs->i_acmod == 0 )
         p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
 
-    if( i_lfeon )
+    if( bs->i_lfeon )
         p_header->i_channels_conf |= AOUT_CHAN_LFE;
 
     p_header->i_channels = vlc_popcount(p_header->i_channels_conf);
 
-    const unsigned i_rate_shift = VLC_CLIP(i_bsid, 8, 11) - 8;
-    p_header->i_bitrate = (pi_frmsizcod_bitrates[i_frmsizcod >> 1] * 1000)
+    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
+    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
                         >> i_rate_shift;
-    p_header->i_rate = pi_fscod_samplerates[i_fscod] >> i_rate_shift;
+    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
 
-    p_header->i_size = ppi_frmsizcod_fscod_sizes[i_frmsizcod][2 - i_fscod] * 2;
+    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
+                                                [2 - bs->i_fscod] * 2;
     p_header->i_blocks_per_sync_frame = 6;
     p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
 
@@ -186,19 +202,21 @@ static inline int vlc_a52_header_ParseEac3( vlc_a52_header_t *p_header,
                                             const uint32_t *p_acmod,
                                             const unsigned *pi_fscod_samplerates )
 {
+    struct vlc_a52_bitstream_info *bs = &p_header->bs;
+
     bs_t s;
     bs_init( &s, (void*)p_buf, VLC_A52_HEADER_SIZE );
     bs_skip( &s, 16 );  /* start code */
-    p_header->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
-    p_header->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
+    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
+    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
 
     const uint16_t i_frmsiz = bs_read( &s, 11 );
     if( i_frmsiz < 2 )
         return VLC_EGENERIC;
     p_header->i_size = 2 * (i_frmsiz + 1 );
 
-    const uint8_t i_fscod = bs_read( &s, 2 );
-    if( i_fscod == 0x03 )
+    bs->i_fscod = bs_read( &s, 2 );
+    if( bs->i_fscod == 0x03 )
     {
         const uint8_t i_fscod2 = bs_read( &s, 2 );
         if( i_fscod2 == 0x03 )
@@ -210,18 +228,18 @@ static inline int vlc_a52_header_ParseEac3( vlc_a52_header_t *p_header,
     {
         static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
 
-        p_header->i_rate = pi_fscod_samplerates[i_fscod];
+        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
         p_header->i_blocks_per_sync_frame = pi_numblkscod[bs_read( &s, 2 )];
     }
 
-    const unsigned i_acmod = bs_read( &s, 3 );
-    const unsigned i_lfeon = bs_read1( &s );
+    bs->i_acmod = bs_read( &s, 3 );
+    bs->i_lfeon = bs_read1( &s );
 
-    p_header->i_channels_conf = p_acmod[i_acmod];
+    p_header->i_channels_conf = p_acmod[bs->i_acmod];
     p_header->i_chan_mode = 0;
-    if( i_acmod == 0 )
+    if( bs->i_acmod == 0 )
         p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
-    if( i_lfeon )
+    if( bs->i_lfeon )
         p_header->i_channels_conf |= AOUT_CHAN_LFE;
     p_header->i_channels = vlc_popcount( p_header->i_channels_conf );
     p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate



More information about the vlc-commits mailing list