| OLD | NEW |
| 1 /* | 1 /* |
| 2 * AAC decoder | 2 * AAC decoder |
| 3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) | 3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) |
| 4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) | 4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) |
| 5 * | 5 * |
| 6 * This file is part of FFmpeg. | 6 * This file is part of FFmpeg. |
| 7 * | 7 * |
| 8 * FFmpeg is free software; you can redistribute it and/or | 8 * FFmpeg is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 * N Error Protection tool | 55 * N Error Protection tool |
| 56 * N CELP | 56 * N CELP |
| 57 * N Silence Compression | 57 * N Silence Compression |
| 58 * N HVXC | 58 * N HVXC |
| 59 * N HVXC 4kbits/s VR | 59 * N HVXC 4kbits/s VR |
| 60 * N Structured Audio tools | 60 * N Structured Audio tools |
| 61 * N Structured Audio Sample Bank Format | 61 * N Structured Audio Sample Bank Format |
| 62 * N MIDI | 62 * N MIDI |
| 63 * N Harmonic and Individual Lines plus Noise | 63 * N Harmonic and Individual Lines plus Noise |
| 64 * N Text-To-Speech Interface | 64 * N Text-To-Speech Interface |
| 65 * N (in progress) Spectral Band Replication | 65 * Y Spectral Band Replication |
| 66 * Y (not in this code) Layer-1 | 66 * Y (not in this code) Layer-1 |
| 67 * Y (not in this code) Layer-2 | 67 * Y (not in this code) Layer-2 |
| 68 * Y (not in this code) Layer-3 | 68 * Y (not in this code) Layer-3 |
| 69 * N SinuSoidal Coding (Transient, Sinusoid, Noise) | 69 * N SinuSoidal Coding (Transient, Sinusoid, Noise) |
| 70 * N (planned) Parametric Stereo | 70 * N (planned) Parametric Stereo |
| 71 * N Direct Stream Transfer | 71 * N Direct Stream Transfer |
| 72 * | 72 * |
| 73 * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. | 73 * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. |
| 74 * - HE AAC v2 comprises LC AAC with Spectral Band Replication and | 74 * - HE AAC v2 comprises LC AAC with Spectral Band Replication and |
| 75 Parametric Stereo. | 75 Parametric Stereo. |
| 76 */ | 76 */ |
| 77 | 77 |
| 78 | 78 |
| 79 #include "avcodec.h" | 79 #include "avcodec.h" |
| 80 #include "internal.h" | 80 #include "internal.h" |
| 81 #include "get_bits.h" | 81 #include "get_bits.h" |
| 82 #include "dsputil.h" | 82 #include "dsputil.h" |
| 83 #include "fft.h" |
| 83 #include "lpc.h" | 84 #include "lpc.h" |
| 84 | 85 |
| 85 #include "aac.h" | 86 #include "aac.h" |
| 86 #include "aactab.h" | 87 #include "aactab.h" |
| 87 #include "aacdectab.h" | 88 #include "aacdectab.h" |
| 89 #include "sbr.h" |
| 90 #include "aacsbr.h" |
| 88 #include "mpeg4audio.h" | 91 #include "mpeg4audio.h" |
| 89 #include "aac_parser.h" | 92 #include "aac_parser.h" |
| 90 | 93 |
| 91 #include <assert.h> | 94 #include <assert.h> |
| 92 #include <errno.h> | 95 #include <errno.h> |
| 93 #include <math.h> | 96 #include <math.h> |
| 94 #include <string.h> | 97 #include <string.h> |
| 95 | 98 |
| 96 #if ARCH_ARM | 99 #if ARCH_ARM |
| 97 # include "arm/aac.h" | 100 # include "arm/aac.h" |
| 98 #endif | 101 #endif |
| 99 | 102 |
| 100 union float754 { | 103 union float754 { |
| 101 float f; | 104 float f; |
| 102 uint32_t i; | 105 uint32_t i; |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 static VLC vlc_scalefactors; | 108 static VLC vlc_scalefactors; |
| 106 static VLC vlc_spectral[11]; | 109 static VLC vlc_spectral[11]; |
| 107 | 110 |
| 108 static uint32_t cbrt_tab[1<<13]; | 111 static uint32_t cbrt_tab[1<<13]; |
| 109 | 112 |
| 113 static const char overread_err[] = "Input buffer exhausted before END element fo
und\n"; |
| 114 |
| 110 static ChannelElement *get_che(AACContext *ac, int type, int elem_id) | 115 static ChannelElement *get_che(AACContext *ac, int type, int elem_id) |
| 111 { | 116 { |
| 112 if (ac->tag_che_map[type][elem_id]) { | 117 if (ac->tag_che_map[type][elem_id]) { |
| 113 return ac->tag_che_map[type][elem_id]; | 118 return ac->tag_che_map[type][elem_id]; |
| 114 } | 119 } |
| 115 if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) { | 120 if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) { |
| 116 return NULL; | 121 return NULL; |
| 117 } | 122 } |
| 118 switch (ac->m4ac.chan_config) { | 123 switch (ac->m4ac.chan_config) { |
| 119 case 7: | 124 case 7: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 * If it exists, make sure the appropriate element is allocated and map the | 167 * If it exists, make sure the appropriate element is allocated and map the |
| 163 * channel order to match the internal FFmpeg channel layout. | 168 * channel order to match the internal FFmpeg channel layout. |
| 164 * | 169 * |
| 165 * @param che_pos current channel position configuration | 170 * @param che_pos current channel position configuration |
| 166 * @param type channel element type | 171 * @param type channel element type |
| 167 * @param id channel element id | 172 * @param id channel element id |
| 168 * @param channels count of the number of channels in the configuration | 173 * @param channels count of the number of channels in the configuration |
| 169 * | 174 * |
| 170 * @return Returns error status. 0 - OK, !0 - error | 175 * @return Returns error status. 0 - OK, !0 - error |
| 171 */ | 176 */ |
| 172 static int che_configure(AACContext *ac, | 177 static av_cold int che_configure(AACContext *ac, |
| 173 enum ChannelPosition che_pos[4][MAX_ELEM_ID], | 178 enum ChannelPosition che_pos[4][MAX_ELEM_ID], |
| 174 int type, int id, | 179 int type, int id, |
| 175 int *channels) | 180 int *channels) |
| 176 { | 181 { |
| 177 if (che_pos[type][id]) { | 182 if (che_pos[type][id]) { |
| 178 if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(Channe
lElement)))) | 183 if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(Channe
lElement)))) |
| 179 return AVERROR(ENOMEM); | 184 return AVERROR(ENOMEM); |
| 185 ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); |
| 180 if (type != TYPE_CCE) { | 186 if (type != TYPE_CCE) { |
| 181 ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; | 187 ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; |
| 182 if (type == TYPE_CPE) { | 188 if (type == TYPE_CPE) { |
| 183 ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; | 189 ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; |
| 184 } | 190 } |
| 185 } | 191 } |
| 186 } else | 192 } else { |
| 193 if (ac->che[type][id]) |
| 194 ff_aac_sbr_ctx_close(&ac->che[type][id]->sbr); |
| 187 av_freep(&ac->che[type][id]); | 195 av_freep(&ac->che[type][id]); |
| 196 } |
| 188 return 0; | 197 return 0; |
| 189 } | 198 } |
| 190 | 199 |
| 191 /** | 200 /** |
| 192 * Configure output channel order based on the current program configuration ele
ment. | 201 * Configure output channel order based on the current program configuration ele
ment. |
| 193 * | 202 * |
| 194 * @param che_pos current channel position configuration | 203 * @param che_pos current channel position configuration |
| 195 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. | 204 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. |
| 196 * | 205 * |
| 197 * @return Returns error status. 0 - OK, !0 - error | 206 * @return Returns error status. 0 - OK, !0 - error |
| 198 */ | 207 */ |
| 199 static int output_configure(AACContext *ac, | 208 static av_cold int output_configure(AACContext *ac, |
| 200 enum ChannelPosition che_pos[4][MAX_ELEM_ID], | 209 enum ChannelPosition che_pos[4][MAX_ELEM_ID], |
| 201 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], | 210 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], |
| 202 int channel_config, enum OCStatus oc_type) | 211 int channel_config, enum OCStatus oc_type) |
| 203 { | 212 { |
| 204 AVCodecContext *avctx = ac->avccontext; | 213 AVCodecContext *avctx = ac->avccontext; |
| 205 int i, type, channels = 0, ret; | 214 int i, type, channels = 0, ret; |
| 206 | 215 |
| 207 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | 216 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
| 208 | 217 |
| 209 if (channel_config) { | 218 if (channel_config) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 * Decode program configuration element; reference: table 4.2. | 280 * Decode program configuration element; reference: table 4.2. |
| 272 * | 281 * |
| 273 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. | 282 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. |
| 274 * | 283 * |
| 275 * @return Returns error status. 0 - OK, !0 - error | 284 * @return Returns error status. 0 - OK, !0 - error |
| 276 */ | 285 */ |
| 277 static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL
EM_ID], | 286 static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL
EM_ID], |
| 278 GetBitContext *gb) | 287 GetBitContext *gb) |
| 279 { | 288 { |
| 280 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling
_index; | 289 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling
_index; |
| 290 int comment_len; |
| 281 | 291 |
| 282 skip_bits(gb, 2); // object_type | 292 skip_bits(gb, 2); // object_type |
| 283 | 293 |
| 284 sampling_index = get_bits(gb, 4); | 294 sampling_index = get_bits(gb, 4); |
| 285 if (ac->m4ac.sampling_index != sampling_index) | 295 if (ac->m4ac.sampling_index != sampling_index) |
| 286 av_log(ac->avccontext, AV_LOG_WARNING, "Sample rate index in program con
fig element does not match the sample rate index configured by the container.\n"
); | 296 av_log(ac->avccontext, AV_LOG_WARNING, "Sample rate index in program con
fig element does not match the sample rate index configured by the container.\n"
); |
| 287 | 297 |
| 288 num_front = get_bits(gb, 4); | 298 num_front = get_bits(gb, 4); |
| 289 num_side = get_bits(gb, 4); | 299 num_side = get_bits(gb, 4); |
| 290 num_back = get_bits(gb, 4); | 300 num_back = get_bits(gb, 4); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 305 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL
_BACK, gb, num_back ); | 315 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL
_BACK, gb, num_back ); |
| 306 decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL
_LFE, gb, num_lfe ); | 316 decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL
_LFE, gb, num_lfe ); |
| 307 | 317 |
| 308 skip_bits_long(gb, 4 * num_assoc_data); | 318 skip_bits_long(gb, 4 * num_assoc_data); |
| 309 | 319 |
| 310 decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL
_CC, gb, num_cc ); | 320 decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL
_CC, gb, num_cc ); |
| 311 | 321 |
| 312 align_get_bits(gb); | 322 align_get_bits(gb); |
| 313 | 323 |
| 314 /* comment field, first byte is length */ | 324 /* comment field, first byte is length */ |
| 315 skip_bits_long(gb, 8 * get_bits(gb, 8)); | 325 comment_len = get_bits(gb, 8) * 8; |
| 326 if (get_bits_left(gb) < comment_len) { |
| 327 av_log(ac->avccontext, AV_LOG_ERROR, overread_err); |
| 328 return -1; |
| 329 } |
| 330 skip_bits_long(gb, comment_len); |
| 316 return 0; | 331 return 0; |
| 317 } | 332 } |
| 318 | 333 |
| 319 /** | 334 /** |
| 320 * Set up channel positions based on a default channel configuration | 335 * Set up channel positions based on a default channel configuration |
| 321 * as specified in table 1.17. | 336 * as specified in table 1.17. |
| 322 * | 337 * |
| 323 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. | 338 * @param new_che_pos New channel position configuration - we only do somethin
g if it differs from the current one. |
| 324 * | 339 * |
| 325 * @return Returns error status. 0 - OK, !0 - error | 340 * @return Returns error status. 0 - OK, !0 - error |
| 326 */ | 341 */ |
| 327 static int set_default_channel_config(AACContext *ac, | 342 static av_cold int set_default_channel_config(AACContext *ac, |
| 328 enum ChannelPosition new_che_pos[4][MAX_EL
EM_ID], | 343 enum ChannelPosition new_che_pos[4][MAX_EL
EM_ID], |
| 329 int channel_config) | 344 int channel_config) |
| 330 { | 345 { |
| 331 if (channel_config < 1 || channel_config > 7) { | 346 if (channel_config < 1 || channel_config > 7) { |
| 332 av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configurat
ion (%d)\n", | 347 av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configurat
ion (%d)\n", |
| 333 channel_config); | 348 channel_config); |
| 334 return -1; | 349 return -1; |
| 335 } | 350 } |
| 336 | 351 |
| 337 /* default channel configurations: | 352 /* default channel configurations: |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 * | 479 * |
| 465 * @param previous_val pointer to the current state of the generator | 480 * @param previous_val pointer to the current state of the generator |
| 466 * | 481 * |
| 467 * @return Returns a 32-bit pseudorandom integer | 482 * @return Returns a 32-bit pseudorandom integer |
| 468 */ | 483 */ |
| 469 static av_always_inline int lcg_random(int previous_val) | 484 static av_always_inline int lcg_random(int previous_val) |
| 470 { | 485 { |
| 471 return previous_val * 1664525 + 1013904223; | 486 return previous_val * 1664525 + 1013904223; |
| 472 } | 487 } |
| 473 | 488 |
| 474 static void reset_predict_state(PredictorState *ps) | 489 static av_always_inline void reset_predict_state(PredictorState *ps) |
| 475 { | 490 { |
| 476 ps->r0 = 0.0f; | 491 ps->r0 = 0.0f; |
| 477 ps->r1 = 0.0f; | 492 ps->r1 = 0.0f; |
| 478 ps->cor0 = 0.0f; | 493 ps->cor0 = 0.0f; |
| 479 ps->cor1 = 0.0f; | 494 ps->cor1 = 0.0f; |
| 480 ps->var0 = 1.0f; | 495 ps->var0 = 1.0f; |
| 481 ps->var1 = 1.0f; | 496 ps->var1 = 1.0f; |
| 482 } | 497 } |
| 483 | 498 |
| 484 static void reset_all_predictors(PredictorState *ps) | 499 static void reset_all_predictors(PredictorState *ps) |
| 485 { | 500 { |
| 486 int i; | 501 int i; |
| 487 for (i = 0; i < MAX_PREDICTORS; i++) | 502 for (i = 0; i < MAX_PREDICTORS; i++) |
| 488 reset_predict_state(&ps[i]); | 503 reset_predict_state(&ps[i]); |
| 489 } | 504 } |
| 490 | 505 |
| 491 static void reset_predictor_group(PredictorState *ps, int group_num) | 506 static void reset_predictor_group(PredictorState *ps, int group_num) |
| 492 { | 507 { |
| 493 int i; | 508 int i; |
| 494 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) | 509 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) |
| 495 reset_predict_state(&ps[i]); | 510 reset_predict_state(&ps[i]); |
| 496 } | 511 } |
| 497 | 512 |
| 498 static av_cold int aac_decode_init(AVCodecContext *avccontext) | 513 static av_cold int aac_decode_init(AVCodecContext *avccontext) |
| 499 { | 514 { |
| 500 AACContext *ac = avccontext->priv_data; | 515 AACContext *ac = avccontext->priv_data; |
| 501 int i; | 516 int i; |
| 502 | 517 |
| 503 ac->avccontext = avccontext; | 518 ac->avccontext = avccontext; |
| 519 ac->m4ac.sample_rate = avccontext->sample_rate; |
| 504 | 520 |
| 505 if (avccontext->extradata_size > 0) { | 521 if (avccontext->extradata_size > 0) { |
| 506 if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->
extradata_size)) | 522 if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->
extradata_size)) |
| 507 return -1; | 523 return -1; |
| 508 avccontext->sample_rate = ac->m4ac.sample_rate; | |
| 509 } else if (avccontext->channels > 0) { | |
| 510 ac->m4ac.sample_rate = avccontext->sample_rate; | |
| 511 } | 524 } |
| 512 | 525 |
| 513 avccontext->sample_fmt = SAMPLE_FMT_S16; | 526 avccontext->sample_fmt = SAMPLE_FMT_S16; |
| 514 avccontext->frame_size = 1024; | |
| 515 | 527 |
| 516 AAC_INIT_VLC_STATIC( 0, 304); | 528 AAC_INIT_VLC_STATIC( 0, 304); |
| 517 AAC_INIT_VLC_STATIC( 1, 270); | 529 AAC_INIT_VLC_STATIC( 1, 270); |
| 518 AAC_INIT_VLC_STATIC( 2, 550); | 530 AAC_INIT_VLC_STATIC( 2, 550); |
| 519 AAC_INIT_VLC_STATIC( 3, 300); | 531 AAC_INIT_VLC_STATIC( 3, 300); |
| 520 AAC_INIT_VLC_STATIC( 4, 328); | 532 AAC_INIT_VLC_STATIC( 4, 328); |
| 521 AAC_INIT_VLC_STATIC( 5, 294); | 533 AAC_INIT_VLC_STATIC( 5, 294); |
| 522 AAC_INIT_VLC_STATIC( 6, 306); | 534 AAC_INIT_VLC_STATIC( 6, 306); |
| 523 AAC_INIT_VLC_STATIC( 7, 268); | 535 AAC_INIT_VLC_STATIC( 7, 268); |
| 524 AAC_INIT_VLC_STATIC( 8, 510); | 536 AAC_INIT_VLC_STATIC( 8, 510); |
| 525 AAC_INIT_VLC_STATIC( 9, 366); | 537 AAC_INIT_VLC_STATIC( 9, 366); |
| 526 AAC_INIT_VLC_STATIC(10, 462); | 538 AAC_INIT_VLC_STATIC(10, 462); |
| 527 | 539 |
| 540 ff_aac_sbr_init(); |
| 541 |
| 528 dsputil_init(&ac->dsp, avccontext); | 542 dsputil_init(&ac->dsp, avccontext); |
| 529 | 543 |
| 530 ac->random_state = 0x1f2e3d4c; | 544 ac->random_state = 0x1f2e3d4c; |
| 531 | 545 |
| 532 // -1024 - Compensate wrong IMDCT method. | 546 // -1024 - Compensate wrong IMDCT method. |
| 533 // 32768 - Required to scale values to the correct range for the bias method | 547 // 32768 - Required to scale values to the correct range for the bias method |
| 534 // for float to int16 conversion. | 548 // for float to int16 conversion. |
| 535 | 549 |
| 536 if (ac->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { | 550 if (ac->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { |
| 537 ac->add_bias = 385.0f; | 551 ac->add_bias = 385.0f; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 568 cbrt_tab[i] = f.i; | 582 cbrt_tab[i] = f.i; |
| 569 } | 583 } |
| 570 } | 584 } |
| 571 | 585 |
| 572 return 0; | 586 return 0; |
| 573 } | 587 } |
| 574 | 588 |
| 575 /** | 589 /** |
| 576 * Skip data_stream_element; reference: table 4.10. | 590 * Skip data_stream_element; reference: table 4.10. |
| 577 */ | 591 */ |
| 578 static void skip_data_stream_element(GetBitContext *gb) | 592 static int skip_data_stream_element(AACContext *ac, GetBitContext *gb) |
| 579 { | 593 { |
| 580 int byte_align = get_bits1(gb); | 594 int byte_align = get_bits1(gb); |
| 581 int count = get_bits(gb, 8); | 595 int count = get_bits(gb, 8); |
| 582 if (count == 255) | 596 if (count == 255) |
| 583 count += get_bits(gb, 8); | 597 count += get_bits(gb, 8); |
| 584 if (byte_align) | 598 if (byte_align) |
| 585 align_get_bits(gb); | 599 align_get_bits(gb); |
| 600 |
| 601 if (get_bits_left(gb) < 8 * count) { |
| 602 av_log(ac->avccontext, AV_LOG_ERROR, overread_err); |
| 603 return -1; |
| 604 } |
| 586 skip_bits_long(gb, 8 * count); | 605 skip_bits_long(gb, 8 * count); |
| 606 return 0; |
| 587 } | 607 } |
| 588 | 608 |
| 589 static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, | 609 static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, |
| 590 GetBitContext *gb) | 610 GetBitContext *gb) |
| 591 { | 611 { |
| 592 int sfb; | 612 int sfb; |
| 593 if (get_bits1(gb)) { | 613 if (get_bits1(gb)) { |
| 594 ics->predictor_reset_group = get_bits(gb, 5); | 614 ics->predictor_reset_group = get_bits(gb, 5); |
| 595 if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30)
{ | 615 if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30)
{ |
| 596 av_log(ac->avccontext, AV_LOG_ERROR, "Invalid Predictor Reset Group.
\n"); | 616 av_log(ac->avccontext, AV_LOG_ERROR, "Invalid Predictor Reset Group.
\n"); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 uint8_t sect_end = k; | 715 uint8_t sect_end = k; |
| 696 int sect_len_incr; | 716 int sect_len_incr; |
| 697 int sect_band_type = get_bits(gb, 4); | 717 int sect_band_type = get_bits(gb, 4); |
| 698 if (sect_band_type == 12) { | 718 if (sect_band_type == 12) { |
| 699 av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n"); | 719 av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n"); |
| 700 return -1; | 720 return -1; |
| 701 } | 721 } |
| 702 while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) | 722 while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) |
| 703 sect_end += sect_len_incr; | 723 sect_end += sect_len_incr; |
| 704 sect_end += sect_len_incr; | 724 sect_end += sect_len_incr; |
| 705 if (sect_end > ics->max_sfb || sect_end == k) { | 725 if (get_bits_left(gb) < 0) { |
| 726 av_log(ac->avccontext, AV_LOG_ERROR, overread_err); |
| 727 return -1; |
| 728 } |
| 729 if (sect_end > ics->max_sfb) { |
| 706 av_log(ac->avccontext, AV_LOG_ERROR, | 730 av_log(ac->avccontext, AV_LOG_ERROR, |
| 707 "Number of bands (%d) is invalid, limit (%d).\n", | 731 "Number of bands (%d) exceeds limit (%d).\n", |
| 708 sect_end, ics->max_sfb); | 732 sect_end, ics->max_sfb); |
| 709 return -1; | 733 return -1; |
| 710 } | 734 } |
| 711 for (; k < sect_end; k++) { | 735 for (; k < sect_end; k++) { |
| 712 band_type [idx] = sect_band_type; | 736 band_type [idx] = sect_band_type; |
| 713 band_type_run_end[idx++] = sect_end; | 737 band_type_run_end[idx++] = sect_end; |
| 714 } | 738 } |
| 715 } | 739 } |
| 716 } | 740 } |
| 717 return 0; | 741 return 0; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 2
0 : 12; | 845 const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 2
0 : 12; |
| 822 for (w = 0; w < ics->num_windows; w++) { | 846 for (w = 0; w < ics->num_windows; w++) { |
| 823 if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { | 847 if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { |
| 824 coef_res = get_bits1(gb); | 848 coef_res = get_bits1(gb); |
| 825 | 849 |
| 826 for (filt = 0; filt < tns->n_filt[w]; filt++) { | 850 for (filt = 0; filt < tns->n_filt[w]; filt++) { |
| 827 int tmp2_idx; | 851 int tmp2_idx; |
| 828 tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); | 852 tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); |
| 829 | 853 |
| 830 if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_
order) { | 854 if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_
order) { |
| 831 av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is
greater than maximum %d.", | 855 av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is
greater than maximum %d.\n", |
| 832 tns->order[w][filt], tns_max_order); | 856 tns->order[w][filt], tns_max_order); |
| 833 tns->order[w][filt] = 0; | 857 tns->order[w][filt] = 0; |
| 834 return -1; | 858 return -1; |
| 835 } | 859 } |
| 836 if (tns->order[w][filt]) { | 860 if (tns->order[w][filt]) { |
| 837 tns->direction[w][filt] = get_bits1(gb); | 861 tns->direction[w][filt] = get_bits1(gb); |
| 838 coef_compress = get_bits1(gb); | 862 coef_compress = get_bits1(gb); |
| 839 coef_len = coef_res + 3 - coef_compress; | 863 coef_len = coef_res + 3 - coef_compress; |
| 840 tmp2_idx = 2 * coef_compress + coef_res; | 864 tmp2_idx = 2 * coef_compress + coef_res; |
| 841 | 865 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 } | 1247 } |
| 1224 | 1248 |
| 1225 static av_always_inline float flt16_trunc(float pf) | 1249 static av_always_inline float flt16_trunc(float pf) |
| 1226 { | 1250 { |
| 1227 union float754 pun; | 1251 union float754 pun; |
| 1228 pun.f = pf; | 1252 pun.f = pf; |
| 1229 pun.i &= 0xFFFF0000U; | 1253 pun.i &= 0xFFFF0000U; |
| 1230 return pun.f; | 1254 return pun.f; |
| 1231 } | 1255 } |
| 1232 | 1256 |
| 1233 static void predict(AACContext *ac, PredictorState *ps, float *coef, | 1257 static av_always_inline void predict(AACContext *ac, PredictorState *ps, float *
coef, |
| 1234 int output_enable) | 1258 int output_enable) |
| 1235 { | 1259 { |
| 1236 const float a = 0.953125; // 61.0 / 64 | 1260 const float a = 0.953125; // 61.0 / 64 |
| 1237 const float alpha = 0.90625; // 29.0 / 32 | 1261 const float alpha = 0.90625; // 29.0 / 32 |
| 1238 float e0, e1; | 1262 float e0, e1; |
| 1239 float pv; | 1263 float pv; |
| 1240 float k1, k2; | 1264 float k1, k2; |
| 1241 | 1265 |
| 1242 k1 = ps->var0 > 1 ? ps->cor0 * flt16_even(a / ps->var0) : 0; | 1266 k1 = ps->var0 > 1 ? ps->cor0 * flt16_even(a / ps->var0) : 0; |
| 1243 k2 = ps->var1 > 1 ? ps->cor1 * flt16_even(a / ps->var1) : 0; | 1267 k2 = ps->var1 > 1 ? ps->cor1 * flt16_even(a / ps->var1) : 0; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 coup->gain[c][idx] = gain_cache; | 1547 coup->gain[c][idx] = gain_cache; |
| 1524 } | 1548 } |
| 1525 } | 1549 } |
| 1526 } | 1550 } |
| 1527 } | 1551 } |
| 1528 } | 1552 } |
| 1529 return 0; | 1553 return 0; |
| 1530 } | 1554 } |
| 1531 | 1555 |
| 1532 /** | 1556 /** |
| 1533 * Decode Spectral Band Replication extension data; reference: table 4.55. | |
| 1534 * | |
| 1535 * @param crc flag indicating the presence of CRC checksum | |
| 1536 * @param cnt length of TYPE_FIL syntactic element in bytes | |
| 1537 * | |
| 1538 * @return Returns number of bytes consumed from the TYPE_FIL element. | |
| 1539 */ | |
| 1540 static int decode_sbr_extension(AACContext *ac, GetBitContext *gb, | |
| 1541 int crc, int cnt) | |
| 1542 { | |
| 1543 // TODO : sbr_extension implementation | |
| 1544 av_log_missing_feature(ac->avccontext, "SBR", 0); | |
| 1545 skip_bits_long(gb, 8 * cnt - 4); // -4 due to reading extension type | |
| 1546 return cnt; | |
| 1547 } | |
| 1548 | |
| 1549 /** | |
| 1550 * Parse whether channels are to be excluded from Dynamic Range Compression; ref
erence: table 4.53. | 1557 * Parse whether channels are to be excluded from Dynamic Range Compression; ref
erence: table 4.53. |
| 1551 * | 1558 * |
| 1552 * @return Returns number of bytes consumed. | 1559 * @return Returns number of bytes consumed. |
| 1553 */ | 1560 */ |
| 1554 static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, | 1561 static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, |
| 1555 GetBitContext *gb) | 1562 GetBitContext *gb) |
| 1556 { | 1563 { |
| 1557 int i; | 1564 int i; |
| 1558 int num_excl_chan = 0; | 1565 int num_excl_chan = 0; |
| 1559 | 1566 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 return n; | 1626 return n; |
| 1620 } | 1627 } |
| 1621 | 1628 |
| 1622 /** | 1629 /** |
| 1623 * Decode extension data (incomplete); reference: table 4.51. | 1630 * Decode extension data (incomplete); reference: table 4.51. |
| 1624 * | 1631 * |
| 1625 * @param cnt length of TYPE_FIL syntactic element in bytes | 1632 * @param cnt length of TYPE_FIL syntactic element in bytes |
| 1626 * | 1633 * |
| 1627 * @return Returns number of bytes consumed | 1634 * @return Returns number of bytes consumed |
| 1628 */ | 1635 */ |
| 1629 static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt) | 1636 static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, |
| 1637 ChannelElement *che, enum RawDataBlockType e
lem_type) |
| 1630 { | 1638 { |
| 1631 int crc_flag = 0; | 1639 int crc_flag = 0; |
| 1632 int res = cnt; | 1640 int res = cnt; |
| 1633 switch (get_bits(gb, 4)) { // extension type | 1641 switch (get_bits(gb, 4)) { // extension type |
| 1634 case EXT_SBR_DATA_CRC: | 1642 case EXT_SBR_DATA_CRC: |
| 1635 crc_flag++; | 1643 crc_flag++; |
| 1636 case EXT_SBR_DATA: | 1644 case EXT_SBR_DATA: |
| 1637 res = decode_sbr_extension(ac, gb, crc_flag, cnt); | 1645 if (!che) { |
| 1646 av_log(ac->avccontext, AV_LOG_ERROR, "SBR was found before the first
channel element.\n"); |
| 1647 return res; |
| 1648 } else if (!ac->m4ac.sbr) { |
| 1649 av_log(ac->avccontext, AV_LOG_ERROR, "SBR signaled to be not-present
but was found in the bitstream.\n"); |
| 1650 skip_bits_long(gb, 8 * cnt - 4); |
| 1651 return res; |
| 1652 } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) { |
| 1653 av_log(ac->avccontext, AV_LOG_ERROR, "Implicit SBR was found with a
first occurrence after the first frame.\n"); |
| 1654 skip_bits_long(gb, 8 * cnt - 4); |
| 1655 return res; |
| 1656 } else { |
| 1657 ac->m4ac.sbr = 1; |
| 1658 } |
| 1659 res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_typ
e); |
| 1638 break; | 1660 break; |
| 1639 case EXT_DYNAMIC_RANGE: | 1661 case EXT_DYNAMIC_RANGE: |
| 1640 res = decode_dynamic_range(&ac->che_drc, gb, cnt); | 1662 res = decode_dynamic_range(&ac->che_drc, gb, cnt); |
| 1641 break; | 1663 break; |
| 1642 case EXT_FILL: | 1664 case EXT_FILL: |
| 1643 case EXT_FILL_DATA: | 1665 case EXT_FILL_DATA: |
| 1644 case EXT_DATA_ELEMENT: | 1666 case EXT_DATA_ELEMENT: |
| 1645 default: | 1667 default: |
| 1646 skip_bits_long(gb, 8 * cnt - 4); | 1668 skip_bits_long(gb, 8 * cnt - 4); |
| 1647 break; | 1669 break; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 */ | 1830 */ |
| 1809 static void apply_independent_coupling(AACContext *ac, | 1831 static void apply_independent_coupling(AACContext *ac, |
| 1810 SingleChannelElement *target, | 1832 SingleChannelElement *target, |
| 1811 ChannelElement *cce, int index) | 1833 ChannelElement *cce, int index) |
| 1812 { | 1834 { |
| 1813 int i; | 1835 int i; |
| 1814 const float gain = cce->coup.gain[index][0]; | 1836 const float gain = cce->coup.gain[index][0]; |
| 1815 const float bias = ac->add_bias; | 1837 const float bias = ac->add_bias; |
| 1816 const float *src = cce->ch[0].ret; | 1838 const float *src = cce->ch[0].ret; |
| 1817 float *dest = target->ret; | 1839 float *dest = target->ret; |
| 1840 const int len = 1024 << (ac->m4ac.sbr == 1); |
| 1818 | 1841 |
| 1819 for (i = 0; i < 1024; i++) | 1842 for (i = 0; i < len; i++) |
| 1820 dest[i] += gain * (src[i] - bias); | 1843 dest[i] += gain * (src[i] - bias); |
| 1821 } | 1844 } |
| 1822 | 1845 |
| 1823 /** | 1846 /** |
| 1824 * channel coupling transformation interface | 1847 * channel coupling transformation interface |
| 1825 * | 1848 * |
| 1826 * @param index index into coupling gain array | 1849 * @param index index into coupling gain array |
| 1827 * @param apply_coupling_method pointer to (in)dependent coupling function | 1850 * @param apply_coupling_method pointer to (in)dependent coupling function |
| 1828 */ | 1851 */ |
| 1829 static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, | 1852 static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 ChannelElement *che = ac->che[type][i]; | 1890 ChannelElement *che = ac->che[type][i]; |
| 1868 if (che) { | 1891 if (che) { |
| 1869 if (type <= TYPE_CPE) | 1892 if (type <= TYPE_CPE) |
| 1870 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_d
ependent_coupling); | 1893 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_d
ependent_coupling); |
| 1871 if (che->ch[0].tns.present) | 1894 if (che->ch[0].tns.present) |
| 1872 apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ic
s, 1); | 1895 apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ic
s, 1); |
| 1873 if (che->ch[1].tns.present) | 1896 if (che->ch[1].tns.present) |
| 1874 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ic
s, 1); | 1897 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ic
s, 1); |
| 1875 if (type <= TYPE_CPE) | 1898 if (type <= TYPE_CPE) |
| 1876 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMD
CT, apply_dependent_coupling); | 1899 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMD
CT, apply_dependent_coupling); |
| 1877 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) | 1900 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT)
{ |
| 1878 imdct_and_windowing(ac, &che->ch[0]); | 1901 imdct_and_windowing(ac, &che->ch[0]); |
| 1879 if (type == TYPE_CPE) | 1902 if (ac->m4ac.sbr > 0) { |
| 1903 ff_sbr_dequant(ac, &che->sbr, type == TYPE_CPE ? TYPE_CP
E : TYPE_SCE); |
| 1904 ff_sbr_apply(ac, &che->sbr, 0, che->ch[0].ret, che->ch[0
].ret); |
| 1905 } |
| 1906 } |
| 1907 if (type == TYPE_CPE) { |
| 1880 imdct_and_windowing(ac, &che->ch[1]); | 1908 imdct_and_windowing(ac, &che->ch[1]); |
| 1909 if (ac->m4ac.sbr > 0) |
| 1910 ff_sbr_apply(ac, &che->sbr, 1, che->ch[1].ret, che->ch[1
].ret); |
| 1911 } |
| 1881 if (type <= TYPE_CCE) | 1912 if (type <= TYPE_CCE) |
| 1882 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_
independent_coupling); | 1913 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_
independent_coupling); |
| 1883 } | 1914 } |
| 1884 } | 1915 } |
| 1885 } | 1916 } |
| 1886 } | 1917 } |
| 1887 | 1918 |
| 1888 static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) | 1919 static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) |
| 1889 { | 1920 { |
| 1890 int size; | 1921 int size; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1920 } | 1951 } |
| 1921 return size; | 1952 return size; |
| 1922 } | 1953 } |
| 1923 | 1954 |
| 1924 static int aac_decode_frame(AVCodecContext *avccontext, void *data, | 1955 static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 1925 int *data_size, AVPacket *avpkt) | 1956 int *data_size, AVPacket *avpkt) |
| 1926 { | 1957 { |
| 1927 const uint8_t *buf = avpkt->data; | 1958 const uint8_t *buf = avpkt->data; |
| 1928 int buf_size = avpkt->size; | 1959 int buf_size = avpkt->size; |
| 1929 AACContext *ac = avccontext->priv_data; | 1960 AACContext *ac = avccontext->priv_data; |
| 1930 ChannelElement *che = NULL; | 1961 ChannelElement *che = NULL, *che_prev = NULL; |
| 1931 GetBitContext gb; | 1962 GetBitContext gb; |
| 1932 enum RawDataBlockType elem_type; | 1963 enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; |
| 1933 int err, elem_id, data_size_tmp; | 1964 int err, elem_id, data_size_tmp; |
| 1965 int buf_consumed; |
| 1966 int samples = 1024, multiplier; |
| 1934 | 1967 |
| 1935 init_get_bits(&gb, buf, buf_size * 8); | 1968 init_get_bits(&gb, buf, buf_size * 8); |
| 1936 gb.buffer_enforcing = 1; | 1969 gb.buffer_enforcing = 1; |
| 1937 | 1970 |
| 1938 if (show_bits(&gb, 12) == 0xfff) { | 1971 if (show_bits(&gb, 12) == 0xfff) { |
| 1939 if (parse_adts_frame_header(ac, &gb) < 0) { | 1972 if (parse_adts_frame_header(ac, &gb) < 0) { |
| 1940 av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n
"); | 1973 av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n
"); |
| 1941 return -1; | 1974 return -1; |
| 1942 } | 1975 } |
| 1943 if (ac->m4ac.sampling_index > 12) { | 1976 if (ac->m4ac.sampling_index > 12) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1973 | 2006 |
| 1974 case TYPE_CCE: | 2007 case TYPE_CCE: |
| 1975 err = decode_cce(ac, &gb, che); | 2008 err = decode_cce(ac, &gb, che); |
| 1976 break; | 2009 break; |
| 1977 | 2010 |
| 1978 case TYPE_LFE: | 2011 case TYPE_LFE: |
| 1979 err = decode_ics(ac, &che->ch[0], &gb, 0, 0); | 2012 err = decode_ics(ac, &che->ch[0], &gb, 0, 0); |
| 1980 break; | 2013 break; |
| 1981 | 2014 |
| 1982 case TYPE_DSE: | 2015 case TYPE_DSE: |
| 1983 skip_data_stream_element(&gb); | 2016 err = skip_data_stream_element(ac, &gb); |
| 1984 err = 0; | |
| 1985 break; | 2017 break; |
| 1986 | 2018 |
| 1987 case TYPE_PCE: { | 2019 case TYPE_PCE: { |
| 1988 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; | 2020 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; |
| 1989 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | 2021 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
| 1990 if ((err = decode_pce(ac, new_che_pos, &gb))) | 2022 if ((err = decode_pce(ac, new_che_pos, &gb))) |
| 1991 break; | 2023 break; |
| 1992 if (ac->output_configured > OC_TRIAL_PCE) | 2024 if (ac->output_configured > OC_TRIAL_PCE) |
| 1993 av_log(avccontext, AV_LOG_ERROR, | 2025 av_log(avccontext, AV_LOG_ERROR, |
| 1994 "Not evaluating a further program_config_element as this
construct is dubious at best.\n"); | 2026 "Not evaluating a further program_config_element as this
construct is dubious at best.\n"); |
| 1995 else | 2027 else |
| 1996 err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL
_PCE); | 2028 err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL
_PCE); |
| 1997 break; | 2029 break; |
| 1998 } | 2030 } |
| 1999 | 2031 |
| 2000 case TYPE_FIL: | 2032 case TYPE_FIL: |
| 2001 if (elem_id == 15) | 2033 if (elem_id == 15) |
| 2002 elem_id += get_bits(&gb, 8) - 1; | 2034 elem_id += get_bits(&gb, 8) - 1; |
| 2035 if (get_bits_left(&gb) < 8 * elem_id) { |
| 2036 av_log(avccontext, AV_LOG_ERROR, overread_err); |
| 2037 return -1; |
| 2038 } |
| 2003 while (elem_id > 0) | 2039 while (elem_id > 0) |
| 2004 elem_id -= decode_extension_payload(ac, &gb, elem_id); | 2040 elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev,
elem_type_prev); |
| 2005 err = 0; /* FIXME */ | 2041 err = 0; /* FIXME */ |
| 2006 break; | 2042 break; |
| 2007 | 2043 |
| 2008 default: | 2044 default: |
| 2009 err = -1; /* should not happen, but keeps compiler happy */ | 2045 err = -1; /* should not happen, but keeps compiler happy */ |
| 2010 break; | 2046 break; |
| 2011 } | 2047 } |
| 2012 | 2048 |
| 2049 che_prev = che; |
| 2050 elem_type_prev = elem_type; |
| 2051 |
| 2013 if (err) | 2052 if (err) |
| 2014 return err; | 2053 return err; |
| 2054 |
| 2055 if (get_bits_left(&gb) < 3) { |
| 2056 av_log(avccontext, AV_LOG_ERROR, overread_err); |
| 2057 return -1; |
| 2058 } |
| 2015 } | 2059 } |
| 2016 | 2060 |
| 2017 spectral_to_sample(ac); | 2061 spectral_to_sample(ac); |
| 2018 | 2062 |
| 2019 if (!ac->is_saved) { | 2063 multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sampl
e_rate : 0; |
| 2020 ac->is_saved = 1; | 2064 samples <<= multiplier; |
| 2021 *data_size = 0; | 2065 if (ac->output_configured < OC_LOCKED) { |
| 2022 return buf_size; | 2066 avccontext->sample_rate = ac->m4ac.sample_rate << multiplier; |
| 2067 avccontext->frame_size = samples; |
| 2023 } | 2068 } |
| 2024 | 2069 |
| 2025 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t); | 2070 data_size_tmp = samples * avccontext->channels * sizeof(int16_t); |
| 2026 if (*data_size < data_size_tmp) { | 2071 if (*data_size < data_size_tmp) { |
| 2027 av_log(avccontext, AV_LOG_ERROR, | 2072 av_log(avccontext, AV_LOG_ERROR, |
| 2028 "Output buffer too small (%d) or trying to output too many sample
s (%d) for this frame.\n", | 2073 "Output buffer too small (%d) or trying to output too many sample
s (%d) for this frame.\n", |
| 2029 *data_size, data_size_tmp); | 2074 *data_size, data_size_tmp); |
| 2030 return -1; | 2075 return -1; |
| 2031 } | 2076 } |
| 2032 *data_size = data_size_tmp; | 2077 *data_size = data_size_tmp; |
| 2033 | 2078 |
| 2034 ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 102
4, avccontext->channels); | 2079 ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, sam
ples, avccontext->channels); |
| 2035 | 2080 |
| 2036 if (ac->output_configured) | 2081 if (ac->output_configured) |
| 2037 ac->output_configured = OC_LOCKED; | 2082 ac->output_configured = OC_LOCKED; |
| 2038 | 2083 |
| 2039 return buf_size; | 2084 buf_consumed = (get_bits_count(&gb) + 7) >> 3; |
| 2085 return buf_size > buf_consumed ? buf_consumed : buf_size; |
| 2040 } | 2086 } |
| 2041 | 2087 |
| 2042 static av_cold int aac_decode_close(AVCodecContext *avccontext) | 2088 static av_cold int aac_decode_close(AVCodecContext *avccontext) |
| 2043 { | 2089 { |
| 2044 AACContext *ac = avccontext->priv_data; | 2090 AACContext *ac = avccontext->priv_data; |
| 2045 int i, type; | 2091 int i, type; |
| 2046 | 2092 |
| 2047 for (i = 0; i < MAX_ELEM_ID; i++) { | 2093 for (i = 0; i < MAX_ELEM_ID; i++) { |
| 2048 for (type = 0; type < 4; type++) | 2094 for (type = 0; type < 4; type++) { |
| 2095 if (ac->che[type][i]) |
| 2096 ff_aac_sbr_ctx_close(&ac->che[type][i]->sbr); |
| 2049 av_freep(&ac->che[type][i]); | 2097 av_freep(&ac->che[type][i]); |
| 2098 } |
| 2050 } | 2099 } |
| 2051 | 2100 |
| 2052 ff_mdct_end(&ac->mdct); | 2101 ff_mdct_end(&ac->mdct); |
| 2053 ff_mdct_end(&ac->mdct_small); | 2102 ff_mdct_end(&ac->mdct_small); |
| 2054 return 0; | 2103 return 0; |
| 2055 } | 2104 } |
| 2056 | 2105 |
| 2057 AVCodec aac_decoder = { | 2106 AVCodec aac_decoder = { |
| 2058 "aac", | 2107 "aac", |
| 2059 CODEC_TYPE_AUDIO, | 2108 CODEC_TYPE_AUDIO, |
| 2060 CODEC_ID_AAC, | 2109 CODEC_ID_AAC, |
| 2061 sizeof(AACContext), | 2110 sizeof(AACContext), |
| 2062 aac_decode_init, | 2111 aac_decode_init, |
| 2063 NULL, | 2112 NULL, |
| 2064 aac_decode_close, | 2113 aac_decode_close, |
| 2065 aac_decode_frame, | 2114 aac_decode_frame, |
| 2066 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), | 2115 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), |
| 2067 .sample_fmts = (const enum SampleFormat[]) { | 2116 .sample_fmts = (const enum SampleFormat[]) { |
| 2068 SAMPLE_FMT_S16,SAMPLE_FMT_NONE | 2117 SAMPLE_FMT_S16,SAMPLE_FMT_NONE |
| 2069 }, | 2118 }, |
| 2070 .channel_layouts = aac_channel_layout, | 2119 .channel_layouts = aac_channel_layout, |
| 2071 }; | 2120 }; |
| OLD | NEW |