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