| 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() { | 19 VideoBroadcaster::VideoBroadcaster() { |
| 20 thread_checker_.DetachFromThread(); | 20 thread_checker_.DetachFromThread(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void VideoBroadcaster::AddOrUpdateSink( | 23 void VideoBroadcaster::AddOrUpdateSink( |
| 24 VideoSinkInterface<cricket::VideoFrame>* sink, | 24 VideoSinkInterface<cricket::VideoFrame>* sink, |
| 25 const VideoSinkWants& wants) { | 25 const VideoSinkWants& wants) { |
| 26 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 26 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 27 RTC_DCHECK(sink != nullptr); | 27 RTC_DCHECK(sink != nullptr); |
| 28 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 28 | 29 |
| 29 SinkPair* sink_pair = FindSinkPair(sink); | 30 SinkPair* sink_pair = FindSinkPair(sink); |
| 30 if (!sink_pair) { | 31 if (!sink_pair) { |
| 31 sinks_.push_back(SinkPair(sink, wants)); | 32 sinks_.push_back(SinkPair(sink, wants)); |
| 32 } else { | 33 } else { |
| 33 sink_pair->wants = wants; | 34 sink_pair->wants = wants; |
| 34 } | 35 } |
| 35 UpdateWants(); | 36 UpdateWants(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void VideoBroadcaster::RemoveSink( | 39 void VideoBroadcaster::RemoveSink( |
| 39 VideoSinkInterface<cricket::VideoFrame>* sink) { | 40 VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 40 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 41 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 41 RTC_DCHECK(sink != nullptr); | 42 RTC_DCHECK(sink != nullptr); |
| 43 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 42 RTC_DCHECK(FindSinkPair(sink)); | 44 RTC_DCHECK(FindSinkPair(sink)); |
| 43 | |
| 44 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(), | 45 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(), |
| 45 [sink](const SinkPair& sink_pair) { | 46 [sink](const SinkPair& sink_pair) { |
| 46 return sink_pair.sink == sink; | 47 return sink_pair.sink == sink; |
| 47 }), | 48 }), |
| 48 sinks_.end()); | 49 sinks_.end()); |
| 49 UpdateWants(); | 50 UpdateWants(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool VideoBroadcaster::frame_wanted() const { | 53 bool VideoBroadcaster::frame_wanted() const { |
| 53 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 54 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 54 return !sinks_.empty(); | 56 return !sinks_.empty(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 VideoSinkWants VideoBroadcaster::wants() const { | 59 VideoSinkWants VideoBroadcaster::wants() const { |
| 58 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 60 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 59 return current_wants_; | 62 return current_wants_; |
| 60 } | 63 } |
| 61 | 64 |
| 62 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { | 65 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { |
| 63 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 66 rtc::CritScope cs(&sinks_and_wants_lock_); |
| 64 for (auto& sink_pair : sinks_) { | 67 for (auto& sink_pair : sinks_) { |
| 65 sink_pair.sink->OnFrame(frame); | 68 sink_pair.sink->OnFrame(frame); |
| 66 } | 69 } |
| 67 } | 70 } |
| 68 | 71 |
| 69 VideoBroadcaster::SinkPair* VideoBroadcaster::FindSinkPair( | 72 VideoBroadcaster::SinkPair* VideoBroadcaster::FindSinkPair( |
| 70 const VideoSinkInterface<cricket::VideoFrame>* sink) { | 73 const VideoSinkInterface<cricket::VideoFrame>* sink) { |
| 71 auto sink_pair_it = std::find_if( | 74 auto sink_pair_it = std::find_if( |
| 72 sinks_.begin(), sinks_.end(), | 75 sinks_.begin(), sinks_.end(), |
| 73 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); | 76 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 103 } | 106 } |
| 104 | 107 |
| 105 if (wants.max_pixel_count && wants.max_pixel_count_step_up && | 108 if (wants.max_pixel_count && wants.max_pixel_count_step_up && |
| 106 *wants.max_pixel_count_step_up >= *wants.max_pixel_count) { | 109 *wants.max_pixel_count_step_up >= *wants.max_pixel_count) { |
| 107 wants.max_pixel_count_step_up = Optional<int>(); | 110 wants.max_pixel_count_step_up = Optional<int>(); |
| 108 } | 111 } |
| 109 current_wants_ = wants; | 112 current_wants_ = wants; |
| 110 } | 113 } |
| 111 | 114 |
| 112 } // namespace rtc | 115 } // namespace rtc |
| OLD | NEW |