2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 AVBitStreamFilter *first_bitstream_filter= NULL;
23 void av_register_bitstream_filter(AVBitStreamFilter *bsf){
24 bsf->next = first_bitstream_filter;
25 first_bitstream_filter= bsf;
28 AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
29 AVBitStreamFilter *bsf= first_bitstream_filter;
32 if(!strcmp(name, bsf->name)){
33 AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
35 bsfc->priv_data= av_mallocz(bsf->priv_data_size);
43 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
44 av_freep(&bsfc->priv_data);
45 av_parser_close(bsfc->parser);
49 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
50 AVCodecContext *avctx, const char *args,
51 uint8_t **poutbuf, int *poutbuf_size,
52 const uint8_t *buf, int buf_size, int keyframe){
53 *poutbuf= (uint8_t *) buf;
54 *poutbuf_size= buf_size;
55 return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
58 static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
59 uint8_t **poutbuf, int *poutbuf_size,
60 const uint8_t *buf, int buf_size, int keyframe){
61 int cmd= args ? *args : 0;
62 /* cast to avoid warning about discarding qualifiers */
64 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
65 ||(keyframe && (cmd=='k' || !cmd))
67 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
68 int size= buf_size + avctx->extradata_size;
70 *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
72 memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
73 memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
80 static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
81 uint8_t **poutbuf, int *poutbuf_size,
82 const uint8_t *buf, int buf_size, int keyframe){
83 int cmd= args ? *args : 0;
84 AVCodecParserContext *s;
87 bsfc->parser= av_parser_init(avctx->codec_id);
91 if(s && s->parser->split){
92 if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a')
93 ||(!keyframe && cmd=='k')
96 int i= s->parser->split(avctx, buf, buf_size);
101 *poutbuf= (uint8_t *) buf;
102 *poutbuf_size= buf_size;
107 static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
108 uint8_t **poutbuf, int *poutbuf_size,
109 const uint8_t *buf, int buf_size, int keyframe){
110 int amount= args ? atoi(args) : 10000;
111 unsigned int *state= bsfc->priv_data;
114 *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
116 memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
117 for(i=0; i<buf_size; i++){
118 (*state) += (*poutbuf)[i] + 1;
119 if(*state % amount == 0)
120 (*poutbuf)[i] = *state;
125 AVBitStreamFilter dump_extradata_bsf={
131 AVBitStreamFilter remove_extradata_bsf={
137 AVBitStreamFilter noise_bsf={