On Sat, 7 Apr 2012, Luca Barbato wrote:
From: Sergiy Gur'yev <[email protected]>
The library is a wrapper to the reference implementation, thus non
redistributable.
Signed-off-by: Luca Barbato <[email protected]>
---
Changelog | 1 +
LICENSE | 6 +-
configure | 6 ++
doc/general.texi | 2 +
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/libaacplus.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 148 insertions(+), 3 deletions(-)
create mode 100644 libavcodec/libaacplus.c
diff --git a/Changelog b/Changelog
index 629d407..9c89921 100644
--- a/Changelog
+++ b/Changelog
@@ -178,6 +178,7 @@ version 0.7_beta1:
- Demuxer for On2's IVF format
- Pictor/PC Paint decoder
- HE-AAC v2 decoder
+- HE-AAC v2 encoding with libaacplus
This is part of a previous release, please move it to the section of new
features.
- libfaad2 wrapper removed
- DTS-ES extension (XCh) decoding support
- native VP8 decoder
diff --git a/LICENSE b/LICENSE
index 97923b1..f2ddafb 100644
--- a/LICENSE
+++ b/LICENSE
@@ -44,6 +44,6 @@ is incompatible with the LGPL v2.1 and the GPL v2, but not
with version 3 of
those licenses. So to combine the OpenCORE libraries with Libav, the license
version needs to be upgraded by passing --enable-version3 to configure.
-The nonfree external library libfaac can be hooked up in Libav. You need to
-pass --enable-nonfree to configure to enable it. Employ this option with care
-as Libav then becomes nonfree and unredistributable.
+The nonfree external library libfaac and libaacplus can be hooked up in Libav.
libraries
+You need to pass --enable-nonfree to configure to enable it. Employ this option
enable them
+with care as Libav then becomes nonfree and unredistributable.
diff --git a/configure b/configure
index 4606b23..899e020 100755
--- a/configure
+++ b/configure
@@ -165,6 +165,7 @@ External library support:
--enable-bzlib enable bzlib [autodetect]
--enable-frei0r enable frei0r video filtering
--enable-gnutls enable gnutls [no]
+ --enable-libaacplus enable AAC+ encoding via libaacplus [no]
--enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb
[no]
--enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
--enable-libopencv enable video filtering via libopencv [no]
@@ -941,6 +942,7 @@ CONFIG_LIST="
gpl
gray
hardcoded_tables
+ libaacplus
libcdio
libdc1394
libdirac
@@ -1422,6 +1424,7 @@ vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
h264_parser_select="golomb h264dsp h264pred"
# external libraries
+libaacplus_encoder_deps="libaacplus"
libdirac_decoder_deps="libdirac !libschroedinger"
libfaac_encoder_deps="libfaac"
libgsm_decoder_deps="libgsm"
@@ -2619,6 +2622,7 @@ die_license_disabled gpl libxavs
die_license_disabled gpl libxvid
die_license_disabled gpl x11grab
+die_license_disabled nonfree libaacplus
die_license_disabled nonfree libfaac
die_license_disabled nonfree openssl
@@ -2939,6 +2943,7 @@ check_mathfunc truncf
enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not
found"; }
enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h
gnutls_global_init
+enabled libaacplus && require "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen
-laacplus
enabled libdirac && require_pkg_config dirac \
"libdirac_decoder/dirac_parser.h" \
"dirac_decoder_init"
@@ -3233,6 +3238,7 @@ echo "libcdio support ${libcdio-no}"
echo "libdc1394 support ${libdc1394-no}"
echo "libdirac enabled ${libdirac-no}"
echo "libfaac enabled ${libfaac-no}"
+echo "libaacplus enabled ${libaacplus-no}"
echo "libgsm enabled ${libgsm-no}"
echo "libmp3lame enabled ${libmp3lame-no}"
echo "libnut enabled ${libnut-no}"
diff --git a/doc/general.texi b/doc/general.texi
index 0c14003..d6f6d70 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -625,6 +625,8 @@ following image formats are supported:
@multitable @columnfractions .4 .1 .1 .4
@item Name @tab Encoding @tab Decoding @tab Comments
@item 8SVX audio @tab @tab X
+@item AAC+ @tab E @tab X
+ @tab encoding supported through external library libaacplus
@item AAC @tab E @tab X
@tab encoding supported through external library libfaac and libvo-aacenc
@item AC-3 @tab IX @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4dc218a..b18d0be 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -582,6 +582,7 @@ OBJS-$(CONFIG_WEBM_MUXER) += xiph.o
mpeg4audio.o \
OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
# external codec libraries
+OBJS-$(CONFIG_LIBAACPLUS_ENCODER) += libaacplus.o
OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o
OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o audio_frame_queue.o
OBJS-$(CONFIG_LIBGSM_DECODER) += libgsm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 60b3e08..4f1a9c1 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -375,6 +375,7 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (XSUB, xsub);
/* external libraries */
+ REGISTER_ENCODER (LIBAACPLUS, libaacplus);
REGISTER_DECODER (LIBDIRAC, libdirac);
REGISTER_ENCODER (LIBFAAC, libfaac);
REGISTER_ENCDEC (LIBGSM, libgsm);
diff --git a/libavcodec/libaacplus.c b/libavcodec/libaacplus.c
new file mode 100644
index 0000000..b6d99ef
--- /dev/null
+++ b/libavcodec/libaacplus.c
@@ -0,0 +1,134 @@
+/*
+ * Interface to libaacplus for aac+ (sbr+ps) encoding
+ * Copyright (c) 2010 tipok <[email protected]>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Interface to libaacplus for aac+ (sbr+ps) encoding.
+ */
+
+#include "avcodec.h"
+#include <aacplus.h>
+
+typedef struct aacPlusAudioContext {
+ aacplusEncHandle aacplus_handle;
+} aacPlusAudioContext;
+
Please change the struct name to start with a capital, as elsewhere.
+static av_cold int aacPlus_encode_init(AVCodecContext *avctx)
+{
Please get rid of the camelCase function names
+ aacPlusAudioContext *s = avctx->priv_data;
+ aacplusEncConfiguration *aacplus_cfg;
+ unsigned long samples_input, max_bytes_output;
+
+ /* number of channels */
+ if (avctx->channels < 1 || avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n",
avctx->channels);
+ return -1;
+ }
+
+ s->aacplus_handle = aacplusEncOpen(avctx->sample_rate,
+ avctx->channels,
+ &samples_input, &max_bytes_output);
Nit: Align the parameters
+ if(!s->aacplus_handle) {
+ av_log(avctx, AV_LOG_ERROR, "can't open encoder\n");
+ return -1;
+ }
+
Weird indentation, seems to be using 8 spaces instead of 4 for the second
level
+ /* check aacplus version */
+ aacplus_cfg = aacplusEncGetCurrentConfiguration(s->aacplus_handle);
+
+ /* put the options in the configuration struct */
+ if(avctx->profile != FF_PROFILE_AAC_LOW && avctx->profile !=
FF_PROFILE_UNKNOWN) {
+ av_log(avctx, AV_LOG_ERROR, "invalid AAC profile: %d, only LC
supported\n", avctx->profile);
+ aacplusEncClose(s->aacplus_handle);
+ return -1;
+ }
+
+ aacplus_cfg->bitRate = avctx->bit_rate;
+ aacplus_cfg->bandWidth = avctx->cutoff;
+ aacplus_cfg->outputFormat = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER);
+ aacplus_cfg->inputFormat = AACPLUS_INPUT_16BIT;
+ if (!aacplusEncSetConfiguration(s->aacplus_handle, aacplus_cfg)) {
+ av_log(avctx, AV_LOG_ERROR, "libaacplus doesn't support this output
format!\n");
+ return -1;
+ }
+
+ avctx->frame_size = samples_input / avctx->channels;
+
+ avctx->coded_frame= avcodec_alloc_frame();
+ avctx->coded_frame->key_frame= 1;
+
+ /* Set decoder specific info */
+ avctx->extradata_size = 0;
+ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+
+ unsigned char *buffer = NULL;
+ unsigned long decoder_specific_info_size;
+
+ if (aacplusEncGetDecoderSpecificInfo(s->aacplus_handle, &buffer,
+ &decoder_specific_info_size) == 1) {
+ avctx->extradata = av_malloc(decoder_specific_info_size +
FF_INPUT_BUFFER_PADDING_SIZE);
+ avctx->extradata_size = decoder_specific_info_size;
+ memcpy(avctx->extradata, buffer, avctx->extradata_size);
+ }
+#undef free
+ free(buffer);
+#define free please_use_av_free
+ }
+ return 0;
+}
+
+static int aacPlus_encode_frame(AVCodecContext *avctx,
+ unsigned char *frame, int buf_size, void *data)
+{
+ aacPlusAudioContext *s = avctx->priv_data;
+ int bytes_written;
+
+ bytes_written = aacplusEncEncode(s->aacplus_handle,
+ data,
+ avctx->frame_size * avctx->channels,
+ frame,
+ buf_size);
+
+ return bytes_written;
+}
+
+static av_cold int aacPlus_encode_close(AVCodecContext *avctx)
+{
+ aacPlusAudioContext *s = avctx->priv_data;
+
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
+
+ aacplusEncClose(s->aacplus_handle);
+ return 0;
+}
+
+AVCodec ff_libaacplus_encoder = {
+ "libaacplus",
+ AVMEDIA_TYPE_AUDIO,
+ CODEC_ID_AAC,
+ sizeof(aacPlusAudioContext),
+ aacPlus_encode_init,
+ aacPlus_encode_frame,
+ aacPlus_encode_close,
+ .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("libaacplus AAC+ (Advanced Audio Codec with
SBR+PS)"),
+};
--
1.7.8.rc1
Please use designated initializers (but I see you fix that in patch #2).
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel