From 49a19f85b8c49b891cdc2fdfaebce5e176c9b0c3 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 21 Dec 2015 10:25:46 -0300 Subject: [PATCH] -different attempt to avod deadlock problem --- scene/audio/stream_player.cpp | 6 ++++-- scene/audio/stream_player.h | 2 +- servers/audio/audio_server_sw.cpp | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scene/audio/stream_player.cpp b/scene/audio/stream_player.cpp index 004c20bc359..4cfca0492a9 100644 --- a/scene/audio/stream_player.cpp +++ b/scene/audio/stream_player.cpp @@ -67,7 +67,7 @@ bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { void StreamPlayer::sp_update() { - _THREAD_SAFE_METHOD_ + //_THREAD_SAFE_METHOD_ if (!paused && resampler.is_ready() && playback.is_valid()) { if (!playback->is_playing()) { @@ -143,6 +143,8 @@ void StreamPlayer::play(float p_from_offset) { return; //if (is_playing()) stop(); + + //_THREAD_SAFE_METHOD_ playback->play(p_from_offset); //feed the ringbuffer as long as no update callback is going on sp_update(); @@ -160,8 +162,8 @@ void StreamPlayer::stop() { if (playback.is_null()) return; + //_THREAD_SAFE_METHOD_ AudioServer::get_singleton()->stream_set_active(stream_rid,false); - _THREAD_SAFE_METHOD_ playback->stop(); resampler.flush(); diff --git a/scene/audio/stream_player.h b/scene/audio/stream_player.h index b5aa943067c..be090f50e14 100644 --- a/scene/audio/stream_player.h +++ b/scene/audio/stream_player.h @@ -37,7 +37,7 @@ class StreamPlayer : public Node { OBJ_TYPE(StreamPlayer,Node); - _THREAD_SAFE_CLASS_ + //_THREAD_SAFE_CLASS_ struct InternalStream : public AudioServer::AudioStream { StreamPlayer *player; diff --git a/servers/audio/audio_server_sw.cpp b/servers/audio/audio_server_sw.cpp index 3c55b10dacb..47e4ccbf32c 100644 --- a/servers/audio/audio_server_sw.cpp +++ b/servers/audio/audio_server_sw.cpp @@ -693,18 +693,28 @@ void AudioServerSW::stream_set_active(RID p_stream, bool p_active) { Stream *s = stream_owner.get(p_stream); ERR_FAIL_COND(!s); + _THREAD_SAFE_METHOD_ if (s->active==p_active) return; - AUDIO_LOCK; - _THREAD_SAFE_METHOD_ - s->active=p_active; - if (p_active) - s->E=active_audio_streams.push_back(s); - else { - active_audio_streams.erase(s->E); - s->E=NULL; + if (!thread || thread->get_ID()!=Thread::get_caller_ID()) { + //do not lock in mix thread + lock(); } + { + s->active=p_active; + if (p_active) + s->E=active_audio_streams.push_back(s); + else { + active_audio_streams.erase(s->E); + s->E=NULL; + } + } + if (!thread || thread->get_ID()!=Thread::get_caller_ID()) { + //do not lock in mix thread + unlock(); + } + } bool AudioServerSW::stream_is_active(RID p_stream) const {