diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index 9dece421a768..9e15b4722a12 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -371,6 +371,7 @@ PeerConnectionImpl::~PeerConnectionImpl() { // probably want to shut it down more aggressively to save memory. We // could shut down here when there are no uses. It might be more optimal // to release off a timer (and XPCOM Shutdown) to avoid churn + ShutdownMedia(); } nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver, @@ -469,27 +470,6 @@ nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver, return NS_ERROR_FAILURE; } - mMedia = new PeerConnectionMedia(this); - - // Connect ICE slots. - mMedia->SignalIceGatheringStateChange.connect( - this, &PeerConnectionImpl::IceGatheringStateChange); - mMedia->SignalUpdateDefaultCandidate.connect( - this, &PeerConnectionImpl::UpdateDefaultCandidate); - mMedia->SignalIceConnectionStateChange.connect( - this, &PeerConnectionImpl::IceConnectionStateChange); - - mMedia->SignalCandidate.connect(this, &PeerConnectionImpl::CandidateReady); - - // Initialize the media object. - res = mMedia->Init(); - if (NS_FAILED(res)) { - CSFLogError(LOGTAG, "%s: Couldn't initialize media object", __FUNCTION__); - return res; - } - - PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this; - mJsepSession = MakeUnique(mName, MakeUnique()); @@ -523,6 +503,27 @@ nsresult PeerConnectionImpl::Initialize(PeerConnectionObserver& aObserver, return res; } + mMedia = new PeerConnectionMedia(this); + + // Initialize the media object. + res = mMedia->Init(); + if (NS_FAILED(res)) { + CSFLogError(LOGTAG, "%s: Couldn't initialize media object", __FUNCTION__); + ShutdownMedia(); + return res; + } + + // Connect ICE slots. + mMedia->SignalIceGatheringStateChange.connect( + this, &PeerConnectionImpl::IceGatheringStateChange); + mMedia->SignalUpdateDefaultCandidate.connect( + this, &PeerConnectionImpl::UpdateDefaultCandidate); + mMedia->SignalIceConnectionStateChange.connect( + this, &PeerConnectionImpl::IceConnectionStateChange); + mMedia->SignalCandidate.connect(this, &PeerConnectionImpl::CandidateReady); + + PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this; + return NS_OK; }