lavd/alsa: fix timestamp calculation
Current implementation didn't include duration of last processed packet. Device may return negative timestamps without this correction. Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
This commit is contained in:
parent
8a701ef7dd
commit
6ac9afd16e
@ -80,6 +80,10 @@ static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
uint8_t *buf = pkt->data;
|
uint8_t *buf = pkt->data;
|
||||||
|
|
||||||
size /= s->frame_size;
|
size /= s->frame_size;
|
||||||
|
if (pkt->dts != AV_NOPTS_VALUE)
|
||||||
|
s->timestamp = pkt->dts;
|
||||||
|
s->timestamp += pkt->duration ? pkt->duration : size;
|
||||||
|
|
||||||
if (s->reorder_func) {
|
if (s->reorder_func) {
|
||||||
if (size > s->reorder_buf_size)
|
if (size > s->reorder_buf_size)
|
||||||
if (ff_alsa_extend_reorder_buf(s, size))
|
if (ff_alsa_extend_reorder_buf(s, size))
|
||||||
@ -112,7 +116,7 @@ audio_get_output_timestamp(AVFormatContext *s1, int stream,
|
|||||||
snd_pcm_sframes_t delay = 0;
|
snd_pcm_sframes_t delay = 0;
|
||||||
*wall = av_gettime();
|
*wall = av_gettime();
|
||||||
snd_pcm_delay(s->h, &delay);
|
snd_pcm_delay(s->h, &delay);
|
||||||
*dts = s1->streams[0]->cur_dts - delay;
|
*dts = s->timestamp - delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVOutputFormat ff_alsa_muxer = {
|
AVOutputFormat ff_alsa_muxer = {
|
||||||
|
@ -57,6 +57,7 @@ typedef struct AlsaData {
|
|||||||
void (*reorder_func)(const void *, void *, int);
|
void (*reorder_func)(const void *, void *, int);
|
||||||
void *reorder_buf;
|
void *reorder_buf;
|
||||||
int reorder_buf_size; ///< in frames
|
int reorder_buf_size; ///< in frames
|
||||||
|
int64_t timestamp; ///< current timestamp, without latency applied.
|
||||||
} AlsaData;
|
} AlsaData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user