Mercurial > libavcodec.hg
annotate mp3_header_compress_bsf.c @ 9929:354e23134dfc libavcodec
Remove support for nonfree libamr library for AMR-NB/WB decoding/encoding.
libopencore can now be used as a replacement except for AMR-WB encoding.
author | diego |
---|---|
date | Tue, 07 Jul 2009 00:28:16 +0000 |
parents | b955154b7ca9 |
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" |
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
|
23 |
3422 | 24 |
4166 | 25 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
26 uint8_t **poutbuf, int *poutbuf_size, | |
27 const uint8_t *buf, int buf_size, int keyframe){ | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
28 uint32_t header, extraheader; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
29 int mode_extension, header_size; |
4166 | 30 |
31 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ | |
32 av_log(avctx, AV_LOG_ERROR, "not standards compliant\n"); | |
33 return -1; | |
34 } | |
35 | |
4364 | 36 header = AV_RB32(buf); |
4166 | 37 mode_extension= (header>>4)&3; |
38 | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
39 if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){ |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
40 output_unchanged: |
4166 | 41 *poutbuf= (uint8_t *) buf; |
42 *poutbuf_size= buf_size; | |
43 | |
44 av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header); | |
45 return 0; | |
46 } | |
47 | |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
48 if(avctx->extradata_size == 0){ |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
49 avctx->extradata_size=15; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
50 avctx->extradata= av_malloc(avctx->extradata_size); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
51 strcpy(avctx->extradata, "FFCMP3 0.0"); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
52 memcpy(avctx->extradata+11, buf, 4); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
53 } |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
54 if(avctx->extradata_size != 15){ |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
55 av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n"); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
56 return -1; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
57 } |
4364 | 58 extraheader = AV_RB32(avctx->extradata+11); |
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
59 if((extraheader&MP3_MASK) != (header&MP3_MASK)) |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
60 goto output_unchanged; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
61 |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
62 header_size= (header&0x10000) ? 4 : 6; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
63 |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
64 *poutbuf_size= buf_size - header_size; |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
65 *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); |
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
66 memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); |
4166 | 67 |
68 if(avctx->channels==2){ | |
69 if((header & (3<<19)) != 3<<19){ | |
70 (*poutbuf)[1] &= 0x3F; | |
71 (*poutbuf)[1] |= mode_extension<<6; | |
72 FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]); | |
73 }else{ | |
74 (*poutbuf)[1] &= 0x8F; | |
75 (*poutbuf)[1] |= mode_extension<<4; | |
76 } | |
77 } | |
78 | |
79 return 1; | |
80 } | |
81 | |
82 AVBitStreamFilter mp3_header_compress_bsf={ | |
83 "mp3comp", | |
84 0, | |
85 mp3_header_compress, | |
86 }; |