| Line | Branch | Exec | Source |
|---|---|---|---|
| 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/avfilter_internal.h" | ||
| 30 | #include "libavfilter/formats.h" | ||
| 31 | #include "libavfilter/framequeue.h" | ||
| 32 | |||
| 33 | 132 | static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads, | |
| 34 | unsigned nb, size_t fmts_cfg_offset, | ||
| 35 | const char *inout_string) | ||
| 36 | { | ||
| 37 |
2/2✓ Branch 0 taken 132 times.
✓ Branch 1 taken 132 times.
|
264 | for (unsigned i = 0; i < nb; i++) { |
| 38 | 132 | const AVFilterLink *const link = links[i]; | |
| 39 | 132 | const AVFilterFormatsConfig *const cfg = (AVFilterFormatsConfig*)((const char*)link + fmts_cfg_offset); | |
| 40 | 132 | const char *pad_name = avfilter_pad_get_name(pads, i); | |
| 41 | |||
| 42 |
1/2✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
|
132 | if (link->type == AVMEDIA_TYPE_VIDEO) { |
| 43 | 132 | const AVFilterFormats *const fmts = cfg->formats; | |
| 44 |
3/4✓ Branch 0 taken 24983 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24851 times.
✓ Branch 3 taken 132 times.
|
24983 | for (unsigned j = 0; fmts && j < fmts->nb_formats; j++) { |
| 45 | 24851 | printf("%s[%u] %s: fmt:%s\n", | |
| 46 | inout_string, i, pad_name, | ||
| 47 | 24851 | av_get_pix_fmt_name(fmts->formats[j])); | |
| 48 | } | ||
| 49 | ✗ | } else if (link->type == AVMEDIA_TYPE_AUDIO) { | |
| 50 | ✗ | const AVFilterFormats *const fmts = cfg->formats; | |
| 51 | ✗ | const AVFilterChannelLayouts *const layouts = cfg->channel_layouts; | |
| 52 | |||
| 53 | ✗ | for (unsigned j = 0; fmts && j < fmts->nb_formats; j++) | |
| 54 | ✗ | printf("%s[%u] %s: fmt:%s\n", | |
| 55 | inout_string, i, pad_name, | ||
| 56 | ✗ | av_get_sample_fmt_name(fmts->formats[j])); | |
| 57 | |||
| 58 | ✗ | for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) { | |
| 59 | char buf[256]; | ||
| 60 | ✗ | av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf)); | |
| 61 | ✗ | printf("%s[%u] %s: chlayout:%s\n", | |
| 62 | inout_string, i, pad_name, buf); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | 132 | } | |
| 67 | |||
| 68 | 66 | static void print_formats(AVFilterContext *filter_ctx) | |
| 69 | { | ||
| 70 | 66 | print_formats_internal(filter_ctx->inputs, filter_ctx->input_pads, | |
| 71 | filter_ctx->nb_inputs, | ||
| 72 | offsetof(AVFilterLink, outcfg), "INPUT"); | ||
| 73 | 66 | print_formats_internal(filter_ctx->outputs, filter_ctx->output_pads, | |
| 74 | filter_ctx->nb_outputs, | ||
| 75 | offsetof(AVFilterLink, incfg), "OUTPUT"); | ||
| 76 | 66 | } | |
| 77 | |||
| 78 | 66 | int main(int argc, char **argv) | |
| 79 | { | ||
| 80 | const AVFilter *filter; | ||
| 81 | const FFFilter *fi; | ||
| 82 | AVFilterContext *filter_ctx; | ||
| 83 | AVFilterGraph *graph_ctx; | ||
| 84 | const char *filter_name; | ||
| 85 | 66 | const char *filter_args = NULL; | |
| 86 | int i; | ||
| 87 | 66 | int ret = 0; | |
| 88 | |||
| 89 | 66 | av_log_set_level(AV_LOG_DEBUG); | |
| 90 | |||
| 91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (argc < 2) { |
| 92 | ✗ | fprintf(stderr, "Missing filter name as argument\n"); | |
| 93 | ✗ | return 1; | |
| 94 | } | ||
| 95 | |||
| 96 | 66 | filter_name = argv[1]; | |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (argc > 2) |
| 98 | ✗ | filter_args = argv[2]; | |
| 99 | |||
| 100 | /* allocate graph */ | ||
| 101 | 66 | graph_ctx = avfilter_graph_alloc(); | |
| 102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!graph_ctx) |
| 103 | ✗ | return 1; | |
| 104 | |||
| 105 | /* get a corresponding filter and open it */ | ||
| 106 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
|
66 | if (!(filter = avfilter_get_by_name(filter_name))) { |
| 107 | ✗ | fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name); | |
| 108 | ✗ | return 1; | |
| 109 | } | ||
| 110 | 66 | fi = fffilter(filter); | |
| 111 | |||
| 112 | /* open filter and add it to the graph */ | ||
| 113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
|
66 | if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) { |
| 114 | ✗ | fprintf(stderr, "Impossible to open filter with name '%s'\n", | |
| 115 | filter_name); | ||
| 116 | ✗ | return 1; | |
| 117 | } | ||
| 118 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
|
66 | if (avfilter_init_str(filter_ctx, filter_args) < 0) { |
| 119 | ✗ | fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", | |
| 120 | filter_name, filter_args); | ||
| 121 | ✗ | return 1; | |
| 122 | } | ||
| 123 | |||
| 124 | /* create a link for each of the input pads */ | ||
| 125 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | for (i = 0; i < filter_ctx->nb_inputs; i++) { |
| 126 | 66 | AVFilterLink *link = av_mallocz(sizeof(FilterLinkInternal)); | |
| 127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!link) { |
| 128 | ✗ | fprintf(stderr, "Unable to allocate memory for filter input link\n"); | |
| 129 | ✗ | ret = 1; | |
| 130 | ✗ | goto fail; | |
| 131 | } | ||
| 132 | 66 | link->type = avfilter_pad_get_type(filter_ctx->input_pads, i); | |
| 133 | 66 | filter_ctx->inputs[i] = link; | |
| 134 | } | ||
| 135 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | for (i = 0; i < filter_ctx->nb_outputs; i++) { |
| 136 | 66 | AVFilterLink *link = av_mallocz(sizeof(FilterLinkInternal)); | |
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!link) { |
| 138 | ✗ | fprintf(stderr, "Unable to allocate memory for filter output link\n"); | |
| 139 | ✗ | ret = 1; | |
| 140 | ✗ | goto fail; | |
| 141 | } | ||
| 142 | 66 | link->type = avfilter_pad_get_type(filter_ctx->output_pads, i); | |
| 143 | 66 | filter_ctx->outputs[i] = link; | |
| 144 | } | ||
| 145 | |||
| 146 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (fi->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) |
| 147 | ✗ | ret = fi->formats.query_func(filter_ctx); | |
| 148 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 11 times.
|
66 | else if (fi->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) { |
| 149 | 55 | AVFilterFormatsConfig **cfg_in = NULL, **cfg_out = NULL; | |
| 150 | |||
| 151 |
1/2✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
|
55 | if (filter_ctx->nb_inputs) { |
| 152 | 55 | cfg_in = av_malloc_array(filter_ctx->nb_inputs, sizeof(*cfg_in)); | |
| 153 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 55 times.
|
110 | for (unsigned i = 0; i < filter_ctx->nb_inputs; i++) |
| 154 | 55 | cfg_in[i] = &filter_ctx->inputs[i]->outcfg; | |
| 155 | } | ||
| 156 |
1/2✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
|
55 | if (filter_ctx->nb_outputs) { |
| 157 | 55 | cfg_out = av_malloc_array(filter_ctx->nb_outputs, sizeof(*cfg_out)); | |
| 158 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 55 times.
|
110 | for (unsigned i = 0; i < filter_ctx->nb_outputs; i++) |
| 159 | 55 | cfg_out[i] = &filter_ctx->outputs[i]->incfg; | |
| 160 | } | ||
| 161 | |||
| 162 | 55 | ret = fi->formats.query_func2(filter_ctx, cfg_in, cfg_out); | |
| 163 | 55 | av_freep(&cfg_in); | |
| 164 | 55 | av_freep(&cfg_out); | |
| 165 | } else | ||
| 166 | 11 | ret = ff_default_query_formats(filter_ctx); | |
| 167 | |||
| 168 | 66 | print_formats(filter_ctx); | |
| 169 | |||
| 170 | 66 | fail: | |
| 171 | 66 | avfilter_free(filter_ctx); | |
| 172 | 66 | avfilter_graph_free(&graph_ctx); | |
| 173 | 66 | fflush(stdout); | |
| 174 | 66 | return ret; | |
| 175 | } | ||
| 176 |