[4/5] Add a libvo-aacenc encoder that outputs LATM AAC

Message ID 1305893663-56629-5-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö May 20, 2011, 12:14 p.m.
---
 configure                 |    1 +
 libavcodec/Makefile       |    1 +
 libavcodec/allcodecs.c    |    1 +
 libavcodec/libvo-aacenc.c |   21 +++++++++++++++++++--
 4 files changed, 22 insertions(+), 2 deletions(-)

Patch

diff --git a/configure b/configure
index fc5bab3..0adbea3 100755
--- a/configure
+++ b/configure
@@ -1391,6 +1391,7 @@  libschroedinger_encoder_deps="libschroedinger"
 libspeex_decoder_deps="libspeex"
 libtheora_encoder_deps="libtheora"
 libvo_aacenc_encoder_deps="libvo_aacenc"
+libvo_aacenc_latm_encoder_deps="libvo_aacenc"
 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
 libvorbis_encoder_deps="libvorbis"
 libvpx_decoder_deps="libvpx"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 04b3e24..78c819c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -572,6 +572,7 @@  OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)    += libschroedingerenc.o \
 OBJS-$(CONFIG_LIBSPEEX_DECODER)           += libspeexdec.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)          += libtheoraenc.o
 OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)       += libvo-aacenc.o mpeg4audio.o
+OBJS-$(CONFIG_LIBVO_AACENC_LATM_ENCODER)  += libvo-aacenc.o mpeg4audio.o
 OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER)     += libvo-amrwbenc.o
 OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbis.o vorbis_data.o
 OBJS-$(CONFIG_LIBVPX_DECODER)             += libvpxdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 5fce48c..e5abfb8 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -369,6 +369,7 @@  void avcodec_register_all(void)
     REGISTER_DECODER (LIBSPEEX, libspeex);
     REGISTER_ENCODER (LIBTHEORA, libtheora);
     REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
+    REGISTER_ENCODER (LIBVO_AACENC_LATM, libvo_aacenc_latm);
     REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc);
     REGISTER_ENCODER (LIBVORBIS, libvorbis);
     REGISTER_ENCDEC  (LIBVPX, libvpx);
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 5a75bcb..a014fa4 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -55,7 +55,8 @@  static av_cold int aac_encode_init(AVCodecContext *avctx)
     params.sampleRate = avctx->sample_rate;
     params.bitRate    = avctx->bit_rate;
     params.nChannels  = avctx->channels;
-    params.adtsUsed   = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER);
+    params.adtsUsed   = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER ||
+                          avctx->codec_id == CODEC_ID_AAC_LATM);
     if (s->codec_api.SetParam(s->handle, VO_PID_AAC_ENCPARAM, &params)
         != VO_ERR_NONE) {
         av_log(avctx, AV_LOG_ERROR, "Unable to set encoding parameters\n");
@@ -70,7 +71,9 @@  static av_cold int aac_encode_init(AVCodecContext *avctx)
                                     avctx->sample_rate);
         return AVERROR(ENOSYS);
     }
-    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+    if (avctx->codec_id == CODEC_ID_AAC_LATM) {
+        ff_aac_make_latm_header(avctx);
+    } else if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
         avctx->extradata_size = 2;
         avctx->extradata      = av_mallocz(avctx->extradata_size +
                                            FF_INPUT_BUFFER_PADDING_SIZE);
@@ -112,6 +115,8 @@  static int aac_encode_frame(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "Unable to encode frame\n");
         return AVERROR(EINVAL);
     }
+    if (avctx->codec_id == CODEC_ID_AAC_LATM)
+        return ff_aac_latm_wrap(avctx, frame, output.Length, buf_size);
     return output.Length;
 }
 
@@ -128,3 +133,15 @@  AVCodec ff_libvo_aacenc_encoder = {
     .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn AAC"),
 };
 
+AVCodec ff_libvo_aacenc_latm_encoder = {
+    "libvo_aacenc_latm",
+    AVMEDIA_TYPE_AUDIO,
+    CODEC_ID_AAC_LATM,
+    sizeof(AACContext),
+    aac_encode_init,
+    aac_encode_frame,
+    aac_encode_close,
+    NULL,
+    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn AAC"),
+};