Browse code

avfilter/avf_showfreqs: properly handle pts

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2016/02/01 05:38:49
Showing 1 changed files
... ...
@@ -154,6 +154,15 @@ static int query_formats(AVFilterContext *ctx)
154 154
     return 0;
155 155
 }
156 156
 
157
+static av_cold int init(AVFilterContext *ctx)
158
+{
159
+    ShowFreqsContext *s = ctx->priv;
160
+
161
+    s->pts = AV_NOPTS_VALUE;
162
+
163
+    return 0;
164
+}
165
+
157 166
 static int config_output(AVFilterLink *outlink)
158 167
 {
159 168
     AVFilterContext *ctx = outlink->src;
... ...
@@ -423,8 +432,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
423 423
     AVFilterContext *ctx = inlink->dst;
424 424
     ShowFreqsContext *s = ctx->priv;
425 425
     AVFrame *fin = NULL;
426
+    int consumed = 0;
426 427
     int ret = 0;
427 428
 
429
+    if (s->pts == AV_NOPTS_VALUE)
430
+        s->pts = in->pts - av_audio_fifo_size(s->fifo);
431
+
428 432
     av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
429 433
     while (av_audio_fifo_size(s->fifo) >= s->win_size) {
430 434
         fin = ff_get_audio_buffer(inlink, s->win_size);
... ...
@@ -433,8 +446,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
433 433
             goto fail;
434 434
         }
435 435
 
436
-        fin->pts = s->pts;
437
-        s->pts += s->hop_size;
436
+        fin->pts = s->pts + consumed;
437
+        consumed += s->hop_size;
438 438
         ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
439 439
         if (ret < 0)
440 440
             goto fail;
... ...
@@ -447,6 +460,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
447 447
     }
448 448
 
449 449
 fail:
450
+    s->pts = AV_NOPTS_VALUE;
450 451
     av_frame_free(&fin);
451 452
     av_frame_free(&in);
452 453
     return ret;
... ...
@@ -491,6 +505,7 @@ static const AVFilterPad showfreqs_outputs[] = {
491 491
 AVFilter ff_avf_showfreqs = {
492 492
     .name          = "showfreqs",
493 493
     .description   = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
494
+    .init          = init,
494 495
     .uninit        = uninit,
495 496
     .query_formats = query_formats,
496 497
     .priv_size     = sizeof(ShowFreqsContext),