OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/pc/videotrack.h" | 11 #include "webrtc/pc/videotrack.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
17 VideoTrack::VideoTrack(const std::string& label, | 17 VideoTrack::VideoTrack(const std::string& label, |
18 VideoTrackSourceInterface* video_source) | 18 VideoTrackSourceInterface* video_source, |
| 19 rtc::Thread* worker_thread) |
19 : MediaStreamTrack<VideoTrackInterface>(label), | 20 : MediaStreamTrack<VideoTrackInterface>(label), |
| 21 worker_thread_(worker_thread), |
20 video_source_(video_source), | 22 video_source_(video_source), |
21 content_hint_(ContentHint::kNone) { | 23 content_hint_(ContentHint::kNone) { |
22 worker_thread_checker_.DetachFromThread(); | |
23 video_source_->RegisterObserver(this); | 24 video_source_->RegisterObserver(this); |
24 } | 25 } |
25 | 26 |
26 VideoTrack::~VideoTrack() { | 27 VideoTrack::~VideoTrack() { |
27 video_source_->UnregisterObserver(this); | 28 video_source_->UnregisterObserver(this); |
28 } | 29 } |
29 | 30 |
30 std::string VideoTrack::kind() const { | 31 std::string VideoTrack::kind() const { |
31 return kVideoKind; | 32 return kVideoKind; |
32 } | 33 } |
33 | 34 |
34 // AddOrUpdateSink and RemoveSink should be called on the worker | 35 // AddOrUpdateSink and RemoveSink should be called on the worker |
35 // thread. | 36 // thread. |
36 void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | 37 void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
37 const rtc::VideoSinkWants& wants) { | 38 const rtc::VideoSinkWants& wants) { |
38 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 39 RTC_DCHECK(worker_thread_->IsCurrent()); |
39 VideoSourceBase::AddOrUpdateSink(sink, wants); | 40 VideoSourceBase::AddOrUpdateSink(sink, wants); |
40 rtc::VideoSinkWants modified_wants = wants; | 41 rtc::VideoSinkWants modified_wants = wants; |
41 modified_wants.black_frames = !enabled(); | 42 modified_wants.black_frames = !enabled(); |
42 video_source_->AddOrUpdateSink(sink, modified_wants); | 43 video_source_->AddOrUpdateSink(sink, modified_wants); |
43 } | 44 } |
44 | 45 |
45 void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { | 46 void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { |
46 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 47 RTC_DCHECK(worker_thread_->IsCurrent()); |
47 VideoSourceBase::RemoveSink(sink); | 48 VideoSourceBase::RemoveSink(sink); |
48 video_source_->RemoveSink(sink); | 49 video_source_->RemoveSink(sink); |
49 } | 50 } |
50 | 51 |
51 VideoTrackInterface::ContentHint VideoTrack::content_hint() const { | 52 VideoTrackInterface::ContentHint VideoTrack::content_hint() const { |
52 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); | 53 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
53 return content_hint_; | 54 return content_hint_; |
54 } | 55 } |
55 | 56 |
56 void VideoTrack::set_content_hint(ContentHint hint) { | 57 void VideoTrack::set_content_hint(ContentHint hint) { |
57 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); | 58 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
58 if (content_hint_ == hint) | 59 if (content_hint_ == hint) |
59 return; | 60 return; |
60 content_hint_ = hint; | 61 content_hint_ = hint; |
61 Notifier<VideoTrackInterface>::FireOnChanged(); | 62 Notifier<VideoTrackInterface>::FireOnChanged(); |
62 } | 63 } |
63 | 64 |
64 bool VideoTrack::set_enabled(bool enable) { | 65 bool VideoTrack::set_enabled(bool enable) { |
65 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 66 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
66 for (auto& sink_pair : sink_pairs()) { | 67 worker_thread_->Invoke<void>(RTC_FROM_HERE, [enable, this] { |
67 rtc::VideoSinkWants modified_wants = sink_pair.wants; | 68 RTC_DCHECK(worker_thread_->IsCurrent()); |
68 modified_wants.black_frames = !enable; | 69 for (auto& sink_pair : sink_pairs()) { |
69 // video_source_ is a proxy object, marshalling the call to the | 70 rtc::VideoSinkWants modified_wants = sink_pair.wants; |
70 // worker thread. | 71 modified_wants.black_frames = !enable; |
71 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); | 72 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); |
72 } | 73 } |
| 74 }); |
73 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); | 75 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); |
74 } | 76 } |
75 | 77 |
76 void VideoTrack::OnChanged() { | 78 void VideoTrack::OnChanged() { |
77 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 79 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
78 if (video_source_->state() == MediaSourceInterface::kEnded) { | 80 if (video_source_->state() == MediaSourceInterface::kEnded) { |
79 set_state(kEnded); | 81 set_state(kEnded); |
80 } else { | 82 } else { |
81 set_state(kLive); | 83 set_state(kLive); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( | 87 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( |
86 const std::string& id, | 88 const std::string& id, |
87 VideoTrackSourceInterface* source) { | 89 VideoTrackSourceInterface* source, |
| 90 rtc::Thread* worker_thread) { |
88 rtc::RefCountedObject<VideoTrack>* track = | 91 rtc::RefCountedObject<VideoTrack>* track = |
89 new rtc::RefCountedObject<VideoTrack>(id, source); | 92 new rtc::RefCountedObject<VideoTrack>(id, source, worker_thread); |
90 return track; | 93 return track; |
91 } | 94 } |
92 | 95 |
93 } // namespace webrtc | 96 } // namespace webrtc |
OLD | NEW |