提交 514e0831 编写于 作者: M Michael Niedermayer

noise bitstream filter

add priv_data field to AVBitStreamFilterContext

Originally committed as revision 5644 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 748c2fca
...@@ -664,5 +664,6 @@ PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); ...@@ -664,5 +664,6 @@ PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
av_register_bitstream_filter(&dump_extradata_bsf); av_register_bitstream_filter(&dump_extradata_bsf);
av_register_bitstream_filter(&remove_extradata_bsf); av_register_bitstream_filter(&remove_extradata_bsf);
av_register_bitstream_filter(&noise_bsf);
} }
...@@ -2573,6 +2573,7 @@ extern AVCodecParser aac_parser; ...@@ -2573,6 +2573,7 @@ extern AVCodecParser aac_parser;
typedef struct AVBitStreamFilterContext { typedef struct AVBitStreamFilterContext {
void *priv_data;
struct AVBitStreamFilter *filter; struct AVBitStreamFilter *filter;
AVCodecParserContext *parser; AVCodecParserContext *parser;
struct AVBitStreamFilterContext *next; struct AVBitStreamFilterContext *next;
...@@ -2581,6 +2582,7 @@ typedef struct AVBitStreamFilterContext { ...@@ -2581,6 +2582,7 @@ typedef struct AVBitStreamFilterContext {
typedef struct AVBitStreamFilter { typedef struct AVBitStreamFilter {
const char *name; const char *name;
int priv_data_size;
int (*filter)(AVBitStreamFilterContext *bsfc, int (*filter)(AVBitStreamFilterContext *bsfc,
AVCodecContext *avctx, const char *args, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size, uint8_t **poutbuf, int *poutbuf_size,
...@@ -2600,6 +2602,7 @@ void av_bitstream_filter_close(AVBitStreamFilterContext *bsf); ...@@ -2600,6 +2602,7 @@ void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
extern AVBitStreamFilter dump_extradata_bsf; extern AVBitStreamFilter dump_extradata_bsf;
extern AVBitStreamFilter remove_extradata_bsf; extern AVBitStreamFilter remove_extradata_bsf;
extern AVBitStreamFilter noise_bsf;
/* memory */ /* memory */
......
...@@ -15,6 +15,7 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){ ...@@ -15,6 +15,7 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
if(!strcmp(name, bsf->name)){ if(!strcmp(name, bsf->name)){
AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext)); AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
bsfc->filter= bsf; bsfc->filter= bsf;
bsfc->priv_data= av_mallocz(bsf->priv_data_size);
return bsfc; return bsfc;
} }
bsf= bsf->next; bsf= bsf->next;
...@@ -23,6 +24,7 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){ ...@@ -23,6 +24,7 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
} }
void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){ void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
av_freep(&bsfc->priv_data);
av_parser_close(bsfc->parser); av_parser_close(bsfc->parser);
av_free(bsfc); av_free(bsfc);
} }
...@@ -31,6 +33,8 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, ...@@ -31,6 +33,8 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
AVCodecContext *avctx, const char *args, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size, uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){ const uint8_t *buf, int buf_size, int keyframe){
*poutbuf= (uint8_t *) buf;
*poutbuf_size= buf_size;
return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe); return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
} }
...@@ -39,8 +43,6 @@ static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, ...@@ -39,8 +43,6 @@ static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx,
const uint8_t *buf, int buf_size, int keyframe){ const uint8_t *buf, int buf_size, int keyframe){
int cmd= args ? *args : 0; int cmd= args ? *args : 0;
/* cast to avoid warning about discarding qualifiers */ /* cast to avoid warning about discarding qualifiers */
*poutbuf= (uint8_t *) buf;
*poutbuf_size= buf_size;
if(avctx->extradata){ if(avctx->extradata){
if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a') if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
||(keyframe && (cmd=='k' || !cmd)) ||(keyframe && (cmd=='k' || !cmd))
...@@ -85,12 +87,38 @@ static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avct ...@@ -85,12 +87,38 @@ static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avct
return 0; return 0;
} }
static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
int amount= args ? atoi(args) : 10000;
unsigned int *state= bsfc->priv_data;
int i;
*poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
for(i=0; i<buf_size; i++){
(*state) += (*poutbuf)[i] + 1;
if(*state % amount == 0)
(*poutbuf)[i] = *state;
}
return 1;
}
AVBitStreamFilter dump_extradata_bsf={ AVBitStreamFilter dump_extradata_bsf={
"dump_extra", "dump_extra",
0,
dump_extradata, dump_extradata,
}; };
AVBitStreamFilter remove_extradata_bsf={ AVBitStreamFilter remove_extradata_bsf={
"remove_extra", "remove_extra",
0,
remove_extradata, remove_extradata,
}; };
AVBitStreamFilter noise_bsf={
"noise",
sizeof(int),
noise,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册