[Summary] Implemented Condition/Lock synchronization for Engine HW enevt handling

This commit is contained in:
GZharun 2014-07-03 17:12:51 +03:00
parent ff909cf10b
commit daf365ced0
3 changed files with 41 additions and 12 deletions

View file

@ -247,9 +247,13 @@ public:
Glib::Threads::Thread* _hw_reset_event_thread;
gint _hw_reset_request_count;
Glib::Threads::Cond _hw_reset_condition;
Glib::Threads::Mutex _reset_request_lock;
gint _stop_hw_reset_processing;
Glib::Threads::Thread* _hw_devicelist_update_thread;
gint _hw_devicelist_update_count;
Glib::Threads::Cond _hw_devicelist_update_condition;
Glib::Threads::Mutex _devicelist_update_lock;
gint _stop_hw_devicelist_processing;
void start_hw_event_processing();

View file

@ -365,7 +365,9 @@ AudioEngine::process_callback (pframes_t nframes)
void
AudioEngine::request_backend_reset()
{
g_atomic_int_inc(&_hw_reset_request_count);
Glib::Threads::Mutex::Lock guard (_reset_request_lock);
g_atomic_int_inc (&_hw_reset_request_count);
_hw_reset_condition.signal ();
}
@ -374,10 +376,14 @@ AudioEngine::do_reset_backend()
{
SessionEvent::create_per_thread_pool (X_("Backend reset processing thread"), 512);
Glib::Threads::Mutex::Lock guard (_reset_request_lock);
while (!_stop_hw_reset_processing) {
if (_hw_reset_request_count && _backend) {
_reset_request_lock.unlock();
g_atomic_int_dec_and_test (&_hw_reset_request_count);
// backup the device name
@ -387,21 +393,26 @@ AudioEngine::do_reset_backend()
if (_session) {
// it's not a halt, but should be handled the same way:
// disable record, stop transport and I/O processign but save the data.
_session->engine_halted();
_session->engine_halted ();
}
// "hard reset" the device
_backend->drop_device();
_backend->set_device_name(name);
_backend->drop_device ();
_backend->set_device_name (name);
start();
start ();
// inform about possible changes
SampleRateChanged(_backend->sample_rate() );
BufferSizeChanged(_backend->buffer_size() );
}
SampleRateChanged (_backend->sample_rate() );
BufferSizeChanged (_backend->buffer_size() );
g_usleep(0);
_reset_request_lock.lock();
} else {
_hw_reset_condition.wait (_reset_request_lock);
}
}
}
@ -409,7 +420,9 @@ AudioEngine::do_reset_backend()
void
AudioEngine::request_device_list_update()
{
Glib::Threads::Mutex::Lock guard (_devicelist_update_lock);
g_atomic_int_inc (&_hw_devicelist_update_count);
_hw_devicelist_update_condition.signal ();
}
@ -418,12 +431,22 @@ AudioEngine::do_devicelist_update()
{
SessionEvent::create_per_thread_pool (X_("Device list update processing thread"), 512);
Glib::Threads::Mutex::Lock guard (_devicelist_update_lock);
while (!_stop_hw_devicelist_processing) {
if (_hw_devicelist_update_count) {
_devicelist_update_lock.unlock();
g_atomic_int_dec_and_test (&_hw_devicelist_update_count);
DeviceListChanged (); /* EMIT SIGNAL */
DeviceListChanged (); /* EMIT SIGNAL */
_devicelist_update_lock.lock();
} else {
_hw_devicelist_update_condition.wait (_devicelist_update_lock);
}
g_usleep(0);
}
}
@ -451,6 +474,7 @@ AudioEngine::stop_hw_event_processing()
if (_hw_reset_event_thread) {
g_atomic_int_set(&_stop_hw_reset_processing, 1);
g_atomic_int_set(&_hw_reset_request_count, 0);
_hw_reset_condition.signal ();
_hw_reset_event_thread->join ();
_hw_reset_event_thread = 0;
}
@ -458,6 +482,7 @@ AudioEngine::stop_hw_event_processing()
if (_hw_devicelist_update_thread) {
g_atomic_int_set(&_stop_hw_devicelist_processing, 1);
g_atomic_int_set(&_hw_devicelist_update_count, 0);
_hw_devicelist_update_condition.signal ();
_hw_devicelist_update_thread->join ();
_hw_devicelist_update_thread = 0;
}

View file

@ -2198,7 +2198,7 @@ OSStatus WCMRCoreAudioDevice::AudioIOProc(AudioUnitRenderActionFlags * ioAction
AudioBufferList inputAudioBufferList;
inputAudioBufferList.mNumberBuffers = 1;
inputAudioBufferList.mBuffers[0].mNumberChannels = m_InputChannels.size();
inputAudioBufferList.mBuffers[0].mDataByteSize = expectedDataSize*10;
inputAudioBufferList.mBuffers[0].mDataByteSize = expectedDataSize;
inputAudioBufferList.mBuffers[0].mData = NULL;//new float[expectedDataSize]; // we are going to get buffer from CoreAudio
retVal = AudioUnitRender(m_AUHALAudioUnit, ioActionFlags, inTimeStamp, AUHAL_INPUT_ELEMENT, inNumberFrames, &inputAudioBufferList);