00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avfilter.h"
00027 #include "audio.h"
00028 #include "video.h"
00029
00030 static int split_init(AVFilterContext *ctx, const char *args, void *opaque)
00031 {
00032 int i, nb_outputs = 2;
00033
00034 if (args) {
00035 nb_outputs = strtol(args, NULL, 0);
00036 if (nb_outputs <= 0) {
00037 av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
00038 nb_outputs);
00039 return AVERROR(EINVAL);
00040 }
00041 }
00042
00043 for (i = 0; i < nb_outputs; i++) {
00044 char name[32];
00045 AVFilterPad pad = { 0 };
00046
00047 snprintf(name, sizeof(name), "output%d", i);
00048 pad.type = ctx->filter->inputs[0].type;
00049 pad.name = av_strdup(name);
00050
00051 avfilter_insert_outpad(ctx, i, &pad);
00052 }
00053
00054 return 0;
00055 }
00056
00057 static void split_uninit(AVFilterContext *ctx)
00058 {
00059 int i;
00060
00061 for (i = 0; i < ctx->output_count; i++)
00062 av_freep(&ctx->output_pads[i].name);
00063 }
00064
00065 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
00066 {
00067 AVFilterContext *ctx = inlink->dst;
00068 int i;
00069
00070 for (i = 0; i < ctx->output_count; i++)
00071 avfilter_start_frame(ctx->outputs[i],
00072 avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
00073 }
00074
00075 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
00076 {
00077 AVFilterContext *ctx = inlink->dst;
00078 int i;
00079
00080 for (i = 0; i < ctx->output_count; i++)
00081 avfilter_draw_slice(ctx->outputs[i], y, h, slice_dir);
00082 }
00083
00084 static void end_frame(AVFilterLink *inlink)
00085 {
00086 AVFilterContext *ctx = inlink->dst;
00087 int i;
00088
00089 for (i = 0; i < ctx->output_count; i++)
00090 avfilter_end_frame(ctx->outputs[i]);
00091
00092 avfilter_unref_buffer(inlink->cur_buf);
00093 }
00094
00095 AVFilter avfilter_vf_split = {
00096 .name = "split",
00097 .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
00098
00099 .init = split_init,
00100 .uninit = split_uninit,
00101
00102 .inputs = (const AVFilterPad[]) {{ .name = "default",
00103 .type = AVMEDIA_TYPE_VIDEO,
00104 .get_video_buffer= ff_null_get_video_buffer,
00105 .start_frame = start_frame,
00106 .draw_slice = draw_slice,
00107 .end_frame = end_frame, },
00108 { .name = NULL}},
00109 .outputs = (AVFilterPad[]) {{ .name = NULL}},
00110 };
00111
00112 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
00113 {
00114 AVFilterContext *ctx = inlink->dst;
00115 int i;
00116
00117 for (i = 0; i < ctx->output_count; i++)
00118 ff_filter_samples(inlink->dst->outputs[i],
00119 avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
00120 }
00121
00122 AVFilter avfilter_af_asplit = {
00123 .name = "asplit",
00124 .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
00125
00126 .init = split_init,
00127 .uninit = split_uninit,
00128
00129 .inputs = (const AVFilterPad[]) {{ .name = "default",
00130 .type = AVMEDIA_TYPE_AUDIO,
00131 .get_audio_buffer = ff_null_get_audio_buffer,
00132 .filter_samples = filter_samples },
00133 { .name = NULL }},
00134 .outputs = (const AVFilterPad[]) {{ .name = NULL }},
00135 };