X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Faacenc.c;h=2156fc03e1ec7878ef107e8d6656228b3a0ebf8e;hb=102842d5fbb7c38a437bc128938466b231fe0ce9;hp=796038c0dab0679f03bb7e67e5ef652cf47aaec4;hpb=23277aa24c1d3679ebb3f2f0ab13bea5c402fc8f;p=ffmpeg diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 796038c0dab..2156fc03e1e 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -29,6 +29,7 @@ * add sane pulse detection ***********************************/ +#include "libavutil/thread.h" #include "libavutil/float_dsp.h" #include "libavutil/opt.h" #include "avcodec.h" @@ -46,6 +47,8 @@ #include "psymodel.h" +static AVOnce aac_table_init = AV_ONCE_INIT; + /** * Make AAC audio config object. * @see 1.6.2.1 "Syntax - AudioSpecificConfig" @@ -292,7 +295,13 @@ static void apply_mid_side_stereo(ChannelElement *cpe) for (w2 = 0; w2 < ics->group_len[w]; w2++) { int start = (w+w2) * 128; for (g = 0; g < ics->num_swb; g++) { - if (!cpe->ms_mask[w*16 + g] && !cpe->is_mask[w*16 + g]) { + /* ms_mask can be used for other purposes in PNS and I/S, + * so must not apply M/S if any band uses either, even if + * ms_mask is set. + */ + if (!cpe->ms_mask[w*16 + g] || cpe->is_mask[w*16 + g] + || cpe->ch[0].band_type[w*16 + g] == NOISE_BT + || cpe->ch[1].band_type[w*16 + g] == NOISE_BT) { start += ics->swb_sizes[g]; continue; } @@ -669,14 +678,14 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, for (ch = 0; ch < chans; ch++) { /* TNS and PNS */ sce = &cpe->ch[ch]; s->cur_channel = start_ch + ch; - if (s->options.pns && s->coder->search_for_pns) - s->coder->search_for_pns(s, avctx, sce); if (s->options.tns && s->coder->search_for_tns) s->coder->search_for_tns(s, sce); if (s->options.tns && s->coder->apply_tns_filt) s->coder->apply_tns_filt(s, sce); if (sce->tns.present) tns_mode = 1; + if (s->options.pns && s->coder->search_for_pns) + s->coder->search_for_pns(s, avctx, sce); } s->cur_channel = start_ch; if (s->options.intensity_stereo) { /* Intensity Stereo */ @@ -784,7 +793,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->lambda = FFMIN(s->lambda * ratio, 65536.f); /* Keep iterating if we must reduce and lambda is in the sky */ - if ((s->lambda < 300.f || ratio > 0.9f) && (s->lambda > 10.f || ratio < 1.1f)) { + if (ratio > 0.9f && ratio < 1.1f) { break; } else { if (is_mode || ms_mode || tns_mode || pred_mode) { @@ -879,6 +888,11 @@ alloc_fail: return AVERROR(ENOMEM); } +static av_cold void aac_encode_init_tables(void) +{ + ff_aac_tableinit(); +} + static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; @@ -946,13 +960,17 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) avctx->profile = FF_PROFILE_AAC_MAIN; WARN_IF(1, "Chainging profile to \"aac_main\"\n"); - ERROR_IF(s->options.pred, + ERROR_IF(s->options.ltp, "LTP prediction unavailable in the \"aac_main\" profile\n"); } s->profile = avctx->profile; s->coder = &ff_aac_coders[s->options.coder]; if (s->options.coder != AAC_CODER_TWOLOOP) { + ERROR_IF(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL, + "Coders other than twoloop require -strict -2 and some may be removed in the future\n"); + WARN_IF(s->options.coder == AAC_CODER_FAAC, + "The FAAC-like coder will be removed in the near future, please use twoloop!\n"); s->options.intensity_stereo = 0; s->options.pns = 0; } @@ -977,10 +995,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) s->psypp = ff_psy_preprocess_init(avctx); ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON); - if (HAVE_MIPSDSPR1) + if (HAVE_MIPSDSP) ff_aac_coder_init_mips(s); - ff_aac_tableinit(); + if ((ret = ff_thread_once(&aac_table_init, &aac_encode_init_tables)) != 0) + return AVERROR_UNKNOWN; ff_af_queue_init(avctx, &s->afq); @@ -1023,8 +1042,8 @@ AVCodec ff_aac_encoder = { .encode2 = aac_encode_frame, .close = aac_encode_end, .supported_samplerates = mpeg4audio_sample_rates, - .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY | - AV_CODEC_CAP_EXPERIMENTAL, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, + .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, .priv_class = &aacenc_class,