Mercurial > libavcodec.hg
annotate mp3_header_decompress_bsf.c @ 8990:cc8f95accbff libavcodec
Fixing a value returning issue
author | romansh |
---|---|
date | Fri, 20 Feb 2009 02:00:44 +0000 |
parents | 4dbe6578f811 |
children |
rev | line source |
---|---|
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
1 /* |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
3 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
14 * Lesser General Public License for more details. |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
15 * |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3699
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3422
diff
changeset
|
19 */ |
3421
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
20 |
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
21 #include "avcodec.h" |
4166 | 22 #include "mpegaudio.h" |
5031
70f194a2ee53
move some common mpeg audio tables from mpegaudiodectab.h to mpegaudiodata.c
aurel
parents:
4994
diff
changeset
|
23 #include "mpegaudiodata.h" |
3421
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
24 |
4166 | 25 |
26 static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, | |
27 uint8_t **poutbuf, int *poutbuf_size, | |
28 const uint8_t *buf, int buf_size, int keyframe){ | |
29 uint32_t header; | |
30 int sample_rate= avctx->sample_rate; | |
31 int sample_rate_index=0; | |
32 int lsf, mpeg25, bitrate_index, frame_size; | |
33 | |
4364 | 34 header = AV_RB32(buf); |
4166 | 35 if(ff_mpa_check_header(header) >= 0){ |
36 *poutbuf= (uint8_t *) buf; | |
37 *poutbuf_size= buf_size; | |
38 | |
39 return 0; | |
40 } | |
41 | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
42 if(avctx->extradata_size != 15 || strcmp(avctx->extradata, "FFCMP3 0.0")){ |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
43 av_log(avctx, AV_LOG_ERROR, "Extradata invalid %d\n", avctx->extradata_size); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
44 return -1; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
45 } |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
46 |
4364 | 47 header= AV_RB32(avctx->extradata+11) & MP3_MASK; |
4166 | 48 |
49 lsf = sample_rate < (24000+32000)/2; | |
50 mpeg25 = sample_rate < (12000+16000)/2; | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
51 sample_rate_index= (header>>10)&3; |
5032 | 52 sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off |
4166 | 53 |
54 for(bitrate_index=2; bitrate_index<30; bitrate_index++){ | |
5032 | 55 frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; |
4166 | 56 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); |
57 if(frame_size == buf_size + 4) | |
58 break; | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
59 if(frame_size == buf_size + 6) |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
60 break; |
4166 | 61 } |
62 if(bitrate_index == 30){ | |
5127 | 63 av_log(avctx, AV_LOG_ERROR, "Could not find bitrate_index.\n"); |
4166 | 64 return -1; |
65 } | |
66 | |
67 header |= (bitrate_index&1)<<9; | |
68 header |= (bitrate_index>>1)<<12; | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
69 header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 |
4166 | 70 |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
71 *poutbuf_size= frame_size; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
72 *poutbuf= av_malloc(frame_size + FF_INPUT_BUFFER_PADDING_SIZE); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
73 memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
4166 | 74 |
75 if(avctx->channels==2){ | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
76 uint8_t *p= *poutbuf + frame_size - buf_size; |
4166 | 77 if(lsf){ |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
78 FFSWAP(int, p[1], p[2]); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
79 header |= (p[1] & 0xC0)>>2; |
4168 | 80 p[1] &= 0x3F; |
4166 | 81 }else{ |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
82 header |= p[1] & 0x30; |
4168 | 83 p[1] &= 0xCF; |
4166 | 84 } |
85 } | |
86 | |
5089 | 87 AV_WB32(*poutbuf, header); |
4166 | 88 |
89 return 1; | |
90 } | |
91 | |
92 AVBitStreamFilter mp3_header_decompress_bsf={ | |
93 "mp3decomp", | |
94 0, | |
95 mp3_header_decompress, | |
96 }; |