Chromium Code Reviews| Index: media/video/capture/video_capture_device.cc |
| diff --git a/media/video/capture/video_capture_device.cc b/media/video/capture/video_capture_device.cc |
| index 3b74417cbf823c0e9d235953809fb40a2cadaaef..69d7d1af1eb9b395f9f112ce25028bcc06a7b92b 100644 |
| --- a/media/video/capture/video_capture_device.cc |
| +++ b/media/video/capture/video_capture_device.cc |
| @@ -4,6 +4,8 @@ |
| #include "media/video/capture/video_capture_device.h" |
| +#include <cmath> |
| + |
| #include "base/i18n/timezone.h" |
| #include "base/strings/string_util.h" |
| @@ -85,4 +87,33 @@ bool VideoCaptureDevice::InitializeImageCapture( |
| return false; |
| } |
| +uint64_t DiffVideoCaptureFormat(const VideoCaptureFormat& requested, |
| + const VideoCaptureFormat& supported) { |
| + const uint64_t diff_width = |
| + std::abs(requested.frame_size.width() - supported.frame_size.width()); |
| + const uint64_t diff_height = |
| + std::abs(requested.frame_size.height() - supported.frame_size.height()); |
| + // We need to distinguish between rational frame rates (e.g. 29.97 and 30.0). |
| + // Therefore, multiply with a large constant before converting to int. |
| + const uint64_t diff_frame_rate = static_cast<uint64_t>( |
| + kFrameRatePrecision * |
| + std::fabs(requested.frame_rate - supported.frame_rate)); |
| + const uint64_t diff_color_format = supported.pixel_format; |
|
perkj_chrome
2014/10/10 09:17:13
I am afraid that pixelformat is not really sorted
magjed_chromium
2014/10/10 11:21:26
Done.
|
| + |
| + const int resolution_bit_size = 16; |
|
perkj_chrome
2014/10/10 09:17:13
nit: http://google-styleguide.googlecode.com/svn/t
magjed_chromium
2014/10/10 11:21:25
These constants are in local scope, so it's ok to
|
| + const int frame_rate_bit_size = 24; |
| + const int color_format_bit_size = 8; |
| + |
| + DCHECK(diff_width < (1 << resolution_bit_size)); |
| + DCHECK(diff_height < (1 << resolution_bit_size)); |
| + DCHECK(diff_frame_rate < (1 << frame_rate_bit_size)); |
| + DCHECK(diff_color_format < (1 << color_format_bit_size)); |
| + |
| + uint64_t distance = diff_height; |
| + distance = diff_width | (distance << resolution_bit_size); |
| + distance = diff_frame_rate | (distance << frame_rate_bit_size); |
| + distance = diff_color_format | (distance << color_format_bit_size); |
| + return distance; |
| +} |
| + |
| } // namespace media |