LCOV - code coverage report
Current view: top level - src/libavfilter/tests - filtfmts.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 52 69.2 %
Date: 2017-09-20 05:29:53 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.13