Index: content/browser/media/capture/web_contents_video_capture_device.cc |
diff --git a/content/browser/media/capture/web_contents_video_capture_device.cc b/content/browser/media/capture/web_contents_video_capture_device.cc |
index d90cbd1891668dfa502b55118a22060e5cd0bc80..2eaea1155ed705f6c33a071f87872df5a10f3f7e 100644 |
--- a/content/browser/media/capture/web_contents_video_capture_device.cc |
+++ b/content/browser/media/capture/web_contents_video_capture_device.cc |
@@ -642,6 +642,30 @@ gfx::Size WebContentsCaptureMachine::ComputeOptimalViewSize() const { |
// http://crbug.com/350491 |
gfx::Size optimal_size = oracle_proxy_->max_frame_size(); |
+ // If the max frame size is close to a common video aspect ratio, compute a |
+ // standard resolution for that aspect ratio. For example, given 1365x768, |
+ // which is very close to 16:9, the optimal size would be 1280x720. The |
+ // purpose of this logic is to prevent scaling quality issues caused by "one |
+ // pixel stretching" and/or odd-to-even dimension scaling, and to improve the |
+ // performance of consumers of the captured video. |
+ const auto HasIntendedAspectRatio = [](const gfx::Size& size, int x, int y) { |
Kevin M
2015/07/30 00:23:06
Can you factor this out into a standalone fn that
miu
2015/07/30 20:22:53
Done. Didn't factor anything out, but did write u
|
+ const int a = y * size.width(); |
+ const int b = x * size.height(); |
+ const int percentage_diff = 100 * std::abs((a - b)) / b; |
+ return percentage_diff <= 1; // Effectively, anything strictly <2%. |
+ }; |
+ const auto RoundToExactAspectRatio = [](const gfx::Size& size, int x, int y) { |
+ const int adjusted_height = |
Kevin M
2015/07/30 00:23:06
Can you add some comments or pick a more descripti
miu
2015/07/30 20:22:53
Done.
|
+ std::max(size.height() - (size.height() % y), y); |
+ DCHECK_EQ((adjusted_height * x) % y, 0); |
+ return gfx::Size(adjusted_height * x / y, adjusted_height); |
+ }; |
+ if (HasIntendedAspectRatio(optimal_size, 16, 9)) |
+ optimal_size = RoundToExactAspectRatio(optimal_size, 160, 90); |
+ else if (HasIntendedAspectRatio(optimal_size, 4, 3)) |
+ optimal_size = RoundToExactAspectRatio(optimal_size, 64, 48); |
+ // Else, do not make an adjustment. |
+ |
// If the ratio between physical and logical pixels is greater than 1:1, |
// shrink |optimal_size| by that amount. Then, when external code resizes the |
// render widget to the "preferred size," the widget will be physically |