diff options
-rw-r--r-- | contrib/ffmpeg/A04-aacenc-chan-order.patch | 46 | ||||
-rw-r--r-- | libhb/encavcodecaudio.c | 30 |
2 files changed, 11 insertions, 65 deletions
diff --git a/contrib/ffmpeg/A04-aacenc-chan-order.patch b/contrib/ffmpeg/A04-aacenc-chan-order.patch deleted file mode 100644 index 6a8a6c988..000000000 --- a/contrib/ffmpeg/A04-aacenc-chan-order.patch +++ /dev/null @@ -1,46 +0,0 @@ -diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c -index 66af2b1..16c5906 100644 ---- a/libavcodec/aacenc.c -+++ b/libavcodec/aacenc.c -@@ -135,6 +135,15 @@ static const uint8_t aac_chan_configs[6][5] = { - {4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE - }; - -+static const uint8_t channel_maps[][AAC_MAX_CHANNELS] = { -+ { 0 }, -+ { 0, 1 }, -+ { 2, 0, 1 }, -+ { 2, 0, 1, 3 }, -+ { 2, 0, 1, 3, 4 }, -+ { 2, 0, 1, 4, 5, 3 }, -+}; -+ - /** - * Make AAC audio config object. - * @see 1.6.2.1 "Syntax - AudioSpecificConfig" -@@ -499,15 +508,24 @@ static int aac_encode_frame(AVCodecContext *avctx, - return 0; - if (data) { - if (!s->psypp) { -+ if (avctx->channels <= 2) { - memcpy(s->samples + 1024 * avctx->channels, data, - 1024 * avctx->channels * sizeof(s->samples[0])); -+ } else { -+ for (i = 0; i < 1024; i++) -+ for (ch = 0; ch < avctx->channels; ch++) -+ s->samples[(i + 1024) * avctx->channels + ch] = -+ ((int16_t*)data)[i * avctx->channels + -+ channel_maps[avctx->channels-1][ch]]; -+ } - } else { - start_ch = 0; - samples2 = s->samples + 1024 * avctx->channels; - for (i = 0; i < chan_map[0]; i++) { - tag = chan_map[i+1]; - chans = tag == TYPE_CPE ? 2 : 1; -- ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch, -+ ff_psy_preprocess(s->psypp, -+ (uint16_t*)data + channel_maps[avctx->channels-1][start_ch], - samples2 + start_ch, start_ch, chans); - start_ch += chans; - } diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index 78d1a0565..9239c519a 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -16,6 +16,7 @@ struct hb_work_private_s int out_discrete_channels; int samples_per_frame; + int layout; unsigned long input_samples; unsigned long output_bytes; hb_list_t * list; @@ -69,16 +70,19 @@ static int encavcodecaInit( hb_work_object_t * w, hb_job_t * job ) { case HB_AMIXDOWN_MONO: context->channel_layout = AV_CH_LAYOUT_MONO; + pv->layout = HB_INPUT_CH_LAYOUT_MONO; break; case HB_AMIXDOWN_STEREO: case HB_AMIXDOWN_DOLBY: case HB_AMIXDOWN_DOLBYPLII: context->channel_layout = AV_CH_LAYOUT_STEREO; + pv->layout = HB_INPUT_CH_LAYOUT_STEREO; break; case HB_AMIXDOWN_6CH: context->channel_layout = AV_CH_LAYOUT_5POINT1; + pv->layout = HB_INPUT_CH_LAYOUT_3F2R | HB_INPUT_CH_LAYOUT_HAS_LFE; break; default: @@ -168,26 +172,14 @@ static hb_buffer_t * Encode( hb_work_object_t * w ) hb_list_getbytes( pv->list, pv->buf, pv->input_samples * sizeof( float ), &pts, &pos); - if ( audio->config.in.channel_map != &hb_smpte_chan_map ) + // XXX: ffaac fails to remap from the internal libav* channel map (SMPTE) to the native AAC channel map + // do it here - this hack should be removed if Libav fixes the bug + hb_chan_map_t * out_map = ( w->codec_param == CODEC_ID_AAC ) ? &hb_qt_chan_map : &hb_smpte_chan_map; + + if ( audio->config.in.channel_map != out_map ) { - int layout; - switch (audio->config.out.mixdown) - { - case HB_AMIXDOWN_MONO: - layout = HB_INPUT_CH_LAYOUT_MONO; - break; - case HB_AMIXDOWN_STEREO: - case HB_AMIXDOWN_DOLBY: - case HB_AMIXDOWN_DOLBYPLII: - layout = HB_INPUT_CH_LAYOUT_STEREO; - break; - case HB_AMIXDOWN_6CH: - default: - layout = HB_INPUT_CH_LAYOUT_3F2R | HB_INPUT_CH_LAYOUT_HAS_LFE; - break; - } - hb_layout_remap( audio->config.in.channel_map, &hb_smpte_chan_map, layout, - (float*)pv->buf, pv->samples_per_frame); + hb_layout_remap( audio->config.in.channel_map, out_map, pv->layout, + (float*)pv->buf, pv->samples_per_frame ); } // Do we need to convert our internal float format? |