summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean LaPlante <laplante.sean@gmail.com>2021-01-08 20:29:49 -0500
committerSean LaPlante <laplante.sean@gmail.com>2021-01-16 13:10:05 -0500
commit17ac0127284145d366a4611960525ecbdac8ab10 (patch)
tree50eaa2debe9e5fac65335f45442d60c65dee0a7b
parent3099f6fae4da58f6c55d7bf4a060e21b5968a0bf (diff)
Fixes #45025 - Protects _last_mix_time and _last_frame_time with the AudioDriver lock() and unlock() methods
-rw-r--r--servers/audio_server.cpp17
-rw-r--r--servers/audio_server.h4
2 files changed, 14 insertions, 7 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 295059a1ea..d4f7876b4b 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -71,13 +71,20 @@ void AudioDriver::update_mix_time(int p_frames) {
}
}
-double AudioDriver::get_time_since_last_mix() const {
- return (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
+double AudioDriver::get_time_since_last_mix() {
+ lock();
+ uint64_t last_mix_time = _last_mix_time;
+ unlock();
+ return (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
}
-double AudioDriver::get_time_to_next_mix() const {
- double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
- double mix_buffer = _last_mix_frames / (double)get_mix_rate();
+double AudioDriver::get_time_to_next_mix() {
+ lock();
+ uint64_t last_mix_time = _last_mix_time;
+ uint64_t last_mix_frames = _last_mix_frames;
+ unlock();
+ double total = (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
+ double mix_buffer = last_mix_frames / (double)get_mix_rate();
return mix_buffer - total;
}
diff --git a/servers/audio_server.h b/servers/audio_server.h
index 631fef0f65..51fbc59851 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -70,8 +70,8 @@ protected:
#endif
public:
- double get_time_since_last_mix() const; //useful for video -> audio sync
- double get_time_to_next_mix() const;
+ double get_time_since_last_mix(); //useful for video -> audio sync
+ double get_time_to_next_mix();
enum SpeakerMode {
SPEAKER_MODE_STEREO,