mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 15:49:25 +01:00
Split SetRunning
into Start
and Stop
This commit is contained in:
parent
6c5aed38b3
commit
4de290dc6f
@ -77,9 +77,21 @@ void AlsaSound::SoundLoop()
|
||||
m_thread_status.store(ALSAThreadStatus::STOPPED);
|
||||
}
|
||||
|
||||
bool AlsaSound::SetRunning(bool running)
|
||||
bool AlsaSound::Start()
|
||||
{
|
||||
m_thread_status.store(running ? ALSAThreadStatus::RUNNING : ALSAThreadStatus::PAUSED);
|
||||
m_thread_status.store(ALSAThreadStatus::RUNNING);
|
||||
|
||||
// Immediately lock and unlock mutex to prevent cv race.
|
||||
std::unique_lock<std::mutex>{cv_m}.unlock();
|
||||
|
||||
// Notify thread that status has changed
|
||||
cv.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AlsaSound::Stop()
|
||||
{
|
||||
m_thread_status.store(ALSAThreadStatus::PAUSED);
|
||||
|
||||
// Immediately lock and unlock mutex to prevent cv race.
|
||||
std::unique_lock<std::mutex>{cv_m}.unlock();
|
||||
|
@ -23,7 +23,8 @@ public:
|
||||
~AlsaSound() override;
|
||||
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
|
||||
static bool IsValid() { return true; }
|
||||
|
||||
|
@ -182,7 +182,7 @@ void StartSoundStream(Core::System& system)
|
||||
|
||||
system.StartSoundStream();
|
||||
|
||||
if (sound_stream->SetRunning(true))
|
||||
if (sound_stream->Start())
|
||||
return;
|
||||
|
||||
ERROR_LOG_FMT(AUDIO, "Error starting stream.");
|
||||
@ -200,7 +200,7 @@ void StopSoundStream(Core::System& system)
|
||||
|
||||
system.StopSoundStream();
|
||||
|
||||
if (sound_stream->SetRunning(false))
|
||||
if (sound_stream->Stop())
|
||||
return;
|
||||
|
||||
ERROR_LOG_FMT(AUDIO, "Error stopping stream.");
|
||||
|
@ -105,8 +105,9 @@ bool CubebStream::Init()
|
||||
return return_value;
|
||||
}
|
||||
|
||||
bool CubebStream::SetRunning(bool running)
|
||||
bool CubebStream::Start()
|
||||
{
|
||||
bool running = true;
|
||||
bool return_value = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -116,9 +117,27 @@ bool CubebStream::SetRunning(bool running)
|
||||
m_work_queue.EmplaceItem([this, running, &return_value, &sync_event] {
|
||||
Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); });
|
||||
#endif
|
||||
if (running)
|
||||
return_value = cubeb_stream_start(m_stream) == CUBEB_OK;
|
||||
else
|
||||
#ifdef _WIN32
|
||||
});
|
||||
sync_event.Wait();
|
||||
#endif
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
bool CubebStream::Stop()
|
||||
{
|
||||
bool running = false;
|
||||
bool return_value = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!m_coinit_success)
|
||||
return false;
|
||||
Common::Event sync_event;
|
||||
m_work_queue.EmplaceItem([this, running, &return_value, &sync_event] {
|
||||
Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); });
|
||||
#endif
|
||||
return_value = cubeb_stream_stop(m_stream) == CUBEB_OK;
|
||||
#ifdef _WIN32
|
||||
});
|
||||
|
@ -23,7 +23,8 @@ public:
|
||||
CubebStream& operator=(CubebStream&& other) = delete;
|
||||
~CubebStream() override;
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
void SetVolume(int) override;
|
||||
|
||||
private:
|
||||
|
@ -8,7 +8,12 @@ bool NullSound::Init()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullSound::SetRunning(bool running)
|
||||
bool NullSound::Start()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullSound::Stop()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ class NullSound final : public SoundStream
|
||||
{
|
||||
public:
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
void SetVolume(int volume) override;
|
||||
|
||||
static bool IsValid() { return true; }
|
||||
|
@ -153,16 +153,15 @@ void OpenALStream::SetVolume(int volume)
|
||||
palSourcef(m_source, AL_GAIN, m_volume);
|
||||
}
|
||||
|
||||
bool OpenALStream::SetRunning(bool running)
|
||||
{
|
||||
if (running)
|
||||
bool OpenALStream::Start()
|
||||
{
|
||||
palSourcePlay(m_source);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
bool OpenALStream::Stop()
|
||||
{
|
||||
palSourceStop(m_source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,8 @@ public:
|
||||
~OpenALStream() override;
|
||||
bool Init() override;
|
||||
void SetVolume(int volume) override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
|
||||
static bool IsValid();
|
||||
|
||||
|
@ -137,10 +137,14 @@ OpenSLESStream::~OpenSLESStream()
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenSLESStream::SetRunning(bool running)
|
||||
bool OpenSLESStream::Start()
|
||||
{
|
||||
SLuint32 new_state = running ? SL_PLAYSTATE_PLAYING : SL_PLAYSTATE_PAUSED;
|
||||
return (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, new_state) == SL_RESULT_SUCCESS;
|
||||
return (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING) == SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
bool OpenSLESStream::Stop()
|
||||
{
|
||||
return (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PAUSED) == SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void OpenSLESStream::SetVolume(int volume)
|
||||
|
@ -14,7 +14,8 @@ class OpenSLESStream final : public SoundStream
|
||||
public:
|
||||
~OpenSLESStream() override;
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
void SetVolume(int volume) override;
|
||||
static bool IsValid() { return true; }
|
||||
|
||||
|
@ -20,7 +20,8 @@ public:
|
||||
~PulseAudio() override;
|
||||
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override { return true; }
|
||||
bool Start() override { return true; }
|
||||
bool Stop() override { return true; }
|
||||
static bool IsValid() { return true; }
|
||||
void StateCallback(pa_context* c);
|
||||
void WriteCallback(pa_stream* s, size_t length);
|
||||
|
@ -21,5 +21,6 @@ public:
|
||||
virtual bool Init() { return false; }
|
||||
virtual void SetVolume(int) {}
|
||||
// Returns true if successful.
|
||||
virtual bool SetRunning(bool running) { return false; }
|
||||
virtual bool Start() { return false; }
|
||||
virtual bool Stop() { return false; }
|
||||
};
|
||||
|
@ -168,9 +168,7 @@ bool WASAPIStream::Init()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WASAPIStream::SetRunning(bool running)
|
||||
{
|
||||
if (running)
|
||||
bool WASAPIStream::Start()
|
||||
{
|
||||
ComPtr<IMMDevice> device;
|
||||
|
||||
@ -300,8 +298,11 @@ bool WASAPIStream::SetRunning(bool running)
|
||||
|
||||
m_running.store(true, std::memory_order_relaxed);
|
||||
m_thread = std::thread(&WASAPIStream::SoundLoop, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
bool WASAPIStream::Stop()
|
||||
{
|
||||
m_running.store(false, std::memory_order_relaxed);
|
||||
|
||||
@ -311,7 +312,6 @@ bool WASAPIStream::SetRunning(bool running)
|
||||
m_need_data_event.reset();
|
||||
m_audio_renderer.Reset();
|
||||
m_audio_client.Reset();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
explicit WASAPIStream();
|
||||
~WASAPIStream();
|
||||
bool Init() override;
|
||||
bool SetRunning(bool running) override;
|
||||
bool Start() override;
|
||||
bool Stop() override;
|
||||
|
||||
static bool IsValid();
|
||||
static std::vector<std::string> GetAvailableDevices();
|
||||
|
Loading…
x
Reference in New Issue
Block a user