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"
|
|
|
|
|
2016-07-19 06:45:27 +03:00
|
|
|
#include "MediaStreamGraph.h"
|
2019-03-22 14:41:39 +03:00
|
|
|
#include "MediaStreamListener.h"
|
2017-10-13 06:57:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-22 14:41:39 +03:00
|
|
|
#include "VideoFrameContainer.h"
|
2016-07-19 06:45:27 +03:00
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
namespace mozilla {
|
2019-03-22 14:41:39 +03:00
|
|
|
|
|
|
|
class VideoOutput : public DirectMediaStreamTrackListener {
|
|
|
|
protected:
|
|
|
|
virtual ~VideoOutput() = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit VideoOutput(VideoFrameContainer* aContainer)
|
|
|
|
: mVideoFrameContainer(aContainer) {}
|
|
|
|
void NotifyRealtimeTrackData(MediaStreamGraph* aGraph,
|
|
|
|
StreamTime aTrackOffset,
|
|
|
|
const MediaSegment& aMedia) override {
|
|
|
|
MOZ_ASSERT(aMedia.GetType() == MediaSegment::VIDEO);
|
|
|
|
const VideoSegment& video = static_cast<const VideoSegment&>(aMedia);
|
2019-03-22 14:41:48 +03:00
|
|
|
mSegment.ForgetUpToTime(TimeStamp::Now());
|
|
|
|
for (VideoSegment::ConstChunkIterator i(video); !i.IsEnded(); i.Next()) {
|
|
|
|
if (!mLastFrameTime.IsNull() && i->mTimeStamp < mLastFrameTime) {
|
|
|
|
// Time can go backwards if the source is a captured MediaDecoder and
|
|
|
|
// it seeks, as the previously buffered frames would stretch into the
|
|
|
|
// future. If this happens, we clear the buffered frames and start over.
|
|
|
|
mSegment.Clear();
|
|
|
|
}
|
|
|
|
const VideoFrame& f = i->mFrame;
|
2019-03-22 14:43:40 +03:00
|
|
|
mSegment.AppendFrame(do_AddRef(f.GetImage()), f.GetIntrinsicSize(),
|
2019-03-22 14:41:48 +03:00
|
|
|
f.GetPrincipalHandle(), f.GetForceBlack(),
|
|
|
|
i->mTimeStamp);
|
|
|
|
mLastFrameTime = i->mTimeStamp;
|
|
|
|
}
|
|
|
|
mVideoFrameContainer->SetCurrentFrames(mSegment);
|
2019-03-22 14:41:39 +03:00
|
|
|
}
|
2019-03-22 14:41:48 +03:00
|
|
|
void NotifyRemoved() override {
|
|
|
|
mSegment.Clear();
|
2019-03-22 14:41:39 +03:00
|
|
|
mVideoFrameContainer->ClearFrames();
|
|
|
|
}
|
2019-03-22 14:41:48 +03:00
|
|
|
void NotifyEnded() override { mSegment.Clear(); }
|
2019-03-22 14:41:39 +03:00
|
|
|
|
2019-03-22 14:41:48 +03:00
|
|
|
TimeStamp mLastFrameTime;
|
|
|
|
VideoSegment mSegment;
|
2019-03-22 14:41:39 +03:00
|
|
|
const RefPtr<VideoFrameContainer> mVideoFrameContainer;
|
|
|
|
};
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2019-03-22 14:41:39 +03:00
|
|
|
VideoStreamTrack::VideoStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
|
|
|
|
TrackID aInputTrackID,
|
|
|
|
MediaStreamTrackSource* aSource,
|
|
|
|
const MediaTrackConstraints& aConstraints)
|
|
|
|
: MediaStreamTrack(aStream, aTrackID, aInputTrackID, aSource,
|
|
|
|
aConstraints) {}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
for (const auto& output : mVideoOutputs) {
|
|
|
|
if (output->mVideoFrameContainer == aSink) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("A VideoFrameContainer was already added");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefPtr<VideoOutput>& output =
|
|
|
|
*mVideoOutputs.AppendElement(MakeRefPtr<VideoOutput>(aSink));
|
2019-03-22 14:41:48 +03:00
|
|
|
AddDirectListener(output);
|
|
|
|
AddListener(output);
|
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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|