[3/5] Add a faac encoder that outputs LATM AAC

Message ID 1305893663-56629-4-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    |    3 ++-
 libavcodec/allcodecs.c |    1 +
 libavcodec/libfaac.c   |   22 +++++++++++++++++++++-
 4 files changed, 25 insertions(+), 2 deletions(-)

Comments

Diego Biurrun May 20, 2011, 2:10 p.m. | #1
Note that the same comments also apply to the libvo-aac encoder
patch you sent, i'm just too lazy to repeat...

On Fri, May 20, 2011 at 03:14:21PM +0300, Martin Storsjö wrote:
> ---
>  configure              |    1 +
>  libavcodec/Makefile    |    3 ++-
>  libavcodec/allcodecs.c |    1 +
>  libavcodec/libfaac.c   |   22 +++++++++++++++++++++-
>  4 files changed, 25 insertions(+), 2 deletions(-)
> 
> --- a/configure
> +++ b/configure
> @@ -1376,6 +1376,7 @@ h264_parser_select="golomb h264dsp h264pred"
>  libfaac_encoder_deps="libfaac"
> +libfaac_latm_encoder_deps="libfaac"
>  libgsm_decoder_deps="libgsm"
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -552,7 +552,8 @@ OBJS-$(CONFIG_WTV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
>  # external codec libraries
>  OBJS-$(CONFIG_LIBDIRAC_ENCODER)           += libdiracenc.o libdirac_libschro.o
> -OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o
> +OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o mpeg4audio.o
> +OBJS-$(CONFIG_LIBFAAC_LATM_ENCODER)       += libfaac.o mpeg4audio.o
>  OBJS-$(CONFIG_LIBGSM_DECODER)             += libgsm.o

I wonder if you couldn't just make the libfaac-latm encoder depend on
the libfaac encoder.  Is there any point in enabling the former without
the latter?

> --- a/libavcodec/libfaac.c
> +++ b/libavcodec/libfaac.c
> @@ -167,3 +173,17 @@ AVCodec ff_libfaac_encoder = {
> +
> +AVCodec ff_libfaac_latm_encoder = {
> +    "libfaac_latm",
> +    AVMEDIA_TYPE_AUDIO,
> +    CODEC_ID_AAC_LATM,
> +    sizeof(FaacAudioContext),
> +    Faac_encode_init,
> +    Faac_encode_frame,
> +    Faac_encode_close,
> +    .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
> +    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
> +    .long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"),
> +    .profiles = NULL_IF_CONFIG_SMALL(profiles),
> +};

All the cool kids use explicit initializers these days...

Diego

Patch

diff --git a/configure b/configure
index 5b81e0b..fc5bab3 100755
--- a/configure
+++ b/configure
@@ -1376,6 +1376,7 @@  h264_parser_select="golomb h264dsp h264pred"
 libdirac_decoder_deps="libdirac !libschroedinger"
 libdirac_encoder_deps="libdirac"
 libfaac_encoder_deps="libfaac"
+libfaac_latm_encoder_deps="libfaac"
 libgsm_decoder_deps="libgsm"
 libgsm_encoder_deps="libgsm"
 libgsm_ms_decoder_deps="libgsm"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fa70216..04b3e24 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -552,7 +552,8 @@  OBJS-$(CONFIG_WTV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
 # external codec libraries
 OBJS-$(CONFIG_LIBDIRAC_DECODER)           += libdiracdec.o
 OBJS-$(CONFIG_LIBDIRAC_ENCODER)           += libdiracenc.o libdirac_libschro.o
-OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o
+OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o mpeg4audio.o
+OBJS-$(CONFIG_LIBFAAC_LATM_ENCODER)       += libfaac.o mpeg4audio.o
 OBJS-$(CONFIG_LIBGSM_DECODER)             += libgsm.o
 OBJS-$(CONFIG_LIBGSM_ENCODER)             += libgsm.o
 OBJS-$(CONFIG_LIBGSM_MS_DECODER)          += libgsm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 3466ad9..5fce48c 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -358,6 +358,7 @@  void avcodec_register_all(void)
     /* external libraries */
     REGISTER_ENCDEC  (LIBDIRAC, libdirac);
     REGISTER_ENCODER (LIBFAAC, libfaac);
+    REGISTER_ENCODER (LIBFAAC_LATM, libfaac_latm);
     REGISTER_ENCDEC  (LIBGSM, libgsm);
     REGISTER_ENCDEC  (LIBGSM_MS, libgsm_ms);
     REGISTER_ENCODER (LIBMP3LAME, libmp3lame);
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index 51d965e..41aaa2d 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -26,6 +26,7 @@ 
 
 #include "avcodec.h"
 #include <faac.h>
+#include "mpeg4audio.h"
 
 typedef struct FaacAudioContext {
     faacEncHandle faac_handle;
@@ -94,7 +95,10 @@  static av_cold int Faac_encode_init(AVCodecContext *avctx)
 
     /* Set decoder specific info */
     avctx->extradata_size = 0;
-    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+    if (avctx->codec_id == CODEC_ID_AAC_LATM) {
+        ff_aac_make_latm_header(avctx);
+        faac_cfg->outputFormat = 0;
+    } else if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
 
         unsigned char *buffer = NULL;
         unsigned long decoder_specific_info_size;
@@ -132,6 +136,8 @@  static int Faac_encode_frame(AVCodecContext *avctx,
                                   frame,
                                   buf_size);
 
+    if (avctx->codec_id == CODEC_ID_AAC_LATM)
+        return ff_aac_latm_wrap(avctx, frame, bytes_written, buf_size);
     return bytes_written;
 }
 
@@ -167,3 +173,17 @@  AVCodec ff_libfaac_encoder = {
     .long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"),
     .profiles = NULL_IF_CONFIG_SMALL(profiles),
 };
+
+AVCodec ff_libfaac_latm_encoder = {
+    "libfaac_latm",
+    AVMEDIA_TYPE_AUDIO,
+    CODEC_ID_AAC_LATM,
+    sizeof(FaacAudioContext),
+    Faac_encode_init,
+    Faac_encode_frame,
+    Faac_encode_close,
+    .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
+    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"),
+    .profiles = NULL_IF_CONFIG_SMALL(profiles),
+};