Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / libavfilter / filtfmts.c
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
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 #include <stdio.h>
22
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/samplefmt.h"
27
28 #include "libavfilter/avfilter.h"
29 #include "libavfilter/formats.h"
30
31 static void print_formats(AVFilterContext *filter_ctx)
32 {
33     int i, j;
34
35 #define PRINT_FMTS(inout, outin, INOUT)                                 \
36     for (i = 0; i < filter_ctx->nb_##inout##puts; i++) {                     \
37         if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) {   \
38             AVFilterFormats *fmts =                                     \
39                 filter_ctx->inout##puts[i]->outin##_formats;            \
40             for (j = 0; j < fmts->nb_formats; j++)                    \
41                 if(av_get_pix_fmt_name(fmts->formats[j]))               \
42                 printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
43                        i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
44                        av_get_pix_fmt_name(fmts->formats[j]));          \
45         } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
46             AVFilterFormats *fmts;                                      \
47             AVFilterChannelLayouts *layouts;                            \
48                                                                         \
49             fmts = filter_ctx->inout##puts[i]->outin##_formats;         \
50             for (j = 0; j < fmts->nb_formats; j++)                    \
51                 printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
52                        i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
53                        av_get_sample_fmt_name(fmts->formats[j]));       \
54                                                                         \
55             layouts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
56             for (j = 0; j < layouts->nb_channel_layouts; j++) {                  \
57                 char buf[256];                                          \
58                 av_get_channel_layout_string(buf, sizeof(buf), -1,      \
59                                              layouts->channel_layouts[j]);         \
60                 printf(#INOUT "PUT[%d] %s: chlayout:%s\n",              \
61                        i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), buf); \
62             }                                                           \
63         }                                                               \
64     }                                                                   \
65
66     PRINT_FMTS(in,  out, IN);
67     PRINT_FMTS(out, in,  OUT);
68 }
69
70 int main(int argc, char **argv)
71 {
72     AVFilter *filter;
73     AVFilterContext *filter_ctx;
74     AVFilterGraph *graph_ctx;
75     const char *filter_name;
76     const char *filter_args = NULL;
77     int i;
78
79     av_log_set_level(AV_LOG_DEBUG);
80
81     if (argc < 2) {
82         fprintf(stderr, "Missing filter name as argument\n");
83         return 1;
84     }
85
86     filter_name = argv[1];
87     if (argc > 2)
88         filter_args = argv[2];
89
90     /* allocate graph */
91     graph_ctx = avfilter_graph_alloc();
92     if (!graph_ctx)
93         return 1;
94
95     avfilter_register_all();
96
97     /* get a corresponding filter and open it */
98     if (!(filter = avfilter_get_by_name(filter_name))) {
99         fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
100         return 1;
101     }
102
103     /* open filter and add it to the graph */
104     if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
105         fprintf(stderr, "Impossible to open filter with name '%s'\n",
106                 filter_name);
107         return 1;
108     }
109     if (avfilter_init_str(filter_ctx, filter_args) < 0) {
110         fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
111                 filter_name, filter_args);
112         return 1;
113     }
114
115     /* create a link for each of the input pads */
116     for (i = 0; i < filter_ctx->nb_inputs; i++) {
117         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
118         link->type = avfilter_pad_get_type(filter_ctx->input_pads, i);
119         filter_ctx->inputs[i] = link;
120     }
121     for (i = 0; i < filter_ctx->nb_outputs; i++) {
122         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
123         link->type = avfilter_pad_get_type(filter_ctx->output_pads, i);
124         filter_ctx->outputs[i] = link;
125     }
126
127     if (filter->query_formats)
128         filter->query_formats(filter_ctx);
129     else
130         ff_default_query_formats(filter_ctx);
131
132     print_formats(filter_ctx);
133
134     avfilter_free(filter_ctx);
135     avfilter_graph_free(&graph_ctx);
136     fflush(stdout);
137     return 0;
138 }