FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/split.c
Date: 2022-12-05 20:26:17
Exec Total Coverage
Lines: 35 45 77.8%
Functions: 2 2 100.0%
Branches: 29 38 76.3%

Line Branch Exec Source
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/avstring.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33
34 #include "avfilter.h"
35 #include "audio.h"
36 #include "filters.h"
37 #include "formats.h"
38 #include "internal.h"
39 #include "video.h"
40
41 typedef struct SplitContext {
42 const AVClass *class;
43 int nb_outputs;
44 } SplitContext;
45
46 32 static av_cold int split_init(AVFilterContext *ctx)
47 {
48 32 SplitContext *s = ctx->priv;
49 int i, ret;
50
51
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (i = 0; i < s->nb_outputs; i++) {
52 64 AVFilterPad pad = { 0 };
53
54 64 pad.type = ctx->filter->inputs[0].type;
55 64 pad.name = av_asprintf("output%d", i);
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (!pad.name)
57 return AVERROR(ENOMEM);
58
59
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
64 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
60 return ret;
61 }
62
63 32 return 0;
64 }
65
66 1294 static int activate(AVFilterContext *ctx)
67 {
68 1294 AVFilterLink *inlink = ctx->inputs[0];
69 AVFrame *in;
70 int status, ret;
71 int64_t pts;
72
73
2/2
✓ Branch 0 taken 2564 times.
✓ Branch 1 taken 1270 times.
3834 for (int i = 0; i < ctx->nb_outputs; i++) {
74
4/4
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 2540 times.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 24 times.
2588 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx);
75 }
76
77 1270 ret = ff_inlink_consume_frame(inlink, &in);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1270 times.
1270 if (ret < 0)
79 return ret;
80
2/2
✓ Branch 0 taken 526 times.
✓ Branch 1 taken 744 times.
1270 if (ret > 0) {
81
2/2
✓ Branch 0 taken 1052 times.
✓ Branch 1 taken 526 times.
1578 for (int i = 0; i < ctx->nb_outputs; i++) {
82 AVFrame *buf_out;
83
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1052 times.
1052 if (ff_outlink_get_status(ctx->outputs[i]))
85 continue;
86 1052 buf_out = av_frame_clone(in);
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1052 times.
1052 if (!buf_out) {
88 ret = AVERROR(ENOMEM);
89 break;
90 }
91
92 1052 ret = ff_filter_frame(ctx->outputs[i], buf_out);
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1052 times.
1052 if (ret < 0)
94 break;
95 }
96
97 526 av_frame_free(&in);
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 526 times.
526 if (ret < 0)
99 return ret;
100 }
101
102
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1254 times.
1270 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
103
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
48 for (int i = 0; i < ctx->nb_outputs; i++) {
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
32 if (ff_outlink_get_status(ctx->outputs[i]))
105 continue;
106 32 ff_outlink_set_status(ctx->outputs[i], status, pts);
107 }
108 16 return 0;
109 }
110
111
2/2
✓ Branch 0 taken 2042 times.
✓ Branch 1 taken 526 times.
2568 for (int i = 0; i < ctx->nb_outputs; i++) {
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2042 times.
2042 if (ff_outlink_get_status(ctx->outputs[i]))
113 continue;
114
115
2/2
✓ Branch 1 taken 728 times.
✓ Branch 2 taken 1314 times.
2042 if (ff_outlink_frame_wanted(ctx->outputs[i])) {
116 728 ff_inlink_request_frame(inlink);
117 728 return 0;
118 }
119 }
120
121 526 return FFERROR_NOT_READY;
122 }
123
124 #define OFFSET(x) offsetof(SplitContext, x)
125 #define FLAGS (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
126 static const AVOption options[] = {
127 { "outputs", "set number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, FLAGS },
128 { NULL }
129 };
130
131 AVFILTER_DEFINE_CLASS_EXT(split, "(a)split", options);
132
133 static const AVFilterPad avfilter_vf_split_inputs[] = {
134 {
135 .name = "default",
136 .type = AVMEDIA_TYPE_VIDEO,
137 },
138 };
139
140 const AVFilter ff_vf_split = {
141 .name = "split",
142 .description = NULL_IF_CONFIG_SMALL("Pass on the input to N video outputs."),
143 .priv_size = sizeof(SplitContext),
144 .priv_class = &split_class,
145 .init = split_init,
146 .activate = activate,
147 FILTER_INPUTS(avfilter_vf_split_inputs),
148 .outputs = NULL,
149 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY,
150 };
151
152 static const AVFilterPad avfilter_af_asplit_inputs[] = {
153 {
154 .name = "default",
155 .type = AVMEDIA_TYPE_AUDIO,
156 },
157 };
158
159 const AVFilter ff_af_asplit = {
160 .name = "asplit",
161 .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
162 .priv_class = &split_class,
163 .priv_size = sizeof(SplitContext),
164 .init = split_init,
165 .activate = activate,
166 FILTER_INPUTS(avfilter_af_asplit_inputs),
167 .outputs = NULL,
168 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | AVFILTER_FLAG_METADATA_ONLY,
169 };
170