blob: 17d32fbc71031890e360b2a970b500a89711e069 [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
11#include "webrtc/api/videotracksource.h"
12
perkj0d3eef22016-03-09 02:39:17 +010013#include <string>
14
perkj0d3eef22016-03-09 02:39:17 +010015namespace webrtc {
16
17VideoTrackSource::VideoTrackSource(
nisse7341ab82016-11-02 03:39:58 -070018 rtc::VideoSourceInterface<cricket::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(
nisse7341ab82016-11-02 03:39:58 -070036 rtc::VideoSinkInterface<cricket::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
nisse7341ab82016-11-02 03:39:58 -070045void VideoTrackSource::RemoveSink(
46 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
nisse5b68ab52016-04-07 07:45:54 -070047 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
perkjf0dcfe22016-03-10 18:32:00 +010048 if (!source_) {
49 return;
50 }
nisse5b68ab52016-04-07 07:45:54 -070051 source_->RemoveSink(sink);
perkj0d3eef22016-03-09 02:39:17 +010052}
53
54} // namespace webrtc