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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 ScopedComPtr<IEnumMoniker> enum_moniker; | 115 ScopedComPtr<IEnumMoniker> enum_moniker; |
116 hr = dev_enum->CreateClassEnumerator( | 116 hr = dev_enum->CreateClassEnumerator( |
117 kDirectShowFilterClasses[class_index].class_id, | 117 kDirectShowFilterClasses[class_index].class_id, |
118 enum_moniker.Receive(), | 118 enum_moniker.Receive(), |
119 0); | 119 0); |
120 // CreateClassEnumerator returns S_FALSE on some Windows OS | 120 // CreateClassEnumerator returns S_FALSE on some Windows OS |
121 // when no camera exist. Therefore the FAILED macro can't be used. | 121 // when no camera exist. Therefore the FAILED macro can't be used. |
122 if (hr != S_OK) | 122 if (hr != S_OK) |
123 continue; | 123 continue; |
124 | 124 |
125 // Name of a fake DirectShow filter that exist on computers with | |
126 // GTalk installed. | |
127 static const char kGoogleCameraAdapter[] = "google camera adapter"; | |
128 | |
129 // Enumerate all video capture devices. | 125 // Enumerate all video capture devices. |
130 ScopedComPtr<IMoniker> moniker; | 126 ScopedComPtr<IMoniker> moniker; |
131 int index = 0; | 127 int index = 0; |
132 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { | 128 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { |
133 ScopedComPtr<IPropertyBag> prop_bag; | 129 ScopedComPtr<IPropertyBag> prop_bag; |
134 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, | 130 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, |
135 prop_bag.ReceiveVoid()); | 131 prop_bag.ReceiveVoid()); |
136 if (FAILED(hr)) { | 132 if (FAILED(hr)) { |
137 moniker.Release(); | 133 moniker.Release(); |
138 continue; | 134 continue; |
139 } | 135 } |
140 | 136 |
141 // Find the description or friendly name. | 137 // Find the description or friendly name. |
142 ScopedVariant name; | 138 ScopedVariant name; |
143 hr = prop_bag->Read(L"Description", name.Receive(), 0); | 139 hr = prop_bag->Read(L"Description", name.Receive(), 0); |
144 if (FAILED(hr)) | 140 if (FAILED(hr)) |
145 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); | 141 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); |
146 | 142 |
147 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { | 143 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { |
mcasas
2014/09/04 13:31:17
Since you are cleaning up around here, suggest cha
magjed_chromium
2014/09/04 15:31:28
I agree.
| |
148 // Ignore all VFW drivers and the special Google Camera Adapter. | 144 // Ignore all VFW drivers and the special Google Camera Adapter. |
149 // Google Camera Adapter is not a real DirectShow camera device. | 145 // Google Camera Adapter is not a real DirectShow camera device. |
150 // VFW are very old Video for Windows drivers that can not be used. | 146 // VFW are very old Video for Windows drivers that can not be used. |
151 const wchar_t* str_ptr = V_BSTR(&name); | 147 const wchar_t* str_ptr = V_BSTR(&name); |
152 const int name_length = arraysize(kGoogleCameraAdapter) - 1; | 148 // Name of a fake DirectShow filter that exist on computers with |
153 | 149 // GTalk installed. |
154 if ((wcsstr(str_ptr, L"(VFW)") == NULL) && | 150 static const char kGoogleCameraAdapter[] = "google camera adapter"; |
155 lstrlenW(str_ptr) < name_length || | 151 if (wcsstr(str_ptr, L"(VFW)") == NULL && |
156 (!(LowerCaseEqualsASCII(str_ptr, str_ptr + name_length, | 152 !LowerCaseEqualsASCII(str_ptr, |
157 kGoogleCameraAdapter)))) { | 153 str_ptr + arraysize(kGoogleCameraAdapter) - 1, |
158 std::string id; | 154 kGoogleCameraAdapter)) { |
159 std::string device_name(base::SysWideToUTF8(str_ptr)); | 155 const std::string device_name(base::SysWideToUTF8(str_ptr)); |
160 name.Reset(); | 156 name.Reset(); |
161 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); | 157 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); |
158 std::string id; | |
162 if (FAILED(hr) || name.type() != VT_BSTR) { | 159 if (FAILED(hr) || name.type() != VT_BSTR) { |
163 id = device_name; | 160 id = device_name; |
164 } else { | 161 } else { |
165 DCHECK_EQ(name.type(), VT_BSTR); | 162 DCHECK_EQ(name.type(), VT_BSTR); |
166 id = base::SysWideToUTF8(V_BSTR(&name)); | 163 id = base::SysWideToUTF8(V_BSTR(&name)); |
167 } | 164 } |
168 device_names->push_back(Name(device_name, id, | 165 device_names->push_back(Name(device_name, id, |
169 kDirectShowFilterClasses[class_index].capture_api_type)); | 166 kDirectShowFilterClasses[class_index].capture_api_type)); |
170 } | 167 } |
171 } | 168 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 const Name& device, | 415 const Name& device, |
419 VideoCaptureFormats* formats) { | 416 VideoCaptureFormats* formats) { |
420 DCHECK(thread_checker_.CalledOnValidThread()); | 417 DCHECK(thread_checker_.CalledOnValidThread()); |
421 if (use_media_foundation_) | 418 if (use_media_foundation_) |
422 GetDeviceSupportedFormatsMediaFoundation(device, formats); | 419 GetDeviceSupportedFormatsMediaFoundation(device, formats); |
423 else | 420 else |
424 GetDeviceSupportedFormatsDirectShow(device, formats); | 421 GetDeviceSupportedFormatsDirectShow(device, formats); |
425 } | 422 } |
426 | 423 |
427 } // namespace media | 424 } // namespace media |
OLD | NEW |