[vlc-devel] [PATCH 2/2] soxr: fix pts

Thomas Guillem thomas at gllm.fr
Thu Feb 28 15:45:53 CET 2019


The output block PTS/length was wrongly set to the PTS/length of the last input
block. This could cause a PTS delay when the filter needed more than one input
block to return an output one. Example: with a rate of 4, the filter
(approximately) returned 3 time a NULL buffer, and used the PTS/length of the
4th one. This caused a PTS delay of 4 * block->i_length.

The returned PTS/length correspond now exactly to what the filer module wrote.
---
 modules/audio_filter/resampler/soxr.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/audio_filter/resampler/soxr.c b/modules/audio_filter/resampler/soxr.c
index 7d7e31fd91..196f935faa 100644
--- a/modules/audio_filter/resampler/soxr.c
+++ b/modules/audio_filter/resampler/soxr.c
@@ -87,7 +87,7 @@ typedef struct
     soxr_t  last_soxr;
     double  f_fixed_ratio;
     size_t  i_last_olen;
-    vlc_tick_t i_last_pts;
+    date_t pts;
 } filter_sys_t;
 
 static block_t *Resample( filter_t *, block_t * );
@@ -192,6 +192,9 @@ Open( vlc_object_t *p_obj, bool b_change_ratio )
     p_filter->pf_audio_filter = Resample;
     p_filter->pf_flush = Flush;
     p_filter->pf_audio_drain = Drain;
+
+    date_Init(&p_sys->pts, p_filter->fmt_in.audio.i_rate, 1);
+
     return VLC_SUCCESS;
 }
 
@@ -290,7 +293,6 @@ static block_t *
 Resample( filter_t *p_filter, block_t *p_in )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
-    const vlc_tick_t i_pts = p_in->i_pts;
 
     if( p_sys->vr_soxr )
     {
@@ -321,6 +323,8 @@ Resample( filter_t *p_filter, block_t *p_in )
             /* using fixed resampler */
             soxr = p_sys->soxr;
         }
+        if( date_Get( &p_sys->pts) == VLC_TICK_INVALID )
+            date_Set( &p_sys->pts, p_in->i_pts );
 
         /* If the new soxr is different than the last one, flush it */
         if( p_sys->last_soxr && soxr != p_sys->last_soxr && p_sys->i_last_olen )
@@ -351,7 +355,8 @@ Resample( filter_t *p_filter, block_t *p_in )
                 goto error;
             p_out->i_nb_samples = i_nb_samples;
         }
-        p_out->i_pts = i_pts;
+        p_out->i_dts = p_out->i_pts = date_Get( &p_sys->pts );
+        date_Increment( &p_sys->pts, p_out->i_nb_samples );
         return p_out;
     }
     else
@@ -362,7 +367,7 @@ Resample( filter_t *p_filter, block_t *p_in )
                                               p_sys->f_fixed_ratio );
         block_t *p_out = SoXR_Resample( p_filter, p_sys->soxr, p_in, i_olen );
         if( p_out )
-            p_out->i_pts = i_pts;
+            p_out->i_pts = p_in->i_pts;
         return p_out;
     }
 error:
@@ -393,4 +398,5 @@ Flush( filter_t *p_filter )
         p_sys->i_last_olen = 0;
         p_sys->last_soxr = NULL;
     }
+    date_Set( &p_sys->pts, VLC_TICK_INVALID );
 }
-- 
2.20.1



More information about the vlc-devel mailing list