summaryrefslogtreecommitdiff
path: root/libavdevice/pulse.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2011-11-14 15:53:59 +0100
committerLuca Barbato <lu_zero@gentoo.org>2011-11-14 16:16:41 +0100
commit2625b621ce7eb2d5f2f42d2a6dff37bffce3c726 (patch)
treee0bc7a85b1148fc27935953844a4cb33d964afa9 /libavdevice/pulse.c
parentcaf27e37b654d6f525d47bc62b914cbee4ca6a4b (diff)
pulse: compute frame_duration once and fix it
The frame duration was calculated without taking in account the bytes per sample. Thanks to Lorenzo Pistone <blaffablaffa@gmail.com> for pointing the issue and providing an initial fix.
Diffstat (limited to 'libavdevice/pulse.c')
-rw-r--r--libavdevice/pulse.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libavdevice/pulse.c b/libavdevice/pulse.c
index 1edd24fdd9..41f88b541f 100644
--- a/libavdevice/pulse.c
+++ b/libavdevice/pulse.c
@@ -46,6 +46,7 @@ typedef struct PulseData {
int fragment_size;
pa_simple *s;
int64_t pts;
+ int64_t frame_duration;
} PulseData;
static pa_sample_format_t codec_id_to_pulse_format(int codec_id) {
@@ -110,6 +111,8 @@ 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->frame_duration = (pd->frame_size * 1000000LL * 8) /
+ (pd->sample_rate * pd->channels * av_get_bits_per_sample(codec_id));
return 0;
}
@@ -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);
@@ -145,7 +146,7 @@ static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->pts = pd->pts;
- pd->pts += frame_duration;
+ pd->pts += pd->frame_duration;
return 0;
}