Bug 1201363 - Adding Add/RemoveVideoOutput into VideoStreamTrack. r=jesup
authorctai <ctai@mozilla.com>
Tue, 19 Jul 2016 11:45:27 +0800
changeset 308255 8ec3f1abad0a0773d924f95c2053b855fe4cfd54
parent 308254 8248c1bc1b17f0ab1b3090bd61493410f81cc546
child 308256 647046fe760c30364990fec0c3c4c40a78d7ef25
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1201363
milestone51.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 1201363 - Adding Add/RemoveVideoOutput into VideoStreamTrack. r=jesup MozReview-Commit-ID: JmKotuB3pBM
dom/html/HTMLMediaElement.cpp
dom/media/VideoStreamTrack.cpp
dom/media/VideoStreamTrack.h
dom/media/VideoTrackList.cpp
dom/media/VideoTrackList.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3636,27 +3636,41 @@ void HTMLMediaElement::UpdateSrcMediaStr
 
     stream->AddAudioOutput(this);
     SetVolumeInternal();
 
     VideoFrameContainer* container = GetVideoFrameContainer();
     if (container) {
       stream->AddVideoOutput(container);
     }
+    VideoTrack* videoTrack = VideoTracks()->GetSelectedTrack();
+    if (videoTrack) {
+      VideoStreamTrack* videoStreamTrack = videoTrack->GetVideoStreamTrack();
+      if (videoStreamTrack && container) {
+        videoStreamTrack->AddVideoOutput(container);
+      }
+    }
   } else {
     if (stream) {
       mSrcStreamPausedCurrentTime = CurrentTime();
 
       stream->RemoveListener(mMediaStreamListener);
 
       stream->RemoveAudioOutput(this);
       VideoFrameContainer* container = GetVideoFrameContainer();
       if (container) {
         stream->RemoveVideoOutput(container);
       }
+      VideoTrack* videoTrack = VideoTracks()->GetSelectedTrack();
+      if (videoTrack) {
+        VideoStreamTrack* videoStreamTrack = videoTrack->GetVideoStreamTrack();
+        if (videoStreamTrack && container) {
+          videoStreamTrack->RemoveVideoOutput(container);
+        }
+      }
     }
     // If stream is null, then DOMMediaStream::Destroy must have been
     // called and that will remove all listeners/outputs.
 
     mWatchManager.Unwatch(*mMediaStreamListener,
         &HTMLMediaElement::UpdateReadyStateInternal);
 
     mMediaStreamListener->Forget();
--- a/dom/media/VideoStreamTrack.cpp
+++ b/dom/media/VideoStreamTrack.cpp
@@ -1,20 +1,35 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "VideoStreamTrack.h"
 
+#include "MediaStreamVideoSink.h"
+#include "MediaStreamGraph.h"
+
 #include "mozilla/dom/VideoStreamTrackBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 JSObject*
 VideoStreamTrack::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return VideoStreamTrackBinding::Wrap(aCx, this, aGivenProto);
 }
 
+void
+VideoStreamTrack::AddVideoOutput(MediaStreamVideoSink* aSink)
+{
+  GetOwnedStream()->AddVideoOutput(aSink, mTrackID);
+}
+
+void
+VideoStreamTrack::RemoveVideoOutput(MediaStreamVideoSink* aSink)
+{
+  GetOwnedStream()->RemoveVideoOutput(aSink, mTrackID);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/VideoStreamTrack.h
+++ b/dom/media/VideoStreamTrack.h
@@ -5,32 +5,38 @@
 
 #ifndef VIDEOSTREAMTRACK_H_
 #define VIDEOSTREAMTRACK_H_
 
 #include "MediaStreamTrack.h"
 #include "DOMMediaStream.h"
 
 namespace mozilla {
+
+class MediaStreamVideoSink;
+
 namespace dom {
 
 class VideoStreamTrack : public MediaStreamTrack {
 public:
   VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
                    TrackID aInputTrackID,
                    MediaStreamTrackSource* aSource,
                    const MediaTrackConstraints& aConstraints = MediaTrackConstraints())
     : MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource, aConstraints) {}
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   VideoStreamTrack* AsVideoStreamTrack() override { return this; }
 
   const VideoStreamTrack* AsVideoStreamTrack() const override { return this; }
 
+  void AddVideoOutput(MediaStreamVideoSink* aSink);
+  void RemoveVideoOutput(MediaStreamVideoSink* aSink);
+
   // WebIDL
   void GetKind(nsAString& aKind) override { aKind.AssignLiteral("video"); }
 
 protected:
   already_AddRefed<MediaStreamTrack> CloneInternal(DOMMediaStream* aOwningStream,
                                                    TrackID aTrackID) override
   {
     return do_AddRef(new VideoStreamTrack(aOwningStream,
--- a/dom/media/VideoTrackList.cpp
+++ b/dom/media/VideoTrackList.cpp
@@ -60,16 +60,25 @@ VideoTrackList::RemoveTrack(const RefPtr
 
 void
 VideoTrackList::EmptyTracks()
 {
   mSelectedIndex = -1;
   MediaTrackList::EmptyTracks();
 }
 
+VideoTrack* VideoTrackList::GetSelectedTrack()
+{
+  if (mSelectedIndex < 0 || static_cast<size_t>(mSelectedIndex) >= mTracks.Length()) {
+    return nullptr;
+  }
+
+  return operator[](mSelectedIndex);
+}
+
 VideoTrack*
 VideoTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
   MediaTrack* track = MediaTrackList::IndexedGetter(aIndex, aFound);
   return track ? track->AsVideoTrack() : nullptr;
 }
 
 VideoTrack*
--- a/dom/media/VideoTrackList.h
+++ b/dom/media/VideoTrackList.h
@@ -27,16 +27,18 @@ public:
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   VideoTrack* operator[](uint32_t aIndex);
 
   void RemoveTrack(const RefPtr<MediaTrack>& aTrack) override;
 
   void EmptyTracks() override;
 
+  VideoTrack* GetSelectedTrack();
+
   // WebIDL
   int32_t SelectedIndex() const
   {
     return mSelectedIndex;
   }
 
   VideoTrack* IndexedGetter(uint32_t aIndex, bool& aFound);