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

Side by Side Diff: media/video/capture/win/video_capture_device_factory_win.cc

Issue 541603002: Fix if-statement in win video capture that ignores fake DirectShow filters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas@ comments Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScopedComPtr<IMoniker> moniker;
119 int index = 0; 115 int index = 0;
120 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { 116 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) {
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 moniker.Release();
125 return; 121 return;
126 } 122 }
127 123
128 // Find the description or friendly name. 124 // Find the description or friendly name.
129 ScopedVariant name; 125 ScopedVariant name;
130 hr = prop_bag->Read(L"Description", name.Receive(), 0); 126 hr = prop_bag->Read(L"Description", name.Receive(), 0);
131 if (FAILED(hr)) 127 if (FAILED(hr))
132 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); 128 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0);
133 129
134 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { 130 if (FAILED(hr) || name.type() != VT_BSTR)
135 // Ignore all VFW drivers and the special Google Camera Adapter. 131 continue;
mcasas 2014/09/04 16:31:12 Missing moniker.Release();
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 132
141 if ((wcsstr(str_ptr, L"(VFW)") == NULL) && 133 // Ignore all VFW drivers and the special Google Camera Adapter.
142 lstrlenW(str_ptr) < name_length || 134 // Google Camera Adapter is not a real DirectShow camera device.
143 (!(LowerCaseEqualsASCII(str_ptr, str_ptr + name_length, 135 // VFW are very old Video for Windows drivers that can not be used.
144 kGoogleCameraAdapter)))) { 136 const wchar_t* str_ptr = V_BSTR(&name);
145 std::string id; 137 // Name of a fake DirectShow filter that exist on computers with
146 std::string device_name(base::SysWideToUTF8(str_ptr)); 138 // GTalk installed.
147 name.Reset(); 139 static const char kGoogleCameraAdapter[] = "google camera adapter";
148 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); 140 if (wcsstr(str_ptr, L"(VFW)") != NULL ||
149 if (FAILED(hr) || name.type() != VT_BSTR) { 141 LowerCaseEqualsASCII(str_ptr,
150 id = device_name; 142 str_ptr + arraysize(kGoogleCameraAdapter) - 1,
151 } else { 143 kGoogleCameraAdapter)) {
152 DCHECK_EQ(name.type(), VT_BSTR); 144 continue;
mcasas 2014/09/04 16:31:12 missing moniker.Release();
153 id = base::SysWideToUTF8(V_BSTR(&name));
154 }
155 device_names->push_back(Name(device_name, id, capture_api_type));
156 }
157 } 145 }
158 moniker.Release(); 146
147 const std::string device_name(base::SysWideToUTF8(str_ptr));
148 name.Reset();
149 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0);
150 std::string id;
151 if (FAILED(hr) || name.type() != VT_BSTR) {
152 id = device_name;
153 } else {
154 DCHECK_EQ(name.type(), VT_BSTR);
155 id = base::SysWideToUTF8(V_BSTR(&name));
156 }
157 device_names->push_back(Name(device_name, id, capture_api_type));
159 } 158 }
159
160 moniker.Release();
mcasas 2014/09/04 16:31:12 With so many moniker.Release();, is getting too ve
160 } 161 }
161 162
162 static void GetDeviceNamesMediaFoundation(Names* device_names) { 163 static void GetDeviceNamesMediaFoundation(Names* device_names) {
163 DVLOG(1) << " GetDeviceNamesMediaFoundation"; 164 DVLOG(1) << " GetDeviceNamesMediaFoundation";
164 ScopedCoMem<IMFActivate*> devices; 165 ScopedCoMem<IMFActivate*> devices;
165 UINT32 count; 166 UINT32 count;
166 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count)) 167 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count))
167 return; 168 return;
168 169
169 for (UINT32 i = 0; i < count; ++i) { 170 for (UINT32 i = 0; i < count; ++i) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 const Name& device, 434 const Name& device,
434 VideoCaptureFormats* formats) { 435 VideoCaptureFormats* formats) {
435 DCHECK(thread_checker_.CalledOnValidThread()); 436 DCHECK(thread_checker_.CalledOnValidThread());
436 if (use_media_foundation_) 437 if (use_media_foundation_)
437 GetDeviceSupportedFormatsMediaFoundation(device, formats); 438 GetDeviceSupportedFormatsMediaFoundation(device, formats);
438 else 439 else
439 GetDeviceSupportedFormatsDirectShow(device, formats); 440 GetDeviceSupportedFormatsDirectShow(device, formats);
440 } 441 }
441 442
442 } // namespace media 443 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698