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 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 SinkPair* sink_pair = FindSinkPair(sink); | 27 SinkPair* sink_pair = FindSinkPair(sink); |
28 if (!sink_pair) { | 28 if (!sink_pair) { |
29 sinks_.push_back(SinkPair(sink, wants)); | 29 sinks_.push_back(SinkPair(sink, wants)); |
30 } else { | 30 } else { |
31 sink_pair->wants = wants; | 31 sink_pair->wants = wants; |
32 } | 32 } |
33 | 33 |
34 // Rotation must be applied by the source if one sink wants it. | 34 // Rotation must be applied by the source if one sink wants it. |
35 current_wants_.rotation_applied = false; | 35 current_wants_.rotation_applied = false; |
36 current_wants_.resolution = | |
37 rtc::Optional<VideoSinkWants::ResolutionRequest>(); | |
38 rtc::Optional<VideoSinkWants::ResolutionRequest> resolution; | |
39 bool sink_agrees_on_resolution = true; | |
pthatcher1
2016/02/19 06:08:40
I think you mean sinks_agree_on_resolution
| |
36 for (auto& sink_pair : sinks_) { | 40 for (auto& sink_pair : sinks_) { |
37 current_wants_.rotation_applied |= sink_pair.wants.rotation_applied; | 41 current_wants_.rotation_applied |= sink_pair.wants.rotation_applied; |
42 | |
43 if (sink_agrees_on_resolution && sink_pair.wants.resolution) { | |
44 if (sink_pair.wants.resolution->request == | |
45 VideoSinkWants::ResolutionRequest::kLargerThan && | |
46 sink_pair.wants.resolution->seen_number_of_pixels < | |
47 current_number_of_pixels_) { | |
pthatcher1
2016/02/19 06:08:40
This would be more clear reversed as "if (current
| |
48 continue; | |
49 } | |
50 | |
51 if (sink_pair.wants.resolution->request == | |
52 VideoSinkWants::ResolutionRequest::kSmallerThan && | |
53 sink_pair.wants.resolution->seen_number_of_pixels > | |
54 current_number_of_pixels_) { | |
pthatcher1
2016/02/19 06:08:40
Same here: "if (wants < current)" would be more cl
| |
55 continue; | |
56 } | |
57 | |
58 if (!resolution) { | |
59 resolution = sink_pair.wants.resolution; | |
60 continue; | |
61 } | |
62 | |
63 if (*resolution != *sink_pair.wants.resolution) { | |
64 sink_agrees_on_resolution = false; | |
65 } | |
66 } | |
67 } | |
68 | |
69 // If all sinks agree, the source should try to fulfill the resolution | |
70 // request. | |
71 if (sink_agrees_on_resolution) { | |
72 current_wants_.resolution = resolution; | |
38 } | 73 } |
39 } | 74 } |
40 | 75 |
41 void VideoBroadcaster::RemoveSink( | 76 void VideoBroadcaster::RemoveSink( |
42 VideoSinkInterface<cricket::VideoFrame>* sink) { | 77 VideoSinkInterface<cricket::VideoFrame>* sink) { |
43 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 78 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
44 RTC_DCHECK(sink != nullptr); | 79 RTC_DCHECK(sink != nullptr); |
45 RTC_DCHECK(FindSinkPair(sink)); | 80 RTC_DCHECK(FindSinkPair(sink)); |
46 | 81 |
47 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(), | 82 sinks_.erase(std::remove_if(sinks_.begin(), sinks_.end(), |
48 [sink](const SinkPair& sink_pair) { | 83 [sink](const SinkPair& sink_pair) { |
49 return sink_pair.sink == sink; | 84 return sink_pair.sink == sink; |
50 }), | 85 }), |
51 sinks_.end()); | 86 sinks_.end()); |
52 } | 87 } |
53 | 88 |
54 bool VideoBroadcaster::frame_wanted() const { | 89 bool VideoBroadcaster::frame_wanted() const { |
55 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 90 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
56 return !sinks_.empty(); | 91 return !sinks_.empty(); |
57 } | 92 } |
58 | 93 |
59 VideoSinkWants VideoBroadcaster::wants() const { | 94 VideoSinkWants VideoBroadcaster::wants() const { |
60 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 95 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
61 return current_wants_; | 96 return current_wants_; |
62 } | 97 } |
63 | 98 |
64 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { | 99 void VideoBroadcaster::OnFrame(const cricket::VideoFrame& frame) { |
65 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 100 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
101 current_number_of_pixels_ = frame.GetWidth() * frame.GetHeight(); | |
pthatcher1
2016/02/19 06:08:40
I think it would be better to save this as last_fr
pthatcher1
2016/02/19 06:08:40
Since the pixel count may have changed, I think yo
| |
66 for (auto& sink_pair : sinks_) { | 102 for (auto& sink_pair : sinks_) { |
67 sink_pair.sink->OnFrame(frame); | 103 sink_pair.sink->OnFrame(frame); |
68 } | 104 } |
69 } | 105 } |
70 | 106 |
71 VideoBroadcaster::SinkPair* VideoBroadcaster::FindSinkPair( | 107 VideoBroadcaster::SinkPair* VideoBroadcaster::FindSinkPair( |
72 const VideoSinkInterface<cricket::VideoFrame>* sink) { | 108 const VideoSinkInterface<cricket::VideoFrame>* sink) { |
73 auto sink_pair_it = std::find_if( | 109 auto sink_pair_it = std::find_if( |
74 sinks_.begin(), sinks_.end(), | 110 sinks_.begin(), sinks_.end(), |
75 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); | 111 [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); |
76 if (sink_pair_it != sinks_.end()) { | 112 if (sink_pair_it != sinks_.end()) { |
77 return &*sink_pair_it; | 113 return &*sink_pair_it; |
78 } | 114 } |
79 return nullptr; | 115 return nullptr; |
80 } | 116 } |
81 | 117 |
82 } // namespace rtc | 118 } // namespace rtc |
OLD | NEW |