]> git.sesse.net Git - ffmpeg/blob - libavcodec/bitstream_filter.c
dv: Mark internal frame reference as const
[ffmpeg] / libavcodec / bitstream_filter.c
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include <string.h>
22
23 #include "avcodec.h"
24 #include "libavutil/mem.h"
25
26 static AVBitStreamFilter *first_bitstream_filter = NULL;
27
28 AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f)
29 {
30     if (f)
31         return f->next;
32     else
33         return first_bitstream_filter;
34 }
35
36 void av_register_bitstream_filter(AVBitStreamFilter *bsf)
37 {
38     bsf->next              = first_bitstream_filter;
39     first_bitstream_filter = bsf;
40 }
41
42 AVBitStreamFilterContext *av_bitstream_filter_init(const char *name)
43 {
44     AVBitStreamFilter *bsf = first_bitstream_filter;
45
46     while (bsf) {
47         if (!strcmp(name, bsf->name)) {
48             AVBitStreamFilterContext *bsfc =
49                 av_mallocz(sizeof(AVBitStreamFilterContext));
50             if (!bsfc)
51                 return NULL;
52             bsfc->filter    = bsf;
53             bsfc->priv_data = NULL;
54             if (bsf->priv_data_size) {
55                 bsfc->priv_data = av_mallocz(bsf->priv_data_size);
56                 if (!bsfc->priv_data) {
57                     av_freep(&bsfc);
58                     return NULL;
59                 }
60             }
61             return bsfc;
62         }
63         bsf = bsf->next;
64     }
65     return NULL;
66 }
67
68 void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc)
69 {
70     if (bsfc->filter->close)
71         bsfc->filter->close(bsfc);
72     av_freep(&bsfc->priv_data);
73     av_parser_close(bsfc->parser);
74     av_free(bsfc);
75 }
76
77 int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
78                                AVCodecContext *avctx, const char *args,
79                                uint8_t **poutbuf, int *poutbuf_size,
80                                const uint8_t *buf, int buf_size, int keyframe)
81 {
82     *poutbuf      = (uint8_t *)buf;
83     *poutbuf_size = buf_size;
84     return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size,
85                                 buf, buf_size, keyframe);
86 }