[FFmpeg-cvslog] libmp3lame: use avpriv_mpegaudio_decode_header() for output frame parsing

Justin Ruggles git at videolan.org
Tue Feb 21 05:29:39 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Feb 16 23:06:54 2012 -0500| [1f516c045152e428b64e1c69105b447a6c484355] | committer: Justin Ruggles

libmp3lame: use avpriv_mpegaudio_decode_header() for output frame parsing

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1f516c045152e428b64e1c69105b447a6c484355
---

 libavcodec/Makefile     |    2 +-
 libavcodec/libmp3lame.c |   63 +++++-----------------------------------------
 2 files changed, 8 insertions(+), 57 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 92a5c13..93ff7d4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -579,7 +579,7 @@ OBJS-$(CONFIG_LIBGSM_DECODER)             += libgsm.o
 OBJS-$(CONFIG_LIBGSM_ENCODER)             += libgsm.o
 OBJS-$(CONFIG_LIBGSM_MS_DECODER)          += libgsm.o
 OBJS-$(CONFIG_LIBGSM_MS_ENCODER)          += libgsm.o
-OBJS-$(CONFIG_LIBMP3LAME_ENCODER)         += libmp3lame.o
+OBJS-$(CONFIG_LIBMP3LAME_ENCODER)         += libmp3lame.o mpegaudiodecheader.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 1e0beb5..a15aed3 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -29,6 +29,7 @@
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "mpegaudio.h"
+#include "mpegaudiodecheader.h"
 #include <lame/lame.h>
 
 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4)
@@ -100,65 +101,11 @@ static const int sSampleRates[] = {
     44100, 48000,  32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
 };
 
-static const int sBitRates[2][3][15] = {
-    {
-        { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
-        { 0, 32, 48, 56, 64,  80,  96,  112, 128, 160, 192, 224, 256, 320, 384 },
-        { 0, 32, 40, 48, 56,  64,  80,  96,  112, 128, 160, 192, 224, 256, 320 }
-    },
-    {
-        { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
-        { 0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160 },
-        { 0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160 }
-    },
-};
-
-static const int sSamplesPerFrame[2][3] = {
-    { 384, 1152, 1152 },
-    { 384, 1152,  576 }
-};
-
-static const int sBitsPerSlot[3] = { 32, 8, 8 };
-
-static int mp3len(void *data, int *samplesPerFrame, int *sampleRate)
-{
-    uint32_t header  = AV_RB32(data);
-    int layerID      = 3 - ((header >> 17) & 0x03);
-    int bitRateID    = ((header >> 12) & 0x0f);
-    int sampleRateID = ((header >> 10) & 0x03);
-    int bitsPerSlot  = sBitsPerSlot[layerID];
-    int isPadded     = ((header >> 9) & 0x01);
-    static int const mode_tab[4] = { 2, 3, 1, 0 };
-    int mode    = mode_tab[(header >> 19) & 0x03];
-    int mpeg_id = mode > 0;
-    int temp0, temp1, bitRate;
-
-    if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 ||
-        sampleRateID == 3) {
-        return -1;
-    }
-
-    if (!samplesPerFrame)
-        samplesPerFrame = &temp0;
-    if (!sampleRate)
-        sampleRate      = &temp1;
-
-    //*isMono = ((header >>  6) & 0x03) == 0x03;
-
-    *sampleRate      = sSampleRates[sampleRateID] >> mode;
-    bitRate          = sBitRates[mpeg_id][layerID][bitRateID] * 1000;
-    *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID];
-    //av_log(NULL, AV_LOG_DEBUG,
-    //       "sr:%d br:%d spf:%d l:%d m:%d\n",
-    //       *sampleRate, bitRate, *samplesPerFrame, layerID, mode);
-
-    return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded;
-}
-
 static int MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame,
                                 int buf_size, void *data)
 {
     Mp3AudioContext *s = avctx->priv_data;
+    MPADecodeHeader hdr;
     int len;
     int lame_result;
 
@@ -193,7 +140,11 @@ static int MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame,
     if (s->buffer_index < 4)
         return 0;
 
-    len = mp3len(s->buffer, NULL, NULL);
+    if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {
+        av_log(avctx, AV_LOG_ERROR, "free format output not supported\n");
+        return -1;
+    }
+    len = hdr.frame_size;
     av_dlog(avctx, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len,
             s->buffer_index);
     if (len <= s->buffer_index) {



More information about the ffmpeg-cvslog mailing list