| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/media/base/videobroadcaster.h" | 11 #include "webrtc/media/base/videobroadcaster.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 | 16 |
| 17 namespace rtc { | 17 namespace rtc { |
| 18 | 18 |
| 19 VideoBroadcaster::VideoBroadcaster() { | |
| 20 thread_checker_.DetachFromThread(); | |
| 21 } | |
| 22 | |
| 23 void VideoBroadcaster::AddOrUpdateSink( | 19 void VideoBroadcaster::AddOrUpdateSink( |
| 24 VideoSinkInterface<cricket::VideoFrame>* sink, | 20 VideoSinkInterface<cricket::VideoFrame>* sink, |
| 25 const VideoSinkWants& wants) { | 21 const VideoSinkWants& wants) { |
| 26 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 27 RTC_DCHECK(sink != nullptr); | 22 RTC_DCHECK(sink != nullptr); |
| 28 rtc::CritScope cs(&sinks_and_wants_lock_); | 23 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 29 VideoSourceBase::AddOrUpdateSink(sink, wants); | 24 VideoSourceBase::AddOrUpdateSink(sink, wants); |
| 30 UpdateWants(); | 25 UpdateWants(); |
| 31 } | 26 } |
| 32 | 27 |
| 33 void VideoBroadcaster::RemoveSink( | 28 void VideoBroadcaster::RemoveSink( |
| 34 VideoSinkInterface<cricket::VideoFrame>* sink) { | 29 VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 35 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 36 RTC_DCHECK(sink != nullptr); | 30 RTC_DCHECK(sink != nullptr); |
| 37 rtc::CritScope cs(&sinks_and_wants_lock_); | 31 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 38 VideoSourceBase::RemoveSink(sink); | 32 VideoSourceBase::RemoveSink(sink); |
| 39 UpdateWants(); | 33 UpdateWants(); |
| 40 } | 34 } |
| 41 | 35 |
| 42 bool VideoBroadcaster::frame_wanted() const { | 36 bool VideoBroadcaster::frame_wanted() const { |
| 43 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 44 rtc::CritScope cs(&sinks_and_wants_lock_); | 37 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 45 return !sink_pairs().empty(); | 38 return !sink_pairs().empty(); |
| 46 } | 39 } |
| 47 | 40 |
| 48 VideoSinkWants VideoBroadcaster::wants() const { | 41 VideoSinkWants VideoBroadcaster::wants() const { |
| 49 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 50 rtc::CritScope cs(&sinks_and_wants_lock_); | 42 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 51 return current_wants_; | 43 return current_wants_; |
| 52 } | 44 } |
| 53 | 45 |
| 54 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { | 46 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { |
| 55 rtc::CritScope cs(&sinks_and_wants_lock_); | 47 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 56 for (auto& sink_pair : sink_pairs()) { | 48 for (auto& sink_pair : sink_pairs()) { |
| 57 if (sink_pair.wants.black_frames) { | 49 if (sink_pair.wants.black_frames) { |
| 58 sink_pair.sink->OnFrame(GetBlackFrame(frame)); | 50 sink_pair.sink->OnFrame(GetBlackFrame(frame)); |
| 59 } else { | 51 } else { |
| 60 sink_pair.sink->OnFrame(frame); | 52 sink_pair.sink->OnFrame(frame); |
| 61 } | 53 } |
| 62 } | 54 } |
| 63 } | 55 } |
| 64 | 56 |
| 65 void VideoBroadcaster::UpdateWants() { | 57 void VideoBroadcaster::UpdateWants() { |
| 66 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 67 | |
| 68 VideoSinkWants wants; | 58 VideoSinkWants wants; |
| 69 wants.rotation_applied = false; | 59 wants.rotation_applied = false; |
| 70 for (auto& sink : sink_pairs()) { | 60 for (auto& sink : sink_pairs()) { |
| 71 // wants.rotation_applied == ANY(sink.wants.rotation_applied) | 61 // wants.rotation_applied == ANY(sink.wants.rotation_applied) |
| 72 if (sink.wants.rotation_applied) { | 62 if (sink.wants.rotation_applied) { |
| 73 wants.rotation_applied = true; | 63 wants.rotation_applied = true; |
| 74 } | 64 } |
| 75 // wants.max_pixel_count == MIN(sink.wants.max_pixel_count) | 65 // wants.max_pixel_count == MIN(sink.wants.max_pixel_count) |
| 76 if (sink.wants.max_pixel_count && | 66 if (sink.wants.max_pixel_count && |
| 77 (!wants.max_pixel_count || | 67 (!wants.max_pixel_count || |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 } | 94 } |
| 105 black_frame_.reset(new cricket::WebRtcVideoFrame( | 95 black_frame_.reset(new cricket::WebRtcVideoFrame( |
| 106 new rtc::RefCountedObject<webrtc::I420Buffer>(frame.width(), | 96 new rtc::RefCountedObject<webrtc::I420Buffer>(frame.width(), |
| 107 frame.height()), | 97 frame.height()), |
| 108 frame.rotation(), frame.timestamp_us())); | 98 frame.rotation(), frame.timestamp_us())); |
| 109 black_frame_->SetToBlack(); | 99 black_frame_->SetToBlack(); |
| 110 return *black_frame_; | 100 return *black_frame_; |
| 111 } | 101 } |
| 112 | 102 |
| 113 } // namespace rtc | 103 } // namespace rtc |
| OLD | NEW |