Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 if (sink_pair.wants.black_frames) { | 66 if (sink_pair.wants.black_frames) { |
| 67 sink_pair.sink->OnFrame(webrtc::VideoFrame( | 67 sink_pair.sink->OnFrame(webrtc::VideoFrame( |
| 68 GetBlackFrameBuffer(frame.width(), frame.height()), frame.rotation(), | 68 GetBlackFrameBuffer(frame.width(), frame.height()), frame.rotation(), |
| 69 frame.timestamp_us())); | 69 frame.timestamp_us())); |
| 70 } else { | 70 } else { |
| 71 sink_pair.sink->OnFrame(frame); | 71 sink_pair.sink->OnFrame(frame); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void VideoBroadcaster::MergeWantsRange( | |
| 77 rtc::Optional<rtc::VideoSinkWants::Range>* merged_range, | |
| 78 const rtc::VideoSinkWants::Range& item) { | |
| 79 if (!*merged_range) { | |
| 80 merged_range->emplace(item); | |
| 81 return; | |
| 82 } | |
|
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
| |
| 83 | |
| 84 // Merge the constraints if there are more than one wants. Lowest max | |
| 85 // will set the max cap and the highest min will set the min cap, as | |
| 86 // these are pretty hard bounds. For now chose the min of the targets as | |
| 87 // well, erring of the side of caution so that we don't overutilize some | |
| 88 // resource. | |
| 89 // TODO(sprang): Consider using median of targets? | |
| 90 (*merged_range)->max = std::min<uint32_t>((*merged_range)->max, item.max); | |
| 91 (*merged_range)->target = | |
| 92 std::min<uint32_t>((*merged_range)->target, item.target); | |
| 93 (*merged_range)->min = std::max<uint32_t>((*merged_range)->min, item.min); | |
| 94 | |
| 95 // Make sure there is no contradiction in the merged wants. | |
| 96 (*merged_range)->min = | |
| 97 std::min<uint32_t>((*merged_range)->min, (*merged_range)->max); | |
| 98 (*merged_range)->target = | |
| 99 std::min<uint32_t>((*merged_range)->target, (*merged_range)->max); | |
| 100 (*merged_range)->target = | |
| 101 std::max<uint32_t>((*merged_range)->target, (*merged_range)->min); | |
| 102 } | |
| 103 | |
| 76 void VideoBroadcaster::UpdateWants() { | 104 void VideoBroadcaster::UpdateWants() { |
| 77 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 105 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 78 | 106 |
| 79 VideoSinkWants wants; | 107 VideoSinkWants wants; |
| 80 wants.rotation_applied = false; | 108 wants.rotation_applied = false; |
| 81 for (auto& sink : sink_pairs()) { | 109 for (auto& sink : sink_pairs()) { |
| 82 // wants.rotation_applied == ANY(sink.wants.rotation_applied) | 110 // wants.rotation_applied == ANY(sink.wants.rotation_applied) |
| 83 if (sink.wants.rotation_applied) { | 111 if (sink.wants.rotation_applied) |
| 84 wants.rotation_applied = true; | 112 wants.rotation_applied = true; |
| 85 } | 113 |
| 86 // wants.max_pixel_count == MIN(sink.wants.max_pixel_count) | 114 if (sink.wants.pixel_count) |
| 87 if (sink.wants.max_pixel_count && | 115 MergeWantsRange(&wants.pixel_count, *sink.wants.pixel_count); |
| 88 (!wants.max_pixel_count || | 116 if (sink.wants.framerate_fps_) |
| 89 (*sink.wants.max_pixel_count < *wants.max_pixel_count))) { | 117 MergeWantsRange(&wants.framerate_fps_, *sink.wants.framerate_fps_); |
| 90 wants.max_pixel_count = sink.wants.max_pixel_count; | |
| 91 } | |
| 92 // Select the minimum requested target_pixel_count, if any, of all sinks so | |
| 93 // that we don't over utilize the resources for any one. | |
| 94 // TODO(sprang): Consider using the median instead, since the limit can be | |
| 95 // expressed by max_pixel_count. | |
| 96 if (sink.wants.target_pixel_count && | |
| 97 (!wants.target_pixel_count || | |
| 98 (*sink.wants.target_pixel_count < *wants.target_pixel_count))) { | |
| 99 wants.target_pixel_count = sink.wants.target_pixel_count; | |
| 100 } | |
| 101 } | 118 } |
| 102 | 119 |
| 103 if (wants.max_pixel_count && wants.target_pixel_count && | |
| 104 *wants.target_pixel_count >= *wants.max_pixel_count) { | |
| 105 wants.target_pixel_count = wants.max_pixel_count; | |
| 106 } | |
| 107 current_wants_ = wants; | 120 current_wants_ = wants; |
| 108 } | 121 } |
| 109 | 122 |
| 110 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& | 123 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& |
| 111 VideoBroadcaster::GetBlackFrameBuffer(int width, int height) { | 124 VideoBroadcaster::GetBlackFrameBuffer(int width, int height) { |
| 112 if (!black_frame_buffer_ || black_frame_buffer_->width() != width || | 125 if (!black_frame_buffer_ || black_frame_buffer_->width() != width || |
| 113 black_frame_buffer_->height() != height) { | 126 black_frame_buffer_->height() != height) { |
| 114 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 127 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 115 webrtc::I420Buffer::Create(width, height); | 128 webrtc::I420Buffer::Create(width, height); |
| 116 webrtc::I420Buffer::SetBlack(buffer.get()); | 129 webrtc::I420Buffer::SetBlack(buffer.get()); |
| 117 black_frame_buffer_ = buffer; | 130 black_frame_buffer_ = buffer; |
| 118 } | 131 } |
| 119 | 132 |
| 120 return black_frame_buffer_; | 133 return black_frame_buffer_; |
| 121 } | 134 } |
| 122 | 135 |
| 123 } // namespace rtc | 136 } // namespace rtc |
| OLD | NEW |