Bug 1517324 - part1 : try to start blocked AudioContext with active MediaStreamAudioSourceNode stream r=karlt
authorAlastor Wu <alwu@mozilla.com>
Wed, 06 Feb 2019 23:14:09 +0000
changeset 457646 a04946ac4b3cdcd957b6636dd0212c96c6362e18
parent 457645 7f66045a90f2d433aa71064f8ee06d24467dd5ad
child 457647 0f80b6c7fb66f1d1e7c048ca038440328ec632a7
push id35516
push userrmaries@mozilla.com
push dateFri, 08 Feb 2019 04:23:26 +0000
treeherdermozilla-central@d599d1a73a3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1517324
milestone67.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 1517324 - part1 : try to start blocked AudioContext with active MediaStreamAudioSourceNode stream r=karlt This patch would try to start a blocked AudioContext when it creates a MediaStreamAudioSourceNode which has an active input stream or when a node's inactive stream becomes active, which means someone is feeding input data to AudioContext. Therefore, we can do the similar thing like what we did for AudioScheduledSourceNode and MediaElementAudioSourceNode, to start AudioContext if current autoplay policy has allowed AudioContext to start. Differential Revision: https://phabricator.services.mozilla.com/D18576
dom/media/webaudio/MediaStreamAudioSourceNode.cpp
dom/media/webaudio/MediaStreamAudioSourceNode.h
--- a/dom/media/webaudio/MediaStreamAudioSourceNode.cpp
+++ b/dom/media/webaudio/MediaStreamAudioSourceNode.cpp
@@ -92,16 +92,19 @@ void MediaStreamAudioSourceNode::Init(DO
   }
 
   mInputStream = aMediaStream;
   AudioNodeEngine* engine = new MediaStreamAudioSourceNodeEngine(this);
   mStream = AudioNodeExternalInputStream::Create(graph, engine);
   mInputStream->AddConsumerToKeepAlive(ToSupports(this));
 
   mInputStream->RegisterTrackListener(this);
+  if (mInputStream->Active()) {
+    NotifyActive();
+  }
   AttachToFirstTrack(mInputStream);
 }
 
 void MediaStreamAudioSourceNode::Destroy() {
   if (mInputStream) {
     mInputStream->UnregisterTrackListener(this);
     mInputStream = nullptr;
   }
@@ -175,16 +178,21 @@ void MediaStreamAudioSourceNode::NotifyT
   if (aTrack != mInputTrack) {
     return;
   }
 
   DetachFromTrack();
   AttachToFirstTrack(mInputStream);
 }
 
+void MediaStreamAudioSourceNode::NotifyActive() {
+  MOZ_ASSERT(mInputStream);
+  Context()->StartBlockedAudioContextIfAllowed();
+}
+
 /**
  * Changes the principal. Note that this will be called on the main thread, but
  * changes will be enacted on the MediaStreamGraph thread. If the principal
  * change results in the document principal losing access to the stream, then
  * there needs to be other measures in place to ensure that any media that is
  * governed by the new stream principal is not available to the MediaStreamGraph
  * before this change completes. Otherwise, a site could get access to
  * media that they are not authorized to receive.
--- a/dom/media/webaudio/MediaStreamAudioSourceNode.h
+++ b/dom/media/webaudio/MediaStreamAudioSourceNode.h
@@ -81,16 +81,17 @@ class MediaStreamAudioSourceNode
   void DetachFromTrack();
 
   // Attaches to the first available audio track in aMediaStream.
   void AttachToFirstTrack(const RefPtr<DOMMediaStream>& aMediaStream);
 
   // From DOMMediaStream::TrackListener.
   void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) override;
   void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override;
+  void NotifyActive() override;
 
   // From PrincipalChangeObserver<MediaStreamTrack>.
   void PrincipalChanged(MediaStreamTrack* aMediaStreamTrack) override;
 
  protected:
   explicit MediaStreamAudioSourceNode(AudioContext* aContext);
   void Init(DOMMediaStream* aMediaStream, ErrorResult& aRv);
   virtual void Destroy();