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
,
21 const MediaTrackConstraints
& aConstraints
)
22 : MediaStreamTrack(aWindow
, aInputTrack
, aSource
, aReadyState
, aMuted
,
25 void VideoStreamTrack::Destroy() {
26 mVideoOutputs
.Clear();
27 MediaStreamTrack::Destroy();
30 void VideoStreamTrack::AddVideoOutput(VideoFrameContainer
* aSink
) {
34 auto output
= MakeRefPtr
<VideoOutput
>(
35 aSink
, nsGlobalWindowInner::Cast(GetParentObject())
36 ->AbstractMainThreadFor(TaskCategory::Other
));
37 AddVideoOutput(output
);
40 void VideoStreamTrack::AddVideoOutput(VideoOutput
* aOutput
) {
44 for (const auto& output
: mVideoOutputs
) {
45 if (output
== aOutput
) {
46 MOZ_ASSERT_UNREACHABLE("A VideoOutput was already added");
50 mVideoOutputs
.AppendElement(aOutput
);
51 AddDirectListener(aOutput
);
55 void VideoStreamTrack::RemoveVideoOutput(VideoFrameContainer
* aSink
) {
56 for (const auto& output
: mVideoOutputs
.Clone()) {
57 if (output
->mVideoFrameContainer
== aSink
) {
58 mVideoOutputs
.RemoveElement(output
);
59 RemoveDirectListener(output
);
60 RemoveListener(output
);
65 void VideoStreamTrack::RemoveVideoOutput(VideoOutput
* aOutput
) {
66 for (const auto& output
: mVideoOutputs
.Clone()) {
67 if (output
== aOutput
) {
68 mVideoOutputs
.RemoveElement(aOutput
);
69 RemoveDirectListener(aOutput
);
70 RemoveListener(aOutput
);
75 void VideoStreamTrack::GetLabel(nsAString
& aLabel
, CallerType aCallerType
) {
76 nsIGlobalObject
* global
=
77 GetParentObject() ? GetParentObject()->AsGlobal() : nullptr;
78 if (nsContentUtils::ShouldResistFingerprinting(aCallerType
, global
,
79 RFPTarget::StreamTrackLabel
)) {
80 aLabel
.AssignLiteral("Internal Camera");
83 MediaStreamTrack::GetLabel(aLabel
, aCallerType
);
86 already_AddRefed
<MediaStreamTrack
> VideoStreamTrack::CloneInternal() {
87 return do_AddRef(new VideoStreamTrack(mWindow
, mInputTrack
, mSource
,
88 ReadyState(), Muted(), mConstraints
));
91 } // namespace mozilla::dom