| 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/api/videotrack.h" | 11 #include "webrtc/api/videotrack.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 const char MediaStreamTrackInterface::kVideoKind[] = "video"; | 17 const char MediaStreamTrackInterface::kVideoKind[] = "video"; |
| 18 | 18 |
| 19 VideoTrack::VideoTrack(const std::string& label, | 19 VideoTrack::VideoTrack(const std::string& label, |
| 20 VideoTrackSourceInterface* video_source) | 20 VideoTrackSourceInterface* video_source) |
| 21 : MediaStreamTrack<VideoTrackInterface>(label), | 21 : MediaStreamTrack<VideoTrackInterface>(label), |
| 22 video_source_(video_source) { | 22 video_source_(video_source) { |
| 23 RTC_CHECK(video_source); |
| 24 video_source_->RegisterObserver(this); |
| 23 } | 25 } |
| 24 | 26 |
| 25 VideoTrack::~VideoTrack() { | 27 VideoTrack::~VideoTrack() { |
| 28 video_source_->UnregisterObserver(this); |
| 26 } | 29 } |
| 27 | 30 |
| 28 std::string VideoTrack::kind() const { | 31 std::string VideoTrack::kind() const { |
| 29 return kVideoKind; | 32 return kVideoKind; |
| 30 } | 33 } |
| 31 | 34 |
| 32 void VideoTrack::AddOrUpdateSink( | 35 void VideoTrack::AddOrUpdateSink( |
| 33 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | 36 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 34 const rtc::VideoSinkWants& wants) { | 37 const rtc::VideoSinkWants& wants) { |
| 35 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 38 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 VideoSourceBase::AddOrUpdateSink(sink, wants); | 39 VideoSourceBase::AddOrUpdateSink(sink, wants); |
| 37 rtc::VideoSinkWants modified_wants = wants; | 40 rtc::VideoSinkWants modified_wants = wants; |
| 38 modified_wants.black_frames = !enabled(); | 41 modified_wants.black_frames = !enabled(); |
| 39 video_source_->AddOrUpdateSink(sink, modified_wants); | 42 video_source_->AddOrUpdateSink(sink, modified_wants); |
| 40 } | 43 } |
| 41 | 44 |
| 42 void VideoTrack::RemoveSink( | 45 void VideoTrack::RemoveSink( |
| 43 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { | 46 rtc::VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 44 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 47 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 VideoSourceBase::RemoveSink(sink); | 48 VideoSourceBase::RemoveSink(sink); |
| 46 video_source_->RemoveSink(sink); | 49 video_source_->RemoveSink(sink); |
| 47 } | 50 } |
| 48 | 51 |
| 52 void VideoTrack::GetInfo(rtc::VideoSourceInfo *info) { |
| 53 video_source_->GetInfo(info); |
| 54 } |
| 55 |
| 49 bool VideoTrack::set_enabled(bool enable) { | 56 bool VideoTrack::set_enabled(bool enable) { |
| 50 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 57 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 for (auto& sink_pair : sink_pairs()) { | 58 for (auto& sink_pair : sink_pairs()) { |
| 52 rtc::VideoSinkWants modified_wants = sink_pair.wants; | 59 rtc::VideoSinkWants modified_wants = sink_pair.wants; |
| 53 modified_wants.black_frames = !enable; | 60 modified_wants.black_frames = !enable; |
| 54 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); | 61 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); |
| 55 } | 62 } |
| 56 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); | 63 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); |
| 57 } | 64 } |
| 58 | 65 |
| 66 void VideoTrack::OnChanged() { |
| 67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 if (video_source_->state() == MediaSourceInterface::kEnded) { |
| 69 set_state(kEnded); |
| 70 } else { |
| 71 set_state(kLive); |
| 72 } |
| 73 } |
| 74 |
| 59 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( | 75 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( |
| 60 const std::string& id, | 76 const std::string& id, |
| 61 VideoTrackSourceInterface* source) { | 77 VideoTrackSourceInterface* source) { |
| 62 rtc::RefCountedObject<VideoTrack>* track = | 78 rtc::RefCountedObject<VideoTrack>* track = |
| 63 new rtc::RefCountedObject<VideoTrack>(id, source); | 79 new rtc::RefCountedObject<VideoTrack>(id, source); |
| 64 return track; | 80 return track; |
| 65 } | 81 } |
| 66 | 82 |
| 67 } // namespace webrtc | 83 } // namespace webrtc |
| OLD | NEW |