Bug 1506884 - Document member thread access in AudioConduit; r=padenot
☠☠ backed out by a0084ecbf671 ☠ ☠
authorDan Minor <dminor@mozilla.com>
Wed, 27 Mar 2019 16:55:04 +0000
changeset 525220 0182d6543001d10fc7504518df4a487c444d1e7a
parent 525219 5837db3740b54ff6e34d90ee0da41fe909022e06
child 525221 c1e32495cfa21fd094896d0c12201c06a33120a8
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1506884
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506884 - Document member thread access in AudioConduit; r=padenot This also removes some unused member variables. Differential Revision: https://phabricator.services.mozilla.com/D25056
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.h
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -931,51 +931,55 @@ MediaConduitErrorCode WebrtcAudioConduit
     CSFLogError(LOGTAG, "%s Channel Unsupported ", __FUNCTION__);
     return kMediaConduitMalformedArgument;
   }
 
   return kMediaConduitNoError;
 }
 
 void WebrtcAudioConduit::DeleteSendStream() {
+  MOZ_ASSERT(NS_IsMainThread());
   mMutex.AssertCurrentThreadOwns();
   if (mSendStream) {
     mSendStream->Stop();
     mEngineTransmitting = false;
     mCall->Call()->DestroyAudioSendStream(mSendStream);
     mSendStream = nullptr;
   }
   // Destroying the stream unregisters the transport
   mSendChannelProxy->RegisterTransport(nullptr);
 }
 
 MediaConduitErrorCode WebrtcAudioConduit::CreateSendStream() {
+  MOZ_ASSERT(NS_IsMainThread());
   mMutex.AssertCurrentThreadOwns();
 
   mSendStream = mCall->Call()->CreateAudioSendStream(mSendStreamConfig);
   if (!mSendStream) {
     return kMediaConduitUnknownError;
   }
 
   return kMediaConduitNoError;
 }
 
 void WebrtcAudioConduit::DeleteRecvStream() {
+  MOZ_ASSERT(NS_IsMainThread());
   mMutex.AssertCurrentThreadOwns();
   if (mRecvStream) {
     mRecvStream->Stop();
     mEngineReceiving = false;
     mCall->Call()->DestroyAudioReceiveStream(mRecvStream);
     mRecvStream = nullptr;
   }
   // Destroying the stream unregisters the transport
   mRecvChannelProxy->RegisterTransport(nullptr);
 }
 
 MediaConduitErrorCode WebrtcAudioConduit::CreateRecvStream() {
+  MOZ_ASSERT(NS_IsMainThread());
   mMutex.AssertCurrentThreadOwns();
 
   mRecvStreamConfig.rtcp_send_transport = this;
   mRecvStream = mCall->Call()->CreateAudioReceiveStream(mRecvStreamConfig);
   if (!mRecvStream) {
     return kMediaConduitUnknownError;
   }
 
@@ -1078,16 +1082,17 @@ MediaConduitErrorCode WebrtcAudioConduit
   mSendChannelProxy->SetRtpPacketObserver(this);
   mSendChannelProxy->RegisterTransport(this);
 
   return kMediaConduitNoError;
 }
 
 void WebrtcAudioConduit::DeleteChannels() {
   MOZ_ASSERT(NS_IsMainThread());
+  mMutex.AssertCurrentThreadOwns();
 
   if (mSendChannel != -1) {
     mSendChannelProxy = nullptr;
     mPtrVoEBase->DeleteChannel(mSendChannel);
     mSendChannel = -1;
   }
 
   if (mRecvChannel != -1) {
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -169,18 +169,17 @@ class WebrtcAudioConduit : public AudioS
   uint64_t CodecPluginID() override { return 0; }
   void SetPCHandle(const std::string& aPCHandle) override {}
   MediaConduitErrorCode DeliverPacket(const void* data, int len) override;
 
   void DeleteStreams() override;
 
   WebrtcAudioConduit(RefPtr<WebRtcCallWrapper> aCall,
                      nsCOMPtr<nsIEventTarget> aStsThread)
-      : mFakeAudioDevice(new webrtc::FakeAudioDeviceModule()),
-        mTransportMonitor("WebrtcAudioConduit"),
+      : mTransportMonitor("WebrtcAudioConduit"),
         mTransmitterTransport(nullptr),
         mReceiverTransport(nullptr),
         mCall(aCall),
         mRecvStreamConfig(),
         mRecvStream(nullptr),
         mSendStreamConfig(
             this)  // 'this' is stored but not  dereferenced in the constructor.
         ,
@@ -247,17 +246,26 @@ class WebrtcAudioConduit : public AudioS
   void InsertAudioLevelForContributingSource(uint32_t aSource,
                                              int64_t aTimestamp, bool aHasLevel,
                                              uint8_t aLevel);
 
   bool IsSamplingFreqSupported(int freq) const override;
 
  protected:
   // These are protected so they can be accessed by unit tests
+
+  // Written only on main thread. Accessed from audio thread.
+  // Accessed from mStsThread during stats calls.
+  // This is safe, provided audio and stats calls stop before we
+  // destroy the AudioConduit.
   std::unique_ptr<webrtc::voe::ChannelProxy> mRecvChannelProxy = nullptr;
+
+  // Written only on main thread. Accessed from mStsThread during stats calls.
+  // This is safe, provided stats calls stop before we destroy the
+  // AudioConduit.
   std::unique_ptr<webrtc::voe::ChannelProxy> mSendChannelProxy = nullptr;
 
  private:
   WebrtcAudioConduit(const WebrtcAudioConduit& other) = delete;
   void operator=(const WebrtcAudioConduit& other) = delete;
 
   // Function to convert between WebRTC and Conduit codec structures
   bool CodecConfigToWebRTCCodec(const AudioCodecConfig* codecInfo,
@@ -276,60 +284,77 @@ class WebrtcAudioConduit : public AudioS
   void DeleteRecvStream();
 
   bool RecreateSendStreamIfExists();
   bool RecreateRecvStreamIfExists();
 
   MediaConduitErrorCode CreateChannels();
   virtual void DeleteChannels();
 
-  UniquePtr<webrtc::FakeAudioDeviceModule> mFakeAudioDevice;
   mozilla::ReentrantMonitor mTransportMonitor;
+
+  // Accessed on any thread under mTransportMonitor.
   RefPtr<TransportInterface> mTransmitterTransport;
+
+  // Accessed on any thread under mTransportMonitor.
   RefPtr<TransportInterface> mReceiverTransport;
+
+  // Accessed from main thread and audio threads. Used to create and destroy
+  // channels and to send audio data. Access to channels is protected by
+  // locking in channel.cc.
   ScopedCustomReleasePtr<webrtc::VoEBase> mPtrVoEBase;
 
+  // Const so can be accessed on any thread. Most methods are called on
+  // main thread.
   const RefPtr<WebRtcCallWrapper> mCall;
+
+  // Written only on main thread. Guarded by mMutex, except for reads on main.
   webrtc::AudioReceiveStream::Config mRecvStreamConfig;
+
+  // Written only on main thread. Guarded by mMutex, except for reads on main.
   webrtc::AudioReceiveStream* mRecvStream;
+
+  // Written only on main thread. Guarded by mMutex, except for reads on main.
   webrtc::AudioSendStream::Config mSendStreamConfig;
+
+  // Written only on main thread. Guarded by mMutex, except for reads on main.
   webrtc::AudioSendStream* mSendStream;
 
   // accessed on creation, and when receiving packets
   Atomic<uint32_t> mRecvSSRC;  // this can change during a stream!
+
+  // Accessed only on mStsThread.
   RtpPacketQueue mRtpPacketQueue;
 
   // engine states of our interets
   mozilla::Atomic<bool>
       mEngineTransmitting;  // If true => VoiceEngine Send-subsystem is up
   mozilla::Atomic<bool>
       mEngineReceiving;  // If true => VoiceEngine Receive-subsystem is up
                          // and playout is enabled
-  // Keep track of each inserted RTP block and the time it was inserted
-  // so we can estimate the clock time for a specific TimeStamp coming out
-  // (for when we send data to MediaStreamTracks).  Blocks are aged out as
-  // needed.
-  struct Processing {
-    TimeStamp mTimeStamp;
-    uint32_t mRTPTimeStamp;  // RTP timestamps received
-  };
-  AutoTArray<Processing, 8> mProcessing;
+
+  // Accessed only on main thread.
+  int mRecvChannel;
 
-  int mRecvChannel;
+  // Accessed on main thread and from audio thread.
   int mSendChannel;
+
+  // Accessed only on main thread.
   bool mDtmfEnabled;
 
   Mutex mMutex;
-  nsAutoPtr<AudioCodecConfig> mCurSendCodecConfig;
 
   // Current "capture" delay (really output plus input delay)
+  // Written from main thread. Read from audio thread.
   int32_t mCaptureDelay;
 
+  // Accessed from audio thread.
   webrtc::AudioFrame mAudioFrame;  // for output pulls
 
+  // Accessed from both main and mStsThread. Uses locks internally.
   RtpSourceObserver mRtpSourceObserver;
 
   // Socket transport service thread. Any thread.
   const nsCOMPtr<nsIEventTarget> mStsThread;
 };
 
 }  // namespace mozilla