Merge pull request #80294 from Birdulon/PAlatency

[3.x] PulseAudio: Remove `get_latency()` caching
This commit is contained in:
Rémi Verschelde 2023-08-08 14:28:45 +02:00
commit 75f427b8af
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 14 additions and 17 deletions

View File

@ -132,7 +132,7 @@
<method name="get_output_latency" qualifiers="const">
<return type="float" />
<description>
Returns the audio driver's output latency.
Returns the audio driver's output latency. This can be expensive, it is not recommended to call this every frame.
</description>
</method>
<method name="get_speaker_mode" qualifiers="const">

View File

@ -114,7 +114,7 @@
Number of islands in the 3D physics engine.
</constant>
<constant name="AUDIO_OUTPUT_LATENCY" value="30" enum="Monitor">
Output latency of the [AudioServer].
Output latency of the [AudioServer]. Equivalent to calling [method AudioServer.get_output_latency], it is not recommended to call this every frame.
</constant>
<constant name="MONITOR_MAX" value="31" enum="Monitor">
Represents the size of the [enum Monitor] enum.

View File

@ -353,27 +353,24 @@ Error AudioDriverPulseAudio::init() {
}
float AudioDriverPulseAudio::get_latency() {
if (latency == 0) { //only do this once since it's approximate anyway
lock();
lock();
pa_usec_t palat = 0;
if (pa_stream_get_state(pa_str) == PA_STREAM_READY) {
int negative = 0;
pa_usec_t pa_lat = 0;
if (pa_stream_get_state(pa_str) == PA_STREAM_READY) {
int negative = 0;
if (pa_stream_get_latency(pa_str, &palat, &negative) >= 0) {
if (negative) {
palat = 0;
}
if (pa_stream_get_latency(pa_str, &pa_lat, &negative) >= 0) {
if (negative) {
pa_lat = 0;
}
}
if (palat > 0) {
latency = double(palat) / 1000000.0;
}
unlock();
}
if (pa_lat > 0) {
latency = double(pa_lat) / 1000000.0;
}
unlock();
return latency;
}