comparison bitstream_filter.c @ 3421:b7826511f7b6 libavcodec

AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
author michael
date Thu, 06 Jul 2006 15:04:46 +0000
parents
children 6ce5ece8e2ea
comparison
equal deleted inserted replaced
3420:54814e15aa3d 3421:b7826511f7b6
1
2 #include "avcodec.h"
3
4 AVBitStreamFilter *first_bitstream_filter= NULL;
5
6 void av_register_bitstream_filter(AVBitStreamFilter *bsf){
7 bsf->next = first_bitstream_filter;
8 first_bitstream_filter= bsf;
9 }
10
11 AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){
12 AVBitStreamFilter *bsf= first_bitstream_filter;
13
14 while(bsf){
15 if(!strcmp(name, bsf->name)){
16 AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
17 bsfc->filter= bsf;
18 return bsfc;
19 }
20 bsf= bsf->next;
21 }
22 return NULL;
23 }
24
25 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
26 av_parser_close(bsfc->parser);
27 av_free(bsfc);
28 }
29
30 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
31 AVCodecContext *avctx, const char *args,
32 uint8_t **poutbuf, int *poutbuf_size,
33 const uint8_t *buf, int buf_size, int keyframe){
34 return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
35 }
36
37 static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
38 uint8_t **poutbuf, int *poutbuf_size,
39 const uint8_t *buf, int buf_size, int keyframe){
40 int cmd= args ? *args : 0;
41 /* cast to avoid warning about discarding qualifiers */
42 *poutbuf= (uint8_t *) buf;
43 *poutbuf_size= buf_size;
44 if(avctx->extradata){
45 if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
46 ||(keyframe && (cmd=='k' || !cmd))
47 ||(cmd=='e')
48 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
49 int size= buf_size + avctx->extradata_size;
50 *poutbuf_size= size;
51 *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
52
53 memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
54 memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
55 return 1;
56 }
57 }
58 return 0;
59 }
60
61 static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
62 uint8_t **poutbuf, int *poutbuf_size,
63 const uint8_t *buf, int buf_size, int keyframe){
64 int cmd= args ? *args : 0;
65 AVCodecParserContext *s;
66
67 if(!bsfc->parser){
68 bsfc->parser= av_parser_init(avctx->codec_id);
69 }
70 s= bsfc->parser;
71
72 if(s && s->parser->split){
73 if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a')
74 ||(!keyframe && cmd=='k')
75 ||(cmd=='e' || !cmd)
76 ){
77 int i= s->parser->split(avctx, buf, buf_size);
78 buf += i;
79 buf_size -= i;
80 }
81 }
82 *poutbuf= (uint8_t *) buf;
83 *poutbuf_size= buf_size;
84
85 return 0;
86 }
87
88 AVBitStreamFilter dump_extradata_bsf={
89 "dump_extra",
90 dump_extradata,
91 };
92
93 AVBitStreamFilter remove_extradata_bsf={
94 "remove_extra",
95 remove_extradata,
96 };