vlc | branch: master | Thomas Guillem <tho...@gllm.fr> | Tue Jul 10 18:37:30 
2018 +0200| [d701887137e647ecbb0512912b0069367c4bbb80] | 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

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

 modules/packetizer/dts_header.c | 24 ++++++++++++++++++++++++
 modules/packetizer/dts_header.h |  5 +++++
 2 files changed, 29 insertions(+)

diff --git a/modules/packetizer/dts_header.c b/modules/packetizer/dts_header.c
index 36dd8bac5b..943b062036 100644
--- a/modules/packetizer/dts_header.c
+++ b/modules/packetizer/dts_header.c
@@ -286,6 +286,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 +304,29 @@ 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 );
+    if( b_out_le ) /* since Buf14To16 convert to BE */
+        swab( p_dst, p_dst, i_ret );
+    return i_ret;
+}
+
 int vlc_dts_header_Parse( vlc_dts_header_t *p_header,
                           const void *p_buffer, size_t i_buffer)
 {
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 );

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to