Bug 1406941 - Make AudioConduit more easily unit testable; r=padenot
authorDan Minor <dminor@mozilla.com>
Mon, 19 Nov 2018 17:00:43 +0000
changeset 503474 0968b25b736fbc2456ae99e21580e0f204e9ded8
parent 503473 3f0b3e4421c02371dc83404acb259512a278905b
child 503475 d68e7e8e1db2c8620d3678897532569fd711667d
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1406941
milestone65.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 1406941 - Make AudioConduit more easily unit testable; r=padenot This makes Init and DeleteChannels virtual and mRecvChannelProxy and mSendChannelProxy protected. This will allow unit test code to override the creation of channels so that we can use a mocked ChannelProxy instead. Depends on D12016 Differential Revision: https://phabricator.services.mozilla.com/D12017
media/webrtc/signaling/src/media-conduit/AudioConduit.h
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -159,46 +159,44 @@ public:
                 size_t len) override;
 
   uint64_t CodecPluginID() override { return 0; }
   void SetPCHandle(const std::string& aPCHandle) override {}
   MediaConduitErrorCode DeliverPacket(const void *data, int len) override;
 
   void DeleteStreams() override {}
 
-  explicit WebrtcAudioConduit(RefPtr<WebRtcCallWrapper> aCall,
-                              nsCOMPtr<nsIEventTarget> aStsThread)
+  WebrtcAudioConduit(RefPtr<WebRtcCallWrapper> aCall,
+                     nsCOMPtr<nsIEventTarget> aStsThread)
     : mFakeAudioDevice(new webrtc::FakeAudioDeviceModule())
     , mTransportMonitor("WebrtcAudioConduit")
     , mTransmitterTransport(nullptr)
     , mReceiverTransport(nullptr)
     , mCall(aCall)
     , mRecvStreamConfig()
     , mRecvStream(nullptr)
     , mSendStreamConfig(this) // 'this' is stored but not  dereferenced in the constructor.
     , mSendStream(nullptr)
     , mRecvSSRC(0)
     , mEngineTransmitting(false)
     , mEngineReceiving(false)
     , mRecvChannel(-1)
-    , mRecvChannelProxy(nullptr)
     , mSendChannel(-1)
-    , mSendChannelProxy(nullptr)
     , mDtmfEnabled(false)
     , mMutex("WebrtcAudioConduit::mMutex")
     , mCaptureDelay(150)
     , mSamples(0)
     , mLastSyncLog(0)
     , mStsThread(aStsThread)
   {
   }
 
   virtual ~WebrtcAudioConduit();
 
-  MediaConduitErrorCode Init();
+  virtual MediaConduitErrorCode Init();
 
   int GetRecvChannel() { return mRecvChannel; }
   webrtc::VoiceEngine* GetVoiceEngine() {
     return mCall->Call()->voice_engine();
   }
 
   /* Set Local SSRC list.
    * Note: Until the refactor of the VoE into the call API is complete
@@ -270,16 +268,21 @@ public:
   // test-only: inserts fake CSRCs and audio level data
   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
+  std::unique_ptr<webrtc::voe::ChannelProxy> mRecvChannelProxy = nullptr;
+  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,
                                 webrtc::AudioSendStream::Config& config);
 
@@ -290,17 +293,17 @@ private:
   MediaConduitErrorCode ValidateCodecConfig(const AudioCodecConfig* codecInfo, bool send);
 
   MediaConduitErrorCode CreateSendStream();
   void DeleteSendStream();
   MediaConduitErrorCode CreateRecvStream();
   void DeleteRecvStream();
 
   MediaConduitErrorCode CreateChannels();
-  void DeleteChannels();
+  virtual void DeleteChannels();
 
   UniquePtr<webrtc::FakeAudioDeviceModule> mFakeAudioDevice;
   mozilla::ReentrantMonitor mTransportMonitor;
   RefPtr<TransportInterface> mTransmitterTransport;
   RefPtr<TransportInterface> mReceiverTransport;
   ScopedCustomReleasePtr<webrtc::VoEBase> mPtrVoEBase;
 
   const RefPtr<WebRtcCallWrapper> mCall;
@@ -322,19 +325,17 @@ private:
   // (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;
 
   int mRecvChannel;
-  std::unique_ptr<webrtc::voe::ChannelProxy> mRecvChannelProxy;
   int mSendChannel;
-  std::unique_ptr<webrtc::voe::ChannelProxy> mSendChannelProxy;
   bool mDtmfEnabled;
 
   Mutex mMutex;
   nsAutoPtr<AudioCodecConfig> mCurSendCodecConfig;
 
   // Current "capture" delay (really output plus input delay)
   int32_t mCaptureDelay;