mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-09 16:29:59 +00:00
Merge pull request #1038 from MerryMage/lock-cubeb
cubeb_sink: Protect queue with a mutex
This commit is contained in:
commit
e12a07079e
1 changed files with 6 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "audio_core/cubeb_sink.h"
|
#include "audio_core/cubeb_sink.h"
|
||||||
#include "audio_core/stream.h"
|
#include "audio_core/stream.h"
|
||||||
|
@ -66,6 +67,8 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock{queue_mutex};
|
||||||
|
|
||||||
queue.reserve(queue.size() + samples.size() * GetNumChannels());
|
queue.reserve(queue.size() + samples.size() * GetNumChannels());
|
||||||
|
|
||||||
if (is_6_channel) {
|
if (is_6_channel) {
|
||||||
|
@ -94,6 +97,7 @@ private:
|
||||||
u32 num_channels{};
|
u32 num_channels{};
|
||||||
bool is_6_channel{};
|
bool is_6_channel{};
|
||||||
|
|
||||||
|
std::mutex queue_mutex;
|
||||||
std::vector<s16> queue;
|
std::vector<s16> queue;
|
||||||
|
|
||||||
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
||||||
|
@ -153,6 +157,8 @@ long SinkStreamImpl::DataCallback(cubeb_stream* stream, void* user_data, const v
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock{impl->queue_mutex};
|
||||||
|
|
||||||
const size_t frames_to_write{
|
const size_t frames_to_write{
|
||||||
std::min(impl->queue.size() / impl->GetNumChannels(), static_cast<size_t>(num_frames))};
|
std::min(impl->queue.size() / impl->GetNumChannels(), static_cast<size_t>(num_frames))};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue