summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libdts/xine_dts_decoder.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/libdts/xine_dts_decoder.c b/src/libdts/xine_dts_decoder.c
index 6573d5ed0..2b5bedb83 100644
--- a/src/libdts/xine_dts_decoder.c
+++ b/src/libdts/xine_dts_decoder.c
@@ -207,19 +207,27 @@ static void dts_decode_frame (dts_decoder_t *this, int64_t pts, int preview_mode
audio_buffer->num_frames = this->ac5_pcm_length;
- data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */
- data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */
- data_out[4] = ac5_spdif_type; /* DTS data */
- data_out[5] = 0; /* Unknown */
- data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */
- data_out[7] = ((this->ac5_length ) >> 5) & 0xff;
-
- if( this->ac5_pcm_length ) {
- if( this->ac5_pcm_length % 2) {
- swab(data_in, &data_out[8], this->ac5_length );
- } else {
- swab(data_in, &data_out[8], this->ac5_length + 1);
+ // Checking if AC5 data plus IEC958 header will fit into frames samples data
+ if ( this->ac5_length + 8 <= this->ac5_pcm_length * 2 * 2 ) {
+ data_out[0] = 0x72; data_out[1] = 0xf8; /* spdif syncword */
+ data_out[2] = 0x1f; data_out[3] = 0x4e; /* .............. */
+ data_out[4] = ac5_spdif_type; /* DTS data */
+ data_out[5] = 0; /* Unknown */
+ data_out[6] = (this->ac5_length << 3) & 0xff; /* ac5_length * 8 */
+ data_out[7] = ((this->ac5_length ) >> 5) & 0xff;
+
+ if( this->ac5_pcm_length ) {
+ if( this->ac5_pcm_length % 2) {
+ swab(data_in, &data_out[8], this->ac5_length );
+ } else {
+ swab(data_in, &data_out[8], this->ac5_length + 1);
+ }
}
+ // Transmit it without header otherwise, receivers will autodetect DTS
+ } else {
+ lprintf("AC5 data is too large (%i > %i), sending without IEC958 header\n",
+ this->ac5_length + 8, this->ac5_pcm_length * 2 * 2);
+ memcpy(data_out, data_in, this->ac5_length);
}
} else {
/* Software decode */