blob: f8212d7a70cab20cfce2d4dc5349bb172b06cc4f [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
15#include "webrtc/base/bind.h"
16
17namespace webrtc {
18
19VideoTrackSource::VideoTrackSource(
20 rtc::VideoSourceInterface<cricket::VideoFrame>* source,
21 rtc::Thread* worker_thread,
22 bool remote)
23 : source_(source),
24 worker_thread_(worker_thread),
25 state_(kInitializing),
26 remote_(remote) {}
27
28void VideoTrackSource::SetState(SourceState new_state) {
29 if (state_ != new_state) {
30 state_ = new_state;
31 FireOnChanged();
32 }
33}
34
perkjf0dcfe22016-03-10 18:32:00 +010035void VideoTrackSource::OnSourceDestroyed() {
36 source_ = nullptr;
37}
38
perkj0d3eef22016-03-09 02:39:17 +010039void VideoTrackSource::AddOrUpdateSink(
40 rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
41 const rtc::VideoSinkWants& wants) {
perkjf0dcfe22016-03-10 18:32:00 +010042 if (!source_) {
43 return;
44 }
perkj0d3eef22016-03-09 02:39:17 +010045 worker_thread_->Invoke<void>(rtc::Bind(
46 &rtc::VideoSourceInterface<cricket::VideoFrame>::AddOrUpdateSink, source_,
47 sink, wants));
48}
49
50void VideoTrackSource::RemoveSink(
51 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
perkjf0dcfe22016-03-10 18:32:00 +010052 if (!source_) {
53 return;
54 }
perkj0d3eef22016-03-09 02:39:17 +010055 worker_thread_->Invoke<void>(
56 rtc::Bind(&rtc::VideoSourceInterface<cricket::VideoFrame>::RemoveSink,
57 source_, sink));
58}
59
60} // namespace webrtc