diff options
author | Misaki Kasumi <misakikasumi@outlook.com> | 2024-03-26 21:57:12 +0800 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2024-04-05 17:22:17 +0200 |
commit | f974382ca06655ac34debce7284ce87d01e5abd1 (patch) | |
tree | 6da732c8fbe47358d4b3a9141d0a50e1fe33d5fb /player | |
parent | 2cbb13db9edae33d8fe1b078835fd387e69946d3 (diff) | |
download | mpv-f974382ca06655ac34debce7284ce87d01e5abd1.tar.bz2 mpv-f974382ca06655ac34debce7284ce87d01e5abd1.tar.xz |
ao_pipewire: fix delay calculation
A figure from pipewire documentation:
```
stream time domain graph time domain
/-----------------------\/-----------------------------\
queue +-+ +-+ +-----------+ +--------+
----> | | | |->| converter | -> graph -> | kernel | -> speaker
<---- +-+ +-+ +-----------+ +--------+
dequeue buffers \-------------------/\--------/
graph internal
latency latency
\--------/\-------------/\-----------------------------/
queued buffered delay
```
We calculate `end_time` in the following steps:
1. get current timestamp in mpv
```
int64_t end_time = mp_time_ns();
```
2. add duration of samples to enqueue
```
end_time += MP_TIME_S_TO_NS(nframes) / ao->samplerate;
```
3. add delay of the pipewire graph
```
end_time += MP_TIME_S_TO_NS(time.delay) * time.rate.num / time.rate.denom;
```
4. add duration of queued and buffered samples.
```
end_time += MP_TIME_S_TO_NS(time.queued) / ao->samplerate;
end_time += MP_TIME_S_TO_NS(time.buffered) / ao->samplerate;
```
New in this commit. `time.queued` is usually zero as `SPA_PARAM_BUFFERS_buffers`
is default to 1; however it is not always.
`time.buffered` is non-zero if there is a resampler involved.
5. add elapsed duration from when `time` is captured
```
end_time -= pw_stream_get_nsec(p->stream) - time.now;
```
New in this commit. `time` is captured at `time.now`.
From then, time has passed so we need to exclude the elapsed time,
by calculating the diff of `pw_stream_get_nsec()` and `time.now`.
Diffstat (limited to 'player')
0 files changed, 0 insertions, 0 deletions