Chromium Code Reviews| Index: webrtc/media/base/videobroadcaster.cc |
| diff --git a/webrtc/media/base/videobroadcaster.cc b/webrtc/media/base/videobroadcaster.cc |
| index 5d0edeb6dfe4f9dc3129ba19231716f8caea03f5..f48468a063a508b0a3e3452244c41e73ccf77770 100644 |
| --- a/webrtc/media/base/videobroadcaster.cc |
| +++ b/webrtc/media/base/videobroadcaster.cc |
| @@ -73,6 +73,34 @@ void VideoBroadcaster::OnFrame(const webrtc::VideoFrame& frame) { |
| } |
| } |
| +void VideoBroadcaster::MergeWantsRange( |
| + rtc::Optional<rtc::VideoSinkWants::Range>* merged_range, |
| + const rtc::VideoSinkWants::Range& item) { |
| + if (!*merged_range) { |
| + merged_range->emplace(item); |
| + return; |
| + } |
|
nisse-webrtc
2017/02/21 09:33:59
I think this is in the right direction. Might be e
sprang_webrtc
2017/02/21 09:42:38
I think I'll revisit this when/if removing the Opt
|
| + |
| + // Merge the constraints if there are more than one wants. Lowest max |
| + // will set the max cap and the highest min will set the min cap, as |
| + // these are pretty hard bounds. For now chose the min of the targets as |
| + // well, erring of the side of caution so that we don't overutilize some |
| + // resource. |
| + // TODO(sprang): Consider using median of targets? |
| + (*merged_range)->max = std::min<uint32_t>((*merged_range)->max, item.max); |
| + (*merged_range)->target = |
| + std::min<uint32_t>((*merged_range)->target, item.target); |
| + (*merged_range)->min = std::max<uint32_t>((*merged_range)->min, item.min); |
| + |
| + // Make sure there is no contradiction in the merged wants. |
| + (*merged_range)->min = |
| + std::min<uint32_t>((*merged_range)->min, (*merged_range)->max); |
| + (*merged_range)->target = |
| + std::min<uint32_t>((*merged_range)->target, (*merged_range)->max); |
| + (*merged_range)->target = |
| + std::max<uint32_t>((*merged_range)->target, (*merged_range)->min); |
| +} |
| + |
| void VideoBroadcaster::UpdateWants() { |
| RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -80,30 +108,15 @@ void VideoBroadcaster::UpdateWants() { |
| wants.rotation_applied = false; |
| for (auto& sink : sink_pairs()) { |
| // wants.rotation_applied == ANY(sink.wants.rotation_applied) |
| - if (sink.wants.rotation_applied) { |
| + if (sink.wants.rotation_applied) |
| wants.rotation_applied = true; |
| - } |
| - // wants.max_pixel_count == MIN(sink.wants.max_pixel_count) |
| - if (sink.wants.max_pixel_count && |
| - (!wants.max_pixel_count || |
| - (*sink.wants.max_pixel_count < *wants.max_pixel_count))) { |
| - wants.max_pixel_count = sink.wants.max_pixel_count; |
| - } |
| - // Select the minimum requested target_pixel_count, if any, of all sinks so |
| - // that we don't over utilize the resources for any one. |
| - // TODO(sprang): Consider using the median instead, since the limit can be |
| - // expressed by max_pixel_count. |
| - if (sink.wants.target_pixel_count && |
| - (!wants.target_pixel_count || |
| - (*sink.wants.target_pixel_count < *wants.target_pixel_count))) { |
| - wants.target_pixel_count = sink.wants.target_pixel_count; |
| - } |
| - } |
| - if (wants.max_pixel_count && wants.target_pixel_count && |
| - *wants.target_pixel_count >= *wants.max_pixel_count) { |
| - wants.target_pixel_count = wants.max_pixel_count; |
| + if (sink.wants.pixel_count) |
| + MergeWantsRange(&wants.pixel_count, *sink.wants.pixel_count); |
| + if (sink.wants.framerate_fps_) |
| + MergeWantsRange(&wants.framerate_fps_, *sink.wants.framerate_fps_); |
| } |
| + |
| current_wants_ = wants; |
| } |