LCOV - code coverage report
Current view: top level - libavfilter - split.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 32 78.1 %
Date: 2017-12-10 21:22:29 Functions: 3 3 100.0 %

          Line data    Source code
       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             :  * audio and video splitter
      24             :  */
      25             : 
      26             : #include <stdio.h>
      27             : 
      28             : #include "libavutil/attributes.h"
      29             : #include "libavutil/internal.h"
      30             : #include "libavutil/mem.h"
      31             : #include "libavutil/opt.h"
      32             : 
      33             : #define FF_INTERNAL_FIELDS 1
      34             : #include "framequeue.h"
      35             : 
      36             : #include "avfilter.h"
      37             : #include "audio.h"
      38             : #include "formats.h"
      39             : #include "internal.h"
      40             : #include "video.h"
      41             : 
      42             : typedef struct SplitContext {
      43             :     const AVClass *class;
      44             :     int nb_outputs;
      45             : } SplitContext;
      46             : 
      47          28 : static av_cold int split_init(AVFilterContext *ctx)
      48             : {
      49          28 :     SplitContext *s = ctx->priv;
      50             :     int i, ret;
      51             : 
      52         168 :     for (i = 0; i < s->nb_outputs; i++) {
      53             :         char name[32];
      54          56 :         AVFilterPad pad = { 0 };
      55             : 
      56          56 :         snprintf(name, sizeof(name), "output%d", i);
      57          56 :         pad.type = ctx->filter->inputs[0].type;
      58          56 :         pad.name = av_strdup(name);
      59          56 :         if (!pad.name)
      60           0 :             return AVERROR(ENOMEM);
      61             : 
      62          56 :         if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
      63           0 :             av_freep(&pad.name);
      64           0 :             return ret;
      65             :         }
      66             :     }
      67             : 
      68          28 :     return 0;
      69             : }
      70             : 
      71          28 : static av_cold void split_uninit(AVFilterContext *ctx)
      72             : {
      73             :     int i;
      74             : 
      75          84 :     for (i = 0; i < ctx->nb_outputs; i++)
      76          56 :         av_freep(&ctx->output_pads[i].name);
      77          28 : }
      78             : 
      79         520 : static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
      80             : {
      81         520 :     AVFilterContext *ctx = inlink->dst;
      82         520 :     int i, ret = AVERROR_EOF;
      83             : 
      84        1560 :     for (i = 0; i < ctx->nb_outputs; i++) {
      85             :         AVFrame *buf_out;
      86             : 
      87        1040 :         if (ctx->outputs[i]->status_in)
      88           0 :             continue;
      89        1040 :         buf_out = av_frame_clone(frame);
      90        1040 :         if (!buf_out) {
      91           0 :             ret = AVERROR(ENOMEM);
      92           0 :             break;
      93             :         }
      94             : 
      95        1040 :         ret = ff_filter_frame(ctx->outputs[i], buf_out);
      96        1040 :         if (ret < 0)
      97           0 :             break;
      98             :     }
      99         520 :     av_frame_free(&frame);
     100         520 :     return ret;
     101             : }
     102             : 
     103             : #define OFFSET(x) offsetof(SplitContext, x)
     104             : #define FLAGS (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
     105             : static const AVOption options[] = {
     106             :     { "outputs", "set number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, FLAGS },
     107             :     { NULL }
     108             : };
     109             : 
     110             : #define split_options options
     111             : AVFILTER_DEFINE_CLASS(split);
     112             : 
     113             : #define asplit_options options
     114             : AVFILTER_DEFINE_CLASS(asplit);
     115             : 
     116             : static const AVFilterPad avfilter_vf_split_inputs[] = {
     117             :     {
     118             :         .name         = "default",
     119             :         .type         = AVMEDIA_TYPE_VIDEO,
     120             :         .filter_frame = filter_frame,
     121             :     },
     122             :     { NULL }
     123             : };
     124             : 
     125             : AVFilter ff_vf_split = {
     126             :     .name        = "split",
     127             :     .description = NULL_IF_CONFIG_SMALL("Pass on the input to N video outputs."),
     128             :     .priv_size   = sizeof(SplitContext),
     129             :     .priv_class  = &split_class,
     130             :     .init        = split_init,
     131             :     .uninit      = split_uninit,
     132             :     .inputs      = avfilter_vf_split_inputs,
     133             :     .outputs     = NULL,
     134             :     .flags       = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
     135             : };
     136             : 
     137             : static const AVFilterPad avfilter_af_asplit_inputs[] = {
     138             :     {
     139             :         .name         = "default",
     140             :         .type         = AVMEDIA_TYPE_AUDIO,
     141             :         .filter_frame = filter_frame,
     142             :     },
     143             :     { NULL }
     144             : };
     145             : 
     146             : AVFilter ff_af_asplit = {
     147             :     .name        = "asplit",
     148             :     .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
     149             :     .priv_size   = sizeof(SplitContext),
     150             :     .priv_class  = &asplit_class,
     151             :     .init        = split_init,
     152             :     .uninit      = split_uninit,
     153             :     .inputs      = avfilter_af_asplit_inputs,
     154             :     .outputs     = NULL,
     155             :     .flags       = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
     156             : };

Generated by: LCOV version 1.13