Mercurial > libavcodec.hg
comparison bitstream_filter.c @ 5033:3c034e71667f libavcodec
move mp3_header_decompress bitstream filter in its own file
author | aurel |
---|---|
date | Sat, 19 May 2007 00:24:34 +0000 |
parents | d47ee2d1d7da |
children | b955154b7ca9 |
comparison
equal
deleted
inserted
replaced
5032:d47ee2d1d7da | 5033:3c034e71667f |
---|---|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 */ | 19 */ |
20 | 20 |
21 #include "avcodec.h" | 21 #include "avcodec.h" |
22 #include "mpegaudio.h" | 22 #include "mpegaudio.h" |
23 #include "mpegaudiodata.h" | |
24 | 23 |
25 AVBitStreamFilter *first_bitstream_filter= NULL; | 24 AVBitStreamFilter *first_bitstream_filter= NULL; |
26 | 25 |
27 void av_register_bitstream_filter(AVBitStreamFilter *bsf){ | 26 void av_register_bitstream_filter(AVBitStreamFilter *bsf){ |
28 bsf->next = first_bitstream_filter; | 27 bsf->next = first_bitstream_filter; |
124 (*poutbuf)[i] = *state; | 123 (*poutbuf)[i] = *state; |
125 } | 124 } |
126 return 1; | 125 return 1; |
127 } | 126 } |
128 | 127 |
129 #define MP3_MASK 0xFFFE0CCF | |
130 | |
131 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, | 128 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
132 uint8_t **poutbuf, int *poutbuf_size, | 129 uint8_t **poutbuf, int *poutbuf_size, |
133 const uint8_t *buf, int buf_size, int keyframe){ | 130 const uint8_t *buf, int buf_size, int keyframe){ |
134 uint32_t header, extraheader; | 131 uint32_t header, extraheader; |
135 int mode_extension, header_size; | 132 int mode_extension, header_size; |
183 } | 180 } |
184 | 181 |
185 return 1; | 182 return 1; |
186 } | 183 } |
187 | 184 |
188 static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, | |
189 uint8_t **poutbuf, int *poutbuf_size, | |
190 const uint8_t *buf, int buf_size, int keyframe){ | |
191 uint32_t header; | |
192 int sample_rate= avctx->sample_rate; | |
193 int sample_rate_index=0; | |
194 int lsf, mpeg25, bitrate_index, frame_size; | |
195 | |
196 header = AV_RB32(buf); | |
197 if(ff_mpa_check_header(header) >= 0){ | |
198 *poutbuf= (uint8_t *) buf; | |
199 *poutbuf_size= buf_size; | |
200 | |
201 return 0; | |
202 } | |
203 | |
204 if(avctx->extradata_size != 15 || strcmp(avctx->extradata, "FFCMP3 0.0")){ | |
205 av_log(avctx, AV_LOG_ERROR, "Extradata invalid %d\n", avctx->extradata_size); | |
206 return -1; | |
207 } | |
208 | |
209 header= AV_RB32(avctx->extradata+11) & MP3_MASK; | |
210 | |
211 lsf = sample_rate < (24000+32000)/2; | |
212 mpeg25 = sample_rate < (12000+16000)/2; | |
213 sample_rate_index= (header>>10)&3; | |
214 sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off | |
215 | |
216 for(bitrate_index=2; bitrate_index<30; bitrate_index++){ | |
217 frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; | |
218 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); | |
219 if(frame_size == buf_size + 4) | |
220 break; | |
221 if(frame_size == buf_size + 6) | |
222 break; | |
223 } | |
224 if(bitrate_index == 30){ | |
225 av_log(avctx, AV_LOG_ERROR, "couldnt find bitrate_index\n"); | |
226 return -1; | |
227 } | |
228 | |
229 header |= (bitrate_index&1)<<9; | |
230 header |= (bitrate_index>>1)<<12; | |
231 header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 | |
232 | |
233 *poutbuf_size= frame_size; | |
234 *poutbuf= av_malloc(frame_size + FF_INPUT_BUFFER_PADDING_SIZE); | |
235 memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); | |
236 | |
237 if(avctx->channels==2){ | |
238 uint8_t *p= *poutbuf + frame_size - buf_size; | |
239 if(lsf){ | |
240 FFSWAP(int, p[1], p[2]); | |
241 header |= (p[1] & 0xC0)>>2; | |
242 p[1] &= 0x3F; | |
243 }else{ | |
244 header |= p[1] & 0x30; | |
245 p[1] &= 0xCF; | |
246 } | |
247 } | |
248 | |
249 (*poutbuf)[0]= header>>24; | |
250 (*poutbuf)[1]= header>>16; | |
251 (*poutbuf)[2]= header>> 8; | |
252 (*poutbuf)[3]= header ; | |
253 | |
254 return 1; | |
255 } | |
256 | |
257 #ifdef CONFIG_DUMP_EXTRADATA_BSF | 185 #ifdef CONFIG_DUMP_EXTRADATA_BSF |
258 AVBitStreamFilter dump_extradata_bsf={ | 186 AVBitStreamFilter dump_extradata_bsf={ |
259 "dump_extra", | 187 "dump_extra", |
260 0, | 188 0, |
261 dump_extradata, | 189 dump_extradata, |
283 "mp3comp", | 211 "mp3comp", |
284 0, | 212 0, |
285 mp3_header_compress, | 213 mp3_header_compress, |
286 }; | 214 }; |
287 #endif | 215 #endif |
288 | |
289 #ifdef CONFIG_MP3_HEADER_DECOMPRESS_BSF | |
290 AVBitStreamFilter mp3_header_decompress_bsf={ | |
291 "mp3decomp", | |
292 0, | |
293 mp3_header_decompress, | |
294 }; | |
295 #endif |