| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/video/capture/win/capability_list_win.h" | 5 #include "media/video/capture/win/capability_list_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 bool CompareWidth(const ResolutionDiff& item1, const ResolutionDiff& item2) { | 26 bool CompareWidth(const ResolutionDiff& item1, const ResolutionDiff& item2) { |
| 27 return abs(item1.diff_width) < abs(item2.diff_width); | 27 return abs(item1.diff_width) < abs(item2.diff_width); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool CompareFrameRate(const ResolutionDiff& item1, | 30 bool CompareFrameRate(const ResolutionDiff& item1, |
| 31 const ResolutionDiff& item2) { | 31 const ResolutionDiff& item2) { |
| 32 return abs(item1.diff_frame_rate) < abs(item2.diff_frame_rate); | 32 return abs(item1.diff_frame_rate) < abs(item2.diff_frame_rate); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool CompareColor(const ResolutionDiff& item1, const ResolutionDiff& item2) { | 35 bool CompareColor(const ResolutionDiff& item1, const ResolutionDiff& item2) { |
| 36 return item1.capability->supported_format.pixel_format < | 36 return item1.capability->color < item2.capability->color; |
| 37 item2.capability->supported_format.pixel_format; | |
| 38 } | 37 } |
| 39 | 38 |
| 40 } // namespace. | 39 } // namespace. |
| 41 | 40 |
| 42 CapabilityList::CapabilityList() { | 41 CapabilityList::CapabilityList() { |
| 43 DetachFromThread(); | 42 DetachFromThread(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 CapabilityList::~CapabilityList() {} | 45 CapabilityList::~CapabilityList() {} |
| 47 | 46 |
| 48 // Appends an entry to the list. | 47 // Appends an entry to the list. |
| 49 void CapabilityList::Add(const VideoCaptureCapabilityWin& capability) { | 48 void CapabilityList::Add(const VideoCaptureCapabilityWin& capability) { |
| 50 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
| 51 capabilities_.push_back(capability); | 50 capabilities_.push_back(capability); |
| 52 } | 51 } |
| 53 | 52 |
| 54 const VideoCaptureCapabilityWin& CapabilityList::GetBestMatchedFormat( | 53 const VideoCaptureCapabilityWin& CapabilityList::GetBestMatchedCapability( |
| 55 int requested_width, | 54 int requested_width, |
| 56 int requested_height, | 55 int requested_height, |
| 57 int requested_frame_rate) const { | 56 int requested_frame_rate) const { |
| 58 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
| 59 DCHECK(!capabilities_.empty()); | 58 DCHECK(!capabilities_.empty()); |
| 60 | 59 |
| 61 std::list<ResolutionDiff> diff_list; | 60 std::list<ResolutionDiff> diff_list; |
| 62 | 61 |
| 63 // Loop through the candidates to create a list of differentials between the | 62 // Loop through the candidates to create a list of differentials between the |
| 64 // requested resolution and the camera capability. | 63 // requested resolution and the camera capability. |
| 65 for (Capabilities::const_iterator it = capabilities_.begin(); | 64 for (Capabilities::const_iterator it = capabilities_.begin(); |
| 66 it != capabilities_.end(); ++it) { | 65 it != capabilities_.end(); ++it) { |
| 67 ResolutionDiff diff; | 66 ResolutionDiff diff; |
| 68 diff.capability = &(*it); | 67 diff.capability = &(*it); |
| 69 diff.diff_width = it->supported_format.frame_size.width() - requested_width; | 68 diff.diff_width = it->width - requested_width; |
| 70 diff.diff_height = | 69 diff.diff_height = it->height - requested_height; |
| 71 it->supported_format.frame_size.height() - requested_height; | |
| 72 // The 1000 allows using integer arithmetic for f.i. 29.971 fps. | 70 // The 1000 allows using integer arithmetic for f.i. 29.971 fps. |
| 73 diff.diff_frame_rate = | 71 diff.diff_frame_rate = |
| 74 1000 * ((static_cast<float>(it->frame_rate_numerator) / | 72 1000 * ((static_cast<float>(it->frame_rate_numerator) / |
| 75 it->frame_rate_denominator) - | 73 it->frame_rate_denominator) - |
| 76 requested_frame_rate); | 74 requested_frame_rate); |
| 77 diff_list.push_back(diff); | 75 diff_list.push_back(diff); |
| 78 } | 76 } |
| 79 | 77 |
| 80 // Sort the best height candidates. | 78 // Sort the best height candidates. |
| 81 diff_list.sort(&CompareHeight); | 79 diff_list.sort(&CompareHeight); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 111 break; | 109 break; |
| 112 } | 110 } |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Decide the best color format. | 113 // Decide the best color format. |
| 116 diff_list.sort(&CompareColor); | 114 diff_list.sort(&CompareColor); |
| 117 return *diff_list.front().capability; | 115 return *diff_list.front().capability; |
| 118 } | 116 } |
| 119 | 117 |
| 120 } // namespace media | 118 } // namespace media |
| OLD | NEW |