diff options
| author | Markus Wick <degasus@users.noreply.github.com> | 2018-01-02 09:58:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-02 09:58:36 +0100 |
| commit | cb168b184386f169aeb828f660ac63c5bc3e540c (patch) | |
| tree | a7e89360ae75653e46536bd77d9fd27bd44774c1 /Source/Core/AudioCommon/AudioCommon.cpp | |
| parent | 26a9957285aac023ee7d35cf506b82381575df9a (diff) | |
| parent | a988a8a4587bf18d8ad8dba36653b803e3a583b4 (diff) | |
Merge pull request #6134 from ligfx/soundstreamlifecycle
SoundStream: change Start/Stop lifecycle to Init/SetRunning/destruct
Diffstat (limited to 'Source/Core/AudioCommon/AudioCommon.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/AudioCommon.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 77da1e4c70..ceecd4b909 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -21,6 +21,7 @@ std::unique_ptr<SoundStream> g_sound_stream; static bool s_audio_dump_start = false; +static bool s_sound_stream_running = false; namespace AudioCommon { @@ -50,23 +51,15 @@ void InitSoundStream() else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid()) g_sound_stream = std::make_unique<OpenSLESStream>(); - if (!g_sound_stream) + if (!g_sound_stream || !g_sound_stream->Init()) { WARN_LOG(AUDIO, "Could not initialize backend %s, using %s instead.", backend.c_str(), BACKEND_NULLSOUND); g_sound_stream = std::make_unique<NullSound>(); } - if (!g_sound_stream->Start()) - { - ERROR_LOG(AUDIO, "Could not start backend %s, using %s instead", backend.c_str(), - BACKEND_NULLSOUND); - - g_sound_stream = std::make_unique<NullSound>(); - g_sound_stream->Start(); - } - UpdateSoundStream(); + SetSoundStreamRunning(true); if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start) StartAudioDump(); @@ -76,15 +69,11 @@ void ShutdownSoundStream() { INFO_LOG(AUDIO, "Shutting down sound stream"); - if (g_sound_stream) - { - g_sound_stream->Stop(); - - if (SConfig::GetInstance().m_DumpAudio && s_audio_dump_start) - StopAudioDump(); + if (SConfig::GetInstance().m_DumpAudio && s_audio_dump_start) + StopAudioDump(); - g_sound_stream.reset(); - } + SetSoundStreamRunning(false); + g_sound_stream.reset(); INFO_LOG(AUDIO, "Done shutting down sound stream"); } @@ -161,8 +150,19 @@ void UpdateSoundStream() void SetSoundStreamRunning(bool running) { - if (g_sound_stream) - g_sound_stream->SetRunning(running); + if (!g_sound_stream) + return; + + if (s_sound_stream_running == running) + return; + s_sound_stream_running = running; + + if (g_sound_stream->SetRunning(running)) + return; + if (running) + ERROR_LOG(AUDIO, "Error starting stream."); + else + ERROR_LOG(AUDIO, "Error stopping stream."); } void SendAIBuffer(const short* samples, unsigned int num_samples) @@ -198,6 +198,8 @@ void StartAudioDump() void StopAudioDump() { + if (!g_sound_stream) + return; g_sound_stream->GetMixer()->StopLogDTKAudio(); g_sound_stream->GetMixer()->StopLogDSPAudio(); s_audio_dump_start = false; |
