summaryrefslogtreecommitdiff
path: root/voice_engine/transmit_mixer.cc
diff options
context:
space:
mode:
authorpbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-08-07 17:57:36 +0000
committerpbos@webrtc.org <pbos@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-08-07 17:57:36 +0000
commitb3ada1540827c60a63058570a94a57dfd260ad11 (patch)
tree4111b0516651b8faa696542ec02b30fad770c879 /voice_engine/transmit_mixer.cc
parentd7b06eca993d068de0d579a83511640d74ab9f77 (diff)
downloadwebrtc-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/transmit_mixer.cc')
-rw-r--r--voice_engine/transmit_mixer.cc33
1 files changed, 13 insertions, 20 deletions
diff --git a/voice_engine/transmit_mixer.cc b/voice_engine/transmit_mixer.cc
index c7c1aaed..f5ec7f67 100644
--- a/voice_engine/transmit_mixer.cc
+++ b/voice_engine/transmit_mixer.cc
@@ -305,13 +305,11 @@ TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule)
}
void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, int* max_channels) {
- ScopedChannel sc(*_channelManagerPtr);
- void* iterator = NULL;
- Channel* channel = sc.GetFirstChannel(iterator);
-
*max_sample_rate = 8000;
*max_channels = 1;
- while (channel != NULL) {
+ for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid();
+ it.Increment()) {
+ Channel* channel = it.GetChannel();
if (channel->Sending()) {
CodecInst codec;
channel->GetSendCodec(codec);
@@ -321,7 +319,6 @@ void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, int* max_channels) {
std::max(*max_sample_rate, codec.plfreq));
*max_channels = std::max(*max_channels, codec.channels);
}
- channel = sc.GetNextChannel(iterator);
}
}
@@ -424,11 +421,10 @@ TransmitMixer::DemuxAndMix()
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1),
"TransmitMixer::DemuxAndMix()");
- ScopedChannel sc(*_channelManagerPtr);
- void* iterator(NULL);
- Channel* channelPtr = sc.GetFirstChannel(iterator);
- while (channelPtr != NULL)
+ for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid();
+ it.Increment())
{
+ Channel* channelPtr = it.GetChannel();
if (channelPtr->InputIsOnHold())
{
channelPtr->UpdateLocalTimeStamp();
@@ -438,7 +434,6 @@ TransmitMixer::DemuxAndMix()
channelPtr->Demultiplex(_audioFrame);
channelPtr->PrepareEncodeAndSend(_audioFrame.sample_rate_hz_);
}
- channelPtr = sc.GetNextChannel(iterator);
}
return 0;
}
@@ -446,8 +441,8 @@ TransmitMixer::DemuxAndMix()
void TransmitMixer::DemuxAndMix(const int voe_channels[],
int number_of_voe_channels) {
for (int i = 0; i < number_of_voe_channels; ++i) {
- voe::ScopedChannel sc(*_channelManagerPtr, voe_channels[i]);
- voe::Channel* channel_ptr = sc.ChannelPtr();
+ voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]);
+ voe::Channel* channel_ptr = ch.channel();
if (channel_ptr) {
if (channel_ptr->InputIsOnHold()) {
channel_ptr->UpdateLocalTimeStamp();
@@ -466,16 +461,14 @@ TransmitMixer::EncodeAndSend()
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1),
"TransmitMixer::EncodeAndSend()");
- ScopedChannel sc(*_channelManagerPtr);
- void* iterator(NULL);
- Channel* channelPtr = sc.GetFirstChannel(iterator);
- while (channelPtr != NULL)
+ for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid();
+ it.Increment())
{
+ Channel* channelPtr = it.GetChannel();
if (channelPtr->Sending() && !channelPtr->InputIsOnHold())
{
channelPtr->EncodeAndSend();
}
- channelPtr = sc.GetNextChannel(iterator);
}
return 0;
}
@@ -483,8 +476,8 @@ TransmitMixer::EncodeAndSend()
void TransmitMixer::EncodeAndSend(const int voe_channels[],
int number_of_voe_channels) {
for (int i = 0; i < number_of_voe_channels; ++i) {
- voe::ScopedChannel sc(*_channelManagerPtr, voe_channels[i]);
- voe::Channel* channel_ptr = sc.ChannelPtr();
+ voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]);
+ voe::Channel* channel_ptr = ch.channel();
if (channel_ptr && channel_ptr->Sending() && !channel_ptr->InputIsOnHold())
channel_ptr->EncodeAndSend();
}