Unified · Split
| @@ -44,9 +44,12 @@ typedef struct AudioDelayContext { · 43 unmodified lines | |||
| 44 | int block_align; | 44 | int block_align; |
| 45 | int64_t padding; | 45 | int64_t padding; |
| 46 | int64_t max_delay; | 46 | int64_t max_delay; |
| 47 | int64_t offset; | ||
| 47 | int64_t next_pts; | 48 | int64_t next_pts; |
| 48 | int eof; | 49 | int eof; |
| 49 | 50 | ||
| 51 | AVFrame *input; | ||
| 52 | |||
| 50 | void (*delay_channel)(ChanDelay *d, int nb_samples, | 53 | void (*delay_channel)(ChanDelay *d, int nb_samples, |
| 51 | const uint8_t *src, uint8_t *dst); | 54 | const uint8_t *src, uint8_t *dst); |
| 52 | int (*resize_channel_samples)(ChanDelay *d, int64_t new_delay); | 55 | int (*resize_channel_samples)(ChanDelay *d, int64_t new_delay); |
| @@ -187,6 +190,7 @@ static int config_input(AVFilterLink *inlink) · 134 unmodified lines | |||
| 187 | char *p, *saveptr = NULL; | 190 | char *p, *saveptr = NULL; |
| 188 | int i; | 191 | int i; |
| 189 | 192 | ||
| 193 | s->next_pts = AV_NOPTS_VALUE; | ||
| 190 | s->chandelay = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chandelay)); | 194 | s->chandelay = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chandelay)); |
| 191 | if (!s->chandelay) | 195 | if (!s->chandelay) |
| 192 | return AVERROR(ENOMEM); | 196 | return AVERROR(ENOMEM); |
| @@ -224,6 +228,10 @@ static int config_input(AVFilterLink *inlink) · 31 unmodified lines | |||
| 224 | 228 | ||
| 225 | d->delay -= s->padding; | 229 | d->delay -= s->padding; |
| 226 | } | 230 | } |
| 231 | |||
| 232 | s->offset = av_rescale_q(s->padding, | ||
| 233 | av_make_q(1, inlink->sample_rate), | ||
| 234 | inlink->time_base); | ||
| 227 | } | 235 | } |
| 228 | 236 | ||
| 229 | for (i = 0; i < s->nb_delays; i++) { | 237 | for (i = 0; i < s->nb_delays; i++) { |
| @@ -323,11 +331,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 93 unmodified lines | |||
| 323 | AVFrame *out_frame; | 331 | AVFrame *out_frame; |
| 324 | int i; | 332 | int i; |
| 325 | 333 | ||
| 326 | if (ctx->is_disabled || !s->delays) | 334 | if (ctx->is_disabled || !s->delays) { |
| 335 | s->input = NULL; | ||
| 327 | return ff_filter_frame(outlink, frame); | 336 | return ff_filter_frame(outlink, frame); |
| 337 | } | ||
| 338 | |||
| 339 | s->next_pts = av_rescale_q(frame->pts, inlink->time_base, outlink->time_base); | ||
| 328 | 340 | ||
| 329 | out_frame = ff_get_audio_buffer(outlink, frame->nb_samples); | 341 | out_frame = ff_get_audio_buffer(outlink, frame->nb_samples); |
| 330 | if (!out_frame) { | 342 | if (!out_frame) { |
| 343 | s->input = NULL; | ||
| 331 | av_frame_free(&frame); | 344 | av_frame_free(&frame); |
| 332 | return AVERROR(ENOMEM); | 345 | return AVERROR(ENOMEM); |
| 333 | } | 346 | } |
| @@ -344,9 +357,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 10 unmodified lines | |||
| 344 | s->delay_channel(d, frame->nb_samples, src, dst); | 357 | s->delay_channel(d, frame->nb_samples, src, dst); |
| 345 | } | 358 | } |
| 346 | 359 | ||
| 347 | out_frame->pts = s->next_pts; | 360 | out_frame->pts = s->next_pts + s->offset; |
| 348 | s->next_pts += av_rescale_q(frame->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | 361 | out_frame->duration = av_rescale_q(out_frame->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); |
| 362 | s->next_pts += out_frame->duration; | ||
| 349 | av_frame_free(&frame); | 363 | av_frame_free(&frame); |
| 364 | s->input = NULL; | ||
| 350 | return ff_filter_frame(outlink, out_frame); | 365 | return ff_filter_frame(outlink, out_frame); |
| 351 | } | 366 | } |
| 352 | 367 | ||
| @@ -361,6 +376,20 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines | |||
| 361 | 376 | ||
| 362 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); | 377 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); |
| 363 | 378 | ||
| 379 | if (!s->input) { | ||
| 380 | ret = ff_inlink_consume_frame(inlink, &s->input); | ||
| 381 | if (ret < 0) | ||
| 382 | return ret; | ||
| 383 | } | ||
| 384 | |||
| 385 | if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { | ||
| 386 | if (status == AVERROR_EOF) | ||
| 387 | s->eof = 1; | ||
| 388 | } | ||
| 389 | |||
| 390 | if (s->next_pts == AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE) | ||
| 391 | s->next_pts = av_rescale_q(pts, inlink->time_base, outlink->time_base); | ||
| 392 | |||
| 364 | if (s->padding) { | 393 | if (s->padding) { |
| 365 | int nb_samples = FFMIN(s->padding, 2048); | 394 | int nb_samples = FFMIN(s->padding, 2048); |
| 366 | 395 | ||
| @@ -374,24 +403,17 @@ static int activate(AVFilterContext *ctx) · 7 unmodified lines | |||
| 374 | outlink->ch_layout.nb_channels, | 403 | outlink->ch_layout.nb_channels, |
| 375 | frame->format); | 404 | frame->format); |
| 376 | 405 | ||
| 406 | frame->duration = av_rescale_q(frame->nb_samples, | ||
| 407 | (AVRational){1, outlink->sample_rate}, | ||
| 408 | outlink->time_base); | ||
| 377 | frame->pts = s->next_pts; | 409 | frame->pts = s->next_pts; |
| 378 | if (s->next_pts != AV_NOPTS_VALUE) | 410 | s->next_pts += frame->duration; |
| 379 | s->next_pts += av_rescale_q(nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | ||
| 380 | 411 | ||
| 381 | return ff_filter_frame(outlink, frame); | 412 | return ff_filter_frame(outlink, frame); |
| 382 | } | 413 | } |
| 383 | 414 | ||
| 384 | ret = ff_inlink_consume_frame(inlink, &frame); | 415 | if (s->input) |
| 385 | if (ret < 0) | 416 | return filter_frame(inlink, s->input); |
| 386 | return ret; | ||
| 387 | |||
| 388 | if (ret > 0) | ||
| 389 | return filter_frame(inlink, frame); | ||
| 390 | |||
| 391 | if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { | ||
| 392 | if (status == AVERROR_EOF) | ||
| 393 | s->eof = 1; | ||
| 394 | } | ||
| 395 | 417 | ||
| 396 | if (s->eof && s->max_delay) { | 418 | if (s->eof && s->max_delay) { |
| 397 | int nb_samples = FFMIN(s->max_delay, 2048); | 419 | int nb_samples = FFMIN(s->max_delay, 2048); |
| @@ -406,7 +428,11 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines | |||
| 406 | outlink->ch_layout.nb_channels, | 428 | outlink->ch_layout.nb_channels, |
| 407 | frame->format); | 429 | frame->format); |
| 408 | 430 | ||
| 431 | frame->duration = av_rescale_q(frame->nb_samples, | ||
| 432 | (AVRational){1, outlink->sample_rate}, | ||
| 433 | outlink->time_base); | ||
| 409 | frame->pts = s->next_pts; | 434 | frame->pts = s->next_pts; |
| 435 | s->next_pts += frame->duration; | ||
| 410 | return filter_frame(inlink, frame); | 436 | return filter_frame(inlink, frame); |
| 411 | } | 437 | } |
| 412 | 438 | ||