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
>(aSink
, AbstractThread::MainThread());
35 AddVideoOutput(output
);
38 void VideoStreamTrack::AddVideoOutput(VideoOutput
* aOutput
) {
42 for (const auto& output
: mVideoOutputs
) {
43 if (output
== aOutput
) {
44 MOZ_ASSERT_UNREACHABLE("A VideoOutput was already added");
48 mVideoOutputs
.AppendElement(aOutput
);
49 AddDirectListener(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