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
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/videotrack.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-11-25 11:26:01 -08:00
|
|
|
const char MediaStreamTrackInterface::kVideoKind[] = "video";
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
VideoTrack::VideoTrack(const std::string& label,
|
2016-03-08 01:27:48 +01:00
|
|
|
VideoTrackSourceInterface* video_source)
|
2013-07-10 00:45:36 +00:00
|
|
|
: MediaStreamTrack<VideoTrackInterface>(label),
|
|
|
|
|
video_source_(video_source) {
|
2016-04-07 07:45:54 -07:00
|
|
|
worker_thread_checker_.DetachFromThread();
|
2016-03-23 00:33:56 -07:00
|
|
|
video_source_->RegisterObserver(this);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoTrack::~VideoTrack() {
|
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) {
|
2016-04-07 07:45:54 -07:00
|
|
|
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
2016-03-17 10:35:23 +01:00
|
|
|
VideoSourceBase::AddOrUpdateSink(sink, wants);
|
|
|
|
|
rtc::VideoSinkWants modified_wants = wants;
|
|
|
|
|
modified_wants.black_frames = !enabled();
|
|
|
|
|
video_source_->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) {
|
2016-04-07 07:45:54 -07:00
|
|
|
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
2016-03-17 10:35:23 +01:00
|
|
|
VideoSourceBase::RemoveSink(sink);
|
|
|
|
|
video_source_->RemoveSink(sink);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoTrack::set_enabled(bool enable) {
|
2016-04-07 07:45:54 -07:00
|
|
|
RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread());
|
2016-03-17 10:35:23 +01:00
|
|
|
for (auto& sink_pair : sink_pairs()) {
|
|
|
|
|
rtc::VideoSinkWants modified_wants = sink_pair.wants;
|
|
|
|
|
modified_wants.black_frames = !enable;
|
2016-04-07 07:45:54 -07:00
|
|
|
// video_source_ is a proxy object, marshalling the call to the
|
|
|
|
|
// worker thread.
|
2016-03-17 10:35:23 +01:00
|
|
|
video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants);
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 00:33:56 -07:00
|
|
|
void VideoTrack::OnChanged() {
|
2016-04-07 07:45:54 -07:00
|
|
|
RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread());
|
2016-03-23 00:33:56 -07:00
|
|
|
if (video_source_->state() == MediaSourceInterface::kEnded) {
|
|
|
|
|
set_state(kEnded);
|
|
|
|
|
} else {
|
|
|
|
|
set_state(kLive);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<VideoTrack> VideoTrack::Create(
|
2016-02-26 01:24:58 -08:00
|
|
|
const std::string& id,
|
2016-03-08 01:27:48 +01:00
|
|
|
VideoTrackSourceInterface* source) {
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::RefCountedObject<VideoTrack>* track =
|
|
|
|
|
new rtc::RefCountedObject<VideoTrack>(id, source);
|
2013-07-10 00:45:36 +00:00
|
|
|
return track;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|