summaryrefslogtreecommitdiff
authorLukasz Marek <lukasz.m.luki@gmail.com>2013-10-24 13:11:19 (GMT)
committer Lukasz Marek <lukasz.m.luki@gmail.com>2013-10-27 20:43:05 (GMT)
commite5b3b75669fc8f2cf485faa1d44143e442079d82 (patch)
tree8fc072a3593d8cb4ef68bea58cdd78298a1ba2ab
parent75b2bbe21d93ce18b0362f1deaa9f11bfab75e8c (diff)
downloadffmpeg-e5b3b75669fc8f2cf485faa1d44143e442079d82.zip
ffmpeg-e5b3b75669fc8f2cf485faa1d44143e442079d82.tar.gz
ffmpeg-e5b3b75669fc8f2cf485faa1d44143e442079d82.tar.bz2
lavd/pulse_audio_enc: fix timestamp calculation
Current implementation didn't include duration of last processed packet. Also remove access to st->cur_dts and replace with pkt->pts. Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
Diffstat
-rw-r--r--libavdevice/pulse_audio_enc.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index b8b0700..af11494 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -35,6 +35,7 @@ typedef struct PulseData {
const char *device;
pa_simple *pa;
unsigned int stream_index;
+ int64_t timestamp;
} PulseData;
static av_cold int pulse_write_header(AVFormatContext *h)
@@ -116,6 +117,19 @@ static int pulse_write_packet(AVFormatContext *h, AVPacket *pkt)
if (s->stream_index != pkt->stream_index)
return 0;
+ if (pkt->dts != AV_NOPTS_VALUE)
+ s->timestamp = pkt->dts;
+
+ if (pkt->duration) {
+ s->timestamp += pkt->duration;;
+ } else {
+ AVStream *st = h->streams[s->stream_index];
+ AVCodecContext *codec_ctx = st->codec;
+ AVRational r = { 1, codec_ctx->sample_rate };
+ int64_t samples = pkt->size / (av_get_bytes_per_sample(codec_ctx->sample_fmt) * codec_ctx->channels);
+ s->timestamp += av_rescale_q(samples, r, st->time_base);
+ }
+
if (pa_simple_write(s->pa, pkt->data, pkt->size, &error) < 0) {
av_log(s, AV_LOG_ERROR, "pa_simple_write failed: %s\n", pa_strerror(error));
return AVERROR(EIO);
@@ -129,7 +143,7 @@ static void pulse_get_output_timestamp(AVFormatContext *h, int stream, int64_t *
PulseData *s = h->priv_data;
pa_usec_t latency = pa_simple_get_latency(s->pa, NULL);
*wall = av_gettime();
- *dts = h->streams[s->stream_index]->cur_dts - latency;
+ *dts = s->timestamp - latency;
}
#define OFFSET(a) offsetof(PulseData, a)