2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of Libav.
6 * Libav 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.
11 * Libav 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * audio and video splitter
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
35 static int split_init(AVFilterContext *ctx, const char *args)
37 int i, nb_outputs = 2;
40 nb_outputs = strtol(args, NULL, 0);
41 if (nb_outputs <= 0) {
42 av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
44 return AVERROR(EINVAL);
48 for (i = 0; i < nb_outputs; i++) {
50 AVFilterPad pad = { 0 };
52 snprintf(name, sizeof(name), "output%d", i);
53 pad.type = ctx->filter->inputs[0].type;
54 pad.name = av_strdup(name);
56 ff_insert_outpad(ctx, i, &pad);
62 static void split_uninit(AVFilterContext *ctx)
66 for (i = 0; i < ctx->nb_outputs; i++)
67 av_freep(&ctx->output_pads[i].name);
70 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
72 AVFilterContext *ctx = inlink->dst;
75 for (i = 0; i < ctx->nb_outputs; i++) {
76 AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~AV_PERM_WRITE);
78 return AVERROR(ENOMEM);
80 ret = ff_start_frame(ctx->outputs[i], buf_out);
87 static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
89 AVFilterContext *ctx = inlink->dst;
92 for (i = 0; i < ctx->nb_outputs; i++) {
93 ret = ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
100 static int end_frame(AVFilterLink *inlink)
102 AVFilterContext *ctx = inlink->dst;
105 for (i = 0; i < ctx->nb_outputs; i++) {
106 ret = ff_end_frame(ctx->outputs[i]);
113 AVFilter avfilter_vf_split = {
115 .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
118 .uninit = split_uninit,
120 .inputs = (const AVFilterPad[]) {{ .name = "default",
121 .type = AVMEDIA_TYPE_VIDEO,
122 .get_video_buffer= ff_null_get_video_buffer,
123 .start_frame = start_frame,
124 .draw_slice = draw_slice,
125 .end_frame = end_frame, },
127 .outputs = (const AVFilterPad[]) {{ .name = NULL}},
130 static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
132 AVFilterContext *ctx = inlink->dst;
135 for (i = 0; i < ctx->nb_outputs; i++) {
136 AVFilterBufferRef *buf_out = avfilter_ref_buffer(samplesref,
139 ret = AVERROR(ENOMEM);
143 ret = ff_filter_samples(inlink->dst->outputs[i], buf_out);
147 avfilter_unref_buffer(samplesref);
151 AVFilter avfilter_af_asplit = {
153 .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
156 .uninit = split_uninit,
158 .inputs = (const AVFilterPad[]) {{ .name = "default",
159 .type = AVMEDIA_TYPE_AUDIO,
160 .get_audio_buffer = ff_null_get_audio_buffer,
161 .filter_samples = filter_samples },
163 .outputs = (const AVFilterPad[]) {{ .name = NULL }},