Bug 1081819 - Let the output stream itself process input data from MediaStreamAudioDestinationNode::mStream. r=roc
☠☠ backed out by 803e783be389 ☠ ☠
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 02 Mar 2015 17:08:40 +0800
changeset 232392 322d60fc413e
parent 232391 8e4e3a618c9c
child 232393 ff063b9a1ea2
push id56537
push userrjesup@wgate.com
push dateSat, 07 Mar 2015 15:33:47 +0000
treeherdermozilla-inbound@b78fd38002f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1081819
milestone39.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 1081819 - Let the output stream itself process input data from MediaStreamAudioDestinationNode::mStream. r=roc
dom/media/TrackUnionStream.cpp
dom/media/TrackUnionStream.h
dom/media/webaudio/MediaStreamAudioDestinationNode.cpp
--- a/dom/media/TrackUnionStream.cpp
+++ b/dom/media/TrackUnionStream.cpp
@@ -45,18 +45,17 @@ namespace mozilla {
 #ifdef PR_LOGGING
 PRLogModuleInfo* gTrackUnionStreamLog;
 #define STREAM_LOG(type, msg) PR_LOG(gTrackUnionStreamLog, type, msg)
 #else
 #define STREAM_LOG(type, msg)
 #endif
 
 TrackUnionStream::TrackUnionStream(DOMMediaStream* aWrapper) :
-  ProcessedMediaStream(aWrapper),
-  mFilterCallback(nullptr)
+  ProcessedMediaStream(aWrapper)
 {
 #ifdef PR_LOGGING
   if (!gTrackUnionStreamLog) {
     gTrackUnionStreamLog = PR_NewLogModule("TrackUnionStream");
   }
 #endif
 }
 
@@ -109,17 +108,17 @@ TrackUnionStream::TrackUnionStream(DOMMe
               CopyTrackData(tracks.get(), j, aFrom, aTo, &trackFinished);
             }
             mappedTracksFinished[j] = trackFinished;
             mappedTracksWithMatchingInputTracks[j] = true;
             found = true;
             break;
           }
         }
-        if (!found && (!mFilterCallback || mFilterCallback(tracks.get()))) {
+        if (!found) {
           bool trackFinished = false;
           trackAdded = true;
           uint32_t mapIndex = AddTrack(mInputs[i], tracks.get(), aFrom);
           CopyTrackData(tracks.get(), mapIndex, aFrom, aTo, &trackFinished);
           mappedTracksFinished.AppendElement(trackFinished);
           mappedTracksWithMatchingInputTracks.AppendElement(true);
         }
       }
@@ -148,24 +147,16 @@ TrackUnionStream::TrackUnionStream(DOMMe
       mBuffer.AdvanceKnownTracksTime(GraphTimeToStreamTime(aTo));
     }
     if (allHaveCurrentData) {
       // We can make progress if we're not blocked
       mHasCurrentData = true;
     }
   }
 
