[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; Glib::Threads::Thread* _hw_reset_event_thread;
gint _hw_reset_request_count; gint _hw_reset_request_count;
Glib::Threads::Cond _hw_reset_condition;
Glib::Threads::Mutex _reset_request_lock;
gint _stop_hw_reset_processing; gint _stop_hw_reset_processing;
Glib::Threads::Thread* _hw_devicelist_update_thread; Glib::Threads::Thread* _hw_devicelist_update_thread;
gint _hw_devicelist_update_count; gint _hw_devicelist_update_count;
Glib::Threads::Cond _hw_devicelist_update_condition;
Glib::Threads::Mutex _devicelist_update_lock;
gint _stop_hw_devicelist_processing; gint _stop_hw_devicelist_processing;
void start_hw_event_processing(); void start_hw_event_processing();

View file

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

View file

@ -2198,7 +2198,7 @@ OSStatus WCMRCoreAudioDevice::AudioIOProc(AudioUnitRenderActionFlags * ioAction
AudioBufferList inputAudioBufferList; AudioBufferList inputAudioBufferList;
inputAudioBufferList.mNumberBuffers = 1; inputAudioBufferList.mNumberBuffers = 1;
inputAudioBufferList.mBuffers[0].mNumberChannels = m_InputChannels.size(); 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 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); retVal = AudioUnitRender(m_AUHALAudioUnit, ioActionFlags, inTimeStamp, AUHAL_INPUT_ELEMENT, inNumberFrames, &inputAudioBufferList);