OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/video_capture_device_factory_win.h" | 5 #include "media/video/capture/win/video_capture_device_factory_win.h" |
6 | 6 |
7 #include <mfapi.h> | 7 #include <mfapi.h> |
8 #include <mferror.h> | 8 #include <mferror.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 int index = 0; | 212 int index = 0; |
213 ScopedVariant device_id; | 213 ScopedVariant device_id; |
214 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { | 214 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { |
215 ScopedComPtr<IPropertyBag> prop_bag; | 215 ScopedComPtr<IPropertyBag> prop_bag; |
216 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); | 216 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); |
217 if (FAILED(hr)) { | 217 if (FAILED(hr)) { |
218 moniker.Release(); | 218 moniker.Release(); |
219 continue; | 219 continue; |
220 } | 220 } |
221 | 221 |
| 222 std::string id; |
222 device_id.Reset(); | 223 device_id.Reset(); |
223 hr = prop_bag->Read(L"DevicePath", device_id.Receive(), 0); | 224 hr = prop_bag->Read(L"DevicePath", device_id.Receive(), 0); |
224 if (FAILED(hr)) { | 225 if (FAILED(hr) || device_id.type() != VT_BSTR) { |
225 DVLOG(1) << "Couldn't read a device's DevicePath."; | 226 // If there is no clear DevicePath, try with Description and FriendlyName. |
226 return; | 227 ScopedVariant name; |
| 228 if (SUCCEEDED(prop_bag->Read(L"Description", name.Receive(), 0)) || |
| 229 SUCCEEDED(prop_bag->Read(L"FriendlyName", name.Receive(), 0))) { |
| 230 id = base::SysWideToUTF8(V_BSTR(&name)); |
| 231 } |
| 232 } else { |
| 233 DCHECK_EQ(device_id.type(), VT_BSTR); |
| 234 id = base::SysWideToUTF8(V_BSTR(&device_id)); |
227 } | 235 } |
228 if (device.id() == base::SysWideToUTF8(V_BSTR(&device_id))) | 236 |
| 237 if (device.id() == id) |
229 break; | 238 break; |
230 moniker.Release(); | 239 moniker.Release(); |
231 } | 240 } |
232 | 241 |
233 if (moniker.get()) { | 242 if (moniker.get()) { |
234 base::win::ScopedComPtr<IBaseFilter> capture_filter; | 243 base::win::ScopedComPtr<IBaseFilter> capture_filter; |
235 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, | 244 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, |
236 capture_filter.Receive()); | 245 capture_filter.Receive()); |
237 if (!capture_filter) { | 246 if (!capture_filter) { |
238 DVLOG(2) << "Failed to create capture filter."; | 247 DVLOG(2) << "Failed to create capture filter."; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 const VideoCaptureDevice::Name& device, | 436 const VideoCaptureDevice::Name& device, |
428 VideoCaptureFormats* formats) { | 437 VideoCaptureFormats* formats) { |
429 DCHECK(thread_checker_.CalledOnValidThread()); | 438 DCHECK(thread_checker_.CalledOnValidThread()); |
430 if (use_media_foundation_) | 439 if (use_media_foundation_) |
431 GetDeviceSupportedFormatsMediaFoundation(device, formats); | 440 GetDeviceSupportedFormatsMediaFoundation(device, formats); |
432 else | 441 else |
433 GetDeviceSupportedFormatsDirectShow(device, formats); | 442 GetDeviceSupportedFormatsDirectShow(device, formats); |
434 } | 443 } |
435 | 444 |
436 } // namespace media | 445 } // namespace media |
OLD | NEW |