Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: webrtc/media/base/videoadapter.cc

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: Comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/base/videoadapter.h ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/media/base/videoadapter.cc
diff --git a/webrtc/media/base/videoadapter.cc b/webrtc/media/base/videoadapter.cc
index 522d175426bad752dc94134183c2c2de9af0c84b..bee2a5730161e4e926006f8a8b89aa1e1ce90518 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,34 @@ VideoAdapter::~VideoAdapter() {}
bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) {
rtc::CritScope cs(&critical_section_);
- if (!requested_format_ || requested_format_->interval == 0)
+ if (max_framerate_request_ <= 0)
+ return false;
+
+ int64_t frame_interval_ns =
+ requested_format_ ? requested_format_->interval : 0;
+
+ // If |max_framerate_request_| is not set, it will default to maxint, which
+ // will lead to a frame_interval_ns rounded to 0.
+ 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 +151,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 +263,15 @@ 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) {
+ int max_pixel_count,
+ int max_framerate_fps) {
rtc::CritScope cs(&critical_section_);
- resolution_request_max_pixel_count_ =
- max_pixel_count.value_or(std::numeric_limits<int>::max());
+ resolution_request_max_pixel_count_ = max_pixel_count;
resolution_request_target_pixel_count_ =
target_pixel_count.value_or(resolution_request_max_pixel_count_);
+ max_framerate_request_ = max_framerate_fps;
}
} // namespace cricket
« no previous file with comments | « webrtc/media/base/videoadapter.h ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698