Signed-off-by: Mans Rullgard <mans@mansr.com>
Mans Rullgard authored on 2011/05/19 21:44:11... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
# define CONFIG_FLOAT 0 |
31 | 31 |
#endif |
32 | 32 |
|
33 |
-#include "avcodec.h" |
|
33 |
+#include <stdint.h> |
|
34 | 34 |
|
35 | 35 |
/* max frame size, in samples */ |
36 | 36 |
#define MPA_FRAME_SIZE 1152 |
... | ... |
@@ -47,8 +47,6 @@ |
47 | 47 |
#define MPA_DUAL 2 |
48 | 48 |
#define MPA_MONO 3 |
49 | 49 |
|
50 |
-#define MP3_MASK 0xFFFE0CCF |
|
51 |
- |
|
52 | 50 |
#ifndef FRAC_BITS |
53 | 51 |
#define FRAC_BITS 23 /* fractional bits for sb_samples and dct */ |
54 | 52 |
#define WFRAC_BITS 16 /* fractional bits for window */ |
... | ... |
@@ -72,40 +70,6 @@ typedef int32_t MPA_INT; |
72 | 72 |
typedef int16_t OUT_INT; |
73 | 73 |
#endif |
74 | 74 |
|
75 |
-#define MPA_DECODE_HEADER \ |
|
76 |
- int frame_size; \ |
|
77 |
- int error_protection; \ |
|
78 |
- int layer; \ |
|
79 |
- int sample_rate; \ |
|
80 |
- int sample_rate_index; /* between 0 and 8 */ \ |
|
81 |
- int bit_rate; \ |
|
82 |
- int nb_channels; \ |
|
83 |
- int mode; \ |
|
84 |
- int mode_ext; \ |
|
85 |
- int lsf; |
|
86 |
- |
|
87 |
-typedef struct MPADecodeHeader { |
|
88 |
- MPA_DECODE_HEADER |
|
89 |
-} MPADecodeHeader; |
|
90 |
- |
|
91 | 75 |
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf); |
92 |
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); |
|
93 |
- |
|
94 |
-/* fast header check for resync */ |
|
95 |
-static inline int ff_mpa_check_header(uint32_t header){ |
|
96 |
- /* header */ |
|
97 |
- if ((header & 0xffe00000) != 0xffe00000) |
|
98 |
- return -1; |
|
99 |
- /* layer check */ |
|
100 |
- if ((header & (3<<17)) == 0) |
|
101 |
- return -1; |
|
102 |
- /* bit rate */ |
|
103 |
- if ((header & (0xf<<12)) == 0xf<<12) |
|
104 |
- return -1; |
|
105 |
- /* frequency */ |
|
106 |
- if ((header & (3<<10)) == 3<<10) |
|
107 |
- return -1; |
|
108 |
- return 0; |
|
109 |
-} |
|
110 | 76 |
|
111 | 77 |
#endif /* AVCODEC_MPEGAUDIO_H */ |
... | ... |
@@ -38,45 +38,6 @@ typedef struct MpegAudioParseContext { |
38 | 38 |
#define SAME_HEADER_MASK \ |
39 | 39 |
(0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) |
40 | 40 |
|
41 |
-/* useful helper to get mpeg audio stream infos. Return -1 if error in |
|
42 |
- header, otherwise the coded frame size in bytes */ |
|
43 |
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) |
|
44 |
-{ |
|
45 |
- MPADecodeHeader s1, *s = &s1; |
|
46 |
- |
|
47 |
- if (ff_mpa_check_header(head) != 0) |
|
48 |
- return -1; |
|
49 |
- |
|
50 |
- if (ff_mpegaudio_decode_header(s, head) != 0) { |
|
51 |
- return -1; |
|
52 |
- } |
|
53 |
- |
|
54 |
- switch(s->layer) { |
|
55 |
- case 1: |
|
56 |
- avctx->codec_id = CODEC_ID_MP1; |
|
57 |
- *frame_size = 384; |
|
58 |
- break; |
|
59 |
- case 2: |
|
60 |
- avctx->codec_id = CODEC_ID_MP2; |
|
61 |
- *frame_size = 1152; |
|
62 |
- break; |
|
63 |
- default: |
|
64 |
- case 3: |
|
65 |
- avctx->codec_id = CODEC_ID_MP3; |
|
66 |
- if (s->lsf) |
|
67 |
- *frame_size = 576; |
|
68 |
- else |
|
69 |
- *frame_size = 1152; |
|
70 |
- break; |
|
71 |
- } |
|
72 |
- |
|
73 |
- *sample_rate = s->sample_rate; |
|
74 |
- *channels = s->nb_channels; |
|
75 |
- *bit_rate = s->bit_rate; |
|
76 |
- avctx->sub_id = s->layer; |
|
77 |
- return s->frame_size; |
|
78 |
-} |
|
79 |
- |
|
80 | 41 |
static int mpegaudio_parse(AVCodecParserContext *s1, |
81 | 42 |
AVCodecContext *avctx, |
82 | 43 |
const uint8_t **poutbuf, int *poutbuf_size, |
... | ... |
@@ -108,3 +108,40 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) |
108 | 108 |
#endif |
109 | 109 |
return 0; |
110 | 110 |
} |
111 |
+ |
|
112 |
+int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) |
|
113 |
+{ |
|
114 |
+ MPADecodeHeader s1, *s = &s1; |
|
115 |
+ |
|
116 |
+ if (ff_mpa_check_header(head) != 0) |
|
117 |
+ return -1; |
|
118 |
+ |
|
119 |
+ if (ff_mpegaudio_decode_header(s, head) != 0) { |
|
120 |
+ return -1; |
|
121 |
+ } |
|
122 |
+ |
|
123 |
+ switch(s->layer) { |
|
124 |
+ case 1: |
|
125 |
+ avctx->codec_id = CODEC_ID_MP1; |
|
126 |
+ *frame_size = 384; |
|
127 |
+ break; |
|
128 |
+ case 2: |
|
129 |
+ avctx->codec_id = CODEC_ID_MP2; |
|
130 |
+ *frame_size = 1152; |
|
131 |
+ break; |
|
132 |
+ default: |
|
133 |
+ case 3: |
|
134 |
+ avctx->codec_id = CODEC_ID_MP3; |
|
135 |
+ if (s->lsf) |
|
136 |
+ *frame_size = 576; |
|
137 |
+ else |
|
138 |
+ *frame_size = 1152; |
|
139 |
+ break; |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ *sample_rate = s->sample_rate; |
|
143 |
+ *channels = s->nb_channels; |
|
144 |
+ *bit_rate = s->bit_rate; |
|
145 |
+ avctx->sub_id = s->layer; |
|
146 |
+ return s->frame_size; |
|
147 |
+} |
... | ... |
@@ -27,13 +27,50 @@ |
27 | 27 |
#ifndef AVCODEC_MPEGAUDIODECHEADER_H |
28 | 28 |
#define AVCODEC_MPEGAUDIODECHEADER_H |
29 | 29 |
|
30 |
-#include "libavutil/common.h" |
|
31 |
-#include "mpegaudio.h" |
|
30 |
+#include "avcodec.h" |
|
32 | 31 |
|
32 |
+#define MP3_MASK 0xFFFE0CCF |
|
33 |
+ |
|
34 |
+#define MPA_DECODE_HEADER \ |
|
35 |
+ int frame_size; \ |
|
36 |
+ int error_protection; \ |
|
37 |
+ int layer; \ |
|
38 |
+ int sample_rate; \ |
|
39 |
+ int sample_rate_index; /* between 0 and 8 */ \ |
|
40 |
+ int bit_rate; \ |
|
41 |
+ int nb_channels; \ |
|
42 |
+ int mode; \ |
|
43 |
+ int mode_ext; \ |
|
44 |
+ int lsf; |
|
45 |
+ |
|
46 |
+typedef struct MPADecodeHeader { |
|
47 |
+ MPA_DECODE_HEADER |
|
48 |
+} MPADecodeHeader; |
|
33 | 49 |
|
34 | 50 |
/* header decoding. MUST check the header before because no |
35 | 51 |
consistency check is done there. Return 1 if free format found and |
36 | 52 |
that the frame size must be computed externally */ |
37 | 53 |
int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); |
38 | 54 |
|
55 |
+/* useful helper to get mpeg audio stream infos. Return -1 if error in |
|
56 |
+ header, otherwise the coded frame size in bytes */ |
|
57 |
+int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); |
|
58 |
+ |
|
59 |
+/* fast header check for resync */ |
|
60 |
+static inline int ff_mpa_check_header(uint32_t header){ |
|
61 |
+ /* header */ |
|
62 |
+ if ((header & 0xffe00000) != 0xffe00000) |
|
63 |
+ return -1; |
|
64 |
+ /* layer check */ |
|
65 |
+ if ((header & (3<<17)) == 0) |
|
66 |
+ return -1; |
|
67 |
+ /* bit rate */ |
|
68 |
+ if ((header & (0xf<<12)) == 0xf<<12) |
|
69 |
+ return -1; |
|
70 |
+ /* frequency */ |
|
71 |
+ if ((header & (3<<10)) == 3<<10) |
|
72 |
+ return -1; |
|
73 |
+ return 0; |
|
74 |
+} |
|
75 |
+ |
|
39 | 76 |
#endif /* AVCODEC_MPEGAUDIODECHEADER_H */ |