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, |
tommi (sloooow) - chröme
2014/09/04 16:36:19
const &
| |
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 | 113 // Name of a fake DirectShow filter that exist on computers with |
114 // GTalk installed. | 114 // GTalk installed. |
115 static const char kGoogleCameraAdapter[] = "google camera adapter"; | 115 static const char kGoogleCameraAdapter[] = "google camera adapter"; |
tommi (sloooow) - chröme
2014/09/04 16:36:19
Can you check with Per if we can remove this?
| |
116 | 116 |
117 // Enumerate all video capture devices. | 117 // Enumerate all video capture devices. |
118 ScopedComPtr<IMoniker> moniker; | 118 ScopedComPtr<IMoniker> moniker; |
119 int index = 0; | 119 int index = 0; |
120 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { | 120 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { |
121 ScopedComPtr<IPropertyBag> prop_bag; | 121 ScopedComPtr<IPropertyBag> prop_bag; |
122 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); | 122 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); |
123 if (FAILED(hr)) { | 123 if (FAILED(hr)) { |
124 moniker.Release(); | 124 moniker.Release(); |
tommi (sloooow) - chröme
2014/09/04 16:36:19
no need for this if we're returning... however, is
mcasas
2014/09/04 16:38:38
We have a separate CL dealing with this very Scope
tommi (sloooow) - chröme
2014/09/04 16:43:35
Ah, great. Saw your comments too in that CL and +
| |
125 return; | 125 return; |
126 } | 126 } |
127 | 127 |
128 // Find the description or friendly name. | 128 // Find the description or friendly name. |
129 ScopedVariant name; | 129 ScopedVariant name; |
130 hr = prop_bag->Read(L"Description", name.Receive(), 0); | 130 hr = prop_bag->Read(L"Description", name.Receive(), 0); |
131 if (FAILED(hr)) | 131 if (FAILED(hr)) |
132 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); | 132 hr = prop_bag->Read(L"FriendlyName", name.Receive(), 0); |
133 | 133 |
134 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { | 134 if (SUCCEEDED(hr) && name.type() == VT_BSTR) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 continue; | 266 continue; |
267 VIDEOINFOHEADER* h = | 267 VIDEOINFOHEADER* h = |
268 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 268 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
269 format.frame_size.SetSize(h->bmiHeader.biWidth, | 269 format.frame_size.SetSize(h->bmiHeader.biWidth, |
270 h->bmiHeader.biHeight); | 270 h->bmiHeader.biHeight); |
271 // Trust the frame rate from the VIDEOINFOHEADER. | 271 // Trust the frame rate from the VIDEOINFOHEADER. |
272 format.frame_rate = (h->AvgTimePerFrame > 0) ? | 272 format.frame_rate = (h->AvgTimePerFrame > 0) ? |
273 kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame) : | 273 kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame) : |
274 0.0f; | 274 0.0f; |
275 formats->push_back(format); | 275 formats->push_back(format); |
276 DVLOG(1) << device.name() << " resolution: " | 276 DVLOG(1) << device.name() << " " << format.ToString(); |
277 << format.frame_size.ToString() << ", fps: " << format.frame_rate | |
278 << ", pixel format: " << format.pixel_format; | |
279 } | 277 } |
280 } | 278 } |
281 } | 279 } |
282 | 280 |
283 static void GetDeviceSupportedFormatsMediaFoundation( | 281 static void GetDeviceSupportedFormatsMediaFoundation( |
284 const Name& device, | 282 const Name& device, |
285 VideoCaptureFormats* formats) { | 283 VideoCaptureFormats* formats) { |
286 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " << device.name(); | 284 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " << device.name(); |
287 ScopedComPtr<IMFMediaSource> source; | 285 ScopedComPtr<IMFMediaSource> source; |
288 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), | 286 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 DLOG(ERROR) << "GetGUID failed: " | 327 DLOG(ERROR) << "GetGUID failed: " |
330 << logging::SystemErrorCodeToString(hr); | 328 << logging::SystemErrorCodeToString(hr); |
331 return; | 329 return; |
332 } | 330 } |
333 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, | 331 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, |
334 &capture_format.pixel_format); | 332 &capture_format.pixel_format); |
335 type.Release(); | 333 type.Release(); |
336 formats->push_back(capture_format); | 334 formats->push_back(capture_format); |
337 ++stream_index; | 335 ++stream_index; |
338 | 336 |
339 DVLOG(1) << device.name() << " resolution: " | 337 DVLOG(1) << device.name() << " " << capture_format.ToString(); |
340 << capture_format.frame_size.ToString() << ", fps: " | |
341 << capture_format.frame_rate << ", pixel format: " | |
342 << capture_format.pixel_format; | |
343 } | 338 } |
344 } | 339 } |
345 | 340 |
346 // Returns true iff the current platform supports the Media Foundation API | 341 // Returns true iff the current platform supports the Media Foundation API |
347 // and that the DLLs are available. On Vista this API is an optional download | 342 // and that the DLLs are available. On Vista this API is an optional download |
348 // but the API is advertised as a part of Windows 7 and onwards. However, | 343 // but the API is advertised as a part of Windows 7 and onwards. However, |
349 // we've seen that the required DLLs are not available in some Win7 | 344 // we've seen that the required DLLs are not available in some Win7 |
350 // distributions such as Windows 7 N and Windows 7 KN. | 345 // distributions such as Windows 7 N and Windows 7 KN. |
351 // static | 346 // static |
352 bool VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() { | 347 bool VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 const Name& device, | 428 const Name& device, |
434 VideoCaptureFormats* formats) { | 429 VideoCaptureFormats* formats) { |
435 DCHECK(thread_checker_.CalledOnValidThread()); | 430 DCHECK(thread_checker_.CalledOnValidThread()); |
436 if (use_media_foundation_) | 431 if (use_media_foundation_) |
437 GetDeviceSupportedFormatsMediaFoundation(device, formats); | 432 GetDeviceSupportedFormatsMediaFoundation(device, formats); |
438 else | 433 else |
439 GetDeviceSupportedFormatsDirectShow(device, formats); | 434 GetDeviceSupportedFormatsDirectShow(device, formats); |
440 } | 435 } |
441 | 436 |
442 } // namespace media | 437 } // namespace media |
OLD | NEW |