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.
5 #include "media/capture/video/win/capability_list_win.h"
10 #include "base/logging.h"
14 static bool CompareCapability(const VideoCaptureFormat
& requested
,
15 const CapabilityWin
& capability_lhs
,
16 const CapabilityWin
& capability_rhs
) {
17 const VideoCaptureFormat
& lhs
= capability_lhs
.supported_format
;
18 const VideoCaptureFormat
& rhs
= capability_rhs
.supported_format
;
20 const int diff_height_lhs
=
21 std::abs(lhs
.frame_size
.height() - requested
.frame_size
.height());
22 const int diff_height_rhs
=
23 std::abs(rhs
.frame_size
.height() - requested
.frame_size
.height());
24 if (diff_height_lhs
!= diff_height_rhs
)
25 return diff_height_lhs
< diff_height_rhs
;
27 const int diff_width_lhs
=
28 std::abs(lhs
.frame_size
.width() - requested
.frame_size
.width());
29 const int diff_width_rhs
=
30 std::abs(rhs
.frame_size
.width() - requested
.frame_size
.width());
31 if (diff_width_lhs
!= diff_width_rhs
)
32 return diff_width_lhs
< diff_width_rhs
;
34 const float diff_fps_lhs
= std::fabs(lhs
.frame_rate
- requested
.frame_rate
);
35 const float diff_fps_rhs
= std::fabs(rhs
.frame_rate
- requested
.frame_rate
);
36 if (diff_fps_lhs
!= diff_fps_rhs
)
37 return diff_fps_lhs
< diff_fps_rhs
;
39 return lhs
.pixel_format
< rhs
.pixel_format
;
42 const CapabilityWin
& GetBestMatchedCapability(
43 const VideoCaptureFormat
& requested
,
44 const CapabilityList
& capabilities
) {
45 DCHECK(!capabilities
.empty());
46 const CapabilityWin
* best_match
= &(*capabilities
.begin());
47 for (const CapabilityWin
& capability
: capabilities
) {
48 if (CompareCapability(requested
, capability
, *best_match
))
49 best_match
= &capability
;