Commit b3261eaa authored by ramiro's avatar ramiro

mlp, truehd: support non 1:1 channel mapping.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18074 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent d00a5965
...@@ -58,6 +58,8 @@ typedef struct SubStream { ...@@ -58,6 +58,8 @@ typedef struct SubStream {
uint8_t max_channel; uint8_t max_channel;
//! The number of channels input into the rematrix stage. //! The number of channels input into the rematrix stage.
uint8_t max_matrix_channel; uint8_t max_matrix_channel;
//! For each channel output by the matrix, the output channel to map it to
uint8_t ch_assign[MAX_CHANNELS];
//! The left shift applied to random noise in 0x31ea substreams. //! The left shift applied to random noise in 0x31ea substreams.
uint8_t noise_shift; uint8_t noise_shift;
...@@ -380,16 +382,19 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, ...@@ -380,16 +382,19 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
skip_bits(gbp, 16); skip_bits(gbp, 16);
memset(s->ch_assign, 0, sizeof(s->ch_assign));
for (ch = 0; ch <= s->max_matrix_channel; ch++) { for (ch = 0; ch <= s->max_matrix_channel; ch++) {
int ch_assign = get_bits(gbp, 6); int ch_assign = get_bits(gbp, 6);
dprintf(m->avctx, "ch_assign[%d][%d] = %d\n", substr, ch, dprintf(m->avctx, "ch_assign[%d][%d] = %d\n", substr, ch,
ch_assign); ch_assign);
if (ch_assign != ch) { if (ch_assign > s->max_matrix_channel) {
av_log(m->avctx, AV_LOG_ERROR, av_log(m->avctx, AV_LOG_ERROR,
"Non-1:1 channel assignments are used in this stream. %s\n", "Assignment of matrix channel %d to invalid output channel %d. %s\n",
sample_message); ch, ch_assign, sample_message);
return -1; return -1;
} }
s->ch_assign[ch_assign] = ch;
} }
checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count);
...@@ -421,7 +426,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, ...@@ -421,7 +426,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
} }
if (substr == m->max_decoded_substream) { if (substr == m->max_decoded_substream) {
m->avctx->channels = s->max_channel + 1; m->avctx->channels = s->max_matrix_channel + 1;
} }
return 0; return 0;
...@@ -831,7 +836,7 @@ static int output_data_internal(MLPDecodeContext *m, unsigned int substr, ...@@ -831,7 +836,7 @@ static int output_data_internal(MLPDecodeContext *m, unsigned int substr,
uint8_t *data, unsigned int *data_size, int is32) uint8_t *data, unsigned int *data_size, int is32)
{ {
SubStream *s = &m->substream[substr]; SubStream *s = &m->substream[substr];
unsigned int i, ch = 0; unsigned int i, out_ch = 0;
int32_t *data_32 = (int32_t*) data; int32_t *data_32 = (int32_t*) data;
int16_t *data_16 = (int16_t*) data; int16_t *data_16 = (int16_t*) data;
...@@ -839,15 +844,17 @@ static int output_data_internal(MLPDecodeContext *m, unsigned int substr, ...@@ -839,15 +844,17 @@ static int output_data_internal(MLPDecodeContext *m, unsigned int substr,
return -1; return -1;
for (i = 0; i < s->blockpos; i++) { for (i = 0; i < s->blockpos; i++) {
for (ch = 0; ch <= s->max_channel; ch++) { for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) {
int32_t sample = m->sample_buffer[i][ch] << s->output_shift[ch]; int mat_ch = s->ch_assign[out_ch];
s->lossless_check_data ^= (sample & 0xffffff) << ch; int32_t sample = m->sample_buffer[i][mat_ch]
<< s->output_shift[mat_ch];
s->lossless_check_data ^= (sample & 0xffffff) << mat_ch;
if (is32) *data_32++ = sample << 8; if (is32) *data_32++ = sample << 8;
else *data_16++ = sample >> 8; else *data_16++ = sample >> 8;
} }
} }
*data_size = i * ch * (is32 ? 4 : 2); *data_size = i * out_ch * (is32 ? 4 : 2);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment