2013-03-27 05:32:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "VideoStreamTrack.h"
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
#include "MediaTrackGraph.h"
|
|
|
|
#include "MediaTrackListener.h"
|
2017-10-13 06:57:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-22 14:45:31 +03:00
|
|
|
#include "nsGlobalWindowInner.h"
|
2019-06-10 16:10:49 +03:00
|
|
|
#include "VideoOutput.h"
|
2016-07-19 06:45:27 +03:00
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-07-31 10:58:17 +03:00
|
|
|
VideoStreamTrack::VideoStreamTrack(nsPIDOMWindowInner* aWindow,
|
2019-10-02 13:23:02 +03:00
|
|
|
mozilla::MediaTrack* aInputTrack,
|
2019-03-22 14:41:39 +03:00
|
|
|
MediaStreamTrackSource* aSource,
|
2019-08-19 22:26:25 +03:00
|
|
|
MediaStreamTrackState aReadyState,
|
2019-03-22 14:41:39 +03:00
|
|
|
const MediaTrackConstraints& aConstraints)
|
2019-10-02 13:23:02 +03:00
|
|
|
: MediaStreamTrack(aWindow, aInputTrack, aSource, aReadyState,
|
2019-08-19 22:26:25 +03:00
|
|
|
aConstraints) {}
|
2019-03-22 14:41:39 +03:00
|
|
|
|
|
|
|
void VideoStreamTrack::Destroy() {
|
|
|
|
mVideoOutputs.Clear();
|
|
|
|
MediaStreamTrack::Destroy();
|
2016-07-19 06:45:27 +03:00
|
|
|
}
|
|
|
|
|
2019-03-22 14:41:39 +03:00
|
|
|
void VideoStreamTrack::AddVideoOutput(VideoFrameContainer* aSink) {
|
2019-07-31 10:58:17 +03:00
|
|
|
if (Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-10 16:10:49 +03:00
|
|
|
auto output = MakeRefPtr<VideoOutput>(
|
|
|
|
aSink, nsGlobalWindowInner::Cast(GetParentObject())
|
|
|
|
->AbstractMainThreadFor(TaskCategory::Other));
|
|
|
|
AddVideoOutput(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoStreamTrack::AddVideoOutput(VideoOutput* aOutput) {
|
2019-07-31 10:58:17 +03:00
|
|
|
if (Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-22 14:41:39 +03:00
|
|
|
for (const auto& output : mVideoOutputs) {
|
2019-06-10 16:10:49 +03:00
|
|
|
if (output == aOutput) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("A VideoOutput was already added");
|
2019-03-22 14:41:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-06-10 16:10:49 +03:00
|
|
|
mVideoOutputs.AppendElement(aOutput);
|
|
|
|
AddDirectListener(aOutput);
|
|
|
|
AddListener(aOutput);
|
2019-03-22 14:41:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoStreamTrack::RemoveVideoOutput(VideoFrameContainer* aSink) {
|
|
|
|
for (const auto& output : nsTArray<RefPtr<VideoOutput>>(mVideoOutputs)) {
|
|
|
|
if (output->mVideoFrameContainer == aSink) {
|
|
|
|
mVideoOutputs.RemoveElement(output);
|
2019-03-22 14:41:48 +03:00
|
|
|
RemoveDirectListener(output);
|
|
|
|
RemoveListener(output);
|
2019-03-22 14:41:39 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-19 06:45:27 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:10:49 +03:00
|
|
|
void VideoStreamTrack::RemoveVideoOutput(VideoOutput* aOutput) {
|
|
|
|
for (const auto& output : nsTArray<RefPtr<VideoOutput>>(mVideoOutputs)) {
|
|
|
|
if (output == aOutput) {
|
|
|
|
mVideoOutputs.RemoveElement(aOutput);
|
|
|
|
RemoveDirectListener(aOutput);
|
|
|
|
RemoveListener(aOutput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-13 06:57:25 +03:00
|
|
|
void VideoStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
aLabel.AssignLiteral("Internal Camera");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MediaStreamTrack::GetLabel(aLabel, aCallerType);
|
|
|
|
}
|
|
|
|
|
2019-08-19 22:26:25 +03:00
|
|
|
already_AddRefed<MediaStreamTrack> VideoStreamTrack::CloneInternal() {
|
2019-10-02 13:23:02 +03:00
|
|
|
return do_AddRef(new VideoStreamTrack(mWindow, mInputTrack, mSource,
|
2019-10-02 13:22:53 +03:00
|
|
|
ReadyState(), mConstraints));
|
2019-08-19 22:26:25 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|