]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libmp3lame.c
latm: Always reconfigure if no extradata was set previously
[ffmpeg] / libavcodec / libmp3lame.c
index 947edc0503ef05c40d17cbaceef458bcc625cc6c..ee76ff88128fc04362110b5b6217cc4ec3e170f5 100644 (file)
 
 #include <lame/lame.h>
 
-#include "libavutil/audioconvert.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "audio_frame_queue.h"
-#include "dsputil.h"
 #include "internal.h"
 #include "mpegaudio.h"
 #include "mpegaudiodecheader.h"
@@ -50,25 +50,21 @@ typedef struct LAMEContext {
     int reservoir;
     float *samples_flt[2];
     AudioFrameQueue afq;
-    DSPContext dsp;
+    AVFloatDSPContext fdsp;
 } LAMEContext;
 
 
 static int realloc_buffer(LAMEContext *s)
 {
     if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) {
-        uint8_t *tmp;
-        int new_size = s->buffer_index + 2 * BUFFER_SIZE;
+        int new_size = s->buffer_index + 2 * BUFFER_SIZE, err;
 
         av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", s->buffer_size,
                 new_size);
-        tmp = av_realloc(s->buffer, new_size);
-        if (!tmp) {
-            av_freep(&s->buffer);
+        if ((err = av_reallocp(&s->buffer, new_size)) < 0) {
             s->buffer_size = s->buffer_index = 0;
-            return AVERROR(ENOMEM);
+            return err;
         }
-        s->buffer      = tmp;
         s->buffer_size = new_size;
     }
     return 0;
@@ -78,9 +74,6 @@ static av_cold int mp3lame_encode_close(AVCodecContext *avctx)
 {
     LAMEContext *s = avctx->priv_data;
 
-#if FF_API_OLD_ENCODE_AUDIO
-    av_freep(&avctx->coded_frame);
-#endif
     av_freep(&s->samples_flt[0]);
     av_freep(&s->samples_flt[1]);
     av_freep(&s->buffer);
@@ -142,14 +135,6 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
 
     avctx->frame_size  = lame_get_framesize(s->gfp);
 
-#if FF_API_OLD_ENCODE_AUDIO
-    avctx->coded_frame = avcodec_alloc_frame();
-    if (!avctx->coded_frame) {
-        ret = AVERROR(ENOMEM);
-        goto error;
-    }
-#endif
-
     /* allocate float sample buffers */
     if (avctx->sample_fmt == AV_SAMPLE_FMT_FLTP) {
         int ch;
@@ -167,7 +152,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
     if (ret < 0)
         goto error;
 
-    ff_dsputil_init(&s->dsp, avctx);
+    avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
 
     return 0;
 error:
@@ -205,10 +190,10 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                 return AVERROR(EINVAL);
             }
             for (ch = 0; ch < avctx->channels; ch++) {
-                s->dsp.vector_fmul_scalar(s->samples_flt[ch],
-                                          (const float *)frame->data[ch],
-                                          32768.0f,
-                                          FFALIGN(frame->nb_samples, 8));
+                s->fdsp.vector_fmul_scalar(s->samples_flt[ch],
+                                           (const float *)frame->data[ch],
+                                           32768.0f,
+                                           FFALIGN(frame->nb_samples, 8));
             }
             ENCODE_BUFFER(lame_encode_buffer_float, float, s->samples_flt);
             break;
@@ -217,7 +202,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
     } else {
         lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index,
-                                        BUFFER_SIZE - s->buffer_index);
+                                        s->buffer_size - s->buffer_index);
     }
     if (lame_result < 0) {
         if (lame_result == -1) {
@@ -236,7 +221,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     /* add current frame to the queue */
     if (frame) {
-        if ((ret = ff_af_queue_add(&s->afq, frame) < 0))
+        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
             return ret;
     }
 
@@ -296,6 +281,7 @@ static const int libmp3lame_sample_rates[] = {
 
 AVCodec ff_libmp3lame_encoder = {
     .name                  = "libmp3lame",
+    .long_name             = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
     .type                  = AVMEDIA_TYPE_AUDIO,
     .id                    = AV_CODEC_ID_MP3,
     .priv_data_size        = sizeof(LAMEContext),
@@ -311,7 +297,6 @@ AVCodec ff_libmp3lame_encoder = {
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO,
                                                   0 },
-    .long_name             = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"),
     .priv_class            = &libmp3lame_class,
     .defaults              = libmp3lame_defaults,
 };