Index: media/video/capture/video_capture_types.cc |
diff --git a/media/video/capture/video_capture_types.cc b/media/video/capture/video_capture_types.cc |
index 39ca75527ed7a7a9eb220a09dc8476aa1c411cd4..4ab586a9f3c8b7f9385855258395c960972d3c82 100644 |
--- a/media/video/capture/video_capture_types.cc |
+++ b/media/video/capture/video_capture_types.cc |
@@ -4,6 +4,8 @@ |
#include "media/video/capture/video_capture_types.h" |
+#include <cmath> |
+ |
#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
#include "media/base/limits.h" |
@@ -69,4 +71,35 @@ std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) { |
VideoCaptureParams::VideoCaptureParams() : allow_resolution_change(false) {} |
+namespace { |
+struct DiffVideoCaptureFormat { |
+ DiffVideoCaptureFormat(const VideoCaptureFormat& requested, |
+ const VideoCaptureFormat& supported) |
+ : diff_width(std::abs(requested.frame_size.width() - |
+ supported.frame_size.width())), |
+ diff_height(std::abs(requested.frame_size.height() - |
+ supported.frame_size.height())), |
+ diff_frame_rate(std::fabs(requested.frame_rate - |
+ supported.frame_rate)) {} |
+ int diff_width; |
tommi (sloooow) - chröme
2014/09/09 20:11:10
make all of these const?
|
+ int diff_height; |
+ float diff_frame_rate; |
+}; |
+} // namespace. |
+ |
+CompareVideoFormat::CompareVideoFormat(const VideoCaptureFormat& requested) |
+ : requested_(requested) {} |
+ |
+bool CompareVideoFormat::operator()( |
+ const VideoCaptureFormat& lhs_format, |
+ const VideoCaptureFormat& rhs_format) const { |
+ const DiffVideoCaptureFormat lhs(requested_, lhs_format); |
+ const DiffVideoCaptureFormat rhs(requested_, rhs_format); |
+ if (lhs.diff_height != rhs.diff_height) |
+ return lhs.diff_height < rhs.diff_height; |
+ if (lhs.diff_width != rhs.diff_width) |
+ return lhs.diff_width < rhs.diff_width; |
+ return lhs.diff_frame_rate < rhs.diff_frame_rate; |
+} |
+ |
} // namespace media |