Revision 514e0831

View differences:

libavcodec/allcodecs.c
664 664

  
665 665
    av_register_bitstream_filter(&dump_extradata_bsf);
666 666
    av_register_bitstream_filter(&remove_extradata_bsf);
667
    av_register_bitstream_filter(&noise_bsf);
667 668
}
668 669

  
libavcodec/avcodec.h
2573 2573

  
2574 2574

  
2575 2575
typedef struct AVBitStreamFilterContext {
2576
    void *priv_data;
2576 2577
    struct AVBitStreamFilter *filter;
2577 2578
    AVCodecParserContext *parser;
2578 2579
    struct AVBitStreamFilterContext *next;
......
2581 2582

  
2582 2583
typedef struct AVBitStreamFilter {
2583 2584
    const char *name;
2585
    int priv_data_size;
2584 2586
    int (*filter)(AVBitStreamFilterContext *bsfc,
2585 2587
                  AVCodecContext *avctx, const char *args,
2586 2588
                  uint8_t **poutbuf, int *poutbuf_size,
......
2600 2602

  
2601 2603
extern AVBitStreamFilter dump_extradata_bsf;
2602 2604
extern AVBitStreamFilter remove_extradata_bsf;
2605
extern AVBitStreamFilter noise_bsf;
2603 2606

  
2604 2607

  
2605 2608
/* memory */
libavcodec/bitstream_filter.c
15 15
        if(!strcmp(name, bsf->name)){
16 16
            AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext));
17 17
            bsfc->filter= bsf;
18
            bsfc->priv_data= av_mallocz(bsf->priv_data_size);
18 19
            return bsfc;
19 20
        }
20 21
        bsf= bsf->next;
......
23 24
}
24 25

  
25 26
void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){
27
    av_freep(&bsfc->priv_data);
26 28
    av_parser_close(bsfc->parser);
27 29
    av_free(bsfc);
28 30
}
......
31 33
                               AVCodecContext *avctx, const char *args,
32 34
                     uint8_t **poutbuf, int *poutbuf_size,
33 35
                     const uint8_t *buf, int buf_size, int keyframe){
36
    *poutbuf= (uint8_t *) buf;
37
    *poutbuf_size= buf_size;
34 38
    return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe);
35 39
}
36 40

  
......
39 43
                     const uint8_t *buf, int buf_size, int keyframe){
40 44
    int cmd= args ? *args : 0;
41 45
    /* cast to avoid warning about discarding qualifiers */
42
    *poutbuf= (uint8_t *) buf;
43
    *poutbuf_size= buf_size;
44 46
    if(avctx->extradata){
45 47
        if(  (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a')
46 48
           ||(keyframe && (cmd=='k' || !cmd))
......
85 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 108
AVBitStreamFilter dump_extradata_bsf={
89 109
    "dump_extra",
110
    0,
90 111
    dump_extradata,
91 112
};
92 113

  
93 114
AVBitStreamFilter remove_extradata_bsf={
94 115
    "remove_extra",
116
    0,
95 117
    remove_extradata,
96 118
};
119

  
120
AVBitStreamFilter noise_bsf={
121
    "noise",
122
    sizeof(int),
123
    noise,
124
};

Also available in: Unified diff