Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -44,9 +44,12 @@ typedef struct AudioDelayContext { · 43 unmodified lines | ||
| 44 | 44 | int block_align; |
| 45 | 45 | int64_t padding; |
| 46 | 46 | int64_t max_delay; |
| 47 | + int64_t offset; | |
| 47 | 48 | int64_t next_pts; |
| 48 | 49 | int eof; |
| 49 | 50 | |
| 51 | + AVFrame *input; | |
| 52 | + | |
| 50 | 53 | void (*delay_channel)(ChanDelay *d, int nb_samples, |
| 51 | 54 | const uint8_t *src, uint8_t *dst); |
| 52 | 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 | 190 | char *p, *saveptr = NULL; |
| 188 | 191 | int i; |
| 189 | 192 | |
| 193 | + s->next_pts = AV_NOPTS_VALUE; | |
| 190 | 194 | s->chandelay = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chandelay)); |
| 191 | 195 | if (!s->chandelay) |
| 192 | 196 | return AVERROR(ENOMEM); |
| @@ -224,6 +228,10 @@ static int config_input(AVFilterLink *inlink) · 31 unmodified lines | ||
| 224 | 228 | |
| 225 | 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 | 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 | 331 | AVFrame *out_frame; |
| 324 | 332 | int i; |
| 325 | 333 | |
| 326 | − if (ctx->is_disabled || !s->delays) | |
| 334 | + if (ctx->is_disabled || !s->delays) { | |
| 335 | + s->input = NULL; | |
| 327 | 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 | 341 | out_frame = ff_get_audio_buffer(outlink, frame->nb_samples); |
| 330 | 342 | if (!out_frame) { |
| 343 | + s->input = NULL; | |
| 331 | 344 | av_frame_free(&frame); |
| 332 | 345 | return AVERROR(ENOMEM); |
| 333 | 346 | } |
| @@ -344,9 +357,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 10 unmodified lines | ||
| 344 | 357 | s->delay_channel(d, frame->nb_samples, src, dst); |
| 345 | 358 | } |
| 346 | 359 | |
| 347 | − out_frame->pts = s->next_pts; | |
| 348 | − s->next_pts += av_rescale_q(frame->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | |
| 360 | + out_frame->pts = s->next_pts + s->offset; | |
| 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 | 363 | av_frame_free(&frame); |
| 364 | + s->input = NULL; | |
| 350 | 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 | 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 | 393 | if (s->padding) { |
| 365 | 394 | int nb_samples = FFMIN(s->padding, 2048); |
| 366 | 395 | |
| @@ -374,24 +403,17 @@ static int activate(AVFilterContext *ctx) · 7 unmodified lines | ||
| 374 | 403 | outlink->ch_layout.nb_channels, |
| 375 | 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 | 409 | frame->pts = s->next_pts; |
| 378 | − if (s->next_pts != AV_NOPTS_VALUE) | |
| 379 | − s->next_pts += av_rescale_q(nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | |
| 410 | + s->next_pts += frame->duration; | |
| 380 | 411 | |
| 381 | 412 | return ff_filter_frame(outlink, frame); |
| 382 | 413 | } |
| 383 | 414 | |
| 384 | − ret = ff_inlink_consume_frame(inlink, &frame); | |
| 385 | − if (ret < 0) | |
| 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 | − } | |
| 415 | + if (s->input) | |
| 416 | + return filter_frame(inlink, s->input); | |
| 395 | 417 | |
| 396 | 418 | if (s->eof && s->max_delay) { |
| 397 | 419 | int nb_samples = FFMIN(s->max_delay, 2048); |
| @@ -406,7 +428,11 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines | ||
| 406 | 428 | outlink->ch_layout.nb_channels, |
| 407 | 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 | 434 | frame->pts = s->next_pts; |
| 435 | + s->next_pts += frame->duration; | |
| 410 | 436 | return filter_frame(inlink, frame); |
| 411 | 437 | } |
| 412 | 438 | |