diff options
author | pbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-08-07 17:57:36 +0000 |
---|---|---|
committer | pbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-08-07 17:57:36 +0000 |
commit | b3ada1540827c60a63058570a94a57dfd260ad11 (patch) | |
tree | 4111b0516651b8faa696542ec02b30fad770c879 /voice_engine/shared_data.cc | |
parent | d7b06eca993d068de0d579a83511640d74ab9f77 (diff) | |
download | webrtc-b3ada1540827c60a63058570a94a57dfd260ad11.tar.gz |
Ref-counted rewrite of ChannelManager.
The complexity of the last ChannelManager and potentially usage of it as well caused race conditions and deadlocks in loopback voe_auto_test. This ref-counted solution takes no long-term locks, uses less locks overall and is significantly easier to understand.
ScopedChannel has been split up into a ChannelOwner with a reference to a channel and an Iterator over ChannelManager. Previous code was really used for both things. ChannelOwner is used as a shared pointer to a channel object, while an Iterator should work as expected.
BUG=2081
R=tommi@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1802004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@4502 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'voice_engine/shared_data.cc')
-rw-r--r-- | voice_engine/shared_data.cc | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/voice_engine/shared_data.cc b/voice_engine/shared_data.cc index e993778b..843d5db6 100644 --- a/voice_engine/shared_data.cc +++ b/voice_engine/shared_data.cc @@ -76,32 +76,17 @@ void SharedData::set_audio_processing(AudioProcessing* audioproc) { _outputMixerPtr->SetAudioProcessingModule(audioproc); } -uint16_t SharedData::NumOfSendingChannels() -{ - int32_t numOfChannels = _channelManager.NumOfChannels(); - if (numOfChannels <= 0) - { - return 0; - } +uint16_t SharedData::NumOfSendingChannels() { + ChannelManager::Iterator it(&_channelManager); + uint16_t sending_channels = 0; - uint16_t nChannelsSending(0); - int32_t* channelsArray = new int32_t[numOfChannels]; + for (ChannelManager::Iterator it(&_channelManager); it.IsValid(); + it.Increment()) { + if (it.GetChannel()->Sending()) + ++sending_channels; + } - _channelManager.GetChannelIds(channelsArray, numOfChannels); - for (int i = 0; i < numOfChannels; i++) - { - voe::ScopedChannel sc(_channelManager, channelsArray[i]); - Channel* chPtr = sc.ChannelPtr(); - if (chPtr) - { - if (chPtr->Sending()) - { - nChannelsSending++; - } - } - } - delete [] channelsArray; - return nChannelsSending; + return sending_channels; } void SharedData::SetLastError(int32_t error) const { |