[vlc-commits] packetizer/dts_header: add an helper that converts 14bit words to 16bit

Thomas Guillem git at videolan.org
Wed Jul 11 14:21:20 CEST 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jul 10 18:37:30 2018 +0200| [ec6e03632a55b17c3ebd8bce097be277e0d93ec6] | committer: Thomas Guillem

packetizer/dts_header: add an helper that converts 14bit words to 16bit

cf. https://wiki.multimedia.cx/index.php/DTS#14-bit_words

(cherry picked from commit d701887137e647ecbb0512912b0069367c4bbb80)
(cherry picked from commit a5359226bea6501eaef7050d703762301e618238)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/packetizer/dts_header.c | 32 +++++++++++++++++++++++++++++---
 modules/packetizer/dts_header.h |  5 +++++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/modules/packetizer/dts_header.c b/modules/packetizer/dts_header.c
index 36dd8bac5b..7a2b258a97 100644
--- a/modules/packetizer/dts_header.c
+++ b/modules/packetizer/dts_header.c
@@ -45,7 +45,8 @@ static void BufLeToBe( uint8_t *p_out, const uint8_t *p_in, int i_in )
     }
 }
 
-static int Buf14To16( uint8_t *p_out, const uint8_t *p_in, int i_in, int i_le )
+static int Buf14To16( uint8_t *p_out, const uint8_t *p_in, int i_in, int i_le,
+                      int i_out_le )
 {
     unsigned char tmp, cur = 0;
     int bits_in, bits_out = 0;
@@ -77,7 +78,10 @@ static int Buf14To16( uint8_t *p_out, const uint8_t *p_in, int i_in, int i_le )
 
         if( bits_out == 8 )
         {
-            p_out[i_out] = cur;
+            if( i_out % 2 )
+                p_out[i_out - i_out_le] = cur;
+            else
+                p_out[i_out + i_out_le] = cur;
             cur = 0;
             bits_out = 0;
             i_out++;
@@ -286,6 +290,7 @@ 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 )
@@ -303,6 +308,27 @@ static int dts_header_ParseCore( vlc_dts_header_t *p_header,
     return VLC_SUCCESS;
 }
 
+ssize_t vlc_dts_header_Convert14b16b( void *p_dst, size_t i_dst,
+                                      const void *p_src, size_t i_src,
+                                      bool b_out_le )
+{
+    size_t i_size = i_src * 14 / 16;
+    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 ) )
+        return -1;
+
+    if( bitstream_type != DTS_SYNC_CORE_14BITS_BE
+     && bitstream_type != 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 );
+    return i_ret;
+}
+
 int vlc_dts_header_Parse( vlc_dts_header_t *p_header,
                           const void *p_buffer, size_t i_buffer)
 {
@@ -329,7 +355,7 @@ int vlc_dts_header_Parse( vlc_dts_header_t *p_header,
         {
             uint8_t conv_buf[VLC_DTS_HEADER_SIZE];
             Buf14To16( conv_buf, p_buffer, VLC_DTS_HEADER_SIZE,
-                       bitstream_type == DTS_SYNC_CORE_14BITS_LE );
+                       bitstream_type == DTS_SYNC_CORE_14BITS_LE, 0 );
             return dts_header_ParseCore( p_header, conv_buf, true );
         }
         case DTS_SYNC_SUBSTREAM:
diff --git a/modules/packetizer/dts_header.h b/modules/packetizer/dts_header.h
index 6787161cd9..cdf9053ee5 100644
--- a/modules/packetizer/dts_header.h
+++ b/modules/packetizer/dts_header.h
@@ -31,6 +31,7 @@
 typedef struct
 {
     bool            b_substream;
+    bool            b_14b;
     unsigned int    i_rate;
     unsigned int    i_bitrate;
     unsigned int    i_frame_size;
@@ -43,3 +44,7 @@ int     vlc_dts_header_Parse( vlc_dts_header_t *p_header,
                               const void *p_buffer, size_t i_buffer);
 
 bool    vlc_dts_header_IsSync( const void *p_buffer, size_t i_buffer );
+
+ssize_t vlc_dts_header_Convert14b16b( void *p_dst, size_t i_dst,
+                                      const void *p_src, size_t i_src,
+                                      bool b_out_le );



More information about the vlc-commits mailing list