History

avfilter/af_adelay: fix frame pts and set frame duration

Paul B Mahol committed 3 years ago

Commit 67ca64c1 parent 217bb591 file · +42 −16Browse files

Unified · Split

libavfilter/af_adelay.c+42−16
@@ -44,9 +44,12 @@ typedef struct AudioDelayContext { · 43 unmodified lines
4444 int block_align;
4545 int64_t padding;
4646 int64_t max_delay;
47+ int64_t offset;
4748 int64_t next_pts;
4849 int eof;
4950
51+ AVFrame *input;
52+
5053 void (*delay_channel)(ChanDelay *d, int nb_samples,
5154 const uint8_t *src, uint8_t *dst);
5255 int (*resize_channel_samples)(ChanDelay *d, int64_t new_delay);
@@ -187,6 +190,7 @@ static int config_input(AVFilterLink *inlink) · 134 unmodified lines
187190 char *p, *saveptr = NULL;
188191 int i;
189192
193+ s->next_pts = AV_NOPTS_VALUE;
190194 s->chandelay = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chandelay));
191195 if (!s->chandelay)
192196 return AVERROR(ENOMEM);
@@ -224,6 +228,10 @@ static int config_input(AVFilterLink *inlink) · 31 unmodified lines
224228
225229 d->delay -= s->padding;
226230 }
231+
232+ s->offset = av_rescale_q(s->padding,
233+ av_make_q(1, inlink->sample_rate),
234+ inlink->time_base);
227235 }
228236
229237 for (i = 0; i < s->nb_delays; i++) {
@@ -323,11 +331,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 93 unmodified lines
323331 AVFrame *out_frame;
324332 int i;
325333
326− if (ctx->is_disabled || !s->delays)
334+ if (ctx->is_disabled || !s->delays) {
335+ s->input = NULL;
327336 return ff_filter_frame(outlink, frame);
337+ }
338+
339+ s->next_pts = av_rescale_q(frame->pts, inlink->time_base, outlink->time_base);
328340
329341 out_frame = ff_get_audio_buffer(outlink, frame->nb_samples);
330342 if (!out_frame) {
343+ s->input = NULL;
331344 av_frame_free(&frame);
332345 return AVERROR(ENOMEM);
333346 }
@@ -344,9 +357,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 10 unmodified lines
344357 s->delay_channel(d, frame->nb_samples, src, dst);
345358 }
346359
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;
349363 av_frame_free(&frame);
364+ s->input = NULL;
350365 return ff_filter_frame(outlink, out_frame);
351366 }
352367
@@ -361,6 +376,20 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines
361376
362377 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
363378
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+
364393 if (s->padding) {
365394 int nb_samples = FFMIN(s->padding, 2048);
366395
@@ -374,24 +403,17 @@ static int activate(AVFilterContext *ctx) · 7 unmodified lines
374403 outlink->ch_layout.nb_channels,
375404 frame->format);
376405
406+ frame->duration = av_rescale_q(frame->nb_samples,
407+ (AVRational){1, outlink->sample_rate},
408+ outlink->time_base);
377409 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;
380411
381412 return ff_filter_frame(outlink, frame);
382413 }
383414
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);
395417
396418 if (s->eof && s->max_delay) {
397419 int nb_samples = FFMIN(s->max_delay, 2048);
@@ -406,7 +428,11 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines
406428 outlink->ch_layout.nb_channels,
407429 frame->format);
408430
431+ frame->duration = av_rescale_q(frame->nb_samples,
432+ (AVRational){1, outlink->sample_rate},
433+ outlink->time_base);
409434 frame->pts = s->next_pts;
435+ s->next_pts += frame->duration;
410436 return filter_frame(inlink, frame);
411437 }
412438

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t