Browse code

loosen dependencies over mpegaudiodec

Originally committed as revision 9080 to svn://svn.ffmpeg.org/ffmpeg/trunk

Aurelien Jacobs authored on 2007/05/20 22:40:07
Showing 7 changed files
... ...
@@ -726,6 +726,7 @@ dv1394_demuxer_deps="dv1394"
726 726
 gxf_muxer_deps="gpl"
727 727
 libnut_demuxer_deps="libnut"
728 728
 libnut_muxer_deps="libnut"
729
+mp3_demuxer_deps="mpegaudio_parser"
729 730
 ogg_muxer_deps="libogg"
730 731
 redir_demuxer_deps="network"
731 732
 rtp_muxer_deps="network mpegts_demuxer"
... ...
@@ -19,7 +19,7 @@ OBJS= bitstream.o \
19 19
       motion_est.o \
20 20
       imgconvert.o \
21 21
       mpeg12.o \
22
-      mpegaudiodec.o mpegaudiodata.o \
22
+      mpegaudiodec.o mpegaudiodecheader.o mpegaudiodata.o \
23 23
       simple_idct.o \
24 24
       ratecontrol.o \
25 25
       eval.o \
... ...
@@ -300,7 +300,7 @@ OBJS-$(CONFIG_H263_PARSER)             += h263_parser.o
300 300
 OBJS-$(CONFIG_H264_PARSER)             += h264_parser.o
301 301
 OBJS-$(CONFIG_MJPEG_PARSER)            += mjpeg_parser.o
302 302
 OBJS-$(CONFIG_MPEG4VIDEO_PARSER)       += mpeg4video_parser.o
303
-OBJS-$(CONFIG_MPEGAUDIO_PARSER)        += mpegaudio_parser.o
303
+OBJS-$(CONFIG_MPEGAUDIO_PARSER)        += mpegaudio_parser.o mpegaudiodecheader.o
304 304
 OBJS-$(CONFIG_MPEGVIDEO_PARSER)        += mpegvideo_parser.o
305 305
 OBJS-$(CONFIG_PNM_PARSER)              += pnm_parser.o pnm.o
306 306
 OBJS-$(CONFIG_VC1_PARSER)              += vc1_parser.o
... ...
@@ -23,6 +23,12 @@
23 23
  * mpeg audio declarations for both encoder and decoder.
24 24
  */
25 25
 
26
+#ifndef MPEGAUDIO_H
27
+#define MPEGAUDIO_H
28
+
29
+#include "bitstream.h"
30
+#include "dsputil.h"
31
+
26 32
 /* max frame size, in samples */
27 33
 #define MPA_FRAME_SIZE 1152
28 34
 
... ...
@@ -73,6 +79,42 @@ typedef int16_t MPA_INT;
73 73
 typedef int32_t MPA_INT;
74 74
 #endif
75 75
 
76
+#define BACKSTEP_SIZE 512
77
+#define EXTRABYTES 24
78
+
79
+struct GranuleDef;
80
+
81
+typedef struct MPADecodeContext {
82
+    DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
83
+    int last_buf_size;
84
+    int frame_size;
85
+    /* next header (used in free format parsing) */
86
+    uint32_t free_format_next_header;
87
+    int error_protection;
88
+    int layer;
89
+    int sample_rate;
90
+    int sample_rate_index; /* between 0 and 8 */
91
+    int bit_rate;
92
+    GetBitContext gb;
93
+    GetBitContext in_gb;
94
+    int nb_channels;
95
+    int mode;
96
+    int mode_ext;
97
+    int lsf;
98
+    DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
99
+    int synth_buf_offset[MPA_MAX_CHANNELS];
100
+    DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
101
+    int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
102
+#ifdef DEBUG
103
+    int frame_count;
104
+#endif
105
+    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
106
+    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
107
+    int dither_state;
108
+    int error_resilience;
109
+    AVCodecContext* avctx;
110
+} MPADecodeContext;
111
+
76 112
 int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
77 113
 int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
78 114
 void ff_mpa_synth_init(MPA_INT *window);
... ...
@@ -97,3 +139,5 @@ static inline int ff_mpa_check_header(uint32_t header){
97 97
         return -1;
98 98
     return 0;
99 99
 }
