annotate mp3_header_decompress_bsf.c @ 8423:b55ec18fe5e9 libavcodec

Use ARCH_X86_32 instead of !ARCH_X86_64, it is more straightforward.
author diego
date Mon, 22 Dec 2008 00:03:30 +0000
parents 4dbe6578f811
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
25
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
26 static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
27 uint8_t **poutbuf, int *poutbuf_size,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
28 const uint8_t *buf, int buf_size, int keyframe){
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
29 uint32_t header;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
30 int sample_rate= avctx->sample_rate;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
31 int sample_rate_index=0;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
32 int lsf, mpeg25, bitrate_index, frame_size;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
33
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4168
diff changeset
34 header = AV_RB32(buf);
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
35 if(ff_mpa_check_header(header) >= 0){
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
36 *poutbuf= (uint8_t *) buf;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
37 *poutbuf_size= buf_size;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
38
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
39 return 0;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
40 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4168
diff changeset
47 header= AV_RB32(avctx->extradata+11) & MP3_MASK;
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
48
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
49 lsf = sample_rate < (24000+32000)/2;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
d47ee2d1d7da add proper prefix to extern mpeg audio data tables
aurel
parents: 5031
diff changeset
52 sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
53
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
54 for(bitrate_index=2; bitrate_index<30; bitrate_index++){
5032
d47ee2d1d7da add proper prefix to extern mpeg audio data tables
aurel
parents: 5031
diff changeset
55 frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1];
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
56 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
57 if(frame_size == buf_size + 4)
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
61 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
62 if(bitrate_index == 30){
5127
4dbe6578f811 misc spelling fixes
diego
parents: 5089
diff changeset
63 av_log(avctx, AV_LOG_ERROR, "Could not find bitrate_index.\n");
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
64 return -1;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
65 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
66
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
67 header |= (bitrate_index&1)<<9;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
74
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
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
38bb77e11353 zero private bits
michael
parents: 4167
diff changeset
80 p[1] &= 0x3F;
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
81 }else{
4167
a3134db4857e store a identifer and the first header in extradata
michael
parents: 4166
diff changeset
82 header |= p[1] & 0x30;
4168
38bb77e11353 zero private bits
michael
parents: 4167
diff changeset
83 p[1] &= 0xCF;
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
84 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
85 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
86
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 5033
diff changeset
87 AV_WB32(*poutbuf, header);
4166
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
88
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
89 return 1;
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
90 }
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
91
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
92 AVBitStreamFilter mp3_header_decompress_bsf={
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
93 "mp3decomp",
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
94 0,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
95 mp3_header_decompress,
eced83504436 mp3 header (de)compression bitstream filter
michael
parents: 3947
diff changeset
96 };