Mercurial > libavcodec.hg
comparison mlpdec.c @ 9203:5074e89eb15f libavcodec
mlp, truehd: support non 1:1 channel mapping.
author | ramiro |
---|---|
date | Fri, 20 Mar 2009 13:07:09 +0000 |
parents | 42e9c5b34503 |
children | 3c9a424163ee |
comparison
equal
deleted
inserted
replaced
9202:42e9c5b34503 | 9203:5074e89eb15f |
---|---|
56 uint8_t min_channel; | 56 uint8_t min_channel; |
57 //! The index of the last channel coded in this substream. | 57 //! The index of the last channel coded in this substream. |
58 uint8_t max_channel; | 58 uint8_t max_channel; |
59 //! The number of channels input into the rematrix stage. | 59 //! The number of channels input into the rematrix stage. |
60 uint8_t max_matrix_channel; | 60 uint8_t max_matrix_channel; |
61 //! For each channel output by the matrix, the output channel to map it to | |
62 uint8_t ch_assign[MAX_CHANNELS]; | |
61 | 63 |
62 //! The left shift applied to random noise in 0x31ea substreams. | 64 //! The left shift applied to random noise in 0x31ea substreams. |
63 uint8_t noise_shift; | 65 uint8_t noise_shift; |
64 //! The current seed value for the pseudorandom noise generator(s). | 66 //! The current seed value for the pseudorandom noise generator(s). |
65 uint32_t noisegen_seed; | 67 uint32_t noisegen_seed; |
378 substr, tmp); | 380 substr, tmp); |
379 } | 381 } |
380 | 382 |
381 skip_bits(gbp, 16); | 383 skip_bits(gbp, 16); |
382 | 384 |
385 memset(s->ch_assign, 0, sizeof(s->ch_assign)); | |
386 | |
383 for (ch = 0; ch <= s->max_matrix_channel; ch++) { | 387 for (ch = 0; ch <= s->max_matrix_channel; ch++) { |
384 int ch_assign = get_bits(gbp, 6); | 388 int ch_assign = get_bits(gbp, 6); |
385 dprintf(m->avctx, "ch_assign[%d][%d] = %d\n", substr, ch, | 389 dprintf(m->avctx, "ch_assign[%d][%d] = %d\n", substr, ch, |
386 ch_assign); | 390 ch_assign); |
387 if (ch_assign != ch) { | 391 if (ch_assign > s->max_matrix_channel) { |
388 av_log(m->avctx, AV_LOG_ERROR, | 392 av_log(m->avctx, AV_LOG_ERROR, |
389 "Non-1:1 channel assignments are used in this stream. %s\n", | 393 "Assignment of matrix channel %d to invalid output channel %d. %s\n", |
390 sample_message); | 394 ch, ch_assign, sample_message); |
391 return -1; | 395 return -1; |
392 } | 396 } |
397 s->ch_assign[ch_assign] = ch; | |
393 } | 398 } |
394 | 399 |
395 checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); | 400 checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); |
396 | 401 |
397 if (checksum != get_bits(gbp, 8)) | 402 if (checksum != get_bits(gbp, 8)) |
419 cp->codebook = 0; | 424 cp->codebook = 0; |
420 cp->huff_lsbs = 24; | 425 cp->huff_lsbs = 24; |
421 } | 426 } |
422 | 427 |
423 if (substr == m->max_decoded_substream) { | 428 if (substr == m->max_decoded_substream) { |
424 m->avctx->channels = s->max_channel + 1; | 429 m->avctx->channels = s->max_matrix_channel + 1; |
425 } | 430 } |
426 | 431 |
427 return 0; | 432 return 0; |
428 } | 433 } |
429 | 434 |
829 | 834 |
830 static int output_data_internal(MLPDecodeContext *m, unsigned int substr, | 835 static int output_data_internal(MLPDecodeContext *m, unsigned int substr, |
831 uint8_t *data, unsigned int *data_size, int is32) | 836 uint8_t *data, unsigned int *data_size, int is32) |
832 { | 837 { |
833 SubStream *s = &m->substream[substr]; | 838 SubStream *s = &m->substream[substr]; |
834 unsigned int i, ch = 0; | 839 unsigned int i, out_ch = 0; |
835 int32_t *data_32 = (int32_t*) data; | 840 int32_t *data_32 = (int32_t*) data; |
836 int16_t *data_16 = (int16_t*) data; | 841 int16_t *data_16 = (int16_t*) data; |
837 | 842 |
838 if (*data_size < (s->max_channel + 1) * s->blockpos * (is32 ? 4 : 2)) | 843 if (*data_size < (s->max_channel + 1) * s->blockpos * (is32 ? 4 : 2)) |
839 return -1; | 844 return -1; |
840 | 845 |
841 for (i = 0; i < s->blockpos; i++) { | 846 for (i = 0; i < s->blockpos; i++) { |
842 for (ch = 0; ch <= s->max_channel; ch++) { | 847 for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) { |
843 int32_t sample = m->sample_buffer[i][ch] << s->output_shift[ch]; | 848 int mat_ch = s->ch_assign[out_ch]; |
844 s->lossless_check_data ^= (sample & 0xffffff) << ch; | 849 int32_t sample = m->sample_buffer[i][mat_ch] |
850 << s->output_shift[mat_ch]; | |
851 s->lossless_check_data ^= (sample & 0xffffff) << mat_ch; | |
845 if (is32) *data_32++ = sample << 8; | 852 if (is32) *data_32++ = sample << 8; |
846 else *data_16++ = sample >> 8; | 853 else *data_16++ = sample >> 8; |
847 } | 854 } |
848 } | 855 } |
849 | 856 |
850 *data_size = i * ch * (is32 ? 4 : 2); | 857 *data_size = i * out_ch * (is32 ? 4 : 2); |
851 | 858 |
852 return 0; | 859 return 0; |
853 } | 860 } |
854 | 861 |
855 static int output_data(MLPDecodeContext *m, unsigned int substr, | 862 static int output_data(MLPDecodeContext *m, unsigned int substr, |