summaryrefslogtreecommitdiff
path: root/voice_engine/channel.h
diff options
context:
space:
mode:
authorhenrika@webrtc.org <henrika@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-03-18 10:32:33 +0000
committerhenrika@webrtc.org <henrika@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2014-03-18 10:32:33 +0000
commitdf08c5d53f4b11b7687e419e04f99f55b85490c4 (patch)
tree87f072a20c2f8841e6d35936185ddd473effe4ca /voice_engine/channel.h
parent0c0c604cc69b862daffd3f825c335cdc39e0a223 (diff)
downloadwebrtc-df08c5d53f4b11b7687e419e04f99f55b85490c4.tar.gz
Resolves TSan v2 warnings in voe_auto_test.
See bug report for details. BUG=1590 R=tommi@webrtc.org, xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/9859004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@5714 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'voice_engine/channel.h')
-rw-r--r--voice_engine/channel.h110
1 files changed, 91 insertions, 19 deletions
diff --git a/voice_engine/channel.h b/voice_engine/channel.h
index 954d6ea3..f3bc0966 100644
--- a/voice_engine/channel.h
+++ b/voice_engine/channel.h
@@ -63,6 +63,91 @@ class StatisticsProxy;
class TransmitMixer;
class OutputMixer;
+// Helper class to simplify locking scheme for members that are accessed from
+// multiple threads.
+// Example: a member can be set on thread T1 and read by an internal audio
+// thread T2. Accessing the member via this class ensures that we are
+// safe and also avoid TSan v2 warnings.
+class ChannelState {
+ public:
+ struct State {
+ State() : rx_apm_is_enabled(false),
+ input_external_media(false),
+ output_is_on_hold(false),
+ output_file_playing(false),
+ input_file_playing(false),
+ playing(false),
+ sending(false),
+ receiving(false) {}
+
+ bool rx_apm_is_enabled;
+ bool input_external_media;
+ bool output_is_on_hold;
+ bool output_file_playing;
+ bool input_file_playing;
+ bool playing;
+ bool sending;
+ bool receiving;
+ };
+
+ ChannelState() : lock_(CriticalSectionWrapper::CreateCriticalSection()) {
+ }
+ virtual ~ChannelState() {}
+
+ void Reset() {
+ CriticalSectionScoped lock(lock_.get());
+ state_ = State();
+ }
+
+ State Get() const {
+ CriticalSectionScoped lock(lock_.get());
+ return state_;
+ }
+
+ void SetRxApmIsEnabled(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.rx_apm_is_enabled = enable;
+ }
+
+ void SetInputExternalMedia(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.input_external_media = enable;
+ }
+
+ void SetOutputIsOnHold(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.output_is_on_hold = enable;
+ }
+
+ void SetOutputFilePlaying(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.output_file_playing = enable;
+ }
+
+ void SetInputFilePlaying(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.input_file_playing = enable;
+ }
+
+ void SetPlaying(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.playing = enable;
+ }
+
+ void SetSending(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.sending = enable;
+ }
+
+ void SetReceiving(bool enable) {
+ CriticalSectionScoped lock(lock_.get());
+ state_.receiving = enable;
+ }
+
+private:
+ scoped_ptr<CriticalSectionWrapper> lock_;
+ State state_;
+};
class Channel:
public RtpData,
@@ -371,32 +456,25 @@ public:
}
bool Playing() const
{
- return _playing;
+ return channel_state_.Get().playing;
}
bool Sending() const
{
- // A lock is needed because |_sending| is accessed by both
- // TransmitMixer::PrepareDemux() and StartSend()/StopSend(), which
- // are called by different threads.
- CriticalSectionScoped cs(&_callbackCritSect);
- return _sending;
+ return channel_state_.Get().sending;
}
bool Receiving() const
{
- return _receiving;
+ return channel_state_.Get().receiving;
}
bool ExternalTransport() const
{
+ CriticalSectionScoped cs(&_callbackCritSect);
return _externalTransport;
}
bool ExternalMixing() const
{
return _externalMixing;
}
- bool OutputIsOnHold() const
- {
- return _outputIsOnHold;
- }
bool InputIsOnHold() const
{
return _inputIsOnHold;
@@ -448,6 +526,8 @@ private:
uint32_t _instanceId;
int32_t _channelId;
+ ChannelState channel_state_;
+
scoped_ptr<RtpHeaderParser> rtp_header_parser_;
scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
@@ -471,12 +551,9 @@ private:
int _inputFilePlayerId;
int _outputFilePlayerId;
int _outputFileRecorderId;
- bool _inputFilePlaying;
- bool _outputFilePlaying;
bool _outputFileRecording;
DtmfInbandQueue _inbandDtmfQueue;
DtmfInband _inbandDtmfGenerator;
- bool _inputExternalMedia;
bool _outputExternalMedia;
VoEMediaProcess* _inputExternalMediaCallbackPtr;
VoEMediaProcess* _outputExternalMediaCallbackPtr;
@@ -509,13 +586,9 @@ private:
VoERTPObserver* _rtpObserverPtr;
VoERTCPObserver* _rtcpObserverPtr;
// VoEBase
- bool _outputIsOnHold;
bool _externalPlayout;
bool _externalMixing;
bool _inputIsOnHold;
- bool _playing;
- bool _sending;
- bool _receiving;
bool _mixFileWithMicrophone;
bool _rtpObserver;
bool _rtcpObserver;
@@ -548,7 +621,6 @@ private:
uint16_t _recPacketDelayMs;
// VoEAudioProcessing
bool _RxVadDetection;
- bool _rxApmIsEnabled;
bool _rxAgcIsEnabled;
bool _rxNsIsEnabled;
bool restored_packet_in_use_;