Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: webrtc/media/base/videobroadcaster.cc

Issue 1695263002: Move direct use of VideoCapturer::VideoAdapter to VideoSinkWants. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebased Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
14
13 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
14 16
15 namespace rtc { 17 namespace rtc {
16 18
17 VideoBroadcaster::VideoBroadcaster() { 19 VideoBroadcaster::VideoBroadcaster() {
18 thread_checker_.DetachFromThread(); 20 thread_checker_.DetachFromThread();
19 } 21 }
20 22
21 void VideoBroadcaster::AddOrUpdateSink( 23 void VideoBroadcaster::AddOrUpdateSink(
22 VideoSinkInterface<cricket::VideoFrame>* sink, 24 VideoSinkInterface<cricket::VideoFrame>* sink,
23 const VideoSinkWants& wants) { 25 const VideoSinkWants& wants) {
24 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 26 RTC_DCHECK(thread_checker_.CalledOnValidThread());
25 RTC_DCHECK(sink != nullptr); 27 RTC_DCHECK(sink != nullptr);
26 28
27 SinkPair* sink_pair = FindSinkPair(sink); 29 SinkPair* sink_pair = FindSinkPair(sink);
28 if (!sink_pair) { 30 if (!sink_pair) {
29 sinks_.push_back(SinkPair(sink, wants)); 31 sinks_.push_back(SinkPair(sink, wants));
30 } else { 32 } else {
31 sink_pair->wants = wants; 33 sink_pair->wants = wants;
32 } 34 }
33 35 UpdateWants();
34 // Rotation must be applied by the source if one sink wants it.
35 current_wants_.rotation_applied = false;
36 for (auto& sink_pair : sinks_) {
37 current_wants_.rotation_applied |= sink_pair.wants.rotation_applied;
38 }
39 } 36 }
40 37
41 void VideoBroadcaster::RemoveSink( 38 void VideoBroadcaster::RemoveSink(
42 VideoSinkInterface<cricket::VideoFrame>* sink) { 39 VideoSinkInterface<cricket::VideoFrame>* sink) {
43 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 40 RTC_DCHECK(thread_checker_.CalledOnValidThread());
44 RTC_DCHECK(sink != nullptr); 41 RTC_DCHECK(sink != nullptr);
45 RTC_DCHECK(FindSinkPair(sink)); 42 RTC_DCHECK(FindSinkPair(sink));
46 43
47 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(), 44 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(),
48 [sink](const SinkPair& sink_pair) { 45 [sink](const SinkPair& sink_pair) {
49 return sink_pair.sink == sink; 46 return sink_pair.sink == sink;
50 }), 47 }),
51 sinks_.end()); 48 sinks_.end());
49 UpdateWants();
52 } 50 }
53 51
54 bool VideoBroadcaster::frame_wanted() const { 52 bool VideoBroadcaster::frame_wanted() const {
55 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 53 RTC_DCHECK(thread_checker_.CalledOnValidThread());
56 return !sinks_.empty(); 54 return !sinks_.empty();
57 } 55 }
58 56
59 VideoSinkWants VideoBroadcaster::wants() const { 57 VideoSinkWants VideoBroadcaster::wants() const {
60 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 58 RTC_DCHECK(thread_checker_.CalledOnValidThread());
61 return current_wants_; 59 return current_wants_;
(...skipping 10 matching lines...) Expand all
72 const VideoSinkInterface<cricket::VideoFrame>* sink) { 70 const VideoSinkInterface<cricket::VideoFrame>* sink) {
73 auto sink_pair_it = std::find_if( 71 auto sink_pair_it = std::find_if(
74 sinks_.begin(), sinks_.end(), 72 sinks_.begin(), sinks_.end(),
75 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); 73 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
76 if (sink_pair_it != sinks_.end()) { 74 if (sink_pair_it != sinks_.end()) {
77 return &*sink_pair_it; 75 return &*sink_pair_it;
78 } 76 }
79 return nullptr; 77 return nullptr;
80 } 78 }
81 79
80 void VideoBroadcaster::UpdateWants() {
81 RTC_DCHECK(thread_checker_.CalledOnValidThread());
82 // Rotation must be applied by the source if one sink wants it.
83 current_wants_.rotation_applied = false;
84 int max_pixels = std::numeric_limits<int>::max();
85 int more_than_pixels = std::numeric_limits<int>::max();
86 for (auto& sink_pair : sinks_) {
87 current_wants_.rotation_applied |= sink_pair.wants.rotation_applied;
88 if (sink_pair.wants.max_pixel_count &&
89 max_pixels > *sink_pair.wants.max_pixel_count) {
90 max_pixels = *sink_pair.wants.max_pixel_count;
91 }
92
93 if (sink_pair.wants.max_pixel_count_step_up &&
94 more_than_pixels > *sink_pair.wants.max_pixel_count_step_up) {
95 more_than_pixels = *sink_pair.wants.max_pixel_count_step_up;
96 }
97 }
98
99 current_wants_.max_pixel_count_step_up =
100 (more_than_pixels < std::numeric_limits<int>::max() &&
101 max_pixels > more_than_pixels)
102 ? rtc::Optional<int>(more_than_pixels)
103 : rtc::Optional<int>();
104
105 current_wants_.max_pixel_count =
106 (max_pixels < std::numeric_limits<int>::max())
107 ? rtc::Optional<int>(max_pixels)
108 : rtc::Optional<int>();
109 }
110
pthatcher1 2016/02/25 07:40:30 I think this would be more readable: VideoSinkWan
nisse-webrtc 2016/02/25 09:31:07 I think there's one more thing done in Per's versi
perkj_webrtc 2016/02/25 13:57:07 Added that condition afterwards and went with ptha
82 } // namespace rtc 111 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698