]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/aacenc.c
ffplay: give more meaningful names to the buffersink instances
[ffmpeg] / libavcodec / aacenc.c
index bc99a443b3a0906542bb5786c604ce9a07aa31a5..7696e96bdfe84a29b05fadd211966ec0cf41f34c 100644 (file)
@@ -2,20 +2,20 @@
  * AAC encoder
  * Copyright (C) 2008 Konstantin Shishkov
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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,
+ * FFmpeg 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
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -30,6 +30,7 @@
  * add temporal noise shaping
  ***********************************/
 
+#include "libavutil/float_dsp.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "put_bits.h"
@@ -145,7 +146,7 @@ static const uint8_t aac_chan_configs[6][5] = {
 };
 
 /**
- * Table to remap channels from Libav's default order to AAC order.
+ * Table to remap channels from libavcodec's default order to AAC order.
  */
 static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS] = {
     { 0 },
@@ -182,7 +183,9 @@ static void put_audio_specific_config(AVCodecContext *avctx)
 }
 
 #define WINDOW_FUNC(type) \
-static void apply_ ##type ##_window(DSPContext *dsp, SingleChannelElement *sce, const float *audio)
+static void apply_ ##type ##_window(DSPContext *dsp, AVFloatDSPContext *fdsp, \
+                                    SingleChannelElement *sce, \
+                                    const float *audio)
 
 WINDOW_FUNC(only_long)
 {
@@ -190,7 +193,7 @@ WINDOW_FUNC(only_long)
     const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
     float *out = sce->ret;
 
-    dsp->vector_fmul        (out,        audio,        lwindow, 1024);
+    fdsp->vector_fmul       (out,        audio,        lwindow, 1024);
     dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
 }
 
@@ -200,7 +203,7 @@ WINDOW_FUNC(long_start)
     const float *swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
     float *out = sce->ret;
 
-    dsp->vector_fmul(out, audio, lwindow, 1024);
+    fdsp->vector_fmul(out, audio, lwindow, 1024);
     memcpy(out + 1024, audio + 1024, sizeof(out[0]) * 448);
     dsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128);
     memset(out + 1024 + 576, 0, sizeof(out[0]) * 448);
@@ -213,7 +216,7 @@ WINDOW_FUNC(long_stop)
     float *out = sce->ret;
 
     memset(out, 0, sizeof(out[0]) * 448);
-    dsp->vector_fmul(out + 448, audio + 448, swindow, 128);
+    fdsp->vector_fmul(out + 448, audio + 448, swindow, 128);
     memcpy(out + 576, audio + 576, sizeof(out[0]) * 448);
     dsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024);
 }
@@ -227,7 +230,7 @@ WINDOW_FUNC(eight_short)
     int w;
 
     for (w = 0; w < 8; w++) {
-        dsp->vector_fmul        (out, in, w ? pwindow : swindow, 128);
+        fdsp->vector_fmul       (out, in, w ? pwindow : swindow, 128);
         out += 128;
         in  += 128;
         dsp->vector_fmul_reverse(out, in, swindow, 128);
@@ -235,7 +238,9 @@ WINDOW_FUNC(eight_short)
     }
 }
 
-static void (*const apply_window[4])(DSPContext *dsp, SingleChannelElement *sce, const float *audio) = {
+static void (*const apply_window[4])(DSPContext *dsp, AVFloatDSPContext *fdsp,
+                                     SingleChannelElement *sce,
+                                     const float *audio) = {
     [ONLY_LONG_SEQUENCE]   = apply_only_long_window,
     [LONG_START_SEQUENCE]  = apply_long_start_window,
     [EIGHT_SHORT_SEQUENCE] = apply_eight_short_window,
@@ -248,7 +253,7 @@ static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce,
     int i;
     float *output = sce->ret;
 
-    apply_window[sce->ics.window_sequence[0]](&s->dsp, sce, audio);
+    apply_window[sce->ics.window_sequence[0]](&s->dsp, &s->fdsp, sce, audio);
 
     if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE)
         s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output);
@@ -475,7 +480,7 @@ static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s,
 
 /*
  * Deinterleave input samples.
- * Channels are reordered from Libav's default order to AAC order.
+ * Channels are reordered from libavcodec's default order to AAC order.
  */
 static void deinterleave_input_samples(AACEncContext *s, const AVFrame *frame)
 {
@@ -571,13 +576,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
         start_ch += chans;
     }
+    if ((ret = ff_alloc_packet2(avctx, avpkt, 768 * s->channels))) {
+        av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+        return ret;
+    }
     do {
         int frame_bits;
 
-        if ((ret = ff_alloc_packet(avpkt, 768 * s->channels))) {
-            av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
-            return ret;
-        }
         init_put_bits(&s->pb, avpkt->data, avpkt->size);
 
         if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT))
@@ -693,6 +698,7 @@ static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s)
     int ret = 0;
 
     ff_dsputil_init(&s->dsp, avctx);
+    avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
 
     // window init
     ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
@@ -775,7 +781,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     if (ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping))
         goto fail;
     s->psypp = ff_psy_preprocess_init(avctx);
-    s->coder = &ff_aac_coders[2];
+    s->coder = &ff_aac_coders[s->options.aac_coder];
 
     s->lambda = avctx->global_quality ? avctx->global_quality : 120;
 
@@ -799,6 +805,7 @@ static const AVOption aacenc_options[] = {
         {"auto",     "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
         {"ms_off",   "Disable Mid/Side coding", 0, AV_OPT_TYPE_CONST, {.dbl =  0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
         {"ms_force", "Force Mid/Side for the whole frame if possible", 0, AV_OPT_TYPE_CONST, {.dbl =  1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
+    {"aac_coder", "", offsetof(AACEncContext, options.aac_coder), AV_OPT_TYPE_INT, {.dbl = 2}, 0, AAC_CODER_NB-1, AACENC_FLAGS},
     {NULL}
 };
 
@@ -817,8 +824,11 @@ AVCodec ff_aac_encoder = {
     .init           = aac_encode_init,
     .encode2        = aac_encode_frame,
     .close          = aac_encode_end,
-    .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
-    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
-    .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
-    .priv_class = &aacenc_class,
+    .supported_samplerates = avpriv_mpeg4audio_sample_rates,
+    .capabilities   = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY |
+                      CODEC_CAP_EXPERIMENTAL,
+    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
+                                                     AV_SAMPLE_FMT_NONE },
+    .long_name      = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
+    .priv_class     = &aacenc_class,
 };