| 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->color < item2.capability->color; | 36 return item1.capability->supported_format.pixel_format < |
| 37 item2.capability->supported_format.pixel_format; |
| 37 } | 38 } |
| 38 | 39 |
| 39 } // namespace. | 40 } // namespace. |
| 40 | 41 |
| 41 CapabilityList::CapabilityList() { | 42 CapabilityList::CapabilityList() { |
| 42 DetachFromThread(); | 43 DetachFromThread(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 CapabilityList::~CapabilityList() {} | 46 CapabilityList::~CapabilityList() {} |
| 46 | 47 |
| 47 // Appends an entry to the list. | 48 // Appends an entry to the list. |
| 48 void CapabilityList::Add(const VideoCaptureCapabilityWin& capability) { | 49 void CapabilityList::Add(const VideoCaptureCapabilityWin& capability) { |
| 49 DCHECK(CalledOnValidThread()); | 50 DCHECK(CalledOnValidThread()); |
| 50 capabilities_.push_back(capability); | 51 capabilities_.push_back(capability); |
| 51 } | 52 } |
| 52 | 53 |
| 53 const VideoCaptureCapabilityWin& CapabilityList::GetBestMatchedCapability( | 54 const VideoCaptureCapabilityWin& CapabilityList::GetBestMatchedFormat( |
| 54 int requested_width, | 55 int requested_width, |
| 55 int requested_height, | 56 int requested_height, |
| 56 int requested_frame_rate) const { | 57 int requested_frame_rate) const { |
| 57 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
| 58 DCHECK(!capabilities_.empty()); | 59 DCHECK(!capabilities_.empty()); |
| 59 | 60 |
| 60 std::list<ResolutionDiff> diff_list; | 61 std::list<ResolutionDiff> diff_list; |
| 61 | 62 |
| 62 // Loop through the candidates to create a list of differentials between the | 63 // Loop through the candidates to create a list of differentials between the |
| 63 // requested resolution and the camera capability. | 64 // requested resolution and the camera capability. |
| 64 for (Capabilities::const_iterator it = capabilities_.begin(); | 65 for (Capabilities::const_iterator it = capabilities_.begin(); |
| 65 it != capabilities_.end(); ++it) { | 66 it != capabilities_.end(); ++it) { |
| 66 ResolutionDiff diff; | 67 ResolutionDiff diff; |
| 67 diff.capability = &(*it); | 68 diff.capability = &(*it); |
| 68 diff.diff_width = it->width - requested_width; | 69 diff.diff_width = it->supported_format.frame_size.width() - requested_width; |
| 69 diff.diff_height = it->height - requested_height; | 70 diff.diff_height = |
| 71 it->supported_format.frame_size.height() - requested_height; |
| 70 // The 1000 allows using integer arithmetic for f.i. 29.971 fps. | 72 // The 1000 allows using integer arithmetic for f.i. 29.971 fps. |
| 71 diff.diff_frame_rate = | 73 diff.diff_frame_rate = |
| 72 1000 * ((static_cast<float>(it->frame_rate_numerator) / | 74 1000 * ((static_cast<float>(it->frame_rate_numerator) / |
| 73 it->frame_rate_denominator) - | 75 it->frame_rate_denominator) - |
| 74 requested_frame_rate); | 76 requested_frame_rate); |
| 75 diff_list.push_back(diff); | 77 diff_list.push_back(diff); |
| 76 } | 78 } |
| 77 | 79 |
| 78 // Sort the best height candidates. | 80 // Sort the best height candidates. |
| 79 diff_list.sort(&CompareHeight); | 81 diff_list.sort(&CompareHeight); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 break; | 111 break; |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Decide the best color format. | 115 // Decide the best color format. |
| 114 diff_list.sort(&CompareColor); | 116 diff_list.sort(&CompareColor); |
| 115 return *diff_list.front().capability; | 117 return *diff_list.front().capability; |
| 116 } | 118 } |
| 117 | 119 |
| 118 } // namespace media | 120 } // namespace media |
| OLD | NEW |