Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp')
-rw-r--r--extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp62
1 files changed, 30 insertions, 32 deletions
diff --git a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
index 0a50d5db2c7..3ffe97661d8 100644
--- a/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
+++ b/extern/audaspace/plugins/pulseaudio/PulseAudioDevice.cpp
@@ -27,9 +27,9 @@ void PulseAudioDevice::PulseAudio_state_callback(pa_context *context, void *data
{
PulseAudioDevice* device = (PulseAudioDevice*)data;
- device->m_state = AUD_pa_context_get_state(context);
+ std::lock_guard<ILockable> lock(*device);
- AUD_pa_threaded_mainloop_signal(device->m_mainloop, 0);
+ device->m_state = AUD_pa_context_get_state(context);
}
void PulseAudioDevice::PulseAudio_request(pa_stream *stream, size_t num_bytes, void *data)
@@ -68,29 +68,40 @@ void PulseAudioDevice::PulseAudio_underflow(pa_stream *stream, void *data)
}
}
-void PulseAudioDevice::playing(bool playing)
+void PulseAudioDevice::runMixingThread()
{
- m_playback = playing;
+ for(;;)
+ {
+ {
+ std::lock_guard<ILockable> lock(*this);
+
+ if(shouldStop())
+ {
+ AUD_pa_stream_cork(m_stream, 1, nullptr, nullptr);
+ doStop();
+ return;
+ }
+ }
+
+ if(AUD_pa_stream_is_corked(m_stream))
+ AUD_pa_stream_cork(m_stream, 0, nullptr, nullptr);
- AUD_pa_stream_cork(m_stream, playing ? 0 : 1, nullptr, nullptr);
+ AUD_pa_mainloop_iterate(m_mainloop, true, nullptr);
+ }
}
PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buffersize) :
- m_playback(false),
m_state(PA_CONTEXT_UNCONNECTED),
m_buffersize(buffersize),
m_underflows(0)
{
- m_mainloop = AUD_pa_threaded_mainloop_new();
+ m_mainloop = AUD_pa_mainloop_new();
- AUD_pa_threaded_mainloop_lock(m_mainloop);
-
- m_context = AUD_pa_context_new(AUD_pa_threaded_mainloop_get_api(m_mainloop), name.c_str());
+ m_context = AUD_pa_context_new(AUD_pa_mainloop_get_api(m_mainloop), name.c_str());
if(!m_context)
{
- AUD_pa_threaded_mainloop_unlock(m_mainloop);
- AUD_pa_threaded_mainloop_free(m_mainloop);
+ AUD_pa_mainloop_free(m_mainloop);
AUD_THROW(DeviceException, "Could not connect to PulseAudio.");
}
@@ -99,26 +110,21 @@ PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buff
AUD_pa_context_connect(m_context, nullptr, PA_CONTEXT_NOFLAGS, nullptr);
- AUD_pa_threaded_mainloop_start(m_mainloop);
-
while(m_state != PA_CONTEXT_READY)
{
switch(m_state)
{
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
- AUD_pa_threaded_mainloop_unlock(m_mainloop);
- AUD_pa_threaded_mainloop_stop(m_mainloop);
-
AUD_pa_context_disconnect(m_context);
AUD_pa_context_unref(m_context);
- AUD_pa_threaded_mainloop_free(m_mainloop);
+ AUD_pa_mainloop_free(m_mainloop);
AUD_THROW(DeviceException, "Could not connect to PulseAudio.");
break;
default:
- AUD_pa_threaded_mainloop_wait(m_mainloop);
+ AUD_pa_mainloop_iterate(m_mainloop, true, nullptr);
break;
}
}
@@ -166,13 +172,10 @@ PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buff
if(!m_stream)
{
- AUD_pa_threaded_mainloop_unlock(m_mainloop);
- AUD_pa_threaded_mainloop_stop(m_mainloop);
-
AUD_pa_context_disconnect(m_context);
AUD_pa_context_unref(m_context);
- AUD_pa_threaded_mainloop_free(m_mainloop);
+ AUD_pa_mainloop_free(m_mainloop);
AUD_THROW(DeviceException, "Could not create PulseAudio stream.");
}
@@ -188,32 +191,27 @@ PulseAudioDevice::PulseAudioDevice(std::string name, DeviceSpecs specs, int buff
buffer_attr.prebuf = -1U;
buffer_attr.tlength = buffersize;
- if(AUD_pa_stream_connect_playback(m_stream, nullptr, &buffer_attr, static_cast<pa_stream_flags_t>(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE), nullptr, nullptr) < 0)
+ if(AUD_pa_stream_connect_playback(m_stream, nullptr, &buffer_attr, static_cast<pa_stream_flags_t>(PA_STREAM_START_CORKED | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE), nullptr, nullptr) < 0)
{
- AUD_pa_threaded_mainloop_unlock(m_mainloop);
- AUD_pa_threaded_mainloop_stop(m_mainloop);
-
AUD_pa_context_disconnect(m_context);
AUD_pa_context_unref(m_context);
- AUD_pa_threaded_mainloop_free(m_mainloop);
+ AUD_pa_mainloop_free(m_mainloop);
AUD_THROW(DeviceException, "Could not connect PulseAudio stream.");
}
- AUD_pa_threaded_mainloop_unlock(m_mainloop);
-
create();
}
PulseAudioDevice::~PulseAudioDevice()
{
- AUD_pa_threaded_mainloop_stop(m_mainloop);
+ stopMixingThread();
AUD_pa_context_disconnect(m_context);
AUD_pa_context_unref(m_context);
- AUD_pa_threaded_mainloop_free(m_mainloop);
+ AUD_pa_mainloop_free(m_mainloop);
destroy();
}