[vlc-commits] converter/tospdif: convert DTS 14bit to DTS 16bit
Thomas Guillem
git at videolan.org
Wed Jul 11 14:21:21 CEST 2018
vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jul 11 13:01:40 2018 +0200| [4734586236df9074c08324226a6b77b829cf6ed2] | committer: Thomas Guillem
converter/tospdif: convert DTS 14bit to DTS 16bit
DTS inside WAV (@44.1kHZ) use 14bits words and have a fsize of 4096 bytes for
1024 samples. This means there is no room to put the IEC61937 header (IEC frame
size = 4096 = fsize = 1024 samples x 4).
Before this commit, we sent the IEC61937 frame without the header, this worked
only for some receivers.
This commit converts the 14bit sample to 16bit in order to have room for the
IEC61937 header. The new fsize is 4096*14/16 = 3584, so there is room for the 8
bytes header (plus 0 padding until 4096).
(cherry picked from commit 7af9abbecb62f8b77640786a222a78ea6ee29cf2)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=4734586236df9074c08324226a6b77b829cf6ed2
---
modules/audio_filter/converter/tospdif.c | 62 +++++++++++++++++++-------------
1 file changed, 37 insertions(+), 25 deletions(-)
diff --git a/modules/audio_filter/converter/tospdif.c b/modules/audio_filter/converter/tospdif.c
index 9ca72441c5..f228b2091d 100644
--- a/modules/audio_filter/converter/tospdif.c
+++ b/modules/audio_filter/converter/tospdif.c
@@ -194,21 +194,19 @@ static void write_finalize( filter_t *p_filter, uint16_t i_data_type,
{
filter_sys_t *p_sys = p_filter->p_sys;
assert( p_sys->p_out_buf != NULL );
+ assert( i_data_type != 0 );
uint8_t *p_out = p_sys->p_out_buf->p_buffer;
/* S/PDIF header */
- if( i_data_type != 0 )
- {
- assert( p_sys->i_out_offset > SPDIF_HEADER_SIZE );
- assert( i_length_mul == 1 || i_length_mul == 8 );
-
- set_16( p_filter, &p_out[0], 0xf872 ); /* syncword 1 */
- set_16( p_filter, &p_out[2], 0x4e1f ); /* syncword 2 */
- set_16( p_filter, &p_out[4], i_data_type ); /* data type */
- /* length in bits or bytes */
- set_16( p_filter, &p_out[6],
- ( p_sys->i_out_offset - SPDIF_HEADER_SIZE ) * i_length_mul );
- }
+ assert( p_sys->i_out_offset > SPDIF_HEADER_SIZE );
+ assert( i_length_mul == 1 || i_length_mul == 8 );
+
+ set_16( p_filter, &p_out[0], 0xf872 ); /* syncword 1 */
+ set_16( p_filter, &p_out[2], 0x4e1f ); /* syncword 2 */
+ set_16( p_filter, &p_out[4], i_data_type ); /* data type */
+ /* length in bits or bytes */
+ set_16( p_filter, &p_out[6],
+ ( p_sys->i_out_offset - SPDIF_HEADER_SIZE ) * i_length_mul );
/* 0 padding */
if( p_sys->i_out_offset < p_sys->p_out_buf->i_buffer )
@@ -388,6 +386,7 @@ static int write_buffer_truehd( filter_t *p_filter, block_t *p_in_buf )
static int write_buffer_dts( filter_t *p_filter, block_t *p_in_buf )
{
+ filter_sys_t *p_sys = p_filter->p_sys;
uint16_t i_data_type;
/* Only send the DTS core part */
@@ -415,23 +414,36 @@ static int write_buffer_dts( filter_t *p_filter, block_t *p_in_buf )
return SPDIF_ERROR;
}
- if( p_in_buf->i_buffer == p_in_buf->i_nb_samples * 4 )
+ if( core.b_14b )
{
- /* No enough room to put the S/PDIF header. This is the case for DTS
- * inside WAV. */
- i_data_type = 0;
- }
- else if( p_in_buf->i_buffer + SPDIF_HEADER_SIZE > p_in_buf->i_nb_samples * 4 )
- return SPDIF_ERROR;
+ if( p_in_buf->i_buffer > p_in_buf->i_nb_samples * 4 )
+ return SPDIF_ERROR;
+ if( write_init( p_filter, p_in_buf, p_in_buf->i_nb_samples * 4,
+ p_in_buf->i_nb_samples ) )
+ return SPDIF_ERROR;
- if( write_init( p_filter, p_in_buf, p_in_buf->i_nb_samples * 4,
- p_in_buf->i_nb_samples ) )
- return SPDIF_ERROR;
+ uint8_t *p_out = &p_sys->p_out_buf->p_buffer[p_sys->i_out_offset];
+ ssize_t i_size = vlc_dts_header_Convert14b16b( p_out,
+ p_sys->p_out_buf->i_buffer - p_sys->i_out_offset,
+ p_in_buf->p_buffer, p_in_buf->i_buffer,
+ p_filter->fmt_out.audio.i_format == VLC_CODEC_SPDIFL );
+ if( i_size < 0 )
+ return SPDIF_ERROR;
- if( i_data_type == 0 )
- p_filter->p_sys->i_out_offset = 0;
+ p_sys->i_out_offset += i_size;
+ p_sys->p_out_buf->i_length += p_in_buf->i_length;
+ }
+ else
+ {
+ if( p_in_buf->i_buffer + SPDIF_HEADER_SIZE > p_in_buf->i_nb_samples * 4 )
+ return SPDIF_ERROR;
+
+ if( write_init( p_filter, p_in_buf, p_in_buf->i_nb_samples * 4,
+ p_in_buf->i_nb_samples ) )
+ return SPDIF_ERROR;
+ write_buffer( p_filter, p_in_buf );
+ }
- write_buffer( p_filter, p_in_buf );
write_finalize( p_filter, i_data_type, 8 /* in bits */ );
return SPDIF_SUCCESS;
}
More information about the vlc-commits
mailing list