Bug 1414829 - Add DeleteStreams to media conduits. r=jesup, a=RyanVM
authorDan Minor <dminor@mozilla.com>
Mon, 08 Jan 2018 12:40:38 -0500
changeset 473246 1330aa85e30631db9c953b9ae7362e65c2e4b93c
parent 473245 54590a5776c58ed294a157cea3c8fcbd222bd7f1
child 473247 22b0467a2aaa189c7ca7ccc4642213eea7514f9c
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, RyanVM
bugs1414829
milestone61.0
Bug 1414829 - Add DeleteStreams to media conduits. r=jesup, a=RyanVM
media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.h
media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.h
media/webrtc/signaling/src/peerconnection/TransceiverImpl.cpp
--- a/media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
+++ b/media/webrtc/signaling/gtest/mediaconduit_unittests.cpp
@@ -535,16 +535,18 @@ class TransportConduitTest : public ::te
     EXPECT_TRUE(err != mozilla::kMediaConduitNoError);
 
     cerr << "   *************************************************" << endl;
     cerr << "    3. Null Codec Parameter  " << endl;
     cerr << "   *************************************************" << endl;
 
     err = videoSession->ConfigureSendMediaCodec(nullptr);
     EXPECT_TRUE(err != mozilla::kMediaConduitNoError);
+
+    videoSession->DeleteStreams();
   }
 
  private:
   //Audio Conduit Test Objects
   RefPtr<mozilla::AudioSessionConduit> mAudioSession;
   RefPtr<mozilla::AudioSessionConduit> mAudioSession2;
   RefPtr<mozilla::TransportInterface> mAudioTransport;
   AudioSendAndReceive audioTester;
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.h
@@ -166,16 +166,18 @@ public:
    * AudioConduit registers itself as ExternalTransport to the VoiceEngine
    */
   virtual bool SendRtcp(const uint8_t *data,
                         size_t len) override;
 
   virtual uint64_t CodecPluginID() override { return 0; }
   virtual void SetPCHandle(const std::string& aPCHandle) override {}
 
+  virtual void DeleteStreams() override {}
+
   explicit WebrtcAudioConduit():
                       mVoiceEngine(nullptr),
                       mFakeAudioDevice(new webrtc::FakeAudioDeviceModule()),
                       mTransportMonitor("WebrtcAudioConduit"),
                       mTransmitterTransport(nullptr),
                       mReceiverTransport(nullptr),
                       mEngineTransmitting(false),
                       mEngineReceiving(false),
--- a/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
+++ b/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h
@@ -308,16 +308,18 @@ public:
   virtual bool GetRTCPSenderReport(DOMHighResTimeStamp* timestamp,
                                    unsigned int* packetsSent,
                                    uint64_t* bytesSent) = 0;
 
   virtual uint64_t CodecPluginID() = 0;
 
   virtual void SetPCHandle(const std::string& aPCHandle) = 0;
 
+  virtual void DeleteStreams() = 0;
+
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaSessionConduit)
 
 };
 
 // Abstract base classes for external encoder/decoder.
 class CodecPluginID
 {
 public:
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -316,17 +316,17 @@ WebrtcVideoConduit::~WebrtcVideoConduit(
     CSFLogDebug(LOGTAG, "canceling StreamStats for VideoConduit: %p", this);
     MutexAutoLock lock(mCodecMutex);
     CSFLogDebug(LOGTAG, "StreamStats cancelled for VideoConduit: %p", this);
     mVideoStatsTimer->Cancel();
   }
 
   // Release AudioConduit first by dropping reference on MainThread, where it expects to be
   SyncTo(nullptr);
-  Destroy();
+  MOZ_ASSERT(!mSendStream && !mRecvStream, "Call DeleteStreams prior to ~WebrtcVideoConduit.");
 }
 
 MediaConduitErrorCode
 WebrtcVideoConduit::SetLocalRTPExtensions(LocalDirection aDirection,
                                           const RtpExtList& aExtensions)
 {
   auto& extList = aDirection == LocalDirection::kSend ?
                                     mSendStreamConfig.rtp.extensions :
@@ -1214,17 +1214,17 @@ WebrtcVideoConduit::Init()
     return result;
   }
 
   CSFLogError(LOGTAG, "%s Initialization Done", __FUNCTION__);
   return kMediaConduitNoError;
 }
 
 void
-WebrtcVideoConduit::Destroy()
+WebrtcVideoConduit::DeleteStreams()
 {
   // We can't delete the VideoEngine until all these are released!
   // And we can't use a Scoped ptr, since the order is arbitrary
 
   MutexAutoLock lock(mCodecMutex);
   DeleteSendStream();
   DeleteRecvStream();
 }
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h
@@ -227,16 +227,18 @@ public:
   void OnSinkWantsChanged(const rtc::VideoSinkWants& wants);
 
   virtual uint64_t CodecPluginID() override;
 
   virtual void SetPCHandle(const std::string& aPCHandle) override {
     mPCHandle = aPCHandle;
   }
 
+  virtual void DeleteStreams() override;
+
   unsigned int SendingMaxFs() override {
     if(mCurSendCodecConfig) {
       return mCurSendCodecConfig->mEncodingConstraints.maxFs;
     }
     return 0;
   }
 
   unsigned int SendingMaxFr() override {
@@ -263,17 +265,16 @@ public:
   }
 
   WebrtcVideoConduit(RefPtr<WebRtcCallWrapper> aCall,
                      UniquePtr<cricket::VideoAdapter>&& aVideoAdapter);
   virtual ~WebrtcVideoConduit();
 
   MediaConduitErrorCode InitMain();
   virtual MediaConduitErrorCode Init();
-  virtual void Destroy();
 
   std::vector<unsigned int> GetLocalSSRCs() const override;
   bool SetLocalSSRCs(const std::vector<unsigned int> & ssrcs) override;
   bool GetRemoteSSRC(unsigned int* ssrc) override;
   bool SetRemoteSSRC(unsigned int ssrc) override;
   bool SetLocalCNAME(const char* cname) override;
   bool SetLocalMID(const std::string& mid) override;
 
--- a/media/webrtc/signaling/src/peerconnection/TransceiverImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/TransceiverImpl.cpp
@@ -135,16 +135,19 @@ TransceiverImpl::UpdateSinkIdentity(cons
 void
 TransceiverImpl::Shutdown_m()
 {
   mReceivePipeline->Shutdown_m();
   mTransmitPipeline->Shutdown_m();
   mReceivePipeline = nullptr;
   mTransmitPipeline = nullptr;
   mSendTrack = nullptr;
+  if (mConduit) {
+    mConduit->DeleteStreams();
+  }
   mConduit = nullptr;
   RUN_ON_THREAD(mStsThread, WrapRelease(mRtpFlow.forget()), NS_DISPATCH_NORMAL);
   RUN_ON_THREAD(mStsThread, WrapRelease(mRtcpFlow.forget()), NS_DISPATCH_NORMAL);
 }
 
 nsresult
 TransceiverImpl::UpdateSendTrack(dom::MediaStreamTrack* aSendTrack)
 {