OSDN Git Service

libspeex encoder wraper
[coroid/ffmpeg_saccubus.git] / libavfilter / vf_format.c
1 /*
2  * Copyright (c) 2007 Bobby Bingham
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * format and noformat video filters
24  */
25
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "internal.h"
29
30 typedef struct {
31     /**
32      * List of flags telling if a given image format has been listed
33      * as argument to the filter.
34      */
35     int listed_pix_fmt_flags[PIX_FMT_NB];
36 } FormatContext;
37
38 #define PIX_FMT_NAME_MAXSIZE 32
39
40 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
41 {
42     FormatContext *format = ctx->priv;
43     const char *cur, *sep;
44     char             pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
45     int              pix_fmt_name_len, ret;
46     enum PixelFormat pix_fmt;
47
48     /* parse the list of formats */
49     for (cur = args; cur; cur = sep ? sep+1 : NULL) {
50         if (!(sep = strchr(cur, ':')))
51             pix_fmt_name_len = strlen(cur);
52         else
53             pix_fmt_name_len = sep - cur;
54         if (pix_fmt_name_len >= PIX_FMT_NAME_MAXSIZE) {
55             av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
56             return -1;
57         }
58
59         memcpy(pix_fmt_name, cur, pix_fmt_name_len);
60         pix_fmt_name[pix_fmt_name_len] = 0;
61
62         if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
63             return ret;
64
65         format->listed_pix_fmt_flags[pix_fmt] = 1;
66     }
67
68     return 0;
69 }
70
71 static AVFilterFormats *make_format_list(FormatContext *format, int flag)
72 {
73     AVFilterFormats *formats;
74     enum PixelFormat pix_fmt;
75
76     formats = av_mallocz(sizeof(AVFilterFormats));
77     formats->formats = av_malloc(sizeof(enum PixelFormat) * PIX_FMT_NB);
78
79     for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
80         if (format->listed_pix_fmt_flags[pix_fmt] == flag)
81             formats->formats[formats->format_count++] = pix_fmt;
82
83     return formats;
84 }
85
86 #if CONFIG_FORMAT_FILTER
87 static int query_formats_format(AVFilterContext *ctx)
88 {
89     avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1));
90     return 0;
91 }
92
93 AVFilter avfilter_vf_format = {
94     .name      = "format",
95     .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
96
97     .init      = init,
98
99     .query_formats = query_formats_format,
100
101     .priv_size = sizeof(FormatContext),
102
103     .inputs    = (AVFilterPad[]) {{ .name            = "default",
104                                     .type            = AVMEDIA_TYPE_VIDEO,
105                                     .get_video_buffer= avfilter_null_get_video_buffer,
106                                     .start_frame     = avfilter_null_start_frame,
107                                     .draw_slice      = avfilter_null_draw_slice,
108                                     .end_frame       = avfilter_null_end_frame, },
109                                   { .name = NULL}},
110     .outputs   = (AVFilterPad[]) {{ .name            = "default",
111                                     .type            = AVMEDIA_TYPE_VIDEO },
112                                   { .name = NULL}},
113 };
114 #endif /* CONFIG_FORMAT_FILTER */
115
116 #if CONFIG_NOFORMAT_FILTER
117 static int query_formats_noformat(AVFilterContext *ctx)
118 {
119     avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0));
120     return 0;
121 }
122
123 AVFilter avfilter_vf_noformat = {
124     .name      = "noformat",
125     .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
126
127     .init      = init,
128
129     .query_formats = query_formats_noformat,
130
131     .priv_size = sizeof(FormatContext),
132
133     .inputs    = (AVFilterPad[]) {{ .name            = "default",
134                                     .type            = AVMEDIA_TYPE_VIDEO,
135                                     .get_video_buffer= avfilter_null_get_video_buffer,
136                                     .start_frame     = avfilter_null_start_frame,
137                                     .draw_slice      = avfilter_null_draw_slice,
138                                     .end_frame       = avfilter_null_end_frame, },
139                                   { .name = NULL}},
140     .outputs   = (AVFilterPad[]) {{ .name            = "default",
141                                     .type            = AVMEDIA_TYPE_VIDEO },
142                                   { .name = NULL}},
143 };
144 #endif /* CONFIG_NOFORMAT_FILTER */
145