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 = 0; | |
122 if (requested_format_ && requested_format_->interval) | |
nisse-webrtc
2017/03/08 08:08:54
The second part of the conditioal seems unnecessar
sprang_webrtc
2017/03/09 13:19:33
Done.
| |
123 frame_interval_ns = requested_format_->interval; | |
124 | |
125 if (max_framerate_request_ != std::numeric_limits<int>::max()) { | |
126 frame_interval_ns = std::max<int64_t>( | |
nisse-webrtc
2017/03/08 08:08:54
Can we make this part unconditional? We ought to h
sprang_webrtc
2017/03/09 13:19:33
Sure, but I'll add a comment about that as it's a
| |
127 frame_interval_ns, rtc::kNumNanosecsPerSec / max_framerate_request_); | |
128 } | |
129 | |
130 if (frame_interval_ns <= 0) { | |
131 // Frame rate throttling not enabled. | |
118 return true; | 132 return true; |
133 } | |
119 | 134 |
120 if (next_frame_timestamp_ns_) { | 135 if (next_frame_timestamp_ns_) { |
121 // Time until next frame should be outputted. | 136 // Time until next frame should be outputted. |
122 const int64_t time_until_next_frame_ns = | 137 const int64_t time_until_next_frame_ns = |
123 (*next_frame_timestamp_ns_ - in_timestamp_ns); | 138 (*next_frame_timestamp_ns_ - in_timestamp_ns); |
124 | 139 |
125 // Continue if timestamp is withing expected range. | 140 // Continue if timestamp is within expected range. |
126 if (std::abs(time_until_next_frame_ns) < 2 * requested_format_->interval) { | 141 if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) { |
127 // Drop if a frame shouldn't be outputted yet. | 142 // Drop if a frame shouldn't be outputted yet. |
128 if (time_until_next_frame_ns > 0) | 143 if (time_until_next_frame_ns > 0) |
129 return false; | 144 return false; |
130 // Time to output new frame. | 145 // Time to output new frame. |
131 *next_frame_timestamp_ns_ += requested_format_->interval; | 146 *next_frame_timestamp_ns_ += frame_interval_ns; |
132 return true; | 147 return true; |
133 } | 148 } |
134 } | 149 } |
135 | 150 |
136 // First timestamp received or timestamp is way outside expected range, so | 151 // First timestamp received or timestamp is way outside expected range, so |
137 // reset. Set first timestamp target to just half the interval to prefer | 152 // reset. Set first timestamp target to just half the interval to prefer |
138 // keeping frames in case of jitter. | 153 // keeping frames in case of jitter. |
139 next_frame_timestamp_ns_ = | 154 next_frame_timestamp_ns_ = |
140 rtc::Optional<int64_t>(in_timestamp_ns + requested_format_->interval / 2); | 155 rtc::Optional<int64_t>(in_timestamp_ns + frame_interval_ns / 2); |
141 return true; | 156 return true; |
142 } | 157 } |
143 | 158 |
144 bool VideoAdapter::AdaptFrameResolution(int in_width, | 159 bool VideoAdapter::AdaptFrameResolution(int in_width, |
145 int in_height, | 160 int in_height, |
146 int64_t in_timestamp_ns, | 161 int64_t in_timestamp_ns, |
147 int* cropped_width, | 162 int* cropped_width, |
148 int* cropped_height, | 163 int* cropped_height, |
149 int* out_width, | 164 int* out_width, |
150 int* out_height) { | 165 int* out_height) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 257 |
243 return true; | 258 return true; |
244 } | 259 } |
245 | 260 |
246 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { | 261 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { |
247 rtc::CritScope cs(&critical_section_); | 262 rtc::CritScope cs(&critical_section_); |
248 requested_format_ = rtc::Optional<VideoFormat>(format); | 263 requested_format_ = rtc::Optional<VideoFormat>(format); |
249 next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); | 264 next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); |
250 } | 265 } |
251 | 266 |
252 void VideoAdapter::OnResolutionRequest( | 267 void VideoAdapter::OnResolutionFramerateRequest( |
253 const rtc::Optional<int>& target_pixel_count, | 268 const rtc::Optional<int>& target_pixel_count, |
254 const rtc::Optional<int>& max_pixel_count) { | 269 const rtc::Optional<int>& max_pixel_count, |
270 const rtc::Optional<int>& framerate_fps) { | |
255 rtc::CritScope cs(&critical_section_); | 271 rtc::CritScope cs(&critical_section_); |
256 resolution_request_max_pixel_count_ = | 272 resolution_request_max_pixel_count_ = |
257 max_pixel_count.value_or(std::numeric_limits<int>::max()); | 273 max_pixel_count.value_or(std::numeric_limits<int>::max()); |
258 resolution_request_target_pixel_count_ = | 274 resolution_request_target_pixel_count_ = |
259 target_pixel_count.value_or(resolution_request_max_pixel_count_); | 275 target_pixel_count.value_or(resolution_request_max_pixel_count_); |
276 max_framerate_request_ = | |
277 framerate_fps.value_or(std::numeric_limits<int>::max()); | |
260 } | 278 } |
261 | 279 |
262 } // namespace cricket | 280 } // namespace cricket |
OLD | NEW |