Chromium Code Reviews| Index: webrtc/media/base/videoadapter.cc |
| diff --git a/webrtc/media/base/videoadapter.cc b/webrtc/media/base/videoadapter.cc |
| index 589be63c8021351e9d690f611b12705e9ca088e4..98c8056e3eefffbfb352ff3caf00e4aa285c4834 100644 |
| --- a/webrtc/media/base/videoadapter.cc |
| +++ b/webrtc/media/base/videoadapter.cc |
| @@ -106,7 +106,8 @@ VideoAdapter::VideoAdapter(int required_resolution_alignment) |
| previous_height_(0), |
| required_resolution_alignment_(required_resolution_alignment), |
| resolution_request_target_pixel_count_(std::numeric_limits<int>::max()), |
| - resolution_request_max_pixel_count_(std::numeric_limits<int>::max()) {} |
| + resolution_request_max_pixel_count_(std::numeric_limits<int>::max()), |
| + max_framerate_request_(std::numeric_limits<int>::max()) {} |
| VideoAdapter::VideoAdapter() : VideoAdapter(1) {} |
| @@ -114,21 +115,32 @@ VideoAdapter::~VideoAdapter() {} |
| bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { |
| rtc::CritScope cs(&critical_section_); |
| - if (!requested_format_ || requested_format_->interval == 0) |
| + int64_t frame_interval_ns = 0; |
| + if (requested_format_ && requested_format_->interval) |
| + frame_interval_ns = requested_format_->interval; |
| + |
| + 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_ !=
|
| + frame_interval_ns = std::max<int64_t>( |
| + frame_interval_ns, rtc::kNumNanosecsPerSec / max_framerate_request_); |
| + } |
| + |
| + if (frame_interval_ns <= 0) { |
| + // Frame rate throttling not enabled. |
| return true; |
| + } |
| if (next_frame_timestamp_ns_) { |
| // Time until next frame should be outputted. |
| const int64_t time_until_next_frame_ns = |
| (*next_frame_timestamp_ns_ - in_timestamp_ns); |
| - // Continue if timestamp is withing expected range. |
| - if (std::abs(time_until_next_frame_ns) < 2 * requested_format_->interval) { |
| + // Continue if timestamp is within expected range. |
| + if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) { |
| // Drop if a frame shouldn't be outputted yet. |
| if (time_until_next_frame_ns > 0) |
| return false; |
| // Time to output new frame. |
| - *next_frame_timestamp_ns_ += requested_format_->interval; |
| + *next_frame_timestamp_ns_ += frame_interval_ns; |
| return true; |
| } |
| } |
| @@ -137,7 +149,7 @@ bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { |
| // reset. Set first timestamp target to just half the interval to prefer |
| // keeping frames in case of jitter. |
| next_frame_timestamp_ns_ = |
| - rtc::Optional<int64_t>(in_timestamp_ns + requested_format_->interval / 2); |
| + rtc::Optional<int64_t>(in_timestamp_ns + frame_interval_ns / 2); |
| return true; |
| } |
| @@ -249,14 +261,17 @@ void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { |
| next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); |
| } |
| -void VideoAdapter::OnResolutionRequest( |
| +void VideoAdapter::OnResolutionFramerateRequest( |
| const rtc::Optional<int>& target_pixel_count, |
| - const rtc::Optional<int>& max_pixel_count) { |
| + const rtc::Optional<int>& max_pixel_count, |
| + const rtc::Optional<int>& framerate_fps) { |
| rtc::CritScope cs(&critical_section_); |
| resolution_request_max_pixel_count_ = |
| max_pixel_count.value_or(std::numeric_limits<int>::max()); |
| resolution_request_target_pixel_count_ = |
| target_pixel_count.value_or(resolution_request_max_pixel_count_); |
| + max_framerate_request_ = |
| + framerate_fps.value_or(std::numeric_limits<int>::max()); |
| } |
| } // namespace cricket |