Bug 1435673 - Fix calling Deallocate() without SetTrack(). r?padenot
Before
bug 1299515 we assigned stream and track id in Allocate(), meaning that
any Deallocate() had a guarantee of them being set.
This changed to require an extra step of SetTrack() to assign stream and
track id. Deallocate() needs to handle this, which it does with this patch.
MozReview-Commit-ID: Js0cXXOR2Bb
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -211,20 +211,20 @@ MediaEngineRemoteVideoSource::Allocate(
nsresult
MediaEngineRemoteVideoSource::Deallocate(const RefPtr<const AllocationHandle>& aHandle)
{
LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
MOZ_ASSERT(mState == kStopped || mState == kAllocated);
- MOZ_ASSERT(mStream);
- MOZ_ASSERT(IsTrackIDExplicit(mTrackID));
- mStream->EndTrack(mTrackID);
+ if (mStream && IsTrackIDExplicit(mTrackID)) {
+ mStream->EndTrack(mTrackID);
+ }
{
MutexAutoLock lock(mMutex);
mStream = nullptr;
mTrackID = TRACK_NONE;
mPrincipal = PRINCIPAL_HANDLE_NONE;
mState = kReleased;
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -192,17 +192,19 @@ MediaEngineTabVideoSource::Reconfigure(c
nsresult
MediaEngineTabVideoSource::Deallocate(const RefPtr<const AllocationHandle>& aHandle)
{
AssertIsOnOwningThread();
MOZ_ASSERT(!aHandle);
MOZ_ASSERT(mState == kAllocated || mState == kStopped);
- MOZ_ASSERT(IsTrackIDExplicit(mTrackID));
+ if (mStream && IsTrackIDExplicit(mTrackID)) {
+ mStream->EndTrack(mTrackID);
+ }
NS_DispatchToMainThread(do_AddRef(new DestroyRunnable(this)));
{
MutexAutoLock lock(mMutex);
mState = kReleased;
}
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -595,17 +595,20 @@ nsresult
MediaEngineWebRTCMicrophoneSource::Deallocate(const RefPtr<const AllocationHandle>& aHandle)
{
AssertIsOnOwningThread();
size_t i = mAllocations.IndexOf(aHandle, 0, AllocationHandleComparator());
MOZ_ASSERT(i != mAllocations.NoIndex);
MOZ_ASSERT(!mAllocations[i].mEnabled,
"Source should be stopped for the track before removing");
- mAllocations[i].mStream->EndTrack(mAllocations[i].mTrackID);
+ if (mAllocations[i].mStream && IsTrackIDExplicit(mAllocations[i].mTrackID)) {
+ mAllocations[i].mStream->EndTrack(mAllocations[i].mTrackID);
+ }
+
{
MutexAutoLock lock(mMutex);
mAllocations.RemoveElementAt(i);
}
if (mAllocations.IsEmpty()) {
// If empty, no callbacks to deliver data should be occuring
MOZ_ASSERT(mState != kReleased, "Source not allocated");