2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2011 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
2015-01-20 21:36:13 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/video_track.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2021-05-24 16:54:41 +02:00
|
|
|
#include <utility>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <vector>
|
2017-10-30 09:57:42 -07:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/notifier.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2022-02-17 13:19:55 +01:00
|
|
|
VideoTrack::VideoTrack(
|
2022-05-30 11:26:40 +02:00
|
|
|
absl::string_view label,
|
2022-02-17 13:19:55 +01:00
|
|
|
rtc::scoped_refptr<
|
|
|
|
|
VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> source,
|
|
|
|
|
rtc::Thread* worker_thread)
|
2013-07-10 00:45:36 +00:00
|
|
|
: MediaStreamTrack<VideoTrackInterface>(label),
|
2017-07-31 23:22:01 -07:00
|
|
|
worker_thread_(worker_thread),
|
2022-02-17 13:19:55 +01:00
|
|
|
video_source_(std::move(source)),
|
2016-12-16 15:39:11 -08:00
|
|
|
content_hint_(ContentHint::kNone) {
|
2021-05-24 16:54:41 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
|
|
|
|
// Detach the thread checker for VideoSourceBaseGuarded since we'll make calls
|
|
|
|
|
// to VideoSourceBaseGuarded on the worker thread, but we're currently on the
|
|
|
|
|
// signaling thread.
|
|
|
|
|
source_sequence_.Detach();
|
2016-03-23 00:33:56 -07:00
|
|
|
video_source_->RegisterObserver(this);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoTrack::~VideoTrack() {
|
2021-05-24 16:54:41 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
2016-03-23 00:33:56 -07:00
|
|
|
video_source_->UnregisterObserver(this);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string VideoTrack::kind() const {
|
2015-11-25 11:26:01 -08:00
|
|
|
return kVideoKind;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-07 07:45:54 -07:00
|
|
|
// AddOrUpdateSink and RemoveSink should be called on the worker
|
|
|
|
|
// thread.
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
|
|
|
|
|
const rtc::VideoSinkWants& wants) {
|
2021-05-24 16:54:41 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
VideoSourceBaseGuarded::AddOrUpdateSink(sink, wants);
|
2016-03-17 10:35:23 +01:00
|
|
|
rtc::VideoSinkWants modified_wants = wants;
|
2022-02-14 23:48:41 +01:00
|
|
|
modified_wants.black_frames = !enabled_w_;
|
2022-02-17 13:28:57 +01:00
|
|
|
video_source_->internal()->AddOrUpdateSink(sink, modified_wants);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
Reland of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/2471783002/ )
Reason for revert:
Relanding after known downstream breakages have been fixed.
Original issue's description:
> Revert of Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame. (patchset #7 id:120001 of https://codereview.webrtc.org/2383093002/ )
>
> Reason for revert:
> Breaks chrome, see https://build.chromium.org/p/chromium.webrtc.fyi/builders/Mac%20Builder/builds/19019/steps/compile/logs/stdio
>
> Analysis: Chrome uses cricket::VideoFrame, without explicitly including webrtc/media/base/videoframe.h, and breaks when that file is no longer included by any other webrtc headers. Will reland after updating Chrome.
>
> Original issue's description:
> > Delete all use of cricket::VideoFrame and cricket::WebRtcVideoFrame.
> >
> > Replaced with webrtc::VideoFrame.
> >
> > TBR=mflodman@webrtc.org
> > BUG=webrtc:5682
> >
> > Committed: https://crrev.com/45c8b8940042bd2574c39920804ade8343cefdba
> > Cr-Commit-Position: refs/heads/master@{#14885}
>
> TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5682
>
> Committed: https://crrev.com/7341ab8e2505c9763d208e069bda269018357e7d
> Cr-Commit-Position: refs/heads/master@{#14886}
TBR=perkj@webrtc.org,pthatcher@webrtc.org,tkchin@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5682
Review-Url: https://codereview.webrtc.org/2487633002
Cr-Commit-Position: refs/heads/master@{#15039}
2016-11-11 03:55:13 -08:00
|
|
|
void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
|
2021-05-24 16:54:41 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
VideoSourceBaseGuarded::RemoveSink(sink);
|
2022-02-17 13:28:57 +01:00
|
|
|
video_source_->internal()->RemoveSink(sink);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-22 10:47:27 +01:00
|
|
|
void VideoTrack::RequestRefreshFrame() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2022-02-17 13:28:57 +01:00
|
|
|
video_source_->internal()->RequestRefreshFrame();
|
2021-12-22 10:47:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-24 16:54:41 +02:00
|
|
|
VideoTrackSourceInterface* VideoTrack::GetSource() const {
|
|
|
|
|
// Callable from any thread.
|
|
|
|
|
return video_source_.get();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 13:28:57 +01:00
|
|
|
VideoTrackSourceInterface* VideoTrack::GetSourceInternal() const {
|
|
|
|
|
return video_source_->internal();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 15:39:11 -08:00
|
|
|
VideoTrackInterface::ContentHint VideoTrack::content_hint() const {
|
2022-02-15 13:56:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
2016-12-16 15:39:11 -08:00
|
|
|
return content_hint_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoTrack::set_content_hint(ContentHint hint) {
|
2022-02-15 13:56:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
2016-12-16 15:39:11 -08:00
|
|
|
if (content_hint_ == hint)
|
|
|
|
|
return;
|
|
|
|
|
content_hint_ = hint;
|
|
|
|
|
Notifier<VideoTrackInterface>::FireOnChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
bool VideoTrack::set_enabled(bool enable) {
|
2022-02-14 23:48:41 +01:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
|
|
|
|
|
|
|
|
|
bool ret = MediaStreamTrack<VideoTrackInterface>::set_enabled(enable);
|
|
|
|
|
|
2022-09-08 18:38:10 +02:00
|
|
|
worker_thread_->BlockingCall([&]() {
|
2022-02-14 23:48:41 +01:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
enabled_w_ = enable;
|
|
|
|
|
for (auto& sink_pair : sink_pairs()) {
|
|
|
|
|
rtc::VideoSinkWants modified_wants = sink_pair.wants;
|
|
|
|
|
modified_wants.black_frames = !enable;
|
|
|
|
|
video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return ret;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-24 16:54:41 +02:00
|
|
|
bool VideoTrack::enabled() const {
|
2022-02-14 23:48:41 +01:00
|
|
|
if (worker_thread_->IsCurrent()) {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
return enabled_w_;
|
|
|
|
|
}
|
|
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
2021-05-24 16:54:41 +02:00
|
|
|
return MediaStreamTrack<VideoTrackInterface>::enabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaStreamTrackInterface::TrackState VideoTrack::state() const {
|
2022-02-14 11:03:29 +00:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2021-05-24 16:54:41 +02:00
|
|
|
return MediaStreamTrack<VideoTrackInterface>::state();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 00:33:56 -07:00
|
|
|
void VideoTrack::OnChanged() {
|
2021-05-24 16:54:41 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_);
|
2022-02-15 13:56:50 +01:00
|
|
|
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
|
|
|
|
|
MediaSourceInterface::SourceState state = video_source_->state();
|
|
|
|
|
set_state(state == MediaSourceInterface::kEnded ? kEnded : kLive);
|
2016-03-23 00:33:56 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<VideoTrack> VideoTrack::Create(
|
2022-05-30 11:26:40 +02:00
|
|
|
absl::string_view id,
|
2022-03-21 10:40:09 +01:00
|
|
|
rtc::scoped_refptr<VideoTrackSourceInterface> source,
|
2017-07-31 23:22:01 -07:00
|
|
|
rtc::Thread* worker_thread) {
|
2022-02-17 13:19:55 +01:00
|
|
|
rtc::scoped_refptr<
|
|
|
|
|
VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>>
|
2022-03-18 15:57:15 +01:00
|
|
|
source_proxy = VideoTrackSourceProxy::Create(
|
2022-03-21 10:40:09 +01:00
|
|
|
rtc::Thread::Current(), worker_thread, std::move(source));
|
2022-02-17 13:19:55 +01:00
|
|
|
|
|
|
|
|
return rtc::make_ref_counted<VideoTrack>(id, std::move(source_proxy),
|
|
|
|
|
worker_thread);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|