37
37
#include "mlp_parser.h"
38
38
#include "mlpdsp.h"
41
42
/** number of bits used for VLC lookup - longest Huffman code is 9 */
45
#define VLC_STATIC_SIZE 64
48
#define VLC_STATIC_SIZE 512
44
51
typedef struct SubStream {
45
52
/// Set if a valid restart header has been read. Otherwise the substream cannot be decoded.
190
197
if (!huff_vlc[0].bits) {
191
198
INIT_VLC_STATIC(&huff_vlc[0], VLC_BITS, 18,
192
199
&ff_mlp_huffman_tables[0][0][1], 2, 1,
193
&ff_mlp_huffman_tables[0][0][0], 2, 1, 512);
200
&ff_mlp_huffman_tables[0][0][0], 2, 1, VLC_STATIC_SIZE);
194
201
INIT_VLC_STATIC(&huff_vlc[1], VLC_BITS, 16,
195
202
&ff_mlp_huffman_tables[1][0][1], 2, 1,
196
&ff_mlp_huffman_tables[1][0][0], 2, 1, 512);
203
&ff_mlp_huffman_tables[1][0][0], 2, 1, VLC_STATIC_SIZE);
197
204
INIT_VLC_STATIC(&huff_vlc[2], VLC_BITS, 15,
198
205
&ff_mlp_huffman_tables[2][0][1], 2, 1,
199
&ff_mlp_huffman_tables[2][0][0], 2, 1, 512);
206
&ff_mlp_huffman_tables[2][0][0], 2, 1, VLC_STATIC_SIZE);
202
209
ff_mlp_init_crc();
353
360
m->avctx->sample_fmt = AV_SAMPLE_FMT_S32;
355
362
m->avctx->sample_fmt = AV_SAMPLE_FMT_S16;
363
m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(m->substream[m->max_decoded_substream].ch_assign,
364
m->substream[m->max_decoded_substream].output_shift,
365
m->substream[m->max_decoded_substream].max_matrix_channel,
366
m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
357
368
m->params_valid = 1;
358
369
for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
581
592
if (substr == m->max_decoded_substream) {
582
593
m->avctx->channels = s->max_matrix_channel + 1;
583
594
m->avctx->channel_layout = s->ch_layout;
595
m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
597
s->max_matrix_channel,
598
m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
813
828
if (s->param_presence_flags & PARAM_OUTSHIFT)
829
if (get_bits1(gbp)) {
815
830
for (ch = 0; ch <= s->max_matrix_channel; ch++)
816
831
s->output_shift[ch] = get_sbits(gbp, 4);
832
if (substr == m->max_decoded_substream)
833
m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
835
s->max_matrix_channel,
836
m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
818
839
if (s->param_presence_flags & PARAM_QUANTSTEP)
819
840
if (get_bits1(gbp))
978
999
static void rematrix_channels(MLPDecodeContext *m, unsigned int substr)
980
1001
SubStream *s = &m->substream[substr];
981
unsigned int mat, src_ch, i;
982
1003
unsigned int maxchan;
984
1005
maxchan = s->max_matrix_channel;
992
1013
for (mat = 0; mat < s->num_primitive_matrices; mat++) {
993
int matrix_noise_shift = s->matrix_noise_shift[mat];
994
1014
unsigned int dest_ch = s->matrix_out_ch[mat];
995
int32_t mask = MSB_MASK(s->quant_step_size[dest_ch]);
996
int32_t *coeffs = s->matrix_coeff[mat];
997
int index = s->num_primitive_matrices - mat;
998
int index2 = 2 * index + 1;
1000
/* TODO: DSPContext? */
1002
for (i = 0; i < s->blockpos; i++) {
1003
int32_t bypassed_lsb = m->bypassed_lsbs[i][mat];
1004
int32_t *samples = m->sample_buffer[i];
1007
for (src_ch = 0; src_ch <= maxchan; src_ch++)
1008
accum += (int64_t) samples[src_ch] * coeffs[src_ch];
1010
if (matrix_noise_shift) {
1011
index &= m->access_unit_size_pow2 - 1;
1012
accum += m->noise_buffer[index] << (matrix_noise_shift + 7);
1016
samples[dest_ch] = ((accum >> 14) & mask) + bypassed_lsb;
1015
m->dsp.mlp_rematrix_channel(&m->sample_buffer[0][0],
1016
s->matrix_coeff[mat],
1017
&m->bypassed_lsbs[0][mat],
1019
s->num_primitive_matrices - mat,
1023
s->matrix_noise_shift[mat],
1024
m->access_unit_size_pow2,
1025
MSB_MASK(s->quant_step_size[dest_ch]));
1026
1034
AVCodecContext *avctx = m->avctx;
1027
1035
SubStream *s = &m->substream[substr];
1028
unsigned int i, out_ch = 0;
1032
1037
int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
1047
1052
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1050
data_32 = (int32_t *)frame->data[0];
1051
data_16 = (int16_t *)frame->data[0];
1053
for (i = 0; i < s->blockpos; i++) {
1054
for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) {
1055
int mat_ch = s->ch_assign[out_ch];
1056
int32_t sample = m->sample_buffer[i][mat_ch]
1057
<< s->output_shift[mat_ch];
1058
s->lossless_check_data ^= (sample & 0xffffff) << mat_ch;
1059
if (is32) *data_32++ = sample << 8;
1060
else *data_16++ = sample >> 8;
1055
s->lossless_check_data = m->dsp.mlp_pack_output(s->lossless_check_data,
1061
s->max_matrix_channel,
1064
1064
/* Update matrix encoding side data */
1065
1065
if ((ret = ff_side_data_update_matrix_encoding(frame, s->matrix_encoding)) < 0)