Backed out changeset 0c01a856e4c3 (bug 1870427) as requested by Emilio CLOSED TREE
[gecko.git] / dom / media / VideoStreamTrack.cpp
blob732f4fb9b8d46f4a0a889588d3e0a24f272221c5
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/. */
6 #include "VideoStreamTrack.h"
8 #include "MediaTrackGraph.h"
9 #include "MediaTrackListener.h"
10 #include "nsContentUtils.h"
11 #include "nsGlobalWindowInner.h"
12 #include "VideoOutput.h"
14 namespace mozilla::dom {
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) {}
25 void VideoStreamTrack::Destroy() {
26 mVideoOutputs.Clear();
27 MediaStreamTrack::Destroy();
30 void VideoStreamTrack::AddVideoOutput(VideoFrameContainer* aSink) {
31 if (Ended()) {
32 return;
34 auto output = MakeRefPtr<VideoOutput>(aSink, AbstractThread::MainThread());
35 AddVideoOutput(output);
38 void VideoStreamTrack::AddVideoOutput(VideoOutput* aOutput) {
39 if (Ended()) {
40 return;
42 for (const auto& output : mVideoOutputs) {
43 if (output == aOutput) {
44 MOZ_ASSERT_UNREACHABLE("A VideoOutput was already added");
45 return;
48 mVideoOutputs.AppendElement(aOutput);
49 AddDirectListener(aOutput);
50 AddListener(aOutput);
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);
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);
73 void VideoStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) {
74 MediaStreamTrack::GetLabel(aLabel, aCallerType);
77 already_AddRefed<MediaStreamTrack> VideoStreamTrack::CloneInternal() {
78 return do_AddRef(new VideoStreamTrack(mWindow, mInputTrack, mSource,
79 ReadyState(), Muted(), mConstraints));
82 } // namespace mozilla::dom