Bug 1594136 - Check for ended track in MediaStreamTrackAudioSourceNode. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 13 Nov 2019 13:13:48 +0000
changeset 501734 7a55cb6e7aecdd0d3fb786fefe8cc165558b78e0
parent 501733 9473f8de212155dedc4eb74165211636324262bc
child 501735 35436d4e7917bf9d9b96a6173201ca001a8ff7bc
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1594136
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594136 - Check for ended track in MediaStreamTrackAudioSourceNode. r=padenot Depends on D52521 Differential Revision: https://phabricator.services.mozilla.com/D52522
dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
--- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
+++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
@@ -44,17 +44,18 @@ MediaStreamTrackAudioSourceNode::MediaSt
 MediaStreamTrackAudioSourceNode::Create(
     AudioContext& aAudioContext,
     const MediaStreamTrackAudioSourceOptions& aOptions, ErrorResult& aRv) {
   if (aAudioContext.IsOffline()) {
     aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
   }
 
-  if (aAudioContext.Graph() != aOptions.mMediaStreamTrack->Graph()) {
+  if (!aOptions.mMediaStreamTrack->Ended() &&
+      aAudioContext.Graph() != aOptions.mMediaStreamTrack->Graph()) {
     nsCOMPtr<nsPIDOMWindowInner> pWindow = aAudioContext.GetParentObject();
     Document* document = pWindow ? pWindow->GetExtantDoc() : nullptr;
     nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                     NS_LITERAL_CSTRING("Web Audio"), document,
                                     nsContentUtils::eDOM_PROPERTIES,
                                     "MediaStreamAudioSourceNodeDifferentRate");
     aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
@@ -71,21 +72,26 @@ MediaStreamTrackAudioSourceNode::Create(
   return node.forget();
 }
 
 void MediaStreamTrackAudioSourceNode::Init(MediaStreamTrack* aMediaStreamTrack,
                                            ErrorResult& aRv) {
   MOZ_ASSERT(aMediaStreamTrack);
 
   if (!aMediaStreamTrack->AsAudioStreamTrack()) {
-    mTrackListener.NotifyEnded(nullptr);
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
+  if (aMediaStreamTrack->Ended()) {
+    // The track is ended and will never produce any data. Pretend like this is
+    // fine.
+    return;
+  }
+
   MediaTrackGraph* graph = Context()->Graph();
 
   AudioNodeEngine* engine = new MediaStreamTrackAudioSourceNodeEngine(this);
   mTrack = AudioNodeExternalInputTrack::Create(graph, engine);
 
   MOZ_ASSERT(mTrack);
 
   mInputTrack = aMediaStreamTrack;
@@ -95,21 +101,21 @@ void MediaStreamTrackAudioSourceNode::In
   PrincipalChanged(mInputTrack);  // trigger enabling/disabling of the connector
   mInputTrack->AddPrincipalChangeObserver(this);
 
   mInputTrack->AddConsumer(&mTrackListener);
 }
 
 void MediaStreamTrackAudioSourceNode::Destroy() {
   if (mInputTrack) {
+    mTrackListener.NotifyEnded(mInputTrack);
     mInputTrack->RemovePrincipalChangeObserver(this);
     mInputTrack->RemoveConsumer(&mTrackListener);
     mInputTrack = nullptr;
   }
-  mTrackListener.NotifyEnded(mInputTrack);
 
   if (mInputPort) {
     mInputPort->Destroy();
     mInputPort = nullptr;
   }
 }
 
 MediaStreamTrackAudioSourceNode::~MediaStreamTrackAudioSourceNode() {