100
+
101
+#endif /* MPEGAUDIO_H */
... ...
@@ -22,6 +22,7 @@
22 22
 
23 23
 #include "parser.h"
24 24
 #include "mpegaudio.h"
25
+#include "mpegaudiodecheader.h"
25 26
 
26 27
 
27 28
 typedef struct MpegAudioParseContext {
... ...
@@ -41,6 +42,43 @@ typedef struct MpegAudioParseContext {
41 41
 #define SAME_HEADER_MASK \
42 42
    (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
43 43
 
44
+/* useful helper to get mpeg audio stream infos. Return -1 if error in
45
+   header, otherwise the coded frame size in bytes */
46
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
47
+{
48
+    MPADecodeContext s1, *s = &s1;
49
+    s1.avctx = avctx;
50
+
51
+    if (ff_mpa_check_header(head) != 0)
52
+        return -1;
53
+
54
+    if (decode_header(s, head) != 0) {
55
+        return -1;
56
+    }
57
+
58
+    switch(s->layer) {
59
+    case 1:
60
+        avctx->frame_size = 384;
61
+        break;
62
+    case 2:
63
+        avctx->frame_size = 1152;
64
+        break;
65
+    default:
66
+    case 3:
67
+        if (s->lsf)
68
+            avctx->frame_size = 576;
69
+        else
70
+            avctx->frame_size = 1152;
71
+        break;
72
+    }
73
+
74
+    *sample_rate = s->sample_rate;
75
+    avctx->channels = s->nb_channels;
76
+    avctx->bit_rate = s->bit_rate;
77
+    avctx->sub_id = s->layer;
78
+    return s->frame_size;
79
+}
80
+
44 81
 static int mpegaudio_parse_init(AVCodecParserContext *s1)
45 82
 {
46 83
     MpegAudioParseContext *s = s1->priv_data;
... ...
@@ -42,6 +42,7 @@
42 42
 #endif
43 43
 
44 44
 #include "mpegaudio.h"
45
+#include "mpegaudiodecheader.h"
45 46
 
46 47
 #include "mathops.h"
47 48
 
... ...
@@ -57,41 +58,6 @@
57 57
 /****************/
58 58
 
59 59
 #define HEADER_SIZE 4
60
-#define BACKSTEP_SIZE 512
61
-#define EXTRABYTES 24
62
-
63
-struct GranuleDef;
64
-
65
-typedef struct MPADecodeContext {
66
-    DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
67
-    int last_buf_size;
68
-    int frame_size;
69
-    /* next header (used in free format parsing) */
70
-    uint32_t free_format_next_header;
71
-    int error_protection;
72
-    int layer;
73
-    int sample_rate;
74
-    int sample_rate_index; /* between 0 and 8 */
75
-    int bit_rate;
76
-    GetBitContext gb;
77
-    GetBitContext in_gb;
78
-    int nb_channels;
79
-    int mode;
80
-    int mode_ext;
81
-    int lsf;
82
-    DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
83
-    int synth_buf_offset[MPA_MAX_CHANNELS];
84
-    DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
85
-    int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
86
-#ifdef DEBUG
87
-    int frame_count;
88
-#endif
89
-    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
90
-    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
91
-    int dither_state;
92
-    int error_resilience;
93
-    AVCodecContext* avctx;
94
-} MPADecodeContext;
95 60
 
96 61
 /**
97 62
  * Context for MP3On4 decoder
... ...
@@ -1107,124 +1073,6 @@ static void imdct36(int *out, int *buf, int *in, int *win)
1107 1107
     buf[8 - 4] = MULH(t0, win[18 + 8 - 4]);
1108 1108
 }
1109 1109
 
1110
-/* header decoding. MUST check the header before because no
1111
-   consistency check is done there. Return 1 if free format found and
1112
-   that the frame size must be computed externally */
1113
-static int decode_header(MPADecodeContext *s, uint32_t header)
1114
-{
1115
-    int sample_rate, frame_size, mpeg25, padding;
1116
-    int sample_rate_index, bitrate_index;
1117
-    if (header & (1<<20)) {
1118
-        s->lsf = (header & (1<<19)) ? 0 : 1;
1119
-        mpeg25 = 0;
1120
-    } else {
1121
-        s->lsf = 1;
1122
-        mpeg25 = 1;
1123
-    }
1124
-
1125
-    s->layer = 4 - ((header >> 17) & 3);
1126
-    /* extract frequency */
1127
-    sample_rate_index = (header >> 10) & 3;
1128
-    sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
1129
-    sample_rate_index += 3 * (s->lsf + mpeg25);
1130
-    s->sample_rate_index = sample_rate_index;
1131
-    s->error_protection = ((header >> 16) & 1) ^ 1;
1132
-    s->sample_rate = sample_rate;
1133
-
1134
-    bitrate_index = (header >> 12) & 0xf;
1135
-    padding = (header >> 9) & 1;
1136
-    //extension = (header >> 8) & 1;
1137
-    s->mode = (header >> 6) & 3;
1138
-    s->mode_ext = (header >> 4) & 3;
1139
-    //copyright = (header >> 3) & 1;
1140
-    //original = (header >> 2) & 1;
1141
-    //emphasis = header & 3;
1142
-
1143
-    if (s->mode == MPA_MONO)
1144
-        s->nb_channels = 1;
1145
-    else
1146
-        s->nb_channels = 2;
1147
-
1148
-    if (bitrate_index != 0) {
1149
-        frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
1150
-        s->bit_rate = frame_size * 1000;
1151
-        switch(s->layer) {
1152
-        case 1:
1153
-            frame_size = (frame_size * 12000) / sample_rate;
1154
-            frame_size = (frame_size + padding) * 4;
1155
-            break;
1156
-        case 2:
1157
-            frame_size = (frame_size * 144000) / sample_rate;
1158
-            frame_size += padding;
1159
-            break;
1160
-        default:
1161
-        case 3:
1162
-            frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
1163
-            frame_size += padding;
1164
-            break;
1165
-        }
1166
-        s->frame_size = frame_size;
1167
-    } else {
1168
-        /* if no frame size computed, signal it */
1169
-        return 1;
1170
-    }
1171
-
1172
-#if defined(DEBUG)
1173
-    dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",
1174
-           s->layer, s->sample_rate, s->bit_rate);
1175
-    if (s->nb_channels == 2) {
1176
-        if (s->layer == 3) {
1177
-            if (s->mode_ext & MODE_EXT_MS_STEREO)
1178
-                dprintf(s->avctx, "ms-");
1179
-            if (s->mode_ext & MODE_EXT_I_STEREO)
1180
-                dprintf(s->avctx, "i-");
1181
-        }
1182
-        dprintf(s->avctx, "stereo");
1183
-    } else {
1184
-        dprintf(s->avctx, "mono");
1185
-    }
1186
-    dprintf(s->avctx, "\n");
1187
-#endif
1188
-    return 0;
1189
-}
1190
-
1191
-/* useful helper to get mpeg audio stream infos. Return -1 if error in
1192
-   header, otherwise the coded frame size in bytes */
1193
-int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
1194
-{
1195
-    MPADecodeContext s1, *s = &s1;
1196
-    s1.avctx = avctx;
1197
-
1198
-    if (ff_mpa_check_header(head) != 0)
1199
-        return -1;
1200
-
1201
-    if (decode_header(s, head) != 0) {
1202
-        return -1;
1203
-    }
1204
-
1205
-    switch(s->layer) {
1206
-    case 1:
1207
-        avctx->frame_size = 384;
1208
-        break;
1209
-    case 2:
1210
-        avctx->frame_size = 1152;
1211
-        break;
1212
-    default:
1213
-    case 3:
1214
-        if (s->lsf)
1215
-            avctx->frame_size = 576;
1216
-        else
1217
-            avctx->frame_size = 1152;
1218
-        break;
1219
-    }
1220
-
1221
-    *sample_rate = s->sample_rate;
1222
-    avctx->channels = s->nb_channels;
1223
-    avctx->bit_rate = s->bit_rate;
1224
-    avctx->sub_id = s->layer;
1225
-    return s->frame_size;
1226
-}
1227
-
1228 1110
 /* return the number of decoded frames */
1229 1111
 static int mp_decode_layer1(MPADecodeContext *s)
1230 1112
 {
1231 1113
new file mode 100644
... ...
@@ -0,0 +1,109 @@
0
+/*
1
+ * MPEG Audio header decoder
2
+ * Copyright (c) 2001, 2002 Fabrice Bellard.
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file mpegaudiodecheader.c
23
+ * MPEG Audio header decoder.
24
+ */
25
+
26
+//#define DEBUG
27
+#include "avcodec.h"
28
+#include "mpegaudio.h"
29
+#include "mpegaudiodata.h"
30
+
31
+
32
+int decode_header(MPADecodeContext *s, uint32_t header)
33
+{
34
+    int sample_rate, frame_size, mpeg25, padding;
35
+    int sample_rate_index, bitrate_index;
36
+    if (header & (1<<20)) {
37
+        s->lsf = (header & (1<<19)) ? 0 : 1;
38
+        mpeg25 = 0;
39
+    } else {
40
+        s->lsf = 1;
41
+        mpeg25 = 1;
42
+    }
43
+
44
+    s->layer = 4 - ((header >> 17) & 3);
45
+    /* extract frequency */
46
+    sample_rate_index = (header >> 10) & 3;
47
+    sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
48
+    sample_rate_index += 3 * (s->lsf + mpeg25);
49
+    s->sample_rate_index = sample_rate_index;
50
+    s->error_protection = ((header >> 16) & 1) ^ 1;
51
+    s->sample_rate = sample_rate;
52
+
53
+    bitrate_index = (header >> 12) & 0xf;
54
+    padding = (header >> 9) & 1;
55
+    //extension = (header >> 8) & 1;
56
+    s->mode = (header >> 6) & 3;
57
+    s->mode_ext = (header >> 4) & 3;
58
+    //copyright = (header >> 3) & 1;
59
+    //original = (header >> 2) & 1;
60
+    //emphasis = header & 3;
61
+
62
+    if (s->mode == MPA_MONO)
63
+        s->nb_channels = 1;
64
+    else
65
+        s->nb_channels = 2;
66
+
67
+    if (bitrate_index != 0) {
68
+        frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
69
+        s->bit_rate = frame_size * 1000;
70
+        switch(s->layer) {
71
+        case 1:
72
+            frame_size = (frame_size * 12000) / sample_rate;
73
+            frame_size = (frame_size + padding) * 4;
74
+            break;
75
+        case 2:
76
+            frame_size = (frame_size * 144000) / sample_rate;
77
+            frame_size += padding;
78
+            break;
79
+        default:
80
+        case 3:
81
+            frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
82
+            frame_size += padding;
83
+            break;
84
+        }
85
+        s->frame_size = frame_size;
86
+    } else {
87
+        /* if no frame size computed, signal it */
88
+        return 1;
89
+    }
90
+
91
+#if defined(DEBUG)
92
+    dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",
93
+           s->layer, s->sample_rate, s->bit_rate);
94
+    if (s->nb_channels == 2) {
95
+        if (s->layer == 3) {
96
+            if (s->mode_ext & MODE_EXT_MS_STEREO)
97
+                dprintf(s->avctx, "ms-");
98
+            if (s->mode_ext & MODE_EXT_I_STEREO)
99
+                dprintf(s->avctx, "i-");
100
+        }
101
+        dprintf(s->avctx, "stereo");
102
+    } else {
103
+        dprintf(s->avctx, "mono");
104
+    }
105
+    dprintf(s->avctx, "\n");
106
+#endif
107
+    return 0;
108
+}
0 109
new file mode 100644
... ...
@@ -0,0 +1,39 @@
0
+/*
1
+ * MPEG Audio header decoder
2
+ * Copyright (c) 2001, 2002 Fabrice Bellard.
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file mpegaudiodecheader.c
23
+ * MPEG Audio header decoder.
24
+ */
25
+
26
+#ifndef MPEGAUDIODECHEADER_H
27
+#define MPEGAUDIODECHEADER_H
28
+
29
+#include "common.h"
30
+#include "mpegaudio.h"
31
+
32
+
33
+/* header decoding. MUST check the header before because no
34
+   consistency check is done there. Return 1 if free format found and
35
+   that the frame size must be computed externally */
36
+int decode_header(MPADecodeContext *s, uint32_t header);
37
+
38
+#endif /* MPEGAUDIODECHEADER_H */