-  // Consumers may specify a filtering callback to apply to every input track.
-  // Returns true to allow the track to act as an input; false to reject it entirely.
-
-  void TrackUnionStream::SetTrackIDFilter(TrackIDFilterCallback aCallback)
-  {
-    mFilterCallback = aCallback;
-  }
-
   // Forward SetTrackEnabled(output_track_id, enabled) to the Source MediaStream,
   // translating the output track ID into the correct ID in the source.
   void TrackUnionStream::ForwardTrackEnabled(TrackID aOutputID, bool aEnabled)
   {
     for (int32_t i = mTrackMap.Length() - 1; i >= 0; --i) {
       if (mTrackMap[i].mOutputTrackID == aOutputID) {
         mTrackMap[i].mInputPort->GetSource()->
           SetTrackEnabled(mTrackMap[i].mInputTrackID, aEnabled);
--- a/dom/media/TrackUnionStream.h
+++ b/dom/media/TrackUnionStream.h
@@ -16,29 +16,21 @@ namespace mozilla {
  */
 class TrackUnionStream : public ProcessedMediaStream {
 public:
   explicit TrackUnionStream(DOMMediaStream* aWrapper);
 
   virtual void RemoveInput(MediaInputPort* aPort) MOZ_OVERRIDE;
   virtual void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) MOZ_OVERRIDE;
 
-  // Consumers may specify a filtering callback to apply to every input track.
-  // Returns true to allow the track to act as an input; false to reject it entirely.
-  typedef bool (*TrackIDFilterCallback)(StreamBuffer::Track*);
-
-  void SetTrackIDFilter(TrackIDFilterCallback aCallback);
-
   // Forward SetTrackEnabled(output_track_id, enabled) to the Source MediaStream,
   // translating the output track ID into the correct ID in the source.
   virtual void ForwardTrackEnabled(TrackID aOutputID, bool aEnabled) MOZ_OVERRIDE;
 
 protected:
-  TrackIDFilterCallback mFilterCallback;
-
   // Only non-ended tracks are allowed to persist in this map.
   struct TrackMapEntry {
     // mEndOfConsumedInputTicks is the end of the input ticks that we've consumed.
     // 0 if we haven't consumed any yet.
     StreamTime mEndOfConsumedInputTicks;
     // mEndOfLastInputIntervalInInputStream is the timestamp for the end of the
     // previous interval which was unblocked for both the input and output
     // stream, in the input stream's timeline, or -1 if there wasn't one.
--- a/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp
+++ b/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp
@@ -18,70 +18,31 @@ namespace dom {
 NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaStreamAudioDestinationNode, AudioNode, mDOMStream)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamAudioDestinationNode)
 NS_INTERFACE_MAP_END_INHERITING(AudioNode)
 
 NS_IMPL_ADDREF_INHERITED(MediaStreamAudioDestinationNode, AudioNode)
 NS_IMPL_RELEASE_INHERITED(MediaStreamAudioDestinationNode, AudioNode)
 
-static const int MEDIA_STREAM_DEST_TRACK_ID = 2;
-static_assert(MEDIA_STREAM_DEST_TRACK_ID != AudioNodeStream::AUDIO_TRACK,
-              "MediaStreamAudioDestinationNode::MEDIA_STREAM_DEST_TRACK_ID must be a different value than AudioNodeStream::AUDIO_TRACK");
-
-class MediaStreamDestinationEngine : public AudioNodeEngine {
-public:
-  MediaStreamDestinationEngine(AudioNode* aNode, ProcessedMediaStream* aOutputStream)
-    : AudioNodeEngine(aNode)
-    , mOutputStream(aOutputStream)
-  {
-    MOZ_ASSERT(mOutputStream);
-  }
-
-  virtual void ProcessBlock(AudioNodeStream* aStream,
-                            const AudioChunk& aInput,
-                            AudioChunk* aOutput,
-                            bool* aFinished) MOZ_OVERRIDE
-  {
-    *aOutput = aInput;
-    StreamBuffer::Track* track = mOutputStream->EnsureTrack(MEDIA_STREAM_DEST_TRACK_ID);
-    AudioSegment* segment = track->Get<AudioSegment>();
-    segment->AppendAndConsumeChunk(aOutput);
-  }
-
-  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
-  {
-    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
-  }
-
-private:
-  ProcessedMediaStream* mOutputStream;
-};
-
-// This callback is used to ensure that only the audio data for this track is audible
-static bool FilterAudioNodeStreamTrack(StreamBuffer::Track* aTrack)
-{
-  return aTrack->GetID() == MEDIA_STREAM_DEST_TRACK_ID;
-}
-
 MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Explicit,
               ChannelInterpretation::Speakers)
-  , mDOMStream(DOMAudioNodeMediaStream::CreateTrackUnionStream(GetOwner(),
-                                                               this))
+  , mDOMStream(DOMAudioNodeMediaStream::CreateTrackUnionStream(GetOwner(), this))
 {
-  TrackUnionStream* tus = static_cast<TrackUnionStream*>(mDOMStream->GetStream());
-  MOZ_ASSERT(tus == mDOMStream->GetStream()->AsProcessedStream());
-  tus->SetTrackIDFilter(FilterAudioNodeStreamTrack);
+  // Ensure an audio track with the correct ID is exposed to JS
+  mDOMStream->CreateDOMTrack(AudioNodeStream::AUDIO_TRACK, MediaSegment::AUDIO);
 
-  MediaStreamDestinationEngine* engine = new MediaStreamDestinationEngine(this, tus);
-  mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::INTERNAL_STREAM);
-  mPort = tus->AllocateInputPort(mStream, 0);
+  ProcessedMediaStream* outputStream = mDOMStream->GetStream()->AsProcessedStream();
+  MOZ_ASSERT(!!outputStream);
+  AudioNodeEngine* engine = new AudioNodeEngine(this);
+  mStream = aContext->Graph()->CreateAudioNodeStream(engine, MediaStreamGraph::EXTERNAL_STREAM);
+  mPort = outputStream->AllocateInputPort(mStream);
 
   nsIDocument* doc = aContext->GetParentObject()->GetExtantDoc();
   if (doc) {
     mDOMStream->CombineWithPrincipal(doc->NodePrincipal());
   }
 }
 
 MediaStreamAudioDestinationNode::~MediaStreamAudioDestinationNode()