...
|
...
|
@@ -156,8 +156,7 @@ static int config_output(AVFilterLink *outlink)
|
156
|
156
|
return 0;
|
157
|
157
|
}
|
158
|
158
|
|
159
|
|
-static void push_frame(AVFilterContext *ctx, unsigned in_no,
|
160
|
|
- AVFrame *buf)
|
|
159
|
+static int push_frame(AVFilterContext *ctx, unsigned in_no, AVFrame *buf)
|
161
|
160
|
{
|
162
|
161
|
ConcatContext *cat = ctx->priv;
|
163
|
162
|
unsigned out_no = in_no % ctx->nb_outputs;
|
...
|
...
|
@@ -179,10 +178,10 @@ static void push_frame(AVFilterContext *ctx, unsigned in_no,
|
179
|
179
|
in->pts = av_rescale(in->pts, in->nb_frames, in->nb_frames - 1);
|
180
|
180
|
|
181
|
181
|
buf->pts += cat->delta_ts;
|
182
|
|
- ff_filter_frame(outlink, buf);
|
|
182
|
+ return ff_filter_frame(outlink, buf);
|
183
|
183
|
}
|
184
|
184
|
|
185
|
|
-static void process_frame(AVFilterLink *inlink, AVFrame *buf)
|
|
185
|
+static int process_frame(AVFilterLink *inlink, AVFrame *buf)
|
186
|
186
|
{
|
187
|
187
|
AVFilterContext *ctx = inlink->dst;
|
188
|
188
|
ConcatContext *cat = ctx->priv;
|
...
|
...
|
@@ -195,8 +194,9 @@ static void process_frame(AVFilterLink *inlink, AVFrame *buf)
|
195
|
195
|
} else if (in_no >= cat->cur_idx + ctx->nb_outputs) {
|
196
|
196
|
ff_bufqueue_add(ctx, &cat->in[in_no].queue, buf);
|
197
|
197
|
} else {
|
198
|
|
- push_frame(ctx, in_no, buf);
|
|
198
|
+ return push_frame(ctx, in_no, buf);
|
199
|
199
|
}
|
|
200
|
+ return 0;
|
200
|
201
|
}
|
201
|
202
|
|
202
|
203
|
static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
|
...
|
...
|
@@ -219,8 +219,7 @@ static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
|
219
|
219
|
|
220
|
220
|
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
|
221
|
221
|
{
|
222
|
|
- process_frame(inlink, buf);
|
223
|
|
- return 0; /* enhancement: handle error return */
|
|
222
|
+ return process_frame(inlink, buf);
|
224
|
223
|
}
|
225
|
224
|
|
226
|
225
|
static void close_input(AVFilterContext *ctx, unsigned in_no)
|
...
|
...
|
@@ -246,19 +245,19 @@ static void find_next_delta_ts(AVFilterContext *ctx)
|
246
|
246
|
cat->delta_ts += pts;
|
247
|
247
|
}
|
248
|
248
|
|
249
|
|
-static void send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no)
|
|
249
|
+static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no)
|
250
|
250
|
{
|
251
|
251
|
ConcatContext *cat = ctx->priv;
|
252
|
252
|
AVFilterLink *outlink = ctx->outputs[out_no];
|
253
|
253
|
int64_t base_pts = cat->in[in_no].pts + cat->delta_ts;
|
254
|
254
|
int64_t nb_samples, sent = 0;
|
255
|
|
- int frame_nb_samples;
|
|
255
|
+ int frame_nb_samples, ret;
|
256
|
256
|
AVRational rate_tb = { 1, ctx->inputs[in_no]->sample_rate };
|
257
|
257
|
AVFrame *buf;
|
258
|
258
|
int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
|
259
|
259
|
|
260
|
260
|
if (!rate_tb.den)
|
261
|
|
- return;
|
|
261
|
+ return AVERROR_BUG;
|
262
|
262
|
nb_samples = av_rescale_q(cat->delta_ts - base_pts,
|
263
|
263
|
outlink->time_base, rate_tb);
|
264
|
264
|
frame_nb_samples = FFMAX(9600, rate_tb.den / 5); /* arbitrary */
|
...
|
...
|
@@ -266,18 +265,22 @@ static void send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no)
|
266
|
266
|
frame_nb_samples = FFMIN(frame_nb_samples, nb_samples);
|
267
|
267
|
buf = ff_get_audio_buffer(outlink, frame_nb_samples);
|
268
|
268
|
if (!buf)
|
269
|
|
- return;
|
|
269
|
+ return AVERROR(ENOMEM);
|
270
|
270
|
av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
|
271
|
271
|
nb_channels, outlink->format);
|
272
|
272
|
buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
|
273
|
|
- ff_filter_frame(outlink, buf);
|
|
273
|
+ ret = ff_filter_frame(outlink, buf);
|
|
274
|
+ if (ret < 0)
|
|
275
|
+ return ret;
|
274
|
276
|
sent += frame_nb_samples;
|
275
|
277
|
nb_samples -= frame_nb_samples;
|
276
|
278
|
}
|
|
279
|
+ return 0;
|
277
|
280
|
}
|
278
|
281
|
|
279
|
|
-static void flush_segment(AVFilterContext *ctx)
|
|
282
|
+static int flush_segment(AVFilterContext *ctx)
|
280
|
283
|
{
|
|
284
|
+ int ret;
|
281
|
285
|
ConcatContext *cat = ctx->priv;
|
282
|
286
|
unsigned str, str_max;
|
283
|
287
|
|
...
|
...
|
@@ -291,15 +294,23 @@ static void flush_segment(AVFilterContext *ctx)
|
291
|
291
|
/* pad audio streams with silence */
|
292
|
292
|
str = cat->nb_streams[AVMEDIA_TYPE_VIDEO];
|
293
|
293
|
str_max = str + cat->nb_streams[AVMEDIA_TYPE_AUDIO];
|
294
|
|
- for (; str < str_max; str++)
|
295
|
|
- send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str);
|
|
294
|
+ for (; str < str_max; str++) {
|
|
295
|
+ ret = send_silence(ctx, cat->cur_idx - ctx->nb_outputs + str, str);
|
|
296
|
+ if (ret < 0)
|
|
297
|
+ return ret;
|
|
298
|
+ }
|
296
|
299
|
/* flush queued buffers */
|
297
|
300
|
/* possible enhancement: flush in PTS order */
|
298
|
301
|
str_max = cat->cur_idx + ctx->nb_outputs;
|
299
|
|
- for (str = cat->cur_idx; str < str_max; str++)
|
300
|
|
- while (cat->in[str].queue.available)
|
301
|
|
- push_frame(ctx, str, ff_bufqueue_get(&cat->in[str].queue));
|
|
302
|
+ for (str = cat->cur_idx; str < str_max; str++) {
|
|
303
|
+ while (cat->in[str].queue.available) {
|
|
304
|
+ ret = push_frame(ctx, str, ff_bufqueue_get(&cat->in[str].queue));
|
|
305
|
+ if (ret < 0)
|
|
306
|
+ return ret;
|
|
307
|
+ }
|
|
308
|
+ }
|
302
|
309
|
}
|
|
310
|
+ return 0;
|
303
|
311
|
}
|
304
|
312
|
|
305
|
313
|
static int request_frame(AVFilterLink *outlink)
|
...
|
...
|
@@ -333,7 +344,9 @@ static int request_frame(AVFilterLink *outlink)
|
333
|
333
|
else if (ret < 0)
|
334
|
334
|
return ret;
|
335
|
335
|
}
|
336
|
|
- flush_segment(ctx);
|
|
336
|
+ ret = flush_segment(ctx);
|
|
337
|
+ if (ret < 0)
|
|
338
|
+ return ret;
|
337
|
339
|
in_no += ctx->nb_outputs;
|
338
|
340
|
}
|
339
|
341
|
}
|