| 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   worker_thread_checker_.DetachFromThread(); |  | 
| 24   video_source_->RegisterObserver(this); |  | 
| 25 } |  | 
| 26 |  | 
| 27 VideoTrack::~VideoTrack() { |  | 
| 28   video_source_->UnregisterObserver(this); |  | 
| 29 } |  | 
| 30 |  | 
| 31 std::string VideoTrack::kind() const { |  | 
| 32   return kVideoKind; |  | 
| 33 } |  | 
| 34 |  | 
| 35 // AddOrUpdateSink and RemoveSink should be called on the worker |  | 
| 36 // thread. |  | 
| 37 void VideoTrack::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |  | 
| 38                                  const rtc::VideoSinkWants& wants) { |  | 
| 39   RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |  | 
| 40   VideoSourceBase::AddOrUpdateSink(sink, wants); |  | 
| 41   rtc::VideoSinkWants modified_wants = wants; |  | 
| 42   modified_wants.black_frames = !enabled(); |  | 
| 43   video_source_->AddOrUpdateSink(sink, modified_wants); |  | 
| 44 } |  | 
| 45 |  | 
| 46 void VideoTrack::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { |  | 
| 47   RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |  | 
| 48   VideoSourceBase::RemoveSink(sink); |  | 
| 49   video_source_->RemoveSink(sink); |  | 
| 50 } |  | 
| 51 |  | 
| 52 bool VideoTrack::set_enabled(bool enable) { |  | 
| 53   RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |  | 
| 54   for (auto& sink_pair : sink_pairs()) { |  | 
| 55     rtc::VideoSinkWants modified_wants = sink_pair.wants; |  | 
| 56     modified_wants.black_frames = !enable; |  | 
| 57     // video_source_ is a proxy object, marshalling the call to the |  | 
| 58     // worker thread. |  | 
| 59     video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); |  | 
| 60   } |  | 
| 61   return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); |  | 
| 62 } |  | 
| 63 |  | 
| 64 void VideoTrack::OnChanged() { |  | 
| 65   RTC_DCHECK(signaling_thread_checker_.CalledOnValidThread()); |  | 
| 66   if (video_source_->state() == MediaSourceInterface::kEnded) { |  | 
| 67     set_state(kEnded); |  | 
| 68   } else { |  | 
| 69     set_state(kLive); |  | 
| 70   } |  | 
| 71 } |  | 
| 72 |  | 
| 73 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( |  | 
| 74     const std::string& id, |  | 
| 75     VideoTrackSourceInterface* source) { |  | 
| 76   rtc::RefCountedObject<VideoTrack>* track = |  | 
| 77       new rtc::RefCountedObject<VideoTrack>(id, source); |  | 
| 78   return track; |  | 
| 79 } |  | 
| 80 |  | 
| 81 }  // namespace webrtc |  | 
| OLD | NEW | 
|---|