aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpegaudio_parser.c
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2007-05-20 13:40:07 +0000
committerAurelien Jacobs <aurel@gnuage.org>2007-05-20 13:40:07 +0000
commit4bd8e17c8d371dc05af63b15c11342e40184df61 (patch)
tree48525053ccfb759b562f0dd9c43318fbcac57d60 /libavcodec/mpegaudio_parser.c
parent663deb54afd8d504787624160e363df83cb137f0 (diff)
downloadffmpeg-4bd8e17c8d371dc05af63b15c11342e40184df61.tar.gz
loosen dependencies over mpegaudiodec
Originally committed as revision 9080 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/mpegaudio_parser.c')
-rw-r--r--libavcodec/mpegaudio_parser.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 8fb18ca5d4..714857623b 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -22,6 +22,7 @@
#include "parser.h"
#include "mpegaudio.h"
+#include "mpegaudiodecheader.h"
typedef struct MpegAudioParseContext {
@@ -41,6 +42,43 @@ typedef struct MpegAudioParseContext {
#define SAME_HEADER_MASK \
(0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
+/* useful helper to get mpeg audio stream infos. Return -1 if error in
+ header, otherwise the coded frame size in bytes */
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
+{
+ MPADecodeContext s1, *s = &s1;
+ s1.avctx = avctx;
+
+ if (ff_mpa_check_header(head) != 0)
+ return -1;
+
+ if (decode_header(s, head) != 0) {
+ return -1;
+ }
+
+ switch(s->layer) {
+ case 1:
+ avctx->frame_size = 384;
+ break;
+ case 2:
+ avctx->frame_size = 1152;
+ break;
+ default:
+ case 3:
+ if (s->lsf)
+ avctx->frame_size = 576;
+ else
+ avctx->frame_size = 1152;
+ break;
+ }
+
+ *sample_rate = s->sample_rate;
+ avctx->channels = s->nb_channels;
+ avctx->bit_rate = s->bit_rate;
+ avctx->sub_id = s->layer;
+ return s->frame_size;
+}
+
static int mpegaudio_parse_init(AVCodecParserContext *s1)
{
MpegAudioParseContext *s = s1->priv_data;