| 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 video_source_->RegisterObserver(this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 VideoTrack::~VideoTrack() { | 26 VideoTrack::~VideoTrack() { |
| 27 video_source_->UnregisterObserver(this); |
| 26 } | 28 } |
| 27 | 29 |
| 28 std::string VideoTrack::kind() const { | 30 std::string VideoTrack::kind() const { |
| 29 return kVideoKind; | 31 return kVideoKind; |
| 30 } | 32 } |
| 31 | 33 |
| 32 void VideoTrack::AddOrUpdateSink( | 34 void VideoTrack::AddOrUpdateSink( |
| 33 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | 35 rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 34 const rtc::VideoSinkWants& wants) { | 36 const rtc::VideoSinkWants& wants) { |
| 35 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 37 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 bool VideoTrack::set_enabled(bool enable) { | 51 bool VideoTrack::set_enabled(bool enable) { |
| 50 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 52 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 for (auto& sink_pair : sink_pairs()) { | 53 for (auto& sink_pair : sink_pairs()) { |
| 52 rtc::VideoSinkWants modified_wants = sink_pair.wants; | 54 rtc::VideoSinkWants modified_wants = sink_pair.wants; |
| 53 modified_wants.black_frames = !enable; | 55 modified_wants.black_frames = !enable; |
| 54 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); | 56 video_source_->AddOrUpdateSink(sink_pair.sink, modified_wants); |
| 55 } | 57 } |
| 56 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); | 58 return MediaStreamTrack<VideoTrackInterface>::set_enabled(enable); |
| 57 } | 59 } |
| 58 | 60 |
| 61 void VideoTrack::OnChanged() { |
| 62 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 if (video_source_->state() == MediaSourceInterface::kEnded) { |
| 64 set_state(kEnded); |
| 65 } else { |
| 66 set_state(kLive); |
| 67 } |
| 68 } |
| 69 |
| 59 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( | 70 rtc::scoped_refptr<VideoTrack> VideoTrack::Create( |
| 60 const std::string& id, | 71 const std::string& id, |
| 61 VideoTrackSourceInterface* source) { | 72 VideoTrackSourceInterface* source) { |
| 62 rtc::RefCountedObject<VideoTrack>* track = | 73 rtc::RefCountedObject<VideoTrack>* track = |
| 63 new rtc::RefCountedObject<VideoTrack>(id, source); | 74 new rtc::RefCountedObject<VideoTrack>(id, source); |
| 64 return track; | 75 return track; |
| 65 } | 76 } |
| 66 | 77 |
| 67 } // namespace webrtc | 78 } // namespace webrtc |
| OLD | NEW |