blob: 56f48e7375cb9d941e0b8e35f790bfe80297300b [file] [log] [blame]
perkj11e18052016-03-07 22:03:23 +01001/*
perkj11e18052016-03-07 22:03:23 +01002 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "pc/videotracksource.h"
perkj11e18052016-03-07 22:03:23 +010012
perkj0d3eef22016-03-09 02:39:17 +010013#include <string>
14
perkj0d3eef22016-03-09 02:39:17 +010015namespace webrtc {
16
17VideoTrackSource::VideoTrackSource(
nisseacd935b2016-11-11 03:55:13 -080018 rtc::VideoSourceInterface<VideoFrame>* source,
perkj0d3eef22016-03-09 02:39:17 +010019 bool remote)
nisse5b68ab52016-04-07 07:45:54 -070020 : source_(source), state_(kInitializing), remote_(remote) {
21 worker_thread_checker_.DetachFromThread();
22}
perkj0d3eef22016-03-09 02:39:17 +010023
24void VideoTrackSource::SetState(SourceState new_state) {
25 if (state_ != new_state) {
26 state_ = new_state;
27 FireOnChanged();
28 }
29}
30
perkjf0dcfe22016-03-10 18:32:00 +010031void VideoTrackSource::OnSourceDestroyed() {
32 source_ = nullptr;
33}
34
perkj0d3eef22016-03-09 02:39:17 +010035void VideoTrackSource::AddOrUpdateSink(
nisseacd935b2016-11-11 03:55:13 -080036 rtc::VideoSinkInterface<VideoFrame>* sink,
perkj0d3eef22016-03-09 02:39:17 +010037 const rtc::VideoSinkWants& wants) {
nisse5b68ab52016-04-07 07:45:54 -070038 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
perkjf0dcfe22016-03-10 18:32:00 +010039 if (!source_) {
40 return;
41 }
nisse5b68ab52016-04-07 07:45:54 -070042 source_->AddOrUpdateSink(sink, wants);
perkj0d3eef22016-03-09 02:39:17 +010043}
44
nisseacd935b2016-11-11 03:55:13 -080045void VideoTrackSource::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
nisse5b68ab52016-04-07 07:45:54 -070046 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
perkjf0dcfe22016-03-10 18:32:00 +010047 if (!source_) {
48 return;
49 }
nisse5b68ab52016-04-07 07:45:54 -070050 source_->RemoveSink(sink);
perkj0d3eef22016-03-09 02:39:17 +010051}
52
53} // namespace webrtc