[vlc-commits] packetizer: dts: test and return sync word

Francois Cartegnie git at videolan.org
Mon Mar 11 19:39:10 CET 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Mar 11 15:10:49 2019 +0100| [e23d066b5183f6cf6d75f1fbab5d938bd4dc5452] | committer: Francois Cartegnie

packetizer: dts: test and return sync word

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

 modules/audio_filter/converter/tospdif.c |  3 +-
 modules/packetizer/dts.c                 |  4 +-
 modules/packetizer/dts_header.c          | 63 +++++++++++++-------------------
 modules/packetizer/dts_header.h          | 13 ++++++-
 4 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/modules/audio_filter/converter/tospdif.c b/modules/audio_filter/converter/tospdif.c
index 9e9213f660..c468af79d6 100644
--- a/modules/audio_filter/converter/tospdif.c
+++ b/modules/audio_filter/converter/tospdif.c
@@ -414,7 +414,8 @@ static int write_buffer_dts( filter_t *p_filter, block_t *p_in_buf )
         return SPDIF_ERROR;
     }
 
-    if( core.b_14b )
+    if( core.syncword == DTS_SYNC_CORE_14BITS_BE ||
+        core.syncword == DTS_SYNC_CORE_14BITS_LE )
     {
         if( p_in_buf->i_buffer > p_in_buf->i_nb_samples * 4 )
             return SPDIF_ERROR;
diff --git a/modules/packetizer/dts.c b/modules/packetizer/dts.c
index 89cb202523..c4204a6e31 100644
--- a/modules/packetizer/dts.c
+++ b/modules/packetizer/dts.c
@@ -208,7 +208,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
                 break;
             }
 
