comparison aac.c @ 7539:4fca7939ad48 libavcodec

More OKed hunks of the AAC decoder from SoC
author superdump
date Mon, 11 Aug 2008 11:16:06 +0000
parents a3f7ffdb676d
children 5298e05f931d
comparison
equal deleted inserted replaced
7538:06c291f42d5f 7539:4fca7939ad48
97 97
98 static VLC vlc_scalefactors; 98 static VLC vlc_scalefactors;
99 static VLC vlc_spectral[11]; 99 static VLC vlc_spectral[11];
100 100
101 101
102 /**
103 * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
104 *
105 * @param cpe_map Stereo (Channel Pair Element) map, NULL if stereo bit is not present.
106 * @param sce_map mono (Single Channel Element) map
107 * @param type speaker type/position for these channels
108 */
109 static void decode_channel_map(enum ChannelPosition *cpe_map,
110 enum ChannelPosition *sce_map, enum ChannelPosition type, GetBitContext * gb, int n) {
111 while(n--) {
112 enum ChannelPosition *map = cpe_map && get_bits1(gb) ? cpe_map : sce_map; // stereo or mono map
113 map[get_bits(gb, 4)] = type;
114 }
115 }
116
117 /**
118 * Decode program configuration element; reference: table 4.2.
119 *
120 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one.
121 *
122 * @return Returns error status. 0 - OK, !0 - error
123 */
124 static int decode_pce(AACContext * ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
125 GetBitContext * gb) {
126 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
127
128 skip_bits(gb, 2); // object_type
129
130 ac->m4ac.sampling_index = get_bits(gb, 4);
131 if(ac->m4ac.sampling_index > 11) {
132 av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
133 return -1;
134 }
135 ac->m4ac.sample_rate = ff_mpeg4audio_sample_rates[ac->m4ac.sampling_index];
102 num_front = get_bits(gb, 4); 136 num_front = get_bits(gb, 4);
103 num_side = get_bits(gb, 4); 137 num_side = get_bits(gb, 4);
104 num_back = get_bits(gb, 4); 138 num_back = get_bits(gb, 4);
105 num_lfe = get_bits(gb, 2); 139 num_lfe = get_bits(gb, 2);
106 num_assoc_data = get_bits(gb, 3); 140 num_assoc_data = get_bits(gb, 3);
128 /* comment field, first byte is length */ 162 /* comment field, first byte is length */
129 skip_bits_long(gb, 8 * get_bits(gb, 8)); 163 skip_bits_long(gb, 8 * get_bits(gb, 8));
130 return 0; 164 return 0;
131 } 165 }
132 166
167 /**
168 * Set up channel positions based on a default channel configuration
169 * as specified in table 1.17.
170 *
171 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one.
172 *
173 * @return Returns error status. 0 - OK, !0 - error
174 */
175 static int set_default_channel_config(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
176 int channel_config)
177 {
178 if(channel_config < 1 || channel_config > 7) {
179 av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
180 channel_config);
181 return -1;
182 }
183
184 /* default channel configurations:
185 *
186 * 1ch : front center (mono)
187 * 2ch : L + R (stereo)
188 * 3ch : front center + L + R
189 * 4ch : front center + L + R + back center
190 * 5ch : front center + L + R + back stereo
191 * 6ch : front center + L + R + back stereo + LFE
192 * 7ch : front center + L + R + outer front left + outer front right + back stereo + LFE
193 */
194
195 if(channel_config != 2)
196 new_che_pos[TYPE_SCE][0] = AAC_CHANNEL_FRONT; // front center (or mono)
197 if(channel_config > 1)
198 new_che_pos[TYPE_CPE][0] = AAC_CHANNEL_FRONT; // L + R (or stereo)
199 if(channel_config == 4)
200 new_che_pos[TYPE_SCE][1] = AAC_CHANNEL_BACK; // back center
201 if(channel_config > 4)
202 new_che_pos[TYPE_CPE][(channel_config == 7) + 1]
203 = AAC_CHANNEL_BACK; // back stereo
204 if(channel_config > 5)
205 new_che_pos[TYPE_LFE][0] = AAC_CHANNEL_LFE; // LFE
206 if(channel_config == 7)
207 new_che_pos[TYPE_CPE][1] = AAC_CHANNEL_FRONT; // outer front left + outer front right
208
209 return 0;
210 }
211
212 return -1;
213 }
214
215 if (get_bits1(gb)) // dependsOnCoreCoder
216 skip_bits(gb, 14); // coreCoderDelay
217 extension_flag = get_bits1(gb);
218
219 if(ac->m4ac.object_type == AOT_AAC_SCALABLE ||
220 ac->m4ac.object_type == AOT_ER_AAC_SCALABLE)
221 skip_bits(gb, 3); // layerNr
222
223 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
224 if (channel_config == 0) {
225 skip_bits(gb, 4); // element_instance_tag
226 if((ret = decode_pce(ac, new_che_pos, gb)))
227 return ret;
228 } else {
229 if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
230 return ret;
231 }
232 if((ret = output_configure(ac, ac->che_pos, new_che_pos)))
233 return ret;
234
235 if (extension_flag) {
236 switch (ac->m4ac.object_type) {
237 case AOT_ER_BSAC:
238 skip_bits(gb, 5); // numOfSubFrame
239 skip_bits(gb, 11); // layer_length
240 break;
241 case AOT_ER_AAC_LC:
242 case AOT_ER_AAC_LTP:
243 case AOT_ER_AAC_SCALABLE:
244 case AOT_ER_AAC_LD:
245 skip_bits(gb, 3); /* aacSectionDataResilienceFlag
246 * aacScalefactorDataResilienceFlag
247 * aacSpectralDataResilienceFlag
248 */
249 break;
250 }
251 skip_bits1(gb); // extensionFlag3 (TBD in version 3)
252 }
253 return 0;
254 }
255
256 /**
257 * Decode audio specific configuration; reference: table 1.13.
258 *
259 * @param data pointer to AVCodecContext extradata
260 * @param data_size size of AVCCodecContext extradata
261 *
262 * @return Returns error status. 0 - OK, !0 - error
263 */
264 static int decode_audio_specific_config(AACContext * ac, void *data, int data_size) {
265 GetBitContext gb;
266 int i;
267
268 init_get_bits(&gb, data, data_size * 8);
269
270 if((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0)
271 return -1;
272 if(ac->m4ac.sampling_index > 11) {
273 av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
274 return -1;
275 }
276
277 skip_bits_long(&gb, i);
278
279 switch (ac->m4ac.object_type) {
280 case AOT_AAC_LC:
281 if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config))
282 return -1;
283 break;
284 default:
285 av_log(ac->avccontext, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
286 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type);
287 return -1;
288 }
289 return 0;
290 }
291
133 static av_cold int aac_decode_init(AVCodecContext * avccontext) { 292 static av_cold int aac_decode_init(AVCodecContext * avccontext) {
134 AACContext * ac = avccontext->priv_data; 293 AACContext * ac = avccontext->priv_data;
135 int i; 294 int i;
136 295
137 ac->avccontext = avccontext; 296 ac->avccontext = avccontext;
138 297
139 if (avccontext->extradata_size <= 0 || 298 if (avccontext->extradata_size <= 0 ||
140 decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) 299 decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
141 return -1; 300 return -1;
142 301
302 avccontext->sample_fmt = SAMPLE_FMT_S16;
143 avccontext->sample_rate = ac->m4ac.sample_rate; 303 avccontext->sample_rate = ac->m4ac.sample_rate;
144 avccontext->frame_size = 1024; 304 avccontext->frame_size = 1024;
145 305
146 AAC_INIT_VLC_STATIC( 0, 144); 306 AAC_INIT_VLC_STATIC( 0, 144);
147 AAC_INIT_VLC_STATIC( 1, 114); 307 AAC_INIT_VLC_STATIC( 1, 114);
155 AAC_INIT_VLC_STATIC( 9, 248); 315 AAC_INIT_VLC_STATIC( 9, 248);
156 AAC_INIT_VLC_STATIC(10, 384); 316 AAC_INIT_VLC_STATIC(10, 384);
157 317
158 dsputil_init(&ac->dsp, avccontext); 318 dsputil_init(&ac->dsp, avccontext);
159 319
320 ac->random_state = 0x1f2e3d4c;
321
160 // -1024 - Compensate wrong IMDCT method. 322 // -1024 - Compensate wrong IMDCT method.
161 // 32768 - Required to scale values to the correct range for the bias method 323 // 32768 - Required to scale values to the correct range for the bias method
162 // for float to int16 conversion. 324 // for float to int16 conversion.
163 325
164 if(ac->dsp.float_to_int16 == ff_float_to_int16_c) { 326 if(ac->dsp.float_to_int16 == ff_float_to_int16_c) {
186 ff_mdct_init(&ac->mdct, 11, 1); 348 ff_mdct_init(&ac->mdct, 11, 1);
187 ff_mdct_init(&ac->mdct_small, 8, 1); 349 ff_mdct_init(&ac->mdct_small, 8, 1);
188 return 0; 350 return 0;
189 } 351 }
190 352
353 /**
354 * Skip data_stream_element; reference: table 4.10.
355 */
356 static void skip_data_stream_element(GetBitContext * gb) {
191 int byte_align = get_bits1(gb); 357 int byte_align = get_bits1(gb);
192 int count = get_bits(gb, 8); 358 int count = get_bits(gb, 8);
193 if (count == 255) 359 if (count == 255)
194 count += get_bits(gb, 8); 360 count += get_bits(gb, 8);
195 if (byte_align) 361 if (byte_align)
196 align_get_bits(gb); 362 align_get_bits(gb);
197 skip_bits_long(gb, 8 * count); 363 skip_bits_long(gb, 8 * count);
198 } 364 }
199 365
200 /** 366 /**
367 * Decode Individual Channel Stream info; reference: table 4.6.
368 *
369 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
370 */
371 static int decode_ics_info(AACContext * ac, IndividualChannelStream * ics, GetBitContext * gb, int common_window) {
372 if (get_bits1(gb)) {
373 av_log(ac->avccontext, AV_LOG_ERROR, "Reserved bit set.\n");
374 memset(ics, 0, sizeof(IndividualChannelStream));
375 return -1;
376 }
377 ics->window_sequence[1] = ics->window_sequence[0];
378 ics->window_sequence[0] = get_bits(gb, 2);
379 ics->use_kb_window[1] = ics->use_kb_window[0];
380 ics->use_kb_window[0] = get_bits1(gb);
381 ics->num_window_groups = 1;
382 ics->group_len[0] = 1;
383
384 return 0;
385 }
386
387 /**
201 * inverse quantization 388 * inverse quantization
202 * 389 *
203 * @param a quantized value to be dequantized 390 * @param a quantized value to be dequantized
204 * @return Returns dequantized value. 391 * @return Returns dequantized value.
205 */ 392 */
208 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1]; 395 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
209 else 396 else
210 return cbrtf(fabsf(a)) * a; 397 return cbrtf(fabsf(a)) * a;
211 } 398 }
212 399
400 /**
401 * Decode band types (section_data payload); reference: table 4.46.
402 *
403 * @param band_type array of the used band type
404 * @param band_type_run_end array of the last scalefactor band of a band type run
405 *
406 * @return Returns error status. 0 - OK, !0 - error
407 */
408 static int decode_band_types(AACContext * ac, enum BandType band_type[120],
213 int band_type_run_end[120], GetBitContext * gb, IndividualChannelStream * ics) { 409 int band_type_run_end[120], GetBitContext * gb, IndividualChannelStream * ics) {
214 int g, idx = 0; 410 int g, idx = 0;
215 const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; 411 const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5;
216 for (g = 0; g < ics->num_window_groups; g++) { 412 for (g = 0; g < ics->num_window_groups; g++) {
217 int k = 0; 413 int k = 0;
230 av_log(ac->avccontext, AV_LOG_ERROR, 426 av_log(ac->avccontext, AV_LOG_ERROR,
231 "Number of bands (%d) exceeds limit (%d).\n", 427 "Number of bands (%d) exceeds limit (%d).\n",
232 sect_len, ics->max_sfb); 428 sect_len, ics->max_sfb);
233 return -1; 429 return -1;
234 } 430 }
235 431 }
432 }
433 return 0;
434 }
435
436 /**
437 * Decode scalefactors; reference: table 4.47.
236 * 438 *
237 * @param mix_gain channel gain (Not used by AAC bitstream.) 439 * @param mix_gain channel gain (Not used by AAC bitstream.)
238 * @param global_gain first scalefactor value as scalefactors are differentially coded 440 * @param global_gain first scalefactor value as scalefactors are differentially coded
239 * @param band_type array of the used band type 441 * @param band_type array of the used band type
240 * @param band_type_run_end array of the last scalefactor band of a band type run 442 * @param band_type_run_end array of the last scalefactor band of a band type run
312 pulse->amp [i] = get_bits(gb, 4); 514 pulse->amp [i] = get_bits(gb, 4);
313 } 515 }
314 } 516 }
315 517
316 /** 518 /**
519 * Decode Mid/Side data; reference: table 4.54.
520 *
521 * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
522 * [1] mask is decoded from bitstream; [2] mask is all 1s;
523 * [3] reserved for scalable AAC
524 */
525 static void decode_mid_side_stereo(ChannelElement * cpe, GetBitContext * gb,
526 int ms_present) {
527
528 /**
317 * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3. 529 * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3.
318 * 530 *
319 * @param pulse pointer to pulse data struct 531 * @param pulse pointer to pulse data struct
320 * @param icoef array of quantized spectral data 532 * @param icoef array of quantized spectral data
321 */ 533 */
328 icoef[off] += (pulse->amp[i]^ic) - ic; 540 icoef[off] += (pulse->amp[i]^ic) - ic;
329 } 541 }
330 } 542 }
331 543
332 /** 544 /**
333 * Parse Spectral Band Replication extension data; reference: table 4.55. 545 * Decode an individual_channel_stream payload; reference: table 4.44.
546 *
547 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
548 * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.)
549 *
550 * @return Returns error status. 0 - OK, !0 - error
551 */
552 static int decode_ics(AACContext * ac, SingleChannelElement * sce, GetBitContext * gb, int common_window, int scale_flag) {
553 int icoeffs[1024];
554 Pulse pulse;
555 TemporalNoiseShaping * tns = &sce->tns;
556 IndividualChannelStream * ics = &sce->ics;
557 float * out = sce->coeffs;
558 int global_gain, pulse_present = 0;
559
560 /* These two assignments are to silence some GCC warnings about the
561 * variables being used uninitialised when in fact they always are.
562 */
563 pulse.num_pulse = 0;
564 pulse.start = 0;
565
566 global_gain = get_bits(gb, 8);
567
568 if (!common_window && !scale_flag) {
569 if (decode_ics_info(ac, ics, gb, 0) < 0)
570 return -1;
571 }
572
573 if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0)
574 return -1;
575 if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0)
576 return -1;
577
578 pulse_present = 0;
579 if (!scale_flag) {
580 if ((pulse_present = get_bits1(gb))) {
581 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
582 av_log(ac->avccontext, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
583 return -1;
584 }
585 decode_pulses(&pulse, gb);
586 }
587 if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
588 return -1;
589 if (get_bits1(gb)) {
590 av_log_missing_feature(ac->avccontext, "SSR", 1);
591 return -1;
592 }
593 }
594
595 if (decode_spectrum(ac, icoeffs, gb, ics, sce->band_type) < 0)
596 return -1;
597 if (pulse_present)
598 add_pulses(icoeffs, &pulse, ics);
599 dequant(ac, out, icoeffs, sce->sf, ics, sce->band_type);
600 return 0;
601 }
602
603 /**
604 * Decode a channel_pair_element; reference: table 4.4.
605 *
606 * @param elem_id Identifies the instance of a syntax element.
607 *
608 * @return Returns error status. 0 - OK, !0 - error
609 */
610 static int decode_cpe(AACContext * ac, GetBitContext * gb, int elem_id) {
611 int i, ret, common_window, ms_present = 0;
612 ChannelElement * cpe;
613
614 cpe = ac->che[TYPE_CPE][elem_id];
615 common_window = get_bits1(gb);
616 if (common_window) {
617 if (decode_ics_info(ac, &cpe->ch[0].ics, gb, 1))
618 return -1;
619 i = cpe->ch[1].ics.use_kb_window[0];
620 cpe->ch[1].ics = cpe->ch[0].ics;
621 cpe->ch[1].ics.use_kb_window[1] = i;
622 ms_present = get_bits(gb, 2);
623 if(ms_present == 3) {
624 av_log(ac->avccontext, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
625 return -1;
626 } else if(ms_present)
627 decode_mid_side_stereo(cpe, gb, ms_present);
628 }
629 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
630 return ret;
631 if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
632 return ret;
633
634 if (common_window && ms_present)
635 apply_mid_side_stereo(cpe);
636
637 if (cpe->ch[1].ics.intensity_present)
638 apply_intensity_stereo(cpe, ms_present);
639 return 0;
640 }
641
642 /**
643 * Decode Spectral Band Replication extension data; reference: table 4.55.
334 * 644 *
335 * @param crc flag indicating the presence of CRC checksum 645 * @param crc flag indicating the presence of CRC checksum
336 * @param cnt length of TYPE_FIL syntactic element in bytes 646 * @param cnt length of TYPE_FIL syntactic element in bytes
647 *
337 * @return Returns number of bytes consumed from the TYPE_FIL element. 648 * @return Returns number of bytes consumed from the TYPE_FIL element.
338 */ 649 */
339 static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) { 650 static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) {
340 // TODO : sbr_extension implementation 651 // TODO : sbr_extension implementation
341 av_log(ac->avccontext, AV_LOG_DEBUG, "aac: SBR not yet supported.\n"); 652 av_log(ac->avccontext, AV_LOG_DEBUG, "aac: SBR not yet supported.\n");
342 skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type 653 skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type
343 return cnt; 654 return cnt;
344 } 655 }
345 656
657 /**
658 * Decode dynamic range information; reference: table 4.52.
659 *
660 * @param cnt length of TYPE_FIL syntactic element in bytes
661 *
662 * @return Returns number of bytes consumed.
663 */
664 static int decode_dynamic_range(DynamicRangeControl *che_drc, GetBitContext * gb, int cnt) {
665 int n = 1;
666 int drc_num_bands = 1;
667 int i;
668
669 /* pce_tag_present? */
670 if(get_bits1(gb)) {
671 che_drc->pce_instance_tag = get_bits(gb, 4);
672 skip_bits(gb, 4); // tag_reserved_bits
673 n++;
674 }
675
676 /* excluded_chns_present? */
677 if(get_bits1(gb)) {
678 n += decode_drc_channel_exclusions(che_drc, gb);
679 }
680
681 /* drc_bands_present? */
682 if (get_bits1(gb)) {
683 che_drc->band_incr = get_bits(gb, 4);
684 che_drc->interpolation_scheme = get_bits(gb, 4);
685 n++;
686 drc_num_bands += che_drc->band_incr;
687 for (i = 0; i < drc_num_bands; i++) {
688 che_drc->band_top[i] = get_bits(gb, 8);
689 n++;
690 }
691 }
692
693 /* prog_ref_level_present? */
694 if (get_bits1(gb)) {
695 che_drc->prog_ref_level = get_bits(gb, 7);
696 skip_bits1(gb); // prog_ref_level_reserved_bits
697 n++;
698 }
699
700 for (i = 0; i < drc_num_bands; i++) {
701 che_drc->dyn_rng_sgn[i] = get_bits1(gb);
702 che_drc->dyn_rng_ctl[i] = get_bits(gb, 7);
703 n++;
704 }
705
706 return n;
707 }
708
709 /**
710 * Decode extension data (incomplete); reference: table 4.51.
711 *
712 * @param cnt length of TYPE_FIL syntactic element in bytes
713 *
714 * @return Returns number of bytes consumed
715 */
716 static int decode_extension_payload(AACContext * ac, GetBitContext * gb, int cnt) {
346 int crc_flag = 0; 717 int crc_flag = 0;
347 int res = cnt; 718 int res = cnt;
348 switch (get_bits(gb, 4)) { // extension type 719 switch (get_bits(gb, 4)) { // extension type
349 case EXT_SBR_DATA_CRC: 720 case EXT_SBR_DATA_CRC:
350 crc_flag++; 721 crc_flag++;
363 }; 734 };
364 return res; 735 return res;
365 } 736 }
366 737
367 /** 738 /**
739 * Conduct IMDCT and windowing.
740 */
741 static void imdct_and_windowing(AACContext * ac, SingleChannelElement * sce) {
742 IndividualChannelStream * ics = &sce->ics;
743 float * in = sce->coeffs;
744 float * out = sce->ret;
745 float * saved = sce->saved;
746 const float * lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
747 const float * swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
748 const float * lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
749 const float * swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
750 float * buf = ac->buf_mdct;
751 int i;
752
753 /**
368 * Apply dependent channel coupling (applied before IMDCT). 754 * Apply dependent channel coupling (applied before IMDCT).
369 * 755 *
370 * @param index index into coupling gain array 756 * @param index index into coupling gain array
371 */ 757 */
372 static void apply_dependent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) { 758 static void apply_dependent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) {
407 float gain = cc->coup.gain[index][0] * sce->mixing_gain; 793 float gain = cc->coup.gain[index][0] * sce->mixing_gain;
408 for (i = 0; i < 1024; i++) 794 for (i = 0; i < 1024; i++)
409 sce->ret[i] += gain * (cc->ch[0].ret[i] - ac->add_bias); 795 sce->ret[i] += gain * (cc->ch[0].ret[i] - ac->add_bias);
410 } 796 }
411 797
798 if (!ac->is_saved) {
799 ac->is_saved = 1;
800 *data_size = 0;
801 return 0;
802 }
803
804 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);
805 if(*data_size < data_size_tmp) {
806 av_log(avccontext, AV_LOG_ERROR,
807 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",
808 *data_size, data_size_tmp);
809 return -1;
810 }
811 *data_size = data_size_tmp;
812
813 ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels);
814
815 return buf_size;
816 }
817
412 static av_cold int aac_decode_close(AVCodecContext * avccontext) { 818 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
413 AACContext * ac = avccontext->priv_data; 819 AACContext * ac = avccontext->priv_data;
414 int i, j; 820 int i, j;
415 821
416 for (i = 0; i < MAX_ELEM_ID; i++) { 822 for (i = 0; i < MAX_ELEM_ID; i++) {