Bug 1266345 - Let MediaRecorder ignore ended tracks. r=bryce, a=RyanVM
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 08 Jun 2018 12:28:55 +0200
changeset 806039 3258221fa293dbae1560110cfb46d8fcb48ee6e7
parent 806038 a2946175bb470d7ea5f3e59866432a81f19d1c79
child 806040 a2929372f83d32fed6211333c058830065e69843
push id112832
push userbballo@mozilla.com
push dateFri, 08 Jun 2018 21:11:22 +0000
reviewersbryce, RyanVM
bugs1266345
milestone60.0.3
Bug 1266345 - Let MediaRecorder ignore ended tracks. r=bryce, a=RyanVM MozReview-Commit-ID: 8P1p0uI46BZ
dom/media/MediaRecorder.cpp
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -747,41 +747,41 @@ private:
 
     if (!mRunningState.isOk() || mRunningState.unwrap() != RunningState::Idling) {
       return;
     }
 
     mMediaStream = aStream;
     aStream->RegisterTrackListener(this);
 
-    uint8_t trackTypes = 0;
-    nsTArray<RefPtr<mozilla::dom::AudioStreamTrack>> audioTracks;
-    aStream->GetAudioTracks(audioTracks);
-    if (!audioTracks.IsEmpty()) {
-      trackTypes |= ContainerWriter::CREATE_AUDIO_TRACK;
-    }
-
-    nsTArray<RefPtr<mozilla::dom::VideoStreamTrack>> videoTracks;
-    aStream->GetVideoTracks(videoTracks);
-    if (!videoTracks.IsEmpty()) {
-      trackTypes |= ContainerWriter::CREATE_VIDEO_TRACK;
-    }
-
     nsTArray<RefPtr<mozilla::dom::MediaStreamTrack>> tracks;
     aStream->GetTracks(tracks);
+    uint8_t trackTypes = 0;
+    int32_t audioTracks = 0;
+    int32_t videoTracks = 0;
     for (auto& track : tracks) {
       if (track->Ended()) {
         continue;
       }
 
       ConnectMediaStreamTrack(*track);
+
+      if (track->AsAudioStreamTrack()) {
+        ++audioTracks;
+        trackTypes |= ContainerWriter::CREATE_AUDIO_TRACK;
+      } else if (track->AsVideoStreamTrack()) {
+        ++videoTracks;
+        trackTypes |= ContainerWriter::CREATE_VIDEO_TRACK;
+      } else {
+        MOZ_CRASH("Unexpected track type");
+      }
     }
 
-    if (audioTracks.Length() > 1 ||
-        videoTracks.Length() > 1) {
+    if (audioTracks > 1 ||
+        videoTracks > 1) {
       // When MediaRecorder supports multiple tracks, we should set up a single
       // MediaInputPort from the input stream, and let main thread check
       // track principals async later.
       nsPIDOMWindowInner* window = mRecorder->GetParentObject();
       nsIDocument* document = window ? window->GetExtantDoc() : nullptr;
       nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
                                       NS_LITERAL_CSTRING("Media"),
                                       document,