0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00
mpv/audio
Misaki Kasumi f974382ca0 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`.
2024-04-05 17:22:17 +02:00
..
decode audio/ad_spdif: utilize defined freeing function for AVIOContext 2024-04-04 17:03:48 +03:00
filter af_scaletempo2: fix false reporting of frame availability 2024-03-28 16:16:43 +01:00
out ao_pipewire: fix delay calculation 2024-04-05 17:22:17 +02:00
aframe.c various: replace if + abort() with MP_HANDLE_OOM() 2023-01-12 22:02:07 +01:00
aframe.h ad_lavc: strip non-normalized floats 2022-09-02 01:27:31 +02:00
chmap_avchannel.c audio: add AVChannelLayout helpers to convert from/to mp_chmap 2022-06-12 21:05:59 +03:00
chmap_avchannel.h audio: add AVChannelLayout helpers to convert from/to mp_chmap 2022-06-12 21:05:59 +03:00
chmap_sel.c audio: use --audio-channels=auto behavior, except on ALSA 2016-08-04 20:49:20 +02:00
chmap_sel.h audio: use --audio-channels=auto behavior, except on ALSA 2016-08-04 20:49:20 +02:00
chmap.c chmap: mp_image_pool: drop stale mentions of Libav in comments 2024-01-20 16:10:20 +00:00
chmap.h audio/chmap: support up to 64 channels 2023-09-29 02:35:10 +00:00
fmt-conversion.c audio: add support for AV_SAMPLE_FMT_S64* 2019-09-27 21:21:34 +02:00
fmt-conversion.h audio/fmt-conversion: change license to LGPL 2017-05-05 07:25:55 +02:00
format.c audio/format: fix Type 'struct entry' has incompatible definitions in different translation units 2022-10-23 14:57:24 +02:00
format.h audio: add support for AV_SAMPLE_FMT_S64* 2019-09-27 21:21:34 +02:00