[libav-devel] [PATCH] pulse: use the frame duration as timebase

Luca Barbato lu_zero at gentoo.org
Mon Nov 14 00:57:15 CET 2011


Thanks to Lorenzo Pistone <blaffablaffa at gmail.com> for pointing the
issue and providing an initial fix.
---
 libavdevice/pulse.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavdevice/pulse.c b/libavdevice/pulse.c
index 1edd24f..3f30b9f 100644
--- a/libavdevice/pulse.c
+++ b/libavdevice/pulse.c
@@ -107,7 +107,10 @@ static av_cold int pulse_read_header(AVFormatContext *s,
     st->codec->codec_id    = codec_id;
     st->codec->sample_rate = pd->sample_rate;
     st->codec->channels    = pd->channels;
-    av_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
+
+    av_set_pts_info(st, 64, pd->frame_size,
+                    pd->sample_rate * pd->channels *
+                    av_get_bits_per_sample(codec_id) / 8);
 
     pd->pts = AV_NOPTS_VALUE;
 
@@ -119,8 +122,6 @@ static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
     PulseData *pd  = s->priv_data;
     int res;
     pa_usec_t latency;
-    uint64_t frame_duration =
-        (pd->frame_size*1000000LL) / (pd->sample_rate * pd->channels);
 
     if (av_new_packet(pkt, pd->frame_size) < 0) {
         return AVERROR(ENOMEM);
@@ -143,9 +144,7 @@ static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
         pd->pts = -latency;
     }
 
-    pkt->pts = pd->pts;
-
-    pd->pts += frame_duration;
+    pkt->pts = pd->pts++;
 
     return 0;
 }
-- 
1.7.7



More information about the libav-devel mailing list