Advertisement
Guest User

Untitled

a guest
Oct 5th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.71 KB | None | 0 0
  1. diff --git a/mythtv/external/FFmpeg/libavcodec/aac.h b/mythtv/external/FFmpeg/libavcodec/aac.h
  2. index a2bf70b..837f612 100644
  3. --- a/mythtv/external/FFmpeg/libavcodec/aac.h
  4. +++ b/mythtv/external/FFmpeg/libavcodec/aac.h
  5. @@ -130,6 +130,7 @@ typedef struct {
  6. #define SCALE_MAX_POS 255 ///< scalefactor index maximum value
  7. #define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard
  8. #define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference
  9. +#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0);
  10.  
  11. /**
  12. * Long Term Prediction
  13. diff --git a/mythtv/external/FFmpeg/libavcodec/aacdec.c b/mythtv/external/FFmpeg/libavcodec/aacdec.c
  14. index a362d6a..214812d 100644
  15. --- a/mythtv/external/FFmpeg/libavcodec/aacdec.c
  16. +++ b/mythtv/external/FFmpeg/libavcodec/aacdec.c
  17. @@ -178,9 +178,8 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
  18. * @return Returns error status. 0 - OK, !0 - error
  19. */
  20. static av_cold int che_configure(AACContext *ac,
  21. - enum ChannelPosition che_pos[4][MAX_ELEM_ID],
  22. - int type, int id,
  23. - int *channels)
  24. + enum ChannelPosition che_pos[4][MAX_ELEM_ID],
  25. + int type, int id, int *channels)
  26. {
  27. if (che_pos[type][id]) {
  28. if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
  29. @@ -210,9 +209,9 @@ static av_cold int che_configure(AACContext *ac,
  30. * @return Returns error status. 0 - OK, !0 - error
  31. */
  32. static av_cold int output_configure(AACContext *ac,
  33. - enum ChannelPosition che_pos[4][MAX_ELEM_ID],
  34. - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
  35. - int channel_config, enum OCStatus oc_type)
  36. + enum ChannelPosition che_pos[4][MAX_ELEM_ID],
  37. + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
  38. + int channel_config, enum OCStatus oc_type)
  39. {
  40. AVCodecContext *avctx = ac->avctx;
  41. int i, type, channels = 0, ret;
  42. @@ -229,7 +228,7 @@ static av_cold int output_configure(AACContext *ac,
  43. return ret;
  44. }
  45.  
  46. - memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
  47. + memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
  48.  
  49. avctx->channel_layout = aac_channel_layout[channel_config - 1];
  50. } else {
  51. @@ -250,8 +249,6 @@ static av_cold int output_configure(AACContext *ac,
  52. }
  53.  
  54. memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
  55. -
  56. - avctx->channel_layout = 0;
  57. }
  58.  
  59. avctx->channels = channels;
  60. @@ -314,6 +311,10 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
  61. if (get_bits1(gb))
  62. skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
  63.  
  64. + if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
  65. + av_log(avctx, AV_LOG_ERROR, overread_err);
  66. + return -1;
  67. + }
  68. decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front);
  69. decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side );
  70. decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back );
  71. @@ -344,8 +345,8 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
  72. * @return Returns error status. 0 - OK, !0 - error
  73. */
  74. static av_cold int set_default_channel_config(AVCodecContext *avctx,
  75. - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
  76. - int channel_config)
  77. + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
  78. + int channel_config)
  79. {
  80. if (channel_config < 1 || channel_config > 7) {
  81. av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
  82. @@ -457,14 +458,19 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
  83. static int decode_audio_specific_config(AACContext *ac,
  84. AVCodecContext *avctx,
  85. MPEG4AudioConfig *m4ac,
  86. - const uint8_t *data, int data_size)
  87. + const uint8_t *data, int data_size, int asclen)
  88. {
  89. GetBitContext gb;
  90. int i;
  91.  
  92. + av_dlog(avctx, "extradata size %d\n", avctx->extradata_size);
  93. + for (i = 0; i < avctx->extradata_size; i++)
  94. + av_dlog(avctx, "%02x ", avctx->extradata[i]);
  95. + av_dlog(avctx, "\n");
  96. +
  97. init_get_bits(&gb, data, data_size * 8);
  98.  
  99. - if ((i = ff_mpeg4audio_get_config(m4ac, data, data_size)) < 0)
  100. + if ((i = ff_mpeg4audio_get_config(m4ac, data, asclen/8)) < 0)
  101. return -1;
  102. if (m4ac->sampling_index > 12) {
  103. av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index);
  104. @@ -488,6 +494,10 @@ static int decode_audio_specific_config(AACContext *ac,
  105. return -1;
  106. }
  107.  
  108. + av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
  109. + m4ac->object_type, m4ac->chan_config, m4ac->sampling_index,
  110. + m4ac->sample_rate, m4ac->sbr, m4ac->ps);
  111. +
  112. return get_bits_count(&gb);
  113. }
  114.  
  115. @@ -520,6 +530,22 @@ static void reset_all_predictors(PredictorState *ps)
  116. reset_predict_state(&ps[i]);
  117. }
  118.  
  119. +static int sample_rate_idx (int rate)
  120. +{
  121. + if (92017 <= rate) return 0;
  122. + else if (75132 <= rate) return 1;
  123. + else if (55426 <= rate) return 2;
  124. + else if (46009 <= rate) return 3;
  125. + else if (37566 <= rate) return 4;
  126. + else if (27713 <= rate) return 5;
  127. + else if (23004 <= rate) return 6;
  128. + else if (18783 <= rate) return 7;
  129. + else if (13856 <= rate) return 8;
  130. + else if (11502 <= rate) return 9;
  131. + else if (9391 <= rate) return 10;
  132. + else return 11;
  133. +}
  134. +
  135. static void reset_predictor_group(PredictorState *ps, int group_num)
  136. {
  137. int i;
  138. @@ -543,8 +569,29 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
  139. if (avctx->extradata_size > 0) {
  140. if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
  141. avctx->extradata,
  142. - avctx->extradata_size) < 0)
  143. + avctx->extradata_size, 8*avctx->extradata_size) < 0)
  144. return -1;
  145. + } else {
  146. + int sr, i;
  147. + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
  148. +
  149. + sr = sample_rate_idx(avctx->sample_rate);
  150. + ac->m4ac.sampling_index = sr;
  151. + ac->m4ac.channels = avctx->channels;
  152. + ac->m4ac.sbr = -1;
  153. + ac->m4ac.ps = -1;
  154. +
  155. + for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
  156. + if (ff_mpeg4audio_channels[i] == avctx->channels)
  157. + break;
  158. + if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) {
  159. + i = 0;
  160. + }
  161. + ac->m4ac.chan_config = i;
  162. +
  163. + if (ac->m4ac.chan_config) {
  164. + set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config);
  165. + }
  166. }
  167.  
  168. avctx->sample_fmt = AV_SAMPLE_FMT_S16;
  169. @@ -568,12 +615,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
  170.  
  171. ac->random_state = 0x1f2e3d4c;
  172.  
  173. - // -1024 - Compensate wrong IMDCT method.
  174. - // 60 - Required to scale values to the correct range [-32768,32767]
  175. - // for float to int16 conversion. (1 << (60 / 4)) == 32768
  176. - ac->sf_scale = 1. / -1024.;
  177. - ac->sf_offset = 60;
  178. -
  179. ff_aac_tableinit();
  180.  
  181. INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
  182. @@ -581,9 +622,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
  183. ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]),
  184. 352);
  185.  
  186. - ff_mdct_init(&ac->mdct, 11, 1, 1.0);
  187. - ff_mdct_init(&ac->mdct_small, 8, 1, 1.0);
  188. - ff_mdct_init(&ac->mdct_ltp, 11, 0, 1.0);
  189. + ff_mdct_init(&ac->mdct, 11, 1, 1.0/1024.0);
  190. + ff_mdct_init(&ac->mdct_small, 8, 1, 1.0/128.0);
  191. + ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0);
  192. // window initialization
  193. ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
  194. ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
  195. @@ -641,7 +682,7 @@ static void decode_ltp(AACContext *ac, LongTermPrediction *ltp,
  196. int sfb;
  197.  
  198. ltp->lag = get_bits(gb, 11);
  199. - ltp->coef = ltp_coef[get_bits(gb, 3)] * ac->sf_scale;
  200. + ltp->coef = ltp_coef[get_bits(gb, 3)];
  201. for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++)
  202. ltp->used[sfb] = get_bits1(gb);
  203. }
  204. @@ -779,9 +820,9 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
  205. enum BandType band_type[120],
  206. int band_type_run_end[120])
  207. {
  208. - const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0);
  209. int g, i, idx = 0;
  210. - int offset[3] = { global_gain, global_gain - 90, 100 };
  211. + int offset[3] = { global_gain, global_gain - 90, 0 };
  212. + int clipped_offset;
  213. int noise_flag = 1;
  214. static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
  215. for (g = 0; g < ics->num_window_groups; g++) {
  216. @@ -793,12 +834,15 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
  217. } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) {
  218. for (; i < run_end; i++, idx++) {
  219. offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
  220. - if (offset[2] > 255U) {
  221. - av_log(ac->avctx, AV_LOG_ERROR,
  222. - "%s (%d) out of range.\n", sf_str[2], offset[2]);
  223. - return -1;
  224. + clipped_offset = av_clip(offset[2], -155, 100);
  225. + if (offset[2] != clipped_offset) {
  226. +/* av_log_ask_for_sample(ac->avctx, "Intensity stereo "
  227. + "position clipped (%d -> %d).\nIf you heard an "
  228. + "audible artifact, there may be a bug in the "
  229. + "decoder. ", offset[2], clipped_offset);
  230. +*/
  231. }
  232. - sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300];
  233. + sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
  234. }
  235. } else if (band_type[idx] == NOISE_BT) {
  236. for (; i < run_end; i++, idx++) {
  237. @@ -806,12 +850,15 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
  238. offset[1] += get_bits(gb, 9) - 256;
  239. else
  240. offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
  241. - if (offset[1] > 255U) {
  242. - av_log(ac->avctx, AV_LOG_ERROR,
  243. - "%s (%d) out of range.\n", sf_str[1], offset[1]);
  244. - return -1;
  245. + clipped_offset = av_clip(offset[1], -100, 155);
  246. + if (offset[1] != clipped_offset) {
  247. +/* av_log_ask_for_sample(ac->avctx, "Noise gain clipped "
  248. + "(%d -> %d).\nIf you heard an audible "
  249. + "artifact, there may be a bug in the decoder. ",
  250. + offset[1], clipped_offset);
  251. +*/
  252. }
  253. - sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100];
  254. + sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
  255. }
  256. } else {
  257. for (; i < run_end; i++, idx++) {
  258. @@ -821,7 +868,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
  259. "%s (%d) out of range.\n", sf_str[0], offset[0]);
  260. return -1;
  261. }
  262. - sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset];
  263. + sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
  264. }
  265. }
  266. }
  267. @@ -962,19 +1009,19 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
  268. union float754 s = { .f = *scale };
  269. union float754 t;
  270.  
  271. - t.i = s.i ^ (sign & 1<<31);
  272. + t.i = s.i ^ (sign & 1U<<31);
  273. *dst++ = v[idx & 3] * t.f;
  274.  
  275. sign <<= nz & 1; nz >>= 1;
  276. - t.i = s.i ^ (sign & 1<<31);
  277. + t.i = s.i ^ (sign & 1U<<31);
  278. *dst++ = v[idx>>2 & 3] * t.f;
  279.  
  280. sign <<= nz & 1; nz >>= 1;
  281. - t.i = s.i ^ (sign & 1<<31);
  282. + t.i = s.i ^ (sign & 1U<<31);
  283. *dst++ = v[idx>>4 & 3] * t.f;
  284.  
  285. sign <<= nz & 1; nz >>= 1;
  286. - t.i = s.i ^ (sign & 1<<31);
  287. + t.i = s.i ^ (sign & 1U<<31);
  288. *dst++ = v[idx>>6 & 3] * t.f;
  289.  
  290. return dst;
  291. @@ -1167,11 +1214,11 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
  292. b += 4;
  293. n = (1 << b) + SHOW_UBITS(re, gb, b);
  294. LAST_SKIP_BITS(re, gb, b);
  295. - *icf++ = cbrt_tab[n] | (bits & 1<<31);
  296. + *icf++ = cbrt_tab[n] | (bits & 1U<<31);
  297. bits <<= 1;
  298. } else {
  299. unsigned v = ((const uint32_t*)vq)[cb_idx & 15];
  300. - *icf++ = (bits & 1<<31) | v;
  301. + *icf++ = (bits & 1U<<31) | v;
  302. bits <<= !!v;
  303. }
  304. cb_idx >>= 4;
  305. @@ -1232,8 +1279,7 @@ static av_always_inline float flt16_trunc(float pf)
  306. }
  307.  
  308. static av_always_inline void predict(PredictorState *ps, float *coef,
  309. - float sf_scale, float inv_sf_scale,
  310. - int output_enable)
  311. + int output_enable)
  312. {
  313. const float a = 0.953125; // 61.0 / 64
  314. const float alpha = 0.90625; // 29.0 / 32
  315. @@ -1249,9 +1295,9 @@ static av_always_inline void predict(PredictorState *ps, float *coef,
  316.  
  317. pv = flt16_round(k1 * r0 + k2 * r1);
  318. if (output_enable)
  319. - *coef += pv * sf_scale;
  320. + *coef += pv;
  321.  
  322. - e0 = *coef * inv_sf_scale;
  323. + e0 = *coef;
  324. e1 = e0 - k1 * r0;
  325.  
  326. ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
  327. @@ -1269,7 +1315,6 @@ static av_always_inline void predict(PredictorState *ps, float *coef,
  328. static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
  329. {
  330. int sfb, k;
  331. - float sf_scale = ac->sf_scale, inv_sf_scale = 1 / ac->sf_scale;
  332.  
  333. if (!sce->ics.predictor_initialized) {
  334. reset_all_predictors(sce->predictor_state);
  335. @@ -1280,7 +1325,6 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
  336. for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) {
  337. for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
  338. predict(&sce->predictor_state[k], &sce->coeffs[k],
  339. - sf_scale, inv_sf_scale,
  340. sce->ics.predictor_present && sce->ics.prediction_used[sfb]);
  341. }
  342. }
  343. @@ -1741,16 +1785,14 @@ static void windowing_and_mdct_ltp(AACContext *ac, float *out,
  344. } else {
  345. memset(in, 0, 448 * sizeof(float));
  346. ac->dsp.vector_fmul(in + 448, in + 448, swindow_prev, 128);
  347. - memcpy(in + 576, in + 576, 448 * sizeof(float));
  348. }
  349. if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
  350. ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
  351. } else {
  352. - memcpy(in + 1024, in + 1024, 448 * sizeof(float));
  353. ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
  354. memset(in + 1024 + 576, 0, 448 * sizeof(float));
  355. }
  356. - ff_mdct_calc(&ac->mdct_ltp, out, in);
  357. + ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in);
  358. }
  359.  
  360. /**
  361. @@ -1763,8 +1805,8 @@ static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
  362. int i, sfb;
  363.  
  364. if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
  365. - float *predTime = ac->buf_mdct;
  366. - float *predFreq = sce->ret;
  367. + float *predTime = sce->ret;
  368. + float *predFreq = ac->buf_mdct;
  369. int16_t num_samples = 2048;
  370.  
  371. if (ltp->lag < 1024)
  372. @@ -1797,24 +1839,27 @@ static void update_ltp(AACContext *ac, SingleChannelElement *sce)
  373. const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
  374. int i;
  375.  
  376. - for (i = 0; i < 512; i++)
  377. - ac->buf_mdct[1535 - i] = ac->buf_mdct[512 + i];
  378. -
  379. if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
  380. memcpy(saved_ltp, saved, 512 * sizeof(float));
  381. memset(saved_ltp + 576, 0, 448 * sizeof(float));
  382. - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, swindow, 128);
  383. + ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
  384. + for (i = 0; i < 64; i++)
  385. + saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
  386. } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
  387. memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float));
  388. memset(saved_ltp + 576, 0, 448 * sizeof(float));
  389. - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, swindow, 128);
  390. + ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
  391. + for (i = 0; i < 64; i++)
  392. + saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
  393. } else { // LONG_STOP or ONLY_LONG
  394. - ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, lwindow, 1024);
  395. + ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512);
  396. + for (i = 0; i < 512; i++)
  397. + saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i];
  398. }
  399.  
  400. - memcpy(sce->ltp_state, &sce->ltp_state[1024], 1024 * sizeof(int16_t));
  401. - ac->fmt_conv.float_to_int16(&(sce->ltp_state[1024]), sce->ret, 1024);
  402. - ac->fmt_conv.float_to_int16(&(sce->ltp_state[2048]), saved_ltp, 1024);
  403. + memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state));
  404. + memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state));
  405. + memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state));
  406. }
  407.  
  408. /**
  409. @@ -1836,9 +1881,9 @@ static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
  410. // imdct
  411. if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
  412. for (i = 0; i < 1024; i += 128)
  413. - ff_imdct_half(&ac->mdct_small, buf + i, in + i);
  414. + ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i);
  415. } else
  416. - ff_imdct_half(&ac->mdct, buf, in);
  417. + ac->mdct.imdct_half(&ac->mdct, buf, in);
  418.  
  419. /* window overlapping
  420. * NOTE: To simplify the overlapping code, all 'meaningless' short to long
  421. @@ -2023,7 +2068,7 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
  422.  
  423. size = ff_aac_parse_header(gb, &hdr_info);
  424. if (size > 0) {
  425. - if (ac->output_configured != OC_LOCKED && hdr_info.chan_config) {
  426. + if (hdr_info.chan_config) {
  427. enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
  428. memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
  429. ac->m4ac.chan_config = hdr_info.chan_config;
  430. @@ -2032,15 +2077,16 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
  431. if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, OC_TRIAL_FRAME))
  432. return -7;
  433. } else if (ac->output_configured != OC_LOCKED) {
  434. + ac->m4ac.chan_config = 0;
  435. ac->output_configured = OC_NONE;
  436. }
  437. if (ac->output_configured != OC_LOCKED) {
  438. ac->m4ac.sbr = -1;
  439. ac->m4ac.ps = -1;
  440. + ac->m4ac.sample_rate = hdr_info.sample_rate;
  441. + ac->m4ac.sampling_index = hdr_info.sampling_index;
  442. + ac->m4ac.object_type = hdr_info.object_type;
  443. }
  444. - ac->m4ac.sample_rate = hdr_info.sample_rate;
  445. - ac->m4ac.sampling_index = hdr_info.sampling_index;
  446. - ac->m4ac.object_type = hdr_info.object_type;
  447. if (!ac->avctx->sample_rate)
  448. ac->avctx->sample_rate = hdr_info.sample_rate;
  449. if (hdr_info.num_aac_frames == 1) {
  450. @@ -2061,7 +2107,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
  451. ChannelElement *che = NULL, *che_prev = NULL;
  452. enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;
  453. int err, elem_id, data_size_tmp;
  454. - int samples = 0, multiplier;
  455. + int samples = 0, multiplier, audio_found = 0;
  456.  
  457. if (show_bits(gb, 12) == 0xfff) {
  458. if (parse_adts_frame_header(ac, gb) < 0) {
  459. @@ -2092,10 +2138,12 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
  460.  
  461. case TYPE_SCE:
  462. err = decode_ics(ac, &che->ch[0], gb, 0, 0);
  463. + audio_found = 1;
  464. break;
  465.  
  466. case TYPE_CPE:
  467. err = decode_cpe(ac, gb, che);
  468. + audio_found = 1;
  469. break;
  470.  
  471. case TYPE_CCE:
  472. @@ -2104,6 +2152,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
  473.  
  474. case TYPE_LFE:
  475. err = decode_ics(ac, &che->ch[0], gb, 0, 0);
  476. + audio_found = 1;
  477. break;
  478.  
  479. case TYPE_DSE:
  480. @@ -2173,7 +2222,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
  481. if (samples)
  482. ac->fmt_conv.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels);
  483.  
  484. - if (ac->output_configured)
  485. + if (ac->output_configured && audio_found)
  486. ac->output_configured = OC_LOCKED;
  487.  
  488. return 0;
  489. @@ -2242,10 +2291,11 @@ static inline uint32_t latm_get_value(GetBitContext *b)
  490. }
  491.  
  492. static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
  493. - GetBitContext *gb)
  494. + GetBitContext *gb, int asclen)
  495. {
  496. AVCodecContext *avctx = latmctx->aac_ctx.avctx;
  497. MPEG4AudioConfig m4ac;
  498. + AACContext *ac= &latmctx->aac_ctx;
  499. int config_start_bit = get_bits_count(gb);
  500. int bits_consumed, esize;
  501.  
  502. @@ -2255,12 +2305,13 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
  503. return AVERROR_INVALIDDATA;
  504. } else {
  505. bits_consumed =
  506. - decode_audio_specific_config(NULL, avctx, &m4ac,
  507. + decode_audio_specific_config(ac, avctx, &m4ac,
  508. gb->buffer + (config_start_bit / 8),
  509. - get_bits_left(gb) / 8);
  510. + get_bits_left(gb) / 8, asclen);
  511.  
  512. if (bits_consumed < 0)
  513. return AVERROR_INVALIDDATA;
  514. + ac->m4ac= m4ac;
  515.  
  516. esize = (bits_consumed+7) / 8;
  517.  
  518. @@ -2315,11 +2366,11 @@ static int read_stream_mux_config(struct LATMContext *latmctx,
  519.  
  520. // for all but first stream: use_same_config = get_bits(gb, 1);
  521. if (!audio_mux_version) {
  522. - if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0)
  523. + if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0)
  524. return ret;
  525. } else {
  526. int ascLen = latm_get_value(gb);
  527. - if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0)
  528. + if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0)
  529. return ret;
  530. ascLen -= ret;
  531. skip_bits_long(gb, ascLen);
  532. @@ -2442,6 +2493,7 @@ static int latm_decode_frame(AVCodecContext *avctx, void *out, int *out_size,
  533. *out_size = 0;
  534. return avpkt->size;
  535. } else {
  536. + aac_decode_close(avctx);
  537. if ((err = aac_decode_init(avctx)) < 0)
  538. return err;
  539. latmctx->initialized = 1;
  540. diff --git a/mythtv/external/FFmpeg/libavcodec/aacsbr.c b/mythtv/external/FFmpeg/libavcodec/aacsbr.c
  541. index 237d51a..e2b37df 100644
  542. --- a/mythtv/external/FFmpeg/libavcodec/aacsbr.c
  543. +++ b/mythtv/external/FFmpeg/libavcodec/aacsbr.c
  544. @@ -32,9 +32,12 @@
  545. #include "aacsbrdata.h"
  546. #include "fft.h"
  547. #include "aacps.h"
  548. +#include "libavutil/libm.h"
  549. +#include "libavutil/avassert.h"
  550.  
  551. #include <stdint.h>
  552. #include <float.h>
  553. +#include <math.h>
  554.  
  555. #define ENVELOPE_ADJUSTMENT_OFFSET 2
  556. #define NOISE_FLOOR_OFFSET 6.0f
  557. @@ -127,11 +130,13 @@ av_cold void ff_aac_sbr_init(void)
  558.  
  559. av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr)
  560. {
  561. + if(sbr->mdct.mdct_bits)
  562. + return;
  563. sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
  564. sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1;
  565. sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
  566. sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
  567. - ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64);
  568. + ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / 64.0);
  569. ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0);
  570. ff_ps_ctx_init(&sbr->ps);
  571. }
  572. @@ -1155,7 +1160,7 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in,
  573. }
  574. z[64+63] = z[32];
  575.  
  576. - ff_imdct_half(mdct, z, z+64);
  577. + mdct->imdct_half(mdct, z, z+64);
  578. for (k = 0; k < 32; k++) {
  579. W[1][i][k][0] = -z[63-k];
  580. W[1][i][k][1] = z[k];
  581. @@ -1190,7 +1195,7 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
  582. X[0][i][ n] = -X[0][i][n];
  583. X[0][i][32+n] = X[1][i][31-n];
  584. }
  585. - ff_imdct_half(mdct, mdct_buf[0], X[0][i]);
  586. + mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
  587. for (n = 0; n < 32; n++) {
  588. v[ n] = mdct_buf[0][63 - 2*n];
  589. v[63 - n] = -mdct_buf[0][62 - 2*n];
  590. @@ -1199,8 +1204,8 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
  591. for (n = 1; n < 64; n+=2) {
  592. X[1][i][n] = -X[1][i][n];
  593. }
  594. - ff_imdct_half(mdct, mdct_buf[0], X[0][i]);
  595. - ff_imdct_half(mdct, mdct_buf[1], X[1][i]);
  596. + mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
  597. + mdct->imdct_half(mdct, mdct_buf[1], X[1][i]);
  598. for (n = 0; n < 64; n++) {
  599. v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ];
  600. v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ];
  601. @@ -1450,6 +1455,7 @@ static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,
  602. uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
  603. int k;
  604.  
  605. + av_assert0(sbr->kx[1] <= table[0]);
  606. for (i = 0; i < ilim; i++)
  607. for (m = table[i]; m < table[i + 1]; m++)
  608. sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];
  609.  
  610.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement