[FFmpeg-devel] [PATCH 3/3] alsa: use the irregular timefilter update.

Nicolas George nicolas.george at normalesup.org
Wed Feb 15 19:35:12 CET 2012


This fixes timestamps divergence that occurs with too long periods,
especially with some dsnoop plugin settings.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavdevice/alsa-audio-dec.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c
index 62bf42d..38e1f0a 100644
--- a/libavdevice/alsa-audio-dec.c
+++ b/libavdevice/alsa-audio-dec.c
@@ -57,7 +57,7 @@ static av_cold int audio_read_header(AVFormatContext *s1)
 {
     AlsaData *s = s1->priv_data;
     AVStream *st;
-    int ret;
+    int tf_period, ret;
     enum CodecID codec_id;
 
     st = avformat_new_stream(s1, NULL);
@@ -81,8 +81,9 @@ static av_cold int audio_read_header(AVFormatContext *s1)
     st->codec->channels    = s->channels;
     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
     /* microseconds instead of seconds, MHz instead of Hz */
+    tf_period = FFMIN(FFMAX(16, s->sample_rate / 500), s->period_size);
     s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate,
-                                      s->period_size, 1.5E-6);
+                                      tf_period, 1.5E-6);
     if (!s->timefilter)
         goto fail;
 
@@ -122,8 +123,9 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
 
     dts = av_gettime();
     snd_pcm_delay(s->h, &delay);
-    dts -= av_rescale(delay + res, 1000000, s->sample_rate);
-    pkt->pts = ff_timefilter_update(s->timefilter, dts, res);
+    dts -= av_rescale(delay, 1000000, s->sample_rate);
+    ff_timefilter_update_irregular(s->timefilter, dts, res);
+    pkt->pts = ff_timefilter_eval(s->timefilter, -res);
 
     pkt->size = res * s->frame_size;
 
-- 
1.7.9



More information about the ffmpeg-devel mailing list