Bug 1885602 - Part 2: Add a MozillaAccountMenuButton composable for the menu redesign...
[gecko.git] / dom / media / VideoStreamTrack.cpp
blobbfb7da4e2900d987752e152de63fb896a7782099
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 nsIGlobalObject* global =
75 GetParentObject() ? GetParentObject()->AsGlobal() : nullptr;
76 if (nsContentUtils::ShouldResistFingerprinting(aCallerType, global,
77 RFPTarget::StreamTrackLabel)) {
78 aLabel.AssignLiteral("Internal Camera");
79 return;
81 MediaStreamTrack::GetLabel(aLabel, aCallerType);
84 already_AddRefed<MediaStreamTrack> VideoStreamTrack::CloneInternal() {
85 return do_AddRef(new VideoStreamTrack(mWindow, mInputTrack, mSource,
86 ReadyState(), Muted(), mConstraints));
89 } // namespace mozilla::dom