X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flibfdk-aacenc.c;h=5620bb595118c859dcdabf79a5456869437d8d4e;hb=fe1ccc1e91168c855a2720d0a195377f4638cc70;hp=2ad768ed44ef6dde9e692a2b91f85a8222137123;hpb=141c960e21d2860e354f9b90df136184dd00a9a8;p=ffmpeg diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 2ad768ed44e..5620bb59511 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -2,7 +2,7 @@ * AAC encoder wrapper * Copyright (c) 2012 Martin Storsjo * - * This file is part of Libav. + * This file is part of FFmpeg. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,16 +26,20 @@ #include "audio_frame_queue.h" #include "internal.h" +#ifdef AACENCODER_LIB_VL0 #define FDKENC_VER_AT_LEAST(vl0, vl1) \ - (defined(AACENCODER_LIB_VL0) && \ - ((AACENCODER_LIB_VL0 > vl0) || \ - (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 >= vl1))) + ((AACENCODER_LIB_VL0 > vl0) || \ + (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 >= vl1)) +#else +#define FDKENC_VER_AT_LEAST(vl0, vl1) 0 +#endif typedef struct AACContext { const AVClass *class; HANDLE_AACENCODER handle; int afterburner; int eld_sbr; + int eld_v2; int signaling; int latm; int header_period; @@ -47,6 +51,9 @@ typedef struct AACContext { static const AVOption aac_enc_options[] = { { "afterburner", "Afterburner (improved quality)", offsetof(AACContext, afterburner), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, { "eld_sbr", "Enable SBR for ELD (for SBR in other configurations, use the -profile parameter)", offsetof(AACContext, eld_sbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, +#if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0 + { "eld_v2", "Enable ELDv2 (LD-MPS extension for ELD stereo signals)", offsetof(AACContext, eld_v2), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, +#endif { "signaling", "SBR/PS signaling style", offsetof(AACContext, signaling), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, "signaling" }, { "default", "Choose signaling implicitly (explicit hierarchical by default, implicit if global header is disabled)", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, "signaling" }, { "implicit", "Implicit backwards compatible signaling", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, "signaling" }, @@ -152,14 +159,35 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) switch (avctx->channels) { case 1: mode = MODE_1; sce = 1; cpe = 0; break; - case 2: mode = MODE_2; sce = 0; cpe = 1; break; + case 2: +#if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0 + // (profile + 1) to map from profile range to AOT range + if (aot == FF_PROFILE_AAC_ELD + 1 && s->eld_v2) { + if ((err = aacEncoder_SetParam(s->handle, AACENC_CHANNELMODE, + 128)) != AACENC_OK) { + av_log(avctx, AV_LOG_ERROR, "Unable to enable ELDv2: %s\n", + aac_get_error(err)); + goto error; + } else { + mode = MODE_212; + sce = 1; + cpe = 0; + } + } else +#endif + { + mode = MODE_2; + sce = 0; + cpe = 1; + } + break; case 3: mode = MODE_1_2; sce = 1; cpe = 1; break; case 4: mode = MODE_1_2_1; sce = 2; cpe = 1; break; case 5: mode = MODE_1_2_2; sce = 1; cpe = 2; break; case 6: mode = MODE_1_2_2_1; sce = 2; cpe = 2; break; /* The version macro is introduced the same time as the 7.1 support, so this should suffice. */ -#ifdef AACENCODER_LIB_VL0 +#if FDKENC_VER_AT_LEAST(3, 4) // 3.4.12 case 8: sce = 2; cpe = 3; @@ -223,7 +251,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } if ((err = aacEncoder_SetParam(s->handle, AACENC_BITRATE, avctx->bit_rate)) != AACENC_OK) { - av_log(avctx, AV_LOG_ERROR, "Unable to set the bitrate %d: %s\n", + av_log(avctx, AV_LOG_ERROR, "Unable to set the bitrate %"PRId64": %s\n", avctx->bit_rate, aac_get_error(err)); goto error; } @@ -295,7 +323,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } avctx->frame_size = info.frameLength; -#if FDKENC_VER_AT_LEAST(4, 0) +#if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0 avctx->initial_padding = info.nDelay; #else avctx->initial_padding = info.encoderDelay; @@ -362,10 +390,8 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, in_buf.bufElSizes = &in_buffer_element_size; /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ - if ((ret = ff_alloc_packet(avpkt, FFMAX(8192, 768 * avctx->channels)))) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); + if ((ret = ff_alloc_packet2(avctx, avpkt, FFMAX(8192, 768 * avctx->channels), 0)) < 0) return ret; - } out_ptr = avpkt->data; out_buffer_size = avpkt->size; @@ -418,7 +444,7 @@ static const uint64_t aac_channel_layout[] = { AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK, -#ifdef AACENCODER_LIB_VL0 +#if FDKENC_VER_AT_LEAST(3, 4) // 3.4.12 AV_CH_LAYOUT_7POINT1_WIDE_BACK, AV_CH_LAYOUT_7POINT1, #endif