OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 | 99 |
100 VideoAdapter::VideoAdapter(int required_resolution_alignment) | 100 VideoAdapter::VideoAdapter(int required_resolution_alignment) |
101 : frames_in_(0), | 101 : frames_in_(0), |
102 frames_out_(0), | 102 frames_out_(0), |
103 frames_scaled_(0), | 103 frames_scaled_(0), |
104 adaption_changes_(0), | 104 adaption_changes_(0), |
105 previous_width_(0), | 105 previous_width_(0), |
106 previous_height_(0), | 106 previous_height_(0), |
107 required_resolution_alignment_(required_resolution_alignment), | 107 required_resolution_alignment_(required_resolution_alignment), |
108 resolution_request_target_pixel_count_(std::numeric_limits<int>::max()), | 108 resolution_request_target_pixel_count_(std::numeric_limits<int>::max()), |
109 resolution_request_max_pixel_count_(std::numeric_limits<int>::max()) {} | 109 resolution_request_max_pixel_count_(std::numeric_limits<int>::max()), |
110 max_framerate_request_(std::numeric_limits<int>::max()) {} | |
110 | 111 |
111 VideoAdapter::VideoAdapter() : VideoAdapter(1) {} | 112 VideoAdapter::VideoAdapter() : VideoAdapter(1) {} |
112 | 113 |
113 VideoAdapter::~VideoAdapter() {} | 114 VideoAdapter::~VideoAdapter() {} |
114 | 115 |
115 bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { | 116 bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { |
116 rtc::CritScope cs(&critical_section_); | 117 rtc::CritScope cs(&critical_section_); |
117 if (!requested_format_ || requested_format_->interval == 0) | 118 if (max_framerate_request_ <= 0) |
119 return false; | |
120 | |
121 int64_t frame_interval_ns = | |
122 requested_format_ ? requested_format_->interval : 0; | |
123 | |
124 // If |max_framerate_request_| is not set, it will default to maxint, which | |
125 // will lead to a frame_interval_ns rounded to 0. | |
126 frame_interval_ns = std::max<int64_t>( | |
127 frame_interval_ns, rtc::kNumNanosecsPerSec / max_framerate_request_); | |
128 | |
129 if (frame_interval_ns <= 0) { | |
130 // Frame rate throttling not enabled. | |
118 return true; | 131 return true; |
132 } | |
119 | 133 |
120 if (next_frame_timestamp_ns_) { | 134 if (next_frame_timestamp_ns_) { |
121 // Time until next frame should be outputted. | 135 // Time until next frame should be outputted. |
122 const int64_t time_until_next_frame_ns = | 136 const int64_t time_until_next_frame_ns = |
123 (*next_frame_timestamp_ns_ - in_timestamp_ns); | 137 (*next_frame_timestamp_ns_ - in_timestamp_ns); |
124 | 138 |
125 // Continue if timestamp is withing expected range. | 139 // Continue if timestamp is within expected range. |
126 if (std::abs(time_until_next_frame_ns) < 2 * requested_format_->interval) { | 140 if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) { |
127 // Drop if a frame shouldn't be outputted yet. | 141 // Drop if a frame shouldn't be outputted yet. |
128 if (time_until_next_frame_ns > 0) | 142 if (time_until_next_frame_ns > 0) |
129 return false; | 143 return false; |
130 // Time to output new frame. | 144 // Time to output new frame. |
131 *next_frame_timestamp_ns_ += requested_format_->interval; | 145 *next_frame_timestamp_ns_ += frame_interval_ns; |
132 return true; | 146 return true; |
133 } | 147 } |
134 } | 148 } |
135 | 149 |
136 // First timestamp received or timestamp is way outside expected range, so | 150 // First timestamp received or timestamp is way outside expected range, so |
137 // reset. Set first timestamp target to just half the interval to prefer | 151 // reset. Set first timestamp target to just half the interval to prefer |
138 // keeping frames in case of jitter. | 152 // keeping frames in case of jitter. |
139 next_frame_timestamp_ns_ = | 153 next_frame_timestamp_ns_ = |
140 rtc::Optional<int64_t>(in_timestamp_ns + requested_format_->interval / 2); | 154 rtc::Optional<int64_t>(in_timestamp_ns + frame_interval_ns / 2); |
141 return true; | 155 return true; |
142 } | 156 } |
143 | 157 |
144 bool VideoAdapter::AdaptFrameResolution(int in_width, | 158 bool VideoAdapter::AdaptFrameResolution(int in_width, |
145 int in_height, | 159 int in_height, |
146 int64_t in_timestamp_ns, | 160 int64_t in_timestamp_ns, |
147 int* cropped_width, | 161 int* cropped_width, |
148 int* cropped_height, | 162 int* cropped_height, |
149 int* out_width, | 163 int* out_width, |
150 int* out_height) { | 164 int* out_height) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 256 |
243 return true; | 257 return true; |
244 } | 258 } |
245 | 259 |
246 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { | 260 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { |
247 rtc::CritScope cs(&critical_section_); | 261 rtc::CritScope cs(&critical_section_); |
248 requested_format_ = rtc::Optional<VideoFormat>(format); | 262 requested_format_ = rtc::Optional<VideoFormat>(format); |
249 next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); | 263 next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); |
250 } | 264 } |
251 | 265 |
252 void VideoAdapter::OnResolutionRequest( | 266 void VideoAdapter::OnResolutionFramerateRequest( |
253 const rtc::Optional<int>& target_pixel_count, | 267 const rtc::Optional<int>& target_pixel_count, |
254 const rtc::Optional<int>& max_pixel_count) { | 268 const rtc::Optional<int>& max_pixel_count, |
269 const rtc::Optional<int>& framerate_fps) { | |
nisse-webrtc
2017/03/14 09:00:28
Even if you want to keep optional in the SinkWants
sprang_webrtc
2017/03/14 14:15:02
Removed optional everywhere for max_pixel and fps.
| |
255 rtc::CritScope cs(&critical_section_); | 270 rtc::CritScope cs(&critical_section_); |
256 resolution_request_max_pixel_count_ = | 271 resolution_request_max_pixel_count_ = |
257 max_pixel_count.value_or(std::numeric_limits<int>::max()); | 272 max_pixel_count.value_or(std::numeric_limits<int>::max()); |
258 resolution_request_target_pixel_count_ = | 273 resolution_request_target_pixel_count_ = |
259 target_pixel_count.value_or(resolution_request_max_pixel_count_); | 274 target_pixel_count.value_or(resolution_request_max_pixel_count_); |
275 max_framerate_request_ = | |
276 framerate_fps.value_or(std::numeric_limits<int>::max()); | |
260 } | 277 } |
261 | 278 |
262 } // namespace cricket | 279 } // namespace cricket |
OLD | NEW |