Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -29,6 +29,7 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/opt.h" | 29 | #include "libavutil/opt.h" |
| 30 | #include "avfilter.h" | 30 | #include "avfilter.h" |
| 31 | #include "audio.h" | 31 | #include "audio.h" |
| 32 | #include "filters.h" | ||
| 32 | #include "formats.h" | 33 | #include "formats.h" |
| 33 | #include "hermite.h" | 34 | #include "hermite.h" |
| 34 | 35 | ||
| @@ -265,71 +266,76 @@ AVFilter ff_af_agate = { · 230 unmodified lines | |||
| 265 | #define sidechaingate_options options | 266 | #define sidechaingate_options options |
| 266 | AVFILTER_DEFINE_CLASS(sidechaingate); | 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 | AudioGateContext *s = ctx->priv; | 271 | AudioGateContext *s = ctx->priv; |
| 272 | AVFilterLink *outlink = ctx->outputs[0]; | 272 | AVFrame *out = NULL, *in[2] = { NULL }; |
| 273 | AVFrame *out, *in[2] = { NULL }; | 273 | int ret, i, status, nb_samples; |
| 274 | double *dst; | 274 | double *dst; |
| 275 | int nb_samples; | 275 | int64_t pts; |
| 276 | int i; | ||
| 277 | 276 | ||
| 278 | for (i = 0; i < 2; i++) | 277 | if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) { |
| 279 | if (link == ctx->inputs[i]) | 278 | av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data, |
| 280 | break; | 279 | in[0]->nb_samples); |
| 281 | av_assert0(i < 2); | 280 | av_frame_free(&in[0]); |
| 282 | av_audio_fifo_write(s->fifo[i], (void **)frame->extended_data, | 281 | } |
| 283 | frame->nb_samples); | 282 | if (ret < 0) |
| 284 | av_frame_free(&frame); | 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 | nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1])); | 292 | nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1])); |
| 287 | if (!nb_samples) | 293 | if (nb_samples) { |
| 288 | return 0; | 294 | out = ff_get_audio_buffer(ctx->outputs[0], nb_samples); |
| 289 | 295 | if (!out) | |
| 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); | ||
| 299 | return AVERROR(ENOMEM); | 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]; | 308 | dst = (double *)out->data[0]; |
| 305 | out->pts = s->pts; | 309 | out->pts = s->pts; |
| 306 | s->pts += nb_samples; | 310 | s->pts += nb_samples; |
| 307 | 311 | ||
| 308 | gate(s, (double *)in[0]->data[0], dst, | 312 | gate(s, (double *)in[0]->data[0], dst, |
| 309 | (double *)in[1]->data[0], nb_samples, | 313 | (double *)in[1]->data[0], nb_samples, |
| 310 | s->level_in, s->level_sc, | 314 | s->level_in, s->level_sc, |
| 311 | ctx->inputs[0], ctx->inputs[1]); | 315 | ctx->inputs[0], ctx->inputs[1]); |
| 312 | 316 | ||
| 313 | av_frame_free(&in[0]); | 317 | av_frame_free(&in[0]); |
| 314 | av_frame_free(&in[1]); | 318 | av_frame_free(&in[1]); |
| 315 | 319 | ||
| 316 | return ff_filter_frame(outlink, out); | 320 | ret = ff_filter_frame(ctx->outputs[0], out); |
| 317 | } | 321 | if (ret < 0) |
| 318 | 322 | return ret; | |
| 319 | static int screquest_frame(AVFilterLink *outlink) | 323 | } |
| 320 | { | 324 | if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) { |
| 321 | AVFilterContext *ctx = outlink->src; | 325 | ff_outlink_set_status(ctx->outputs[0], status, pts); |
| 322 | AudioGateContext *s = ctx->priv; | 326 | return 0; |
| 323 | int i; | 327 | } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) { |
| 324 | 328 | ff_outlink_set_status(ctx->outputs[0], status, pts); | |
| 325 | /* get a frame on each input */ | 329 | return 0; |
| 326 | for (i = 0; i < 2; i++) { | 330 | } else { |
| 327 | AVFilterLink *inlink = ctx->inputs[i]; | 331 | if (ff_outlink_frame_wanted(ctx->outputs[0])) { |
| 328 | if (!av_audio_fifo_size(s->fifo[i])) | 332 | if (!av_audio_fifo_size(s->fifo[0])) |
| 329 | return ff_request_frame(inlink); | 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 | static int scquery_formats(AVFilterContext *ctx) | 341 | static int scquery_formats(AVFilterContext *ctx) |
| @@ -408,11 +414,9 @@ static const AVFilterPad sidechaingate_inputs[] = { · 72 unmodified lines | |||
| 408 | { | 414 | { |
| 409 | .name = "main", | 415 | .name = "main", |
| 410 | .type = AVMEDIA_TYPE_AUDIO, | 416 | .type = AVMEDIA_TYPE_AUDIO, |
| 411 | .filter_frame = scfilter_frame, | ||
| 412 | },{ | 417 | },{ |
| 413 | .name = "sidechain", | 418 | .name = "sidechain", |
| 414 | .type = AVMEDIA_TYPE_AUDIO, | 419 | .type = AVMEDIA_TYPE_AUDIO, |
| 415 | .filter_frame = scfilter_frame, | ||
| 416 | }, | 420 | }, |
| 417 | { NULL } | 421 | { NULL } |
| 418 | }; | 422 | }; |
| @@ -422,7 +426,6 @@ static const AVFilterPad sidechaingate_outputs[] = { · 3 unmodified lines | |||
| 422 | .name = "default", | 426 | .name = "default", |
| 423 | .type = AVMEDIA_TYPE_AUDIO, | 427 | .type = AVMEDIA_TYPE_AUDIO, |
| 424 | .config_props = scconfig_output, | 428 | .config_props = scconfig_output, |
| 425 | .request_frame = screquest_frame, | ||
| 426 | }, | 429 | }, |
| 427 | { NULL } | 430 | { NULL } |
| 428 | }; | 431 | }; |
| @@ -433,6 +436,7 @@ AVFilter ff_af_sidechaingate = { · 4 unmodified lines | |||
| 433 | .priv_size = sizeof(AudioGateContext), | 436 | .priv_size = sizeof(AudioGateContext), |
| 434 | .priv_class = &sidechaingate_class, | 437 | .priv_class = &sidechaingate_class, |
| 435 | .query_formats = scquery_formats, | 438 | .query_formats = scquery_formats, |
| 439 | .activate = activate, | ||
| 436 | .uninit = uninit, | 440 | .uninit = uninit, |
| 437 | .inputs = sidechaingate_inputs, | 441 | .inputs = sidechaingate_inputs, |
| 438 | .outputs = sidechaingate_outputs, | 442 | .outputs = sidechaingate_outputs, |