[libav-devel] [PATCH] pulse: fix frame duration

Luca Barbato lu_zero at gentoo.org
Sun Nov 13 12:33:01 CET 2011


From: Lorenzo Pistone <blaffablaffa at gmail.com>

The frame_size is in byte not in samples.

Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
---
 libavdevice/pulse.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavdevice/pulse.c b/libavdevice/pulse.c
index 1edd24f..eb9c2f7 100644
--- a/libavdevice/pulse.c
+++ b/libavdevice/pulse.c
@@ -41,6 +41,7 @@ typedef struct PulseData {
     char *name;
     char *stream_name;
     int  sample_rate;
+    int  bytes_per_sample;
     int  channels;
     int  frame_size;
     int  fragment_size;
@@ -110,6 +111,7 @@ static av_cold int pulse_read_header(AVFormatContext *s,
     av_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
 
     pd->pts = AV_NOPTS_VALUE;
+    pd->bytes_per_sample = av_get_bits_per_sample(codec_id) / 8;
 
     return 0;
 }
@@ -120,7 +122,7 @@ static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
     int res;
     pa_usec_t latency;
     uint64_t frame_duration =
-        (pd->frame_size*1000000LL) / (pd->sample_rate * pd->channels);
+        (pd->frame_size*1000000LL) / (pd->sample_rate * pd->channels * pd->bytes_per_sample);
 
     if (av_new_packet(pkt, pd->frame_size) < 0) {
         return AVERROR(ENOMEM);
-- 
1.7.7



More information about the libav-devel mailing list