Mercurial > libavcodec.hg
annotate bitstream_filter.c @ 5032:d47ee2d1d7da libavcodec
add proper prefix to extern mpeg audio data tables
| author | aurel |
|---|---|
| date | Sat, 19 May 2007 00:13:35 +0000 |
| parents | 70f194a2ee53 |
| children | 3c034e71667f |
| 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 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
25 AVBitStreamFilter *first_bitstream_filter= NULL; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
26 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
27 void av_register_bitstream_filter(AVBitStreamFilter *bsf){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
28 bsf->next = first_bitstream_filter; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
29 first_bitstream_filter= bsf; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
30 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
31 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
32 AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
33 AVBitStreamFilter *bsf= first_bitstream_filter; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
34 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
35 while(bsf){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
36 if(!strcmp(name, bsf->name)){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
37 AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext)); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
38 bsfc->filter= bsf; |
| 3422 | 39 bsfc->priv_data= av_mallocz(bsf->priv_data_size); |
|
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
|
40 return bsfc; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
41 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
42 bsf= bsf->next; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
43 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
44 return NULL; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
45 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
46 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
47 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){ |
| 3422 | 48 av_freep(&bsfc->priv_data); |
|
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
|
49 av_parser_close(bsfc->parser); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
50 av_free(bsfc); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
51 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
52 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
53 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
54 AVCodecContext *avctx, const char *args, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
55 uint8_t **poutbuf, int *poutbuf_size, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
56 const uint8_t *buf, int buf_size, int keyframe){ |
| 3422 | 57 *poutbuf= (uint8_t *) buf; |
| 58 *poutbuf_size= buf_size; | |
|
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
|
59 return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
60 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
61 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
62 static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
63 uint8_t **poutbuf, int *poutbuf_size, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
64 const uint8_t *buf, int buf_size, int keyframe){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
65 int cmd= args ? *args : 0; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
66 /* cast to avoid warning about discarding qualifiers */ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
67 if(avctx->extradata){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
68 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a') |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
69 ||(keyframe && (cmd=='k' || !cmd)) |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
70 ||(cmd=='e') |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
71 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
72 int size= buf_size + avctx->extradata_size; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
73 *poutbuf_size= size; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
74 *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
75 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
76 memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
77 memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
78 return 1; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
79 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
80 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
81 return 0; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
82 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
83 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
84 static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
85 uint8_t **poutbuf, int *poutbuf_size, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
86 const uint8_t *buf, int buf_size, int keyframe){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
87 int cmd= args ? *args : 0; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
88 AVCodecParserContext *s; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
89 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
90 if(!bsfc->parser){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
91 bsfc->parser= av_parser_init(avctx->codec_id); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
92 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
93 s= bsfc->parser; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
94 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
95 if(s && s->parser->split){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
96 if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a') |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
97 ||(!keyframe && cmd=='k') |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
98 ||(cmd=='e' || !cmd) |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
99 ){ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
100 int i= s->parser->split(avctx, buf, buf_size); |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
101 buf += i; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
102 buf_size -= i; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
103 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
104 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
105 *poutbuf= (uint8_t *) buf; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
106 *poutbuf_size= buf_size; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
107 |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
108 return 0; |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
109 } |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
110 |
| 3422 | 111 static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
| 112 uint8_t **poutbuf, int *poutbuf_size, | |
| 113 const uint8_t *buf, int buf_size, int keyframe){ | |
| 114 int amount= args ? atoi(args) : 10000; | |
| 115 unsigned int *state= bsfc->priv_data; | |
| 116 int i; | |
| 117 | |
| 118 *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); | |
| 119 | |
| 120 memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); | |
| 121 for(i=0; i<buf_size; i++){ | |
| 122 (*state) += (*poutbuf)[i] + 1; | |
| 123 if(*state % amount == 0) | |
| 124 (*poutbuf)[i] = *state; | |
| 125 } | |
| 126 return 1; | |
| 127 } | |
| 128 | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
129 #define MP3_MASK 0xFFFE0CCF |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
130 |
| 4166 | 131 static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, |
| 132 uint8_t **poutbuf, int *poutbuf_size, | |
| 133 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
|
134 uint32_t header, extraheader; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
135 int mode_extension, header_size; |
| 4166 | 136 |
| 137 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ | |
| 138 av_log(avctx, AV_LOG_ERROR, "not standards compliant\n"); | |
| 139 return -1; | |
| 140 } | |
| 141 | |
| 4364 | 142 header = AV_RB32(buf); |
| 4166 | 143 mode_extension= (header>>4)&3; |
| 144 | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
145 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
|
146 output_unchanged: |
| 4166 | 147 *poutbuf= (uint8_t *) buf; |
| 148 *poutbuf_size= buf_size; | |
| 149 | |
| 150 av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header); | |
| 151 return 0; | |
| 152 } | |
| 153 | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
154 if(avctx->extradata_size == 0){ |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
155 avctx->extradata_size=15; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
156 avctx->extradata= av_malloc(avctx->extradata_size); |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
157 strcpy(avctx->extradata, "FFCMP3 0.0"); |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
158 memcpy(avctx->extradata+11, buf, 4); |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
159 } |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
160 if(avctx->extradata_size != 15){ |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
161 av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n"); |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
162 return -1; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
163 } |
| 4364 | 164 extraheader = AV_RB32(avctx->extradata+11); |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
165 if((extraheader&MP3_MASK) != (header&MP3_MASK)) |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
166 goto output_unchanged; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
167 |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
168 header_size= (header&0x10000) ? 4 : 6; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
169 |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
170 *poutbuf_size= buf_size - header_size; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
171 *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
|
172 memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 4166 | 173 |
| 174 if(avctx->channels==2){ | |
| 175 if((header & (3<<19)) != 3<<19){ | |
| 176 (*poutbuf)[1] &= 0x3F; | |
| 177 (*poutbuf)[1] |= mode_extension<<6; | |
| 178 FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]); | |
| 179 }else{ | |
| 180 (*poutbuf)[1] &= 0x8F; | |
| 181 (*poutbuf)[1] |= mode_extension<<4; | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 return 1; | |
| 186 } | |
| 187 | |
| 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 | |
| 4364 | 196 header = AV_RB32(buf); |
| 4166 | 197 if(ff_mpa_check_header(header) >= 0){ |
| 198 *poutbuf= (uint8_t *) buf; | |
| 199 *poutbuf_size= buf_size; | |
| 200 | |
| 201 return 0; | |
| 202 } | |
| 203 | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
204 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
|
205 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
|
206 return -1; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
207 } |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
208 |
| 4364 | 209 header= AV_RB32(avctx->extradata+11) & MP3_MASK; |
| 4166 | 210 |
| 211 lsf = sample_rate < (24000+32000)/2; | |
| 212 mpeg25 = sample_rate < (12000+16000)/2; | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
213 sample_rate_index= (header>>10)&3; |
| 5032 | 214 sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off |
| 4166 | 215 |
| 216 for(bitrate_index=2; bitrate_index<30; bitrate_index++){ | |
| 5032 | 217 frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; |
| 4166 | 218 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); |
| 219 if(frame_size == buf_size + 4) | |
| 220 break; | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
221 if(frame_size == buf_size + 6) |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
222 break; |
| 4166 | 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; | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
231 header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 |
| 4166 | 232 |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
233 *poutbuf_size= frame_size; |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
234 *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
|
235 memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 4166 | 236 |
| 237 if(avctx->channels==2){ | |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
238 uint8_t *p= *poutbuf + frame_size - buf_size; |
| 4166 | 239 if(lsf){ |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
240 FFSWAP(int, p[1], p[2]); |
|
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
241 header |= (p[1] & 0xC0)>>2; |
| 4168 | 242 p[1] &= 0x3F; |
| 4166 | 243 }else{ |
|
4167
a3134db4857e
store a identifer and the first header in extradata
michael
parents:
4166
diff
changeset
|
244 header |= p[1] & 0x30; |
| 4168 | 245 p[1] &= 0xCF; |
| 4166 | 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 | |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
257 #ifdef CONFIG_DUMP_EXTRADATA_BSF |
|
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
|
258 AVBitStreamFilter dump_extradata_bsf={ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
259 "dump_extra", |
| 3422 | 260 0, |
|
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
|
261 dump_extradata, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
262 }; |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
263 #endif |
|
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
|
264 |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
265 #ifdef CONFIG_REMOVE_EXTRADATA_BSF |
|
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
|
266 AVBitStreamFilter remove_extradata_bsf={ |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
267 "remove_extra", |
| 3422 | 268 0, |
|
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
|
269 remove_extradata, |
|
b7826511f7b6
AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff
changeset
|
270 }; |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
271 #endif |
| 3422 | 272 |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
273 #ifdef CONFIG_NOISE_BSF |
| 3422 | 274 AVBitStreamFilter noise_bsf={ |
| 275 "noise", | |
| 276 sizeof(int), | |
| 277 noise, | |
| 278 }; | |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
279 #endif |
| 4166 | 280 |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
281 #ifdef CONFIG_MP3_HEADER_COMPRESS_BSF |
| 4166 | 282 AVBitStreamFilter mp3_header_compress_bsf={ |
| 283 "mp3comp", | |
| 284 0, | |
| 285 mp3_header_compress, | |
| 286 }; | |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
287 #endif |
| 4166 | 288 |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
289 #ifdef CONFIG_MP3_HEADER_DECOMPRESS_BSF |
| 4166 | 290 AVBitStreamFilter mp3_header_decompress_bsf={ |
| 291 "mp3decomp", | |
| 292 0, | |
| 293 mp3_header_decompress, | |
| 294 }; | |
|
4994
3fa689636240
allow to enable or disable every bitstream filters individually
aurel
parents:
4364
diff
changeset
|
295 #endif |
