annotate bitstream_filter.c @ 3545:e2a589e55906 libavcodec

Minor fix
author lu_zero
date Thu, 03 Aug 2006 14:37:58 +0000
parents 6ce5ece8e2ea
children c537a97eec66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
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
2 #include "avcodec.h"
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
3
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
4 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
5
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
6 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
7 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
8 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
9 }
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
10
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
11 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
12 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
13
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
14 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
15 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
16 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
17 bsfc->filter= bsf;
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
18 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
19 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
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 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
22 }
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
23 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
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
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 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
27 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
28 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
29 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
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 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
33 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
34 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
35 const uint8_t *buf, int buf_size, int keyframe){
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
36 *poutbuf= (uint8_t *) buf;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
37 *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
38 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
39 }
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
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 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
42 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
43 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
44 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
45 /* 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
46 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
47 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
48 ||(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
49 ||(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
50 /*||(? && (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
51 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
52 *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
53 *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
54
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 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
56 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
57 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
58 }
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 }
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 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
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
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 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
64 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
65 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
66 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
67 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
68
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 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
70 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
71 }
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 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
73
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 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
75 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
76 ||(!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
77 ||(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
78 ){
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 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
80 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
81 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
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 *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
85 *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
86
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 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
88 }
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
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
90 static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
91 uint8_t **poutbuf, int *poutbuf_size,
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
92 const uint8_t *buf, int buf_size, int keyframe){
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
93 int amount= args ? atoi(args) : 10000;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
94 unsigned int *state= bsfc->priv_data;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
95 int i;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
96
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
97 *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
98
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
99 memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
100 for(i=0; i<buf_size; i++){
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
101 (*state) += (*poutbuf)[i] + 1;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
102 if(*state % amount == 0)
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
103 (*poutbuf)[i] = *state;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
104 }
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
105 return 1;
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
106 }
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
107
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
108 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
109 "dump_extra",
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
110 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
111 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
112 };
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
113
b7826511f7b6 AVBitStreamFilter (some thingy which can modify the bitstream like add or remove global headers or change the headers or ...)
michael
parents:
diff changeset
114 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
115 "remove_extra",
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
116 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
117 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
118 };
3422
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
119
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
120 AVBitStreamFilter noise_bsf={
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
121 "noise",
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
122 sizeof(int),
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
123 noise,
6ce5ece8e2ea noise bitstream filter
michael
parents: 3421
diff changeset
124 };