-            if( p_sys->dts.b_substream  )
+            if( p_sys->dts.syncword == DTS_SYNC_SUBSTREAM )
             {
                 msg_Warn( p_dec, "substream without the paired core stream, "
                           "skip it" );
@@ -275,7 +275,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
                     vlc_dts_header_t next_header;
                     if( vlc_dts_header_Parse( &next_header, p_header,
                                               VLC_DTS_HEADER_SIZE )
-                        == VLC_SUCCESS && next_header.b_substream )
+                        == VLC_SUCCESS && next_header.syncword == DTS_SYNC_SUBSTREAM )
                     {
                         p_dec->fmt_out.i_profile = PROFILE_DTS_HD;
                         p_sys->i_input_size += next_header.i_frame_size;
diff --git a/modules/packetizer/dts_header.c b/modules/packetizer/dts_header.c
index e1c905c7e2..3f24b1d602 100644
--- a/modules/packetizer/dts_header.c
+++ b/modules/packetizer/dts_header.c
@@ -94,42 +94,32 @@ static int Buf14To16( uint8_t *p_out, const uint8_t *p_in, int i_in, int i_le,
     return i_out;
 }
 
-enum dts_bitsteam_type {
-    DTS_SYNC_CORE_BE,
-    DTS_SYNC_CORE_LE,
-    DTS_SYNC_CORE_14BITS_BE,
-    DTS_SYNC_CORE_14BITS_LE,
-    DTS_SYNC_SUBSTREAM,
-};
-
-static bool dts_header_IsSync( const uint8_t *p_buf,
-                               enum dts_bitsteam_type *p_bitstream_type )
+static enum vlc_dts_syncword_e dts_header_getSyncword( const uint8_t *p_buf )
 {
     if( memcmp( p_buf, "\x7F\xFE\x80\x01", 4 ) == 0 )
-        *p_bitstream_type = DTS_SYNC_CORE_BE;
+        return DTS_SYNC_CORE_BE;
     else
     if( memcmp( p_buf, "\xFE\x7F\x01\x80", 4 ) == 0 )
-        *p_bitstream_type = DTS_SYNC_CORE_LE;
+        return DTS_SYNC_CORE_LE;
     else
     if( memcmp( p_buf, "\x64\x58\x20\x25", 4 ) == 0 )
-        *p_bitstream_type = DTS_SYNC_SUBSTREAM;
+        return DTS_SYNC_SUBSTREAM;
     else
     if( memcmp( p_buf, "\x1F\xFF\xE8\x00", 4 ) == 0
      && p_buf[4] == 0x07 && (p_buf[5] & 0xf0) == 0xf0 )
-        *p_bitstream_type = DTS_SYNC_CORE_14BITS_BE;
+        return DTS_SYNC_CORE_14BITS_BE;
     else
     if( memcmp( p_buf, "\xFF\x1F\x00\xE8", 4 ) == 0
      && (p_buf[4] & 0xf0) == 0xf0 && p_buf[5] == 0x07 )
-        *p_bitstream_type = DTS_SYNC_CORE_14BITS_LE;
+        return DTS_SYNC_CORE_14BITS_LE;
     else
-        return false;
-    return true;
+        return DTS_SYNC_NONE;
 }
 
 bool vlc_dts_header_IsSync( const void *p_buf, size_t i_buf )
 {
     return i_buf >= 6
-        && dts_header_IsSync( p_buf, &(enum dts_bitsteam_type) { 0 } );
+        && dts_header_getSyncword( p_buf ) != DTS_SYNC_NONE;
 }
 
 static unsigned int dca_get_samplerate( uint8_t i_sfreq )
@@ -262,13 +252,13 @@ static int dts_header_ParseSubstream( vlc_dts_header_t *p_header,
         nuBits4ExSSFsize = bs_read( &s, 20 );
     }
     memset( p_header, 0, sizeof(*p_header) );
-    p_header->b_substream = true;
+    p_header->syncword = DTS_SYNC_SUBSTREAM;
     p_header->i_frame_size = nuBits4ExSSFsize + 1;
     return VLC_SUCCESS;
 }
 
 static int dts_header_ParseCore( vlc_dts_header_t *p_header,
-                                 const void *p_buffer, bool b_14b )
+                                 const void *p_buffer)
 {
     bs_t s;
     bs_init( &s, p_buffer, VLC_DTS_HEADER_SIZE );
@@ -288,12 +278,12 @@ static int dts_header_ParseCore( vlc_dts_header_t *p_header,
 
     bool b_lfe = i_lff == 1 || i_lff == 2;
 
-    p_header->b_substream = false;
-    p_header->b_14b = b_14b;
     p_header->i_rate = dca_get_samplerate( i_sfreq );
     p_header->i_bitrate = dca_get_bitrate( i_rate );
-    p_header->i_frame_size = !b_14b ? ( i_fsize + 1 )
-                                    : ( i_fsize + 1 ) * 16 / 14;
+    p_header->i_frame_size = i_fsize + 1;
+    if( p_header->syncword == DTS_SYNC_CORE_14BITS_LE ||
+        p_header->syncword == DTS_SYNC_CORE_14BITS_BE )
+        p_header->i_frame_size = p_header->i_frame_size * 16 / 14;
     /* See ETSI TS 102 114, table 5-2 */
     p_header->i_frame_length = (i_nblks + 1) * 32;
     p_header->i_chan_mode = 0;
@@ -315,47 +305,46 @@ ssize_t vlc_dts_header_Convert14b16b( void *p_dst, size_t i_dst,
     if( i_src <= VLC_DTS_HEADER_SIZE || i_size > i_dst )
         return -1;
 
-    enum dts_bitsteam_type bitstream_type;
-    if( !dts_header_IsSync( p_src, &bitstream_type ) )
+    enum vlc_dts_syncword_e syncword = dts_header_getSyncword( p_src );
+    if( syncword == DTS_SYNC_NONE )
         return -1;
 
-    if( bitstream_type != DTS_SYNC_CORE_14BITS_BE
-     && bitstream_type != DTS_SYNC_CORE_14BITS_LE )
+    if( syncword != DTS_SYNC_CORE_14BITS_BE
+     && syncword != DTS_SYNC_CORE_14BITS_LE )
         return -1;
 
     int i_ret = Buf14To16( p_dst, p_src, i_src,
-                           bitstream_type == DTS_SYNC_CORE_14BITS_LE, b_out_le );
+                           syncword == DTS_SYNC_CORE_14BITS_LE, b_out_le );
     return i_ret;
 }
 
 int vlc_dts_header_Parse( vlc_dts_header_t *p_header,
                           const void *p_buffer, size_t i_buffer)
 {
-    enum dts_bitsteam_type bitstream_type;
-
     if( i_buffer < VLC_DTS_HEADER_SIZE )
         return VLC_EGENERIC;
 
-    if( !dts_header_IsSync( p_buffer, &bitstream_type ) )
+    p_header->syncword = dts_header_getSyncword( p_buffer );
+    if( p_header->syncword == DTS_SYNC_NONE )
         return VLC_EGENERIC;
 
-    switch( bitstream_type )
+    switch( p_header->syncword )
     {
         case DTS_SYNC_CORE_LE:
         {
             uint8_t conv_buf[VLC_DTS_HEADER_SIZE];
             BufLeToBe( conv_buf, p_buffer, VLC_DTS_HEADER_SIZE );
-            return dts_header_ParseCore( p_header, conv_buf, false );
+            return dts_header_ParseCore( p_header, conv_buf );
         }
         case DTS_SYNC_CORE_BE:
-            return dts_header_ParseCore( p_header, p_buffer, false );
+            return dts_header_ParseCore( p_header, p_buffer );
         case DTS_SYNC_CORE_14BITS_BE:
         case DTS_SYNC_CORE_14BITS_LE:
         {
             uint8_t conv_buf[VLC_DTS_HEADER_SIZE];
             Buf14To16( conv_buf, p_buffer, VLC_DTS_HEADER_SIZE,
-                       bitstream_type == DTS_SYNC_CORE_14BITS_LE, 0 );
-            return dts_header_ParseCore( p_header, conv_buf, true );
+                       p_header->syncword == DTS_SYNC_CORE_14BITS_LE, 0 );
+            return dts_header_ParseCore( p_header, conv_buf );
         }
         case DTS_SYNC_SUBSTREAM:
             return dts_header_ParseSubstream( p_header, p_buffer );
diff --git a/modules/packetizer/dts_header.h b/modules/packetizer/dts_header.h
index 2fa537379d..203cec67b1 100644
--- a/modules/packetizer/dts_header.h
+++ b/modules/packetizer/dts_header.h
@@ -27,10 +27,19 @@
 #define PROFILE_DTS 0
 #define PROFILE_DTS_HD 1
 
+enum vlc_dts_syncword_e
+{
+    DTS_SYNC_NONE = 0,
+    DTS_SYNC_CORE_BE,
+    DTS_SYNC_CORE_LE,
+    DTS_SYNC_CORE_14BITS_BE,
+    DTS_SYNC_CORE_14BITS_LE,
+    DTS_SYNC_SUBSTREAM,
+};
+
 typedef struct
 {
-    bool            b_substream;
-    bool            b_14b;
+    enum vlc_dts_syncword_e syncword;
     unsigned int    i_rate;
     unsigned int    i_bitrate;
     unsigned int    i_frame_size;



More information about the vlc-commits mailing list