VideoStreamTrack.cpp (2515B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "VideoStreamTrack.h" 7 8 #include "MediaTrackGraph.h" 9 #include "MediaTrackListener.h" 10 #include "VideoOutput.h" 11 #include "nsContentUtils.h" 12 #include "nsGlobalWindowInner.h" 13 14 namespace mozilla::dom { 15 16 VideoStreamTrack::VideoStreamTrack(nsPIDOMWindowInner* aWindow, 17 mozilla::MediaTrack* aInputTrack, 18 MediaStreamTrackSource* aSource, 19 MediaStreamTrackState aReadyState, 20 bool aMuted, 21 const MediaTrackConstraints& aConstraints) 22 : MediaStreamTrack(aWindow, aInputTrack, aSource, aReadyState, aMuted, 23 aConstraints) {} 24 25 void VideoStreamTrack::Destroy() { 26 mVideoOutputs.Clear(); 27 MediaStreamTrack::Destroy(); 28 } 29 30 void VideoStreamTrack::AddVideoOutput(VideoFrameContainer* aSink) { 31 if (Ended()) { 32 return; 33 } 34 auto output = MakeRefPtr<VideoOutput>(aSink, AbstractThread::MainThread()); 35 AddVideoOutput(output); 36 } 37 38 void VideoStreamTrack::AddVideoOutput(VideoOutput* aOutput) { 39 if (Ended()) { 40 return; 41 } 42 for (const auto& output : mVideoOutputs) { 43 if (output == aOutput) { 44 MOZ_ASSERT_UNREACHABLE("A VideoOutput was already added"); 45 return; 46 } 47 } 48 mVideoOutputs.AppendElement(aOutput); 49 AddDirectListener(aOutput); 50 AddListener(aOutput); 51 } 52 53 void VideoStreamTrack::RemoveVideoOutput(VideoFrameContainer* aSink) { 54 for (const auto& output : mVideoOutputs.Clone()) { 55 if (output->mVideoFrameContainer == aSink) { 56 mVideoOutputs.RemoveElement(output); 57 RemoveDirectListener(output); 58 RemoveListener(output); 59 } 60 } 61 } 62 63 void VideoStreamTrack::RemoveVideoOutput(VideoOutput* aOutput) { 64 for (const auto& output : mVideoOutputs.Clone()) { 65 if (output == aOutput) { 66 mVideoOutputs.RemoveElement(aOutput); 67 RemoveDirectListener(aOutput); 68 RemoveListener(aOutput); 69 } 70 } 71 } 72 73 void VideoStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) { 74 MediaStreamTrack::GetLabel(aLabel, aCallerType); 75 } 76 77 already_AddRefed<MediaStreamTrack> VideoStreamTrack::Clone() { 78 return MediaStreamTrack::CloneInternal<VideoStreamTrack>(); 79 } 80 81 } // namespace mozilla::dom