Bug 1438134 - Resolve ApplyConstraints and end track on unexpected error. r?jib draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 23 Feb 2018 10:06:22 +0100
changeset 768124 126e8729eab65316708c5422481cb50ca1c7d7a7
parent 768123 d23b608ba74ab79f875e87f72c74246a666ce398
push id102808
push userbmo:apehrson@mozilla.com
push dateThu, 15 Mar 2018 18:26:32 +0000
reviewersjib
bugs1438134
milestone60.0a1
Bug 1438134 - Resolve ApplyConstraints and end track on unexpected error. r?jib MozReview-Commit-ID: 1uVHTCOwlQw
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1266,36 +1266,39 @@ public:
                 [p]()
                 {
                   if (!MediaManager::Exists()) {
                     return;
                   }
 
                   p->Resolve(false);
                 },
-                [p, weakWindow = nsWeakPtr(do_GetWeakReference(aWindow))]
+                [p, weakWindow = nsWeakPtr(do_GetWeakReference(aWindow)),
+                 listener = mListener, trackID = mTrackID]
                 (Maybe<nsString>&& aBadConstraint)
                 {
                   if (!MediaManager::Exists()) {
                     return;
                   }
 
                   if (!weakWindow->IsAlive()) {
                     return;
                   }
 
-                  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(weakWindow);
                   if (aBadConstraint.isNothing()) {
-                    auto error = MakeRefPtr<MediaStreamError>(
-                        window,
-                        NS_LITERAL_STRING("InternalError"));
-                    p->Reject(error);
+                    // Unexpected error during reconfig that left the source
+                    // stopped. We resolve the promise and end the track.
+                    if (listener) {
+                      listener->StopTrack(trackID);
+                    }
+                    p->Resolve(false);
                     return;
                   }
 
+                  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(weakWindow);
                   auto error = MakeRefPtr<MediaStreamError>(
                       window,
                       NS_LITERAL_STRING("OverConstrainedError"),
                       NS_LITERAL_STRING(""),
                       aBadConstraint.valueOr(nsString()));
                   p->Reject(error);
                 });