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/capture/video/win/video_capture_device_win.h" | 5 #include "media/capture/video/win/video_capture_device_win.h" |
6 | 6 |
7 #include <ks.h> | 7 #include <ks.h> |
8 #include <ksmedia.h> | 8 #include <ksmedia.h> |
| 9 #include <objbase.h> |
9 | 10 |
10 #include <algorithm> | 11 #include <algorithm> |
11 #include <list> | 12 #include <list> |
12 #include <utility> | 13 #include <utility> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
16 #include "base/win/scoped_co_mem.h" | 17 #include "base/win/scoped_co_mem.h" |
17 #include "base/win/scoped_variant.h" | 18 #include "base/win/scoped_variant.h" |
18 #include "media/base/timestamp_constants.h" | 19 #include "media/base/timestamp_constants.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // CreateClassEnumerator returns S_FALSE on some Windows OS | 80 // CreateClassEnumerator returns S_FALSE on some Windows OS |
80 // when no camera exist. Therefore the FAILED macro can't be used. | 81 // when no camera exist. Therefore the FAILED macro can't be used. |
81 if (hr != S_OK) | 82 if (hr != S_OK) |
82 return hr; | 83 return hr; |
83 | 84 |
84 ScopedComPtr<IBaseFilter> capture_filter; | 85 ScopedComPtr<IBaseFilter> capture_filter; |
85 for (ScopedComPtr<IMoniker> moniker; | 86 for (ScopedComPtr<IMoniker> moniker; |
86 enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK; | 87 enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK; |
87 moniker.Reset()) { | 88 moniker.Reset()) { |
88 ScopedComPtr<IPropertyBag> prop_bag; | 89 ScopedComPtr<IPropertyBag> prop_bag; |
89 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); | 90 hr = moniker->BindToStorage(0, 0, IID_PPV_ARGS(&prop_bag)); |
90 if (FAILED(hr)) | 91 if (FAILED(hr)) |
91 continue; | 92 continue; |
92 | 93 |
93 // Find |device_id| via DevicePath, Description or FriendlyName, whichever | 94 // Find |device_id| via DevicePath, Description or FriendlyName, whichever |
94 // is available first and is a VT_BSTR (i.e. String) type. | 95 // is available first and is a VT_BSTR (i.e. String) type. |
95 static const wchar_t* kPropertyNames[] = { | 96 static const wchar_t* kPropertyNames[] = { |
96 L"DevicePath", L"Description", L"FriendlyName"}; | 97 L"DevicePath", L"Description", L"FriendlyName"}; |
97 | 98 |
98 ScopedVariant name; | 99 ScopedVariant name; |
99 for (const auto* property_name : kPropertyNames) { | 100 for (const auto* property_name : kPropertyNames) { |
100 prop_bag->Read(property_name, name.Receive(), 0); | 101 prop_bag->Read(property_name, name.Receive(), 0); |
101 if (name.type() == VT_BSTR) | 102 if (name.type() == VT_BSTR) |
102 break; | 103 break; |
103 } | 104 } |
104 | 105 |
105 if (name.type() == VT_BSTR) { | 106 if (name.type() == VT_BSTR) { |
106 const std::string device_path(base::SysWideToUTF8(V_BSTR(name.ptr()))); | 107 const std::string device_path(base::SysWideToUTF8(V_BSTR(name.ptr()))); |
107 if (device_path.compare(device_id) == 0) { | 108 if (device_path.compare(device_id) == 0) { |
108 // We have found the requested device | 109 // We have found the requested device |
109 hr = moniker->BindToObject(0, 0, IID_IBaseFilter, | 110 hr = moniker->BindToObject(0, 0, IID_PPV_ARGS(&capture_filter)); |
110 capture_filter.ReceiveVoid()); | |
111 DLOG_IF(ERROR, FAILED(hr)) << "Failed to bind camera filter: " | 111 DLOG_IF(ERROR, FAILED(hr)) << "Failed to bind camera filter: " |
112 << logging::SystemErrorCodeToString(hr); | 112 << logging::SystemErrorCodeToString(hr); |
113 break; | 113 break; |
114 } | 114 } |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 *filter = capture_filter.Detach(); | 118 *filter = capture_filter.Detach(); |
119 if (!*filter && SUCCEEDED(hr)) | 119 if (!*filter && SUCCEEDED(hr)) |
120 hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); | 120 hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 void VideoCaptureDeviceWin::SetErrorState( | 590 void VideoCaptureDeviceWin::SetErrorState( |
591 const tracked_objects::Location& from_here, | 591 const tracked_objects::Location& from_here, |
592 const std::string& reason, | 592 const std::string& reason, |
593 HRESULT hr) { | 593 HRESULT hr) { |
594 DCHECK(thread_checker_.CalledOnValidThread()); | 594 DCHECK(thread_checker_.CalledOnValidThread()); |
595 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); | 595 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); |
596 state_ = kError; | 596 state_ = kError; |
597 client_->OnError(from_here, reason); | 597 client_->OnError(from_here, reason); |
598 } | 598 } |
599 } // namespace media | 599 } // namespace media |
OLD | NEW |