comparison bitstream_filter.c @ 3422:6ce5ece8e2ea libavcodec

noise bitstream filter add priv_data field to AVBitStreamFilterContext
author michael
date Thu, 06 Jul 2006 15:28:17 +0000
parents b7826511f7b6
children c537a97eec66
comparison
equal deleted inserted replaced
3421:b7826511f7b6 3422:6ce5ece8e2ea
13 13
14 while(bsf){ 14 while(bsf){
15 if(!strcmp(name, bsf->name)){ 15 if(!strcmp(name, bsf->name)){
16 AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext)); 16 AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
17 bsfc->filter= bsf; 17 bsfc->filter= bsf;
18 bsfc->priv_data= av_mallocz(bsf->priv_data_size);
18 return bsfc; 19 return bsfc;
19 } 20 }
20 bsf= bsf->next; 21 bsf= bsf->next;
21 } 22 }
22 return NULL; 23 return NULL;
23 } 24 }
24 25
25 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){ 26 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
27 av_freep(&bsfc->priv_data);
26 av_parser_close(bsfc->parser); 28 av_parser_close(bsfc->parser);
27 av_free(bsfc); 29 av_free(bsfc);
28 } 30 }
29 31
30 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, 32 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
31 AVCodecContext *avctx, const char *args, 33 AVCodecContext *avctx, const char *args,
32 uint8_t **poutbuf, int *poutbuf_size, 34 uint8_t **poutbuf, int *poutbuf_size,
33 const uint8_t *buf, int buf_size, int keyframe){ 35 const uint8_t *buf, int buf_size, int keyframe){
36 *poutbuf= (uint8_t *) buf;
37 *poutbuf_size= buf_size;
34 return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe); 38 return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
35 } 39 }
36 40
37 static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, 41 static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
38 uint8_t **poutbuf, int *poutbuf_size, 42 uint8_t **poutbuf, int *poutbuf_size,
39 const uint8_t *buf, int buf_size, int keyframe){ 43 const uint8_t *buf, int buf_size, int keyframe){
40 int cmd= args ? *args : 0; 44 int cmd= args ? *args : 0;
41 /* cast to avoid warning about discarding qualifiers */ 45 /* cast to avoid warning about discarding qualifiers */
42 *poutbuf= (uint8_t *) buf;
43 *poutbuf_size= buf_size;
44 if(avctx->extradata){ 46 if(avctx->extradata){
45 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a') 47 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
46 ||(keyframe && (cmd=='k' || !cmd)) 48 ||(keyframe && (cmd=='k' || !cmd))
47 ||(cmd=='e') 49 ||(cmd=='e')
48 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ 50 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
83 *poutbuf_size= buf_size; 85 *poutbuf_size= buf_size;
84 86
85 return 0; 87 return 0;
86 } 88 }
87 89
90 static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
91 uint8_t **poutbuf, int *poutbuf_size,
92 const uint8_t *buf, int buf_size, int keyframe){
93 int amount= args ? atoi(args) : 10000;
94 unsigned int *state= bsfc->priv_data;
95 int i;
96
97 *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
98
99 memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
100 for(i=0; i<buf_size; i++){
101 (*state) += (*poutbuf)[i] + 1;
102 if(*state % amount == 0)
103 (*poutbuf)[i] = *state;
104 }
105 return 1;
106 }
107
88 AVBitStreamFilter dump_extradata_bsf={ 108 AVBitStreamFilter dump_extradata_bsf={
89 "dump_extra", 109 "dump_extra",
110 0,
90 dump_extradata, 111 dump_extradata,
91 }; 112 };
92 113
93 AVBitStreamFilter remove_extradata_bsf={ 114 AVBitStreamFilter remove_extradata_bsf={
94 "remove_extra", 115 "remove_extra",
116 0,
95 remove_extradata, 117 remove_extradata,
96 }; 118 };
119
120 AVBitStreamFilter noise_bsf={
121 "noise",
122 sizeof(int),
123 noise,
124 };