AudioStream: Fix a crash when opening device fails

This commit is contained in:
Connor McLaughlin 2021-02-20 20:10:35 +10:00
parent ae49215251
commit 357235404a
2 changed files with 7 additions and 1 deletions

View file

@ -35,7 +35,7 @@ bool AudioStream::Reconfigure(u32 input_sample_rate /* = DefaultInputSampleRate
if (!OpenDevice()) if (!OpenDevice())
{ {
EmptyBuffers(); LockedEmptyBuffers();
m_buffer_size = 0; m_buffer_size = 0;
m_output_sample_rate = 0; m_output_sample_rate = 0;
m_channels = 0; m_channels = 0;
@ -289,6 +289,11 @@ void AudioStream::EmptyBuffers()
{ {
std::unique_lock<std::mutex> lock(m_buffer_mutex); std::unique_lock<std::mutex> lock(m_buffer_mutex);
std::unique_lock<std::mutex> resampler_lock(m_resampler_mutex); std::unique_lock<std::mutex> resampler_lock(m_resampler_mutex);
LockedEmptyBuffers();
}
void AudioStream::LockedEmptyBuffers()
{
m_buffer.Clear(); m_buffer.Clear();
m_underflow_flag.store(false); m_underflow_flag.store(false);
m_buffer_filling.store(m_wait_for_buffer_fill); m_buffer_filling.store(m_wait_for_buffer_fill);

View file

@ -75,6 +75,7 @@ protected:
bool SetBufferSize(u32 buffer_size); bool SetBufferSize(u32 buffer_size);
bool IsDeviceOpen() const { return (m_output_sample_rate > 0); } bool IsDeviceOpen() const { return (m_output_sample_rate > 0); }
void LockedEmptyBuffers();
u32 GetSamplesAvailable() const; u32 GetSamplesAvailable() const;
u32 GetSamplesAvailableLocked() const; u32 GetSamplesAvailableLocked() const;
void ReadFrames(SampleType* samples, u32 num_frames, bool apply_volume); void ReadFrames(SampleType* samples, u32 num_frames, bool apply_volume);