Mercurial > libavcodec.hg
comparison mlpdec.c @ 11703:c2461b6b94c9 libavcodec
mlpdec: Allocate channel decoding parameters for each substream. Some file
was encountered with a channel range that overlapped the previous substreams,
and the code assumed no such overlap was possible.
Patch by Nick Brereton <nick at nbrereton dot net>
author | ramiro |
---|---|
date | Tue, 11 May 2010 01:44:52 +0000 |
parents | 7dd2a45249a9 |
children | b57e32bcaa86 |
comparison
equal
deleted
inserted
replaced
11702:21fd8b4dfab9 | 11703:c2461b6b94c9 |
---|---|
60 //! The number of channels input into the rematrix stage. | 60 //! The number of channels input into the rematrix stage. |
61 uint8_t max_matrix_channel; | 61 uint8_t max_matrix_channel; |
62 //! For each channel output by the matrix, the output channel to map it to | 62 //! For each channel output by the matrix, the output channel to map it to |
63 uint8_t ch_assign[MAX_CHANNELS]; | 63 uint8_t ch_assign[MAX_CHANNELS]; |
64 | 64 |
65 ChannelParams channel_params[MAX_CHANNELS]; | |
66 | |
65 //! The left shift applied to random noise in 0x31ea substreams. | 67 //! The left shift applied to random noise in 0x31ea substreams. |
66 uint8_t noise_shift; | 68 uint8_t noise_shift; |
67 //! The current seed value for the pseudorandom noise generator(s). | 69 //! The current seed value for the pseudorandom noise generator(s). |
68 uint32_t noisegen_seed; | 70 uint32_t noisegen_seed; |
69 | 71 |
135 //! next power of two above the number of samples in each frame | 137 //! next power of two above the number of samples in each frame |
136 int access_unit_size_pow2; | 138 int access_unit_size_pow2; |
137 | 139 |
138 SubStream substream[MAX_SUBSTREAMS]; | 140 SubStream substream[MAX_SUBSTREAMS]; |
139 | 141 |
140 ChannelParams channel_params[MAX_CHANNELS]; | |
141 | |
142 int matrix_changed; | 142 int matrix_changed; |
143 int filter_changed[MAX_CHANNELS][NUM_FILTERS]; | 143 int filter_changed[MAX_CHANNELS][NUM_FILTERS]; |
144 | 144 |
145 int8_t noise_buffer[MAX_BLOCKSIZE_POW2]; | 145 int8_t noise_buffer[MAX_BLOCKSIZE_POW2]; |
146 int8_t bypassed_lsbs[MAX_BLOCKSIZE][MAX_CHANNELS]; | 146 int8_t bypassed_lsbs[MAX_BLOCKSIZE][MAX_CHANNELS]; |
171 } | 171 } |
172 | 172 |
173 static inline int32_t calculate_sign_huff(MLPDecodeContext *m, | 173 static inline int32_t calculate_sign_huff(MLPDecodeContext *m, |
174 unsigned int substr, unsigned int ch) | 174 unsigned int substr, unsigned int ch) |
175 { | 175 { |
176 ChannelParams *cp = &m->channel_params[ch]; | 176 SubStream *s = &m->substream[substr]; |
177 SubStream *s = &m->substream[substr]; | 177 ChannelParams *cp = &s->channel_params[ch]; |
178 int lsb_bits = cp->huff_lsbs - s->quant_step_size[ch]; | 178 int lsb_bits = cp->huff_lsbs - s->quant_step_size[ch]; |
179 int sign_shift = lsb_bits + (cp->codebook ? 2 - cp->codebook : -1); | 179 int sign_shift = lsb_bits + (cp->codebook ? 2 - cp->codebook : -1); |
180 int32_t sign_huff_offset = cp->huff_offset; | 180 int32_t sign_huff_offset = cp->huff_offset; |
181 | 181 |
182 if (cp->codebook > 0) | 182 if (cp->codebook > 0) |
200 for (mat = 0; mat < s->num_primitive_matrices; mat++) | 200 for (mat = 0; mat < s->num_primitive_matrices; mat++) |
201 if (s->lsb_bypass[mat]) | 201 if (s->lsb_bypass[mat]) |
202 m->bypassed_lsbs[pos + s->blockpos][mat] = get_bits1(gbp); | 202 m->bypassed_lsbs[pos + s->blockpos][mat] = get_bits1(gbp); |
203 | 203 |
204 for (channel = s->min_channel; channel <= s->max_channel; channel++) { | 204 for (channel = s->min_channel; channel <= s->max_channel; channel++) { |
205 ChannelParams *cp = &m->channel_params[channel]; | 205 ChannelParams *cp = &s->channel_params[channel]; |
206 int codebook = cp->codebook; | 206 int codebook = cp->codebook; |
207 int quant_step_size = s->quant_step_size[channel]; | 207 int quant_step_size = s->quant_step_size[channel]; |
208 int lsb_bits = cp->huff_lsbs - quant_step_size; | 208 int lsb_bits = cp->huff_lsbs - quant_step_size; |
209 int result = 0; | 209 int result = 0; |
210 | 210 |
448 | 448 |
449 memset(s->output_shift , 0, sizeof(s->output_shift )); | 449 memset(s->output_shift , 0, sizeof(s->output_shift )); |
450 memset(s->quant_step_size, 0, sizeof(s->quant_step_size)); | 450 memset(s->quant_step_size, 0, sizeof(s->quant_step_size)); |
451 | 451 |
452 for (ch = s->min_channel; ch <= s->max_channel; ch++) { | 452 for (ch = s->min_channel; ch <= s->max_channel; ch++) { |
453 ChannelParams *cp = &m->channel_params[ch]; | 453 ChannelParams *cp = &s->channel_params[ch]; |
454 cp->filter_params[FIR].order = 0; | 454 cp->filter_params[FIR].order = 0; |
455 cp->filter_params[IIR].order = 0; | 455 cp->filter_params[IIR].order = 0; |
456 cp->filter_params[FIR].shift = 0; | 456 cp->filter_params[FIR].shift = 0; |
457 cp->filter_params[IIR].shift = 0; | 457 cp->filter_params[IIR].shift = 0; |
458 | 458 |
470 } | 470 } |
471 | 471 |
472 /** Read parameters for one of the prediction filters. */ | 472 /** Read parameters for one of the prediction filters. */ |
473 | 473 |
474 static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, | 474 static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, |
475 unsigned int channel, unsigned int filter) | 475 unsigned int substr, unsigned int channel, |
476 { | 476 unsigned int filter) |
477 FilterParams *fp = &m->channel_params[channel].filter_params[filter]; | 477 { |
478 SubStream *s = &m->substream[substr]; | |
479 FilterParams *fp = &s->channel_params[channel].filter_params[filter]; | |
478 const int max_order = filter ? MAX_IIR_ORDER : MAX_FIR_ORDER; | 480 const int max_order = filter ? MAX_IIR_ORDER : MAX_FIR_ORDER; |
479 const char fchar = filter ? 'I' : 'F'; | 481 const char fchar = filter ? 'I' : 'F'; |
480 int i, order; | 482 int i, order; |
481 | 483 |
482 // Filter is 0 for FIR, 1 for IIR. | 484 // Filter is 0 for FIR, 1 for IIR. |
495 return -1; | 497 return -1; |
496 } | 498 } |
497 fp->order = order; | 499 fp->order = order; |
498 | 500 |
499 if (order > 0) { | 501 if (order > 0) { |
500 int32_t *fcoeff = m->channel_params[channel].coeff[filter]; | 502 int32_t *fcoeff = s->channel_params[channel].coeff[filter]; |
501 int coeff_bits, coeff_shift; | 503 int coeff_bits, coeff_shift; |
502 | 504 |
503 fp->shift = get_bits(gbp, 4); | 505 fp->shift = get_bits(gbp, 4); |
504 | 506 |
505 coeff_bits = get_bits(gbp, 5); | 507 coeff_bits = get_bits(gbp, 5); |
608 /** Read channel parameters. */ | 610 /** Read channel parameters. */ |
609 | 611 |
610 static int read_channel_params(MLPDecodeContext *m, unsigned int substr, | 612 static int read_channel_params(MLPDecodeContext *m, unsigned int substr, |
611 GetBitContext *gbp, unsigned int ch) | 613 GetBitContext *gbp, unsigned int ch) |
612 { | 614 { |
613 ChannelParams *cp = &m->channel_params[ch]; | 615 SubStream *s = &m->substream[substr]; |
616 ChannelParams *cp = &s->channel_params[ch]; | |
614 FilterParams *fir = &cp->filter_params[FIR]; | 617 FilterParams *fir = &cp->filter_params[FIR]; |
615 FilterParams *iir = &cp->filter_params[IIR]; | 618 FilterParams *iir = &cp->filter_params[IIR]; |
616 SubStream *s = &m->substream[substr]; | |
617 | 619 |
618 if (s->param_presence_flags & PARAM_FIR) | 620 if (s->param_presence_flags & PARAM_FIR) |
619 if (get_bits1(gbp)) | 621 if (get_bits1(gbp)) |
620 if (read_filter_params(m, gbp, ch, FIR) < 0) | 622 if (read_filter_params(m, gbp, substr, ch, FIR) < 0) |
621 return -1; | 623 return -1; |
622 | 624 |
623 if (s->param_presence_flags & PARAM_IIR) | 625 if (s->param_presence_flags & PARAM_IIR) |
624 if (get_bits1(gbp)) | 626 if (get_bits1(gbp)) |
625 if (read_filter_params(m, gbp, ch, IIR) < 0) | 627 if (read_filter_params(m, gbp, substr, ch, IIR) < 0) |
626 return -1; | 628 return -1; |
627 | 629 |
628 if (fir->order + iir->order > 8) { | 630 if (fir->order + iir->order > 8) { |
629 av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\n"); | 631 av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\n"); |
630 return -1; | 632 return -1; |
695 s->output_shift[ch] = get_sbits(gbp, 4); | 697 s->output_shift[ch] = get_sbits(gbp, 4); |
696 | 698 |
697 if (s->param_presence_flags & PARAM_QUANTSTEP) | 699 if (s->param_presence_flags & PARAM_QUANTSTEP) |
698 if (get_bits1(gbp)) | 700 if (get_bits1(gbp)) |
699 for (ch = 0; ch <= s->max_channel; ch++) { | 701 for (ch = 0; ch <= s->max_channel; ch++) { |
700 ChannelParams *cp = &m->channel_params[ch]; | 702 ChannelParams *cp = &s->channel_params[ch]; |
701 | 703 |
702 s->quant_step_size[ch] = get_bits(gbp, 4); | 704 s->quant_step_size[ch] = get_bits(gbp, 4); |
703 | 705 |
704 cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); | 706 cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); |
705 } | 707 } |
719 | 721 |
720 static void filter_channel(MLPDecodeContext *m, unsigned int substr, | 722 static void filter_channel(MLPDecodeContext *m, unsigned int substr, |
721 unsigned int channel) | 723 unsigned int channel) |
722 { | 724 { |
723 SubStream *s = &m->substream[substr]; | 725 SubStream *s = &m->substream[substr]; |
724 const int32_t *fircoeff = m->channel_params[channel].coeff[FIR]; | 726 const int32_t *fircoeff = s->channel_params[channel].coeff[FIR]; |
725 int32_t state_buffer[NUM_FILTERS][MAX_BLOCKSIZE + MAX_FIR_ORDER]; | 727 int32_t state_buffer[NUM_FILTERS][MAX_BLOCKSIZE + MAX_FIR_ORDER]; |
726 int32_t *firbuf = state_buffer[FIR] + MAX_BLOCKSIZE; | 728 int32_t *firbuf = state_buffer[FIR] + MAX_BLOCKSIZE; |
727 int32_t *iirbuf = state_buffer[IIR] + MAX_BLOCKSIZE; | 729 int32_t *iirbuf = state_buffer[IIR] + MAX_BLOCKSIZE; |
728 FilterParams *fir = &m->channel_params[channel].filter_params[FIR]; | 730 FilterParams *fir = &s->channel_params[channel].filter_params[FIR]; |
729 FilterParams *iir = &m->channel_params[channel].filter_params[IIR]; | 731 FilterParams *iir = &s->channel_params[channel].filter_params[IIR]; |
730 unsigned int filter_shift = fir->shift; | 732 unsigned int filter_shift = fir->shift; |
731 int32_t mask = MSB_MASK(s->quant_step_size[channel]); | 733 int32_t mask = MSB_MASK(s->quant_step_size[channel]); |
732 | 734 |
733 memcpy(firbuf, fir->state, MAX_FIR_ORDER * sizeof(int32_t)); | 735 memcpy(firbuf, fir->state, MAX_FIR_ORDER * sizeof(int32_t)); |
734 memcpy(iirbuf, iir->state, MAX_IIR_ORDER * sizeof(int32_t)); | 736 memcpy(iirbuf, iir->state, MAX_IIR_ORDER * sizeof(int32_t)); |