Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 static bool EnumerateVideoDevicesMediaFoundation(IMFActivate*** devices, | 84 static bool EnumerateVideoDevicesMediaFoundation(IMFActivate*** devices, |
| 85 UINT32* count) { | 85 UINT32* count) { |
| 86 ScopedComPtr<IMFAttributes> attributes; | 86 ScopedComPtr<IMFAttributes> attributes; |
| 87 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 1)) | 87 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 1)) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 return SUCCEEDED(MFEnumDeviceSources(attributes, devices, count)); | 90 return SUCCEEDED(MFEnumDeviceSources(attributes, devices, count)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 static void GetDeviceNamesDirectShow( | 93 static void GetDeviceNamesDirectShow( |
| 94 const CLSID class_id, | 94 const CLSID& class_id, |
| 95 const Name::CaptureApiType capture_api_type, | 95 const Name::CaptureApiType capture_api_type, |
| 96 Names* device_names) { | 96 Names* device_names) { |
| 97 DCHECK(device_names); | 97 DCHECK(device_names); |
| 98 DVLOG(1) << " GetDeviceNamesDirectShow"; | 98 DVLOG(1) << " GetDeviceNamesDirectShow"; |
| 99 | 99 |
| 100 ScopedComPtr<ICreateDevEnum> dev_enum; | 100 ScopedComPtr<ICreateDevEnum> dev_enum; |
| 101 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, | 101 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, |
| 102 CLSCTX_INPROC); | 102 CLSCTX_INPROC); |
| 103 if (FAILED(hr)) | 103 if (FAILED(hr)) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 ScopedComPtr<IEnumMoniker> enum_moniker; | 106 ScopedComPtr<IEnumMoniker> enum_moniker; |
| 107 hr = dev_enum->CreateClassEnumerator(class_id, enum_moniker.Receive(), 0); | 107 hr = dev_enum->CreateClassEnumerator(class_id, enum_moniker.Receive(), 0); |
| 108 // CreateClassEnumerator returns S_FALSE on some Windows OS | 108 // CreateClassEnumerator returns S_FALSE on some Windows OS |
| 109 // when no camera exist. Therefore the FAILED macro can't be used. | 109 // when no camera exist. Therefore the FAILED macro can't be used. |
| 110 if (hr != S_OK) | 110 if (hr != S_OK) |
| 111 return; | 111 return; |
| 112 | 112 |
| 113 // Name of a fake DirectShow filter that exist on computers with | |
| 114 // GTalk installed. | |
| 115 static const char kGoogleCameraAdapter[] = "google camera adapter"; | |
| 116 | |
| 117 // Enumerate all video capture devices. | 113 // Enumerate all video capture devices. |
| 118 ScopedComPtr<IMoniker> moniker; | 114 for (ScopedComPtr<IMoniker> moniker; |
|
tommi (sloooow) - chröme
2014/09/05 09:26:40
nice way of scoping the moniker variable
| |
| 119 int index = 0; | 115 enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK; |
| 120 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { | 116 moniker.Release()) { |
| 121 ScopedComPtr<IPropertyBag> prop_bag; | 117 ScopedComPtr<IPropertyBag> prop_bag; |
| 122 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); | 118 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); |
| 123 if (FAILED(hr)) { | 119 if (FAILED(hr)) |
| 124 moniker.Release(); | 120 continue; |
| 125 return; | |
| 126 } | |
| 127 | 121 |
| 128 // Find the description or friendly name. | 122 // Find the description or friendly name. |
| 129 ScopedVariant name; | 123 ScopedVariant name; |
| 130 hr = prop_bag->Read(L"Description", name.Receive(), 0); | 124 hr = prop_bag->Read(L"Description", name.Receive(), 0); |
| 131 if (FAILED(hr)) | 125 if (FAILED(hr)) |
| 132 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); | 126 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); |
| 133 | 127 |
| 134 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { | 128 if (FAILED(hr) || name.type() != VT_BSTR) |
| 135 // Ignore all VFW drivers and the special Google Camera Adapter. | 129 continue; |
| 136 // Google Camera Adapter is not a real DirectShow camera device. | |
| 137 // VFW are very old Video for Windows drivers that can not be used. | |
| 138 const wchar_t* str_ptr = V_BSTR(&name); | |
| 139 const int name_length = arraysize(kGoogleCameraAdapter) - 1; | |
| 140 | 130 |
| 141 if ((wcsstr(str_ptr, L"(VFW)") == NULL) && | 131 // Ignore all VFW drivers and the special Google Camera Adapter. |
| 142 lstrlenW(str_ptr) < name_length || | 132 // Google Camera Adapter is not a real DirectShow camera device. |
| 143 (!(LowerCaseEqualsASCII(str_ptr, str_ptr + name_length, | 133 // VFW are very old Video for Windows drivers that can not be used. |
| 144 kGoogleCameraAdapter)))) { | 134 const wchar_t* str_ptr = V_BSTR(&name); |
| 145 std::string id; | 135 // Name of a fake DirectShow filter that exist on computers with |
| 146 std::string device_name(base::SysWideToUTF8(str_ptr)); | 136 // GTalk installed. |
| 147 name.Reset(); | 137 static const char kGoogleCameraAdapter[] = "google camera adapter"; |
|
magjed_chromium
2014/09/05 09:15:09
Per, can we remove this?
perkj_chrome
2014/09/05 13:52:39
I would keep it for now. I think this is a fake de
| |
| 148 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); | 138 if (wcsstr(str_ptr, L"(VFW)") != NULL || |
| 149 if (FAILED(hr) || name.type() != VT_BSTR) { | 139 LowerCaseEqualsASCII(str_ptr, |
| 150 id = device_name; | 140 str_ptr + arraysize(kGoogleCameraAdapter) - 1, |
| 151 } else { | 141 kGoogleCameraAdapter)) { |
| 152 DCHECK_EQ(name.type(), VT_BSTR); | 142 continue; |
| 153 id = base::SysWideToUTF8(V_BSTR(&name)); | |
| 154 } | |
| 155 device_names->push_back(Name(device_name, id, capture_api_type)); | |
| 156 } | |
| 157 } | 143 } |
| 158 moniker.Release(); | 144 |
| 145 const std::string device_name(base::SysWideToUTF8(str_ptr)); | |
| 146 name.Reset(); | |
| 147 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); | |
| 148 std::string id; | |
| 149 if (FAILED(hr) || name.type() != VT_BSTR) { | |
| 150 id = device_name; | |
| 151 } else { | |
| 152 DCHECK_EQ(name.type(), VT_BSTR); | |
| 153 id = base::SysWideToUTF8(V_BSTR(&name)); | |
| 154 } | |
| 155 device_names->push_back(Name(device_name, id, capture_api_type)); | |
| 159 } | 156 } |
| 160 } | 157 } |
| 161 | 158 |
| 162 static void GetDeviceNamesMediaFoundation(Names* device_names) { | 159 static void GetDeviceNamesMediaFoundation(Names* device_names) { |
| 163 DVLOG(1) << " GetDeviceNamesMediaFoundation"; | 160 DVLOG(1) << " GetDeviceNamesMediaFoundation"; |
| 164 ScopedCoMem<IMFActivate*> devices; | 161 ScopedCoMem<IMFActivate*> devices; |
| 165 UINT32 count; | 162 UINT32 count; |
| 166 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count)) | 163 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count)) |
| 167 return; | 164 return; |
| 168 | 165 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 const Name& device, | 430 const Name& device, |
| 434 VideoCaptureFormats* formats) { | 431 VideoCaptureFormats* formats) { |
| 435 DCHECK(thread_checker_.CalledOnValidThread()); | 432 DCHECK(thread_checker_.CalledOnValidThread()); |
| 436 if (use_media_foundation_) | 433 if (use_media_foundation_) |
| 437 GetDeviceSupportedFormatsMediaFoundation(device, formats); | 434 GetDeviceSupportedFormatsMediaFoundation(device, formats); |
| 438 else | 435 else |
| 439 GetDeviceSupportedFormatsDirectShow(device, formats); | 436 GetDeviceSupportedFormatsDirectShow(device, formats); |
| 440 } | 437 } |
| 441 | 438 |
| 442 } // namespace media | 439 } // namespace media |
| OLD | NEW |