Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: media/video/capture/win/video_capture_device_factory_win.cc

Issue 510723003: Win Video Capture: add support for enumerating DirectShow WDM devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/video/capture/video_capture_device.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/win/video_capture_device_factory_win.cc
diff --git a/media/video/capture/win/video_capture_device_factory_win.cc b/media/video/capture/win/video_capture_device_factory_win.cc
index 75ee59d3bf495be332468550d2bb9ef22a16ef5d..9eaee164088fcaf4431f08fca9e0e8ba8cfb6fd6 100644
--- a/media/video/capture/win/video_capture_device_factory_win.cc
+++ b/media/video/capture/win/video_capture_device_factory_win.cc
@@ -98,64 +98,77 @@ static void GetDeviceNamesDirectShow(VideoCaptureDevice::Names* device_names) {
if (FAILED(hr))
return;
- ScopedComPtr<IEnumMoniker> enum_moniker;
- hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
- enum_moniker.Receive(), 0);
- // CreateClassEnumerator returns S_FALSE on some Windows OS
- // when no camera exist. Therefore the FAILED macro can't be used.
- if (hr != S_OK)
- return;
+ static const struct{
+ CLSID class_id;
+ VideoCaptureDevice::Name::CaptureApiType capture_api_type;
+ } kDirectShowFilterClasses[] = {
+ { CLSID_VideoInputDeviceCategory, VideoCaptureDevice::Name::DIRECT_SHOW },
+ { AM_KSCATEGORY_CROSSBAR, VideoCaptureDevice::Name::DIRECT_SHOW_WDM}
+ };
- device_names->clear();
- // Name of a fake DirectShow filter that exist on computers with
- // GTalk installed.
- static const char kGoogleCameraAdapter[] = "google camera adapter";
+ device_names->clear();
+ for (int class_index = 0; class_index < arraysize(kDirectShowFilterClasses);
+ ++class_index) {
+ ScopedComPtr<IEnumMoniker> enum_moniker;
+ hr = dev_enum->CreateClassEnumerator(
+ kDirectShowFilterClasses[class_index].class_id,
+ enum_moniker.Receive(),
+ 0);
+ // CreateClassEnumerator returns S_FALSE on some Windows OS
+ // when no camera exist. Therefore the FAILED macro can't be used.
+ if (hr != S_OK)
+ return;
magjed_chromium 2014/08/27 13:05:27 This return statement looks suspicious now when yo
mcasas 2014/08/27 13:29:52 Done.
- // Enumerate all video capture devices.
- ScopedComPtr<IMoniker> moniker;
- int index = 0;
- while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) {
- ScopedComPtr<IPropertyBag> prop_bag;
- hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid());
- if (FAILED(hr)) {
- moniker.Release();
- continue;
- }
+ // Name of a fake DirectShow filter that exist on computers with
+ // GTalk installed.
+ static const char kGoogleCameraAdapter[] = "google camera adapter";
+
+ // Enumerate all video capture devices.
+ ScopedComPtr<IMoniker> moniker;
+ int index = 0;
+ while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) {
+ ScopedComPtr<IPropertyBag> prop_bag;
+ hr = moniker->BindToStorage(0, 0, IID_IPropertyBag,
+ prop_bag.ReceiveVoid());
+ if (FAILED(hr)) {
+ moniker.Release();
+ continue;
+ }
- // Find the description or friendly name.
- ScopedVariant name;
- hr = prop_bag->Read(L"Description", name.Receive(), 0);
- if (FAILED(hr))
- hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0);
-
- if (SUCCEEDED(hr) && name.type() == VT_BSTR) {
- // Ignore all VFW drivers and the special Google Camera Adapter.
- // Google Camera Adapter is not a real DirectShow camera device.
- // VFW are very old Video for Windows drivers that can not be used.
- const wchar_t* str_ptr = V_BSTR(&name);
- const int name_length = arraysize(kGoogleCameraAdapter) - 1;
-
- if ((wcsstr(str_ptr, L"(VFW)") == NULL) &&
- lstrlenW(str_ptr) < name_length ||
- (!(LowerCaseEqualsASCII(str_ptr, str_ptr + name_length,
- kGoogleCameraAdapter)))) {
- std::string id;
- std::string device_name(base::SysWideToUTF8(str_ptr));
- name.Reset();
- hr = prop_bag->Read(L"DevicePath", name.Receive(), 0);
- if (FAILED(hr) || name.type() != VT_BSTR) {
- id = device_name;
- } else {
- DCHECK_EQ(name.type(), VT_BSTR);
- id = base::SysWideToUTF8(V_BSTR(&name));
+ // Find the description or friendly name.
+ ScopedVariant name;
+ hr = prop_bag->Read(L"Description", name.Receive(), 0);
+ if (FAILED(hr))
+ hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0);
+
+ if (SUCCEEDED(hr) && name.type() == VT_BSTR) {
+ // Ignore all VFW drivers and the special Google Camera Adapter.
+ // Google Camera Adapter is not a real DirectShow camera device.
+ // VFW are very old Video for Windows drivers that can not be used.
+ const wchar_t* str_ptr = V_BSTR(&name);
+ const int name_length = arraysize(kGoogleCameraAdapter) - 1;
+
+ if ((wcsstr(str_ptr, L"(VFW)") == NULL) &&
+ lstrlenW(str_ptr) < name_length ||
+ (!(LowerCaseEqualsASCII(str_ptr, str_ptr + name_length,
+ kGoogleCameraAdapter)))) {
+ std::string id;
+ std::string device_name(base::SysWideToUTF8(str_ptr));
+ name.Reset();
+ hr = prop_bag->Read(L"DevicePath", name.Receive(), 0);
+ if (FAILED(hr) || name.type() != VT_BSTR) {
+ id = device_name;
+ } else {
+ DCHECK_EQ(name.type(), VT_BSTR);
+ id = base::SysWideToUTF8(V_BSTR(&name));
+ }
+ device_names->push_back(VideoCaptureDevice::Name(device_name, id,
+ kDirectShowFilterClasses[class_index].capture_api_type));
}
-
- device_names->push_back(VideoCaptureDevice::Name(device_name, id,
- VideoCaptureDevice::Name::DIRECT_SHOW));
}
+ moniker.Release();
}
- moniker.Release();
}
}
@@ -387,8 +400,10 @@ scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryWin::Create(
if (!static_cast<VideoCaptureDeviceMFWin*>(device.get())->Init(source))
device.reset();
} else {
- DCHECK_EQ(device_name.capture_api_type(),
- VideoCaptureDevice::Name::DIRECT_SHOW);
+ DCHECK(device_name.capture_api_type() ==
+ VideoCaptureDevice::Name::DIRECT_SHOW ||
+ device_name.capture_api_type() ==
+ VideoCaptureDevice::Name::DIRECT_SHOW_WDM);
device.reset(new VideoCaptureDeviceWin(device_name));
DVLOG(1) << " DirectShow Device: " << device_name.name();
if (!static_cast<VideoCaptureDeviceWin*>(device.get())->Init())
« no previous file with comments | « media/video/capture/video_capture_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698