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