| 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) | |
| 20 : MediaStreamTrack<VideoTrackInterface>(label), | 19 : MediaStreamTrack<VideoTrackInterface>(label), |
| 21 worker_thread_(worker_thread), | |
| 22 video_source_(video_source), | 20 video_source_(video_source), |
| 23 content_hint_(ContentHint::kNone) { | 21 content_hint_(ContentHint::kNone) { |
| 22 worker_thread_checker_.DetachFromThread(); |
| 24 video_source_->RegisterObserver(this); | 23 video_source_->RegisterObserver(this); |
| 25 } | 24 } |
| 26 | 25 |
| 27 VideoTrack::~VideoTrack() { | 26 VideoTrack::~VideoTrack() { |
| 28 video_source_->UnregisterObserver(this); | 27 video_source_->UnregisterObserver(this); |
| 29 } | 28 } |
| 30 | 29 |
| 31 std::string VideoTrack::kind() const { | 30 std::string VideoTrack::kind() const { |
| 32 return kVideoKind; | 31 return kVideoKind; |
| 33 } | 32 } |
| 34 | 33 |
| 35 // AddOrUpdateSink and RemoveSink should be called on the worker | 34 // AddOrUpdateSink and RemoveSink should be called on the worker |
| 36 // thread. | 35 // thread. |
| 37 void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, | 36 void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 38 const rtc::VideoSinkWants& wants) { | 37 const rtc::VideoSinkWants& wants) { |
| 39 RTC_DCHECK(worker_thread_->IsCurrent()); | 38 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 40 VideoSourceBase::AddOrUpdateSink(sink, wants); | 39 VideoSourceBase::AddOrUpdateSink(sink, wants); |
| 41 rtc::VideoSinkWants modified_wants = wants; | 40 rtc::VideoSinkWants modified_wants = wants; |
| 42 modified_wants.black_frames = !enabled(); | 41 modified_wants.black_frames = !enabled(); |
| 43 video_source_->AddOrUpdateSink(sink, modified_wants); | 42 video_source_->AddOrUpdateSink(sink, modified_wants); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { | 45 void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 47 RTC_DCHECK(worker_thread_->IsCurrent()); | 46 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 48 VideoSourceBase::RemoveSink(sink); | 47 VideoSourceBase::RemoveSink(sink); |
| 49 video_source_->RemoveSink(sink); | 48 video_source_->RemoveSink(sink); |
| 50 } | 49 } |
| 51 | 50 |
| 52 VideoTrackInterface::ContentHint VideoTrack::content_hint() const { | 51 VideoTrackInterface::ContentHint VideoTrack::content_hint() const { |
| 53 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); | 52 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
| 54 return content_hint_; | 53 return content_hint_; |
| 55 } | 54 } |
| 56 | 55 |
| 57 void VideoTrack::set_content_hint(ContentHint hint) { | 56 void VideoTrack::set_content_hint(ContentHint hint) { |
| 58 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); | 57 RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
| 59 if (content_hint_ == hint) | 58 if (content_hint_ == hint) |
| 60 return; | 59 return; |
| 61 content_hint_ = hint; | 60 content_hint_ = hint; |
| 62 Notifier<VideoTrackInterface>::FireOnChanged(); | 61 Notifier<VideoTrackInterface>::FireOnChanged(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 bool VideoTrack::set_enabled(bool enable) { | 64 bool VideoTrack::set_enabled(bool enable) { |
| 66 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 65 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 67 worker_thread_->Invoke<void>(RTC_FROM_HERE, [enable, this] { | 66 for (auto& sink_pair : sink_pairs()) { |
| 68 RTC_DCHECK(worker_thread_->IsCurrent()); | 67 rtc::VideoSinkWants modified_wants = sink_pair.wants; |
| 69 for (auto& sink_pair : sink_pairs()) { | 68 modified_wants.black_frames = !enable; |
| 70 rtc::VideoSinkWants modified_wants = sink_pair.wants; | 69 // video_source_ is a proxy object, marshalling the call to the |
| 71 modified_wants.black_frames = !enable; | 70 // worker thread. |
| 72 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); | 71 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); |
| 73 } | 72 } |
| 74 }); | |
| 75 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); | 73 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); |
| 76 } | 74 } |
| 77 | 75 |
| 78 void VideoTrack::OnChanged() { | 76 void VideoTrack::OnChanged() { |
| 79 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 77 RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 80 if (video_source_->state() == MediaSourceInterface::kEnded) { | 78 if (video_source_->state() == MediaSourceInterface::kEnded) { |
| 81 set_state(kEnded); | 79 set_state(kEnded); |
| 82 } else { | 80 } else { |
| 83 set_state(kLive); | 81 set_state(kLive); |
| 84 } | 82 } |
| 85 } | 83 } |
| 86 | 84 |
| 87 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( | 85 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( |
| 88 const std::string& id, | 86 const std::string& id, |
| 89 VideoTrackSourceInterface* source, | 87 VideoTrackSourceInterface* source) { |
| 90 rtc::Thread* worker_thread) { | |
| 91 rtc::RefCountedObject<VideoTrack>* track = | 88 rtc::RefCountedObject<VideoTrack>* track = |
| 92 new rtc::RefCountedObject<VideoTrack>(id, source, worker_thread); | 89 new rtc::RefCountedObject<VideoTrack>(id, source); |
| 93 return track; | 90 return track; |
| 94 } | 91 } |
| 95 | 92 |
| 96 } // namespace webrtc | 93 } // namespace webrtc |
| OLD | NEW |