| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/video_capture_types.h" | |
| 6 #include "media/capture/video/win/capability_list_win.h" | |
| 7 | |
| 8 #include <algorithm> | |
| 9 #include <functional> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 | |
| 13 namespace media { | |
| 14 | |
| 15 static bool CompareCapability(const VideoCaptureFormat& requested, | |
| 16 const CapabilityWin& capability_lhs, | |
| 17 const CapabilityWin& capability_rhs) { | |
| 18 const VideoCaptureFormat& lhs = capability_lhs.supported_format; | |
| 19 const VideoCaptureFormat& rhs = capability_rhs.supported_format; | |
| 20 | |
| 21 const int diff_height_lhs = | |
| 22 std::abs(lhs.frame_size.height() - requested.frame_size.height()); | |
| 23 const int diff_height_rhs = | |
| 24 std::abs(rhs.frame_size.height() - requested.frame_size.height()); | |
| 25 if (diff_height_lhs != diff_height_rhs) | |
| 26 return diff_height_lhs < diff_height_rhs; | |
| 27 | |
| 28 const int diff_width_lhs = | |
| 29 std::abs(lhs.frame_size.width() - requested.frame_size.width()); | |
| 30 const int diff_width_rhs = | |
| 31 std::abs(rhs.frame_size.width() - requested.frame_size.width()); | |
| 32 if (diff_width_lhs != diff_width_rhs) | |
| 33 return diff_width_lhs < diff_width_rhs; | |
| 34 | |
| 35 const float diff_fps_lhs = std::fabs(lhs.frame_rate - requested.frame_rate); | |
| 36 const float diff_fps_rhs = std::fabs(rhs.frame_rate - requested.frame_rate); | |
| 37 if (diff_fps_lhs != diff_fps_rhs) | |
| 38 return diff_fps_lhs < diff_fps_rhs; | |
| 39 | |
| 40 return VideoCaptureFormat::ComparePixelFormatPreference(lhs.pixel_format, | |
| 41 rhs.pixel_format); | |
| 42 } | |
| 43 | |
| 44 const CapabilityWin& GetBestMatchedCapability( | |
| 45 const VideoCaptureFormat& requested, | |
| 46 const CapabilityList& capabilities) { | |
| 47 DCHECK(!capabilities.empty()); | |
| 48 const CapabilityWin* best_match = &(*capabilities.begin()); | |
| 49 for (const CapabilityWin& capability : capabilities) { | |
| 50 if (CompareCapability(requested, capability, *best_match)) | |
| 51 best_match = &capability; | |
| 52 } | |
| 53 return *best_match; | |
| 54 } | |
| 55 | |
| 56 } // namespace media | |
| OLD | NEW |