Remove the mutex from the backend base

This commit is contained in:
Chris Robinson 2020-03-29 23:57:37 -07:00
parent d70912c034
commit 9b237790b2
5 changed files with 17 additions and 12 deletions

View File

@ -425,6 +425,8 @@ struct AlsaPlayback final : public BackendBase {
snd_pcm_t *mPcmHandle{nullptr};
std::mutex mMutex;
al::vector<al::byte> mBuffer;
std::atomic<bool> mKillNow{true};
@ -493,7 +495,7 @@ int AlsaPlayback::mixerProc()
avail -= avail%update_size;
// it is possible that contiguous areas are smaller, thus we use a loop
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
while(avail > 0)
{
snd_pcm_uframes_t frames{avail};
@ -575,7 +577,7 @@ int AlsaPlayback::mixerNoMMapProc()
al::byte *WritePtr{mBuffer.data()};
avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast<ssize_t>(mBuffer.size()));
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
aluMixData(mDevice, WritePtr, static_cast<ALuint>(avail), frame_step);
while(avail > 0)
{
@ -848,7 +850,7 @@ ClockLatency AlsaPlayback::getClockLatency()
{
ClockLatency ret;
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
ret.ClockTime = GetDeviceClockTime(mDevice);
snd_pcm_sframes_t delay{};
int err{snd_pcm_delay(mPcmHandle, &delay)};
@ -1168,7 +1170,6 @@ ClockLatency AlsaCapture::getClockLatency()
{
ClockLatency ret;
std::lock_guard<std::recursive_mutex> _{mMutex};
ret.ClockTime = GetDeviceClockTime(mDevice);
snd_pcm_sframes_t delay{};
int err{snd_pcm_delay(mPcmHandle, &delay)};

View File

@ -45,8 +45,6 @@ struct BackendBase {
ALCdevice *mDevice;
std::recursive_mutex mMutex;
BackendBase(ALCdevice *device) noexcept;
virtual ~BackendBase();
};

View File

@ -169,6 +169,8 @@ struct JackPlayback final : public BackendBase {
jack_client_t *mClient{nullptr};
jack_port_t *mPort[MAX_OUTPUT_CHANNELS]{};
std::mutex mMutex;
std::atomic<bool> mPlaying{false};
RingBufferPtr mRing;
al::semaphore mSem;
@ -282,7 +284,7 @@ int JackPlayback::mixerProc()
ALuint len1{minu(static_cast<ALuint>(data.first.len), todo)};
ALuint len2{minu(static_cast<ALuint>(data.second.len), todo-len1)};
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
aluMixData(mDevice, data.first.buf, len1, frame_step);
if(len2 > 0)
aluMixData(mDevice, data.second.buf, len2, frame_step);
@ -458,7 +460,7 @@ ClockLatency JackPlayback::getClockLatency()
{
ClockLatency ret;
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
ret.ClockTime = GetDeviceClockTime(mDevice);
ret.Latency = std::chrono::seconds{mRing->readSpace()};
ret.Latency /= mDevice->Frequency;

View File

@ -171,6 +171,8 @@ struct OpenSLPlayback final : public BackendBase {
RingBufferPtr mRing{nullptr};
al::semaphore mSem;
std::mutex mMutex;
ALuint mFrameSize{0};
std::atomic<bool> mKillNow{true};
@ -260,7 +262,7 @@ int OpenSLPlayback::mixerProc()
}
}
std::unique_lock<std::recursive_mutex> dlock{mMutex};
std::unique_lock<std::mutex> dlock{mMutex};
auto data = mRing->getWriteVector();
aluMixData(mDevice, data.first.buf,
static_cast<ALuint>(data.first.len*mDevice->UpdateSize), frame_step);
@ -610,7 +612,7 @@ ClockLatency OpenSLPlayback::getClockLatency()
{
ClockLatency ret;
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
ret.ClockTime = GetDeviceClockTime(mDevice);
ret.Latency = std::chrono::seconds{mRing->readSpace() * mDevice->UpdateSize};
ret.Latency /= mDevice->Frequency;

View File

@ -658,6 +658,8 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy {
UINT32 mFrameStep{0u};
std::atomic<UINT32> mPadding{0u};
std::mutex mMutex;
std::atomic<bool> mKillNow{true};
std::thread mThread;
@ -717,7 +719,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc()
if(SUCCEEDED(hr))
{
{
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
aluMixData(mDevice, buffer, len, mFrameStep);
mPadding.store(written + len, std::memory_order_relaxed);
}
@ -1167,7 +1169,7 @@ ClockLatency WasapiPlayback::getClockLatency()
{
ClockLatency ret;
std::lock_guard<std::recursive_mutex> _{mMutex};
std::lock_guard<std::mutex> _{mMutex};
ret.ClockTime = GetDeviceClockTime(mDevice);
ret.Latency = std::chrono::seconds{mPadding.load(std::memory_order_relaxed)};
ret.Latency /= mDevice->Frequency;