[5/5] Add a ffaac encoder that otuputs LATM AAC

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

Commit Message

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

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 78c819c..37a9d69 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -55,6 +55,10 @@  OBJS-$(CONFIG_AAC_ENCODER)             += aacenc.o aaccoder.o    \
                                           aacpsy.o aactab.o      \
                                           psymodel.o iirfilter.o \
                                           mpeg4audio.o kbdwin.o
+OBJS-$(CONFIG_AAC_LATM_ENCODER)        += aacenc.o aaccoder.o    \
+                                          aacpsy.o aactab.o      \
+                                          psymodel.o iirfilter.o \
+                                          mpeg4audio.o kbdwin.o
 OBJS-$(CONFIG_AASC_DECODER)            += aasc.o msrledec.o
 OBJS-$(CONFIG_AC3_DECODER)             += ac3dec.o ac3dec_data.o ac3.o kbdwin.o
 OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_float.o ac3tab.o ac3.o kbdwin.o
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 92ff4b0..81c7934 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -216,6 +216,9 @@  static av_cold int aac_encode_init(AVCodecContext *avctx)
 
     ff_aac_tableinit();
 
+    if (avctx->codec_id == CODEC_ID_AAC_LATM)
+        ff_aac_make_latm_header(avctx);
+
     return 0;
 }
 
@@ -629,6 +632,9 @@  static int aac_encode_frame(AVCodecContext *avctx,
         s->last_frame = 1;
     memcpy(s->samples, s->samples + 1024 * avctx->channels,
            1024 * avctx->channels * sizeof(s->samples[0]));
+
+    if (avctx->codec_id == CODEC_ID_AAC_LATM)
+        return ff_aac_latm_wrap(avctx, frame, put_bits_count(&s->pb)>>3, buf_size);
     return put_bits_count(&s->pb)>>3;
 }
 
@@ -657,3 +663,16 @@  AVCodec ff_aac_encoder = {
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
 };
+
+AVCodec ff_aac_latm_encoder = {
+    "aac_latm",
+    AVMEDIA_TYPE_AUDIO,
+    CODEC_ID_AAC_LATM,
+    sizeof(AACEncContext),
+    aac_encode_init,
+    aac_encode_frame,
+    aac_encode_end,
+    .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
+    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
+};
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index e5abfb8..1eafb4b 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -226,7 +226,7 @@  void avcodec_register_all(void)
 
     /* audio codecs */
     REGISTER_ENCDEC  (AAC, aac);
-    REGISTER_DECODER (AAC_LATM, aac_latm);
+    REGISTER_ENCDEC  (AAC_LATM, aac_latm);
     REGISTER_ENCDEC  (AC3, ac3);
     REGISTER_ENCODER (AC3_FIXED, ac3_fixed);
     REGISTER_ENCDEC  (ALAC, alac);
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index fe9363c..e677fa6 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -37,6 +37,7 @@  av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx,
     memcpy(ctx->num_bands, num_bands, sizeof(ctx->num_bands[0]) *  num_lens);
     switch (ctx->avctx->codec_id) {
     case CODEC_ID_AAC:
+    case CODEC_ID_AAC_LATM:
         ctx->model = &ff_aac_psy_model;
         break;
     }