Signed-off-by: Paul B Mahol <onemda@gmail.com>
Paul B Mahol authored on 2017/08/25 16:07:28... | ... |
@@ -29,6 +29,7 @@ |
29 | 29 |
#include "libavutil/opt.h" |
30 | 30 |
#include "avfilter.h" |
31 | 31 |
#include "audio.h" |
32 |
+#include "filters.h" |
|
32 | 33 |
#include "formats.h" |
33 | 34 |
#include "hermite.h" |
34 | 35 |
|
... | ... |
@@ -265,71 +266,76 @@ AVFilter ff_af_agate = { |
265 | 265 |
#define sidechaingate_options options |
266 | 266 |
AVFILTER_DEFINE_CLASS(sidechaingate); |
267 | 267 |
|
268 |
-static int scfilter_frame(AVFilterLink *link, AVFrame *frame) |
|
268 |
+static int activate(AVFilterContext *ctx) |
|
269 | 269 |
{ |
270 |
- AVFilterContext *ctx = link->dst; |
|
271 | 270 |
AudioGateContext *s = ctx->priv; |
272 |
- AVFilterLink *outlink = ctx->outputs[0]; |
|
273 |
- AVFrame *out, *in[2] = { NULL }; |
|
271 |
+ AVFrame *out = NULL, *in[2] = { NULL }; |
|
272 |
+ int ret, i, status, nb_samples; |
|
274 | 273 |
double *dst; |
275 |
- int nb_samples; |
|
276 |
- int i; |
|
274 |
+ int64_t pts; |
|
277 | 275 |
|
278 |
- for (i = 0; i < 2; i++) |
|
279 |
- if (link == ctx->inputs[i]) |
|
280 |
- break; |
|
281 |
- av_assert0(i < 2); |
|
282 |
- av_audio_fifo_write(s->fifo[i], (void **)frame->extended_data, |
|
283 |
- frame->nb_samples); |
|
284 |
- av_frame_free(&frame); |
|
276 |
+ if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) { |
|
277 |
+ av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data, |
|
278 |
+ in[0]->nb_samples); |
|
279 |
+ av_frame_free(&in[0]); |
|
280 |
+ } |
|
281 |
+ if (ret < 0) |
|
282 |
+ return ret; |
|
283 |
+ if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) { |
|
284 |
+ av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data, |
|
285 |
+ in[1]->nb_samples); |
|
286 |
+ av_frame_free(&in[1]); |
|
287 |
+ } |
|
288 |
+ if (ret < 0) |
|
289 |
+ return ret; |
|
285 | 290 |
|
286 | 291 |
nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1])); |
287 |
- if (!nb_samples) |
|
288 |
- return 0; |
|
289 |
- |
|
290 |
- out = ff_get_audio_buffer(outlink, nb_samples); |
|
291 |
- if (!out) |
|
292 |
- return AVERROR(ENOMEM); |
|
293 |
- for (i = 0; i < 2; i++) { |
|
294 |
- in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples); |
|
295 |
- if (!in[i]) { |
|
296 |
- av_frame_free(&in[0]); |
|
297 |
- av_frame_free(&in[1]); |
|
298 |
- av_frame_free(&out); |
|
292 |
+ if (nb_samples) { |
|
293 |
+ out = ff_get_audio_buffer(ctx->outputs[0], nb_samples); |
|
294 |
+ if (!out) |
|
299 | 295 |
return AVERROR(ENOMEM); |
296 |
+ for (i = 0; i < 2; i++) { |
|
297 |
+ in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples); |
|
298 |
+ if (!in[i]) { |
|
299 |
+ av_frame_free(&in[0]); |
|
300 |
+ av_frame_free(&in[1]); |
|
301 |
+ av_frame_free(&out); |
|
302 |
+ return AVERROR(ENOMEM); |
|
303 |
+ } |
|
304 |
+ av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples); |
|
300 | 305 |
} |
301 |
- av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples); |
|
302 |
- } |
|
303 | 306 |
|
304 |
- dst = (double *)out->data[0]; |
|
305 |
- out->pts = s->pts; |
|
306 |
- s->pts += nb_samples; |
|
307 |
+ dst = (double *)out->data[0]; |
|
308 |
+ out->pts = s->pts; |
|
309 |
+ s->pts += nb_samples; |
|
307 | 310 |
|
308 |
- gate(s, (double *)in[0]->data[0], dst, |
|
309 |
- (double *)in[1]->data[0], nb_samples, |
|
310 |
- s->level_in, s->level_sc, |
|
311 |
- ctx->inputs[0], ctx->inputs[1]); |
|
311 |
+ gate(s, (double *)in[0]->data[0], dst, |
|
312 |
+ (double *)in[1]->data[0], nb_samples, |
|
313 |
+ s->level_in, s->level_sc, |
|
314 |
+ ctx->inputs[0], ctx->inputs[1]); |
|
312 | 315 |
|
313 |
- av_frame_free(&in[0]); |
|
314 |
- av_frame_free(&in[1]); |
|
316 |
+ av_frame_free(&in[0]); |
|
317 |
+ av_frame_free(&in[1]); |
|
315 | 318 |
|
316 |
- return ff_filter_frame(outlink, out); |
|
317 |
-} |
|
318 |
- |
|
319 |
-static int screquest_frame(AVFilterLink *outlink) |
|
320 |
-{ |
|
321 |
- AVFilterContext *ctx = outlink->src; |
|
322 |
- AudioGateContext *s = ctx->priv; |
|
323 |
- int i; |
|
324 |
- |
|
325 |
- /* get a frame on each input */ |
|
326 |
- for (i = 0; i < 2; i++) { |
|
327 |
- AVFilterLink *inlink = ctx->inputs[i]; |
|
328 |
- if (!av_audio_fifo_size(s->fifo[i])) |
|
329 |
- return ff_request_frame(inlink); |
|
319 |
+ ret = ff_filter_frame(ctx->outputs[0], out); |
|
320 |
+ if (ret < 0) |
|
321 |
+ return ret; |
|
322 |
+ } |
|
323 |
+ if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) { |
|
324 |
+ ff_outlink_set_status(ctx->outputs[0], status, pts); |
|
325 |
+ return 0; |
|
326 |
+ } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) { |
|
327 |
+ ff_outlink_set_status(ctx->outputs[0], status, pts); |
|
328 |
+ return 0; |
|
329 |
+ } else { |
|
330 |
+ if (ff_outlink_frame_wanted(ctx->outputs[0])) { |
|
331 |
+ if (!av_audio_fifo_size(s->fifo[0])) |
|
332 |
+ ff_inlink_request_frame(ctx->inputs[0]); |
|
333 |
+ if (!av_audio_fifo_size(s->fifo[1])) |
|
334 |
+ ff_inlink_request_frame(ctx->inputs[1]); |
|
335 |
+ } |
|
336 |
+ return 0; |
|
330 | 337 |
} |
331 |
- |
|
332 |
- return 0; |
|
333 | 338 |
} |
334 | 339 |
|
335 | 340 |
static int scquery_formats(AVFilterContext *ctx) |
... | ... |
@@ -408,11 +414,9 @@ static const AVFilterPad sidechaingate_inputs[] = { |
408 | 408 |
{ |
409 | 409 |
.name = "main", |
410 | 410 |
.type = AVMEDIA_TYPE_AUDIO, |
411 |
- .filter_frame = scfilter_frame, |
|
412 | 411 |
},{ |
413 | 412 |
.name = "sidechain", |
414 | 413 |
.type = AVMEDIA_TYPE_AUDIO, |
415 |
- .filter_frame = scfilter_frame, |
|
416 | 414 |
}, |
417 | 415 |
{ NULL } |
418 | 416 |
}; |
... | ... |
@@ -422,7 +426,6 @@ static const AVFilterPad sidechaingate_outputs[] = { |
422 | 422 |
.name = "default", |
423 | 423 |
.type = AVMEDIA_TYPE_AUDIO, |
424 | 424 |
.config_props = scconfig_output, |
425 |
- .request_frame = screquest_frame, |
|
426 | 425 |
}, |
427 | 426 |
{ NULL } |
428 | 427 |
}; |
... | ... |
@@ -433,6 +436,7 @@ AVFilter ff_af_sidechaingate = { |
433 | 433 |
.priv_size = sizeof(AudioGateContext), |
434 | 434 |
.priv_class = &sidechaingate_class, |
435 | 435 |
.query_formats = scquery_formats, |
436 |
+ .activate = activate, |
|
436 | 437 |
.uninit = uninit, |
437 | 438 |
.inputs = sidechaingate_inputs, |
438 | 439 |
.outputs = sidechaingate_outputs, |