Unified · Split
| @@ -29,6 +29,7 @@ · 28 unmodified lines | ||
| 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 = { · 230 unmodified lines | ||
| 265 | 266 | #define sidechaingate_options options |
| 266 | 267 | AVFILTER_DEFINE_CLASS(sidechaingate); |
| 267 | 268 | |
| 268 | −static int scfilter_frame(AVFilterLink *link, AVFrame *frame) | |
| 269 | +static int activate(AVFilterContext *ctx) | |
| 269 | 270 | { |
| 270 | − AVFilterContext *ctx = link->dst; | |
| 271 | 271 | AudioGateContext *s = ctx->priv; |
| 272 | − AVFilterLink *outlink = ctx->outputs[0]; | |
| 273 | − AVFrame *out, *in[2] = { NULL }; | |
| 272 | + AVFrame *out = NULL, *in[2] = { NULL }; | |
| 273 | + int ret, i, status, nb_samples; | |
| 274 | 274 | double *dst; |
| 275 | − int nb_samples; | |
| 276 | − int i; | |
| 275 | + int64_t pts; | |
| 277 | 276 | |
| 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); | |
| 277 | + if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) { | |
| 278 | + av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data, | |
| 279 | + in[0]->nb_samples); | |
| 280 | + av_frame_free(&in[0]); | |
| 281 | + } | |
| 282 | + if (ret < 0) | |
| 283 | + return ret; | |
| 284 | + if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) { | |
| 285 | + av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data, | |
| 286 | + in[1]->nb_samples); | |
| 287 | + av_frame_free(&in[1]); | |
| 288 | + } | |
| 289 | + if (ret < 0) | |
| 290 | + return ret; | |
| 285 | 291 | |
| 286 | 292 | 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); | |
| 293 | + if (nb_samples) { | |
| 294 | + out = ff_get_audio_buffer(ctx->outputs[0], nb_samples); | |
| 295 | + if (!out) | |
| 299 | 296 | return AVERROR(ENOMEM); |
| 297 | + for (i = 0; i < 2; i++) { | |
| 298 | + in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples); | |
| 299 | + if (!in[i]) { | |
| 300 | + av_frame_free(&in[0]); | |
| 301 | + av_frame_free(&in[1]); | |
| 302 | + av_frame_free(&out); | |
| 303 | + return AVERROR(ENOMEM); | |
| 304 | + } | |
| 305 | + av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples); | |
| 300 | 306 | } |
| 301 | − av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples); | |
| 302 | − } | |
| 303 | 307 | |
| 304 | − dst = (double *)out->data[0]; | |
| 305 | − out->pts = s->pts; | |
| 306 | − s->pts += nb_samples; | |
| 308 | + dst = (double *)out->data[0]; | |
| 309 | + out->pts = s->pts; | |
| 310 | + s->pts += nb_samples; | |
| 307 | 311 | |
| 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]); | |
| 312 | + gate(s, (double *)in[0]->data[0], dst, | |
| 313 | + (double *)in[1]->data[0], nb_samples, | |
| 314 | + s->level_in, s->level_sc, | |
| 315 | + ctx->inputs[0], ctx->inputs[1]); | |
| 312 | 316 | |
| 313 | − av_frame_free(&in[0]); | |
| 314 | − av_frame_free(&in[1]); | |
| 317 | + av_frame_free(&in[0]); | |
| 318 | + av_frame_free(&in[1]); | |
| 315 | 319 | |
| 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); | |
| 320 | + ret = ff_filter_frame(ctx->outputs[0], out); | |
| 321 | + if (ret < 0) | |
| 322 | + return ret; | |
| 323 | + } | |
| 324 | + if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) { | |
| 325 | + ff_outlink_set_status(ctx->outputs[0], status, pts); | |
| 326 | + return 0; | |
| 327 | + } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) { | |
| 328 | + ff_outlink_set_status(ctx->outputs[0], status, pts); | |
| 329 | + return 0; | |
| 330 | + } else { | |
| 331 | + if (ff_outlink_frame_wanted(ctx->outputs[0])) { | |
| 332 | + if (!av_audio_fifo_size(s->fifo[0])) | |
| 333 | + ff_inlink_request_frame(ctx->inputs[0]); | |
| 334 | + if (!av_audio_fifo_size(s->fifo[1])) | |
| 335 | + ff_inlink_request_frame(ctx->inputs[1]); | |
| 336 | + } | |
| 337 | + return 0; | |
| 330 | 338 | } |
| 331 | − | |
| 332 | − return 0; | |
| 333 | 339 | } |
| 334 | 340 | |
| 335 | 341 | static int scquery_formats(AVFilterContext *ctx) |
| @@ -408,11 +414,9 @@ static const AVFilterPad sidechaingate_inputs[] = { · 72 unmodified lines | ||
| 408 | 414 | { |
| 409 | 415 | .name = "main", |
| 410 | 416 | .type = AVMEDIA_TYPE_AUDIO, |
| 411 | − .filter_frame = scfilter_frame, | |
| 412 | 417 | },{ |
| 413 | 418 | .name = "sidechain", |
| 414 | 419 | .type = AVMEDIA_TYPE_AUDIO, |
| 415 | − .filter_frame = scfilter_frame, | |
| 416 | 420 | }, |
| 417 | 421 | { NULL } |
| 418 | 422 | }; |
| @@ -422,7 +426,6 @@ static const AVFilterPad sidechaingate_outputs[] = { · 3 unmodified lines | ||
| 422 | 426 | .name = "default", |
| 423 | 427 | .type = AVMEDIA_TYPE_AUDIO, |
| 424 | 428 | .config_props = scconfig_output, |
| 425 | − .request_frame = screquest_frame, | |
| 426 | 429 | }, |
| 427 | 430 | { NULL } |
| 428 | 431 | }; |
| @@ -433,6 +436,7 @@ AVFilter ff_af_sidechaingate = { · 4 unmodified lines | ||
| 433 | 436 | .priv_size = sizeof(AudioGateContext), |
| 434 | 437 | .priv_class = &sidechaingate_class, |
| 435 | 438 | .query_formats = scquery_formats, |
| 439 | + .activate = activate, | |
| 436 | 440 | .uninit = uninit, |
| 437 | 441 | .inputs = sidechaingate_inputs, |
| 438 | 442 | .outputs = sidechaingate_outputs, |