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/capture/video/win/video_capture_device_factory_win.h" | 5 #include "media/capture/video/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 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 static bool CreateVideoCaptureDeviceMediaFoundation(const char* sym_link, | 94 static bool CreateVideoCaptureDeviceMediaFoundation(const char* sym_link, |
95 IMFMediaSource** source) { | 95 IMFMediaSource** source) { |
96 ScopedComPtr<IMFAttributes> attributes; | 96 ScopedComPtr<IMFAttributes> attributes; |
97 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 2)) | 97 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 2)) |
98 return false; | 98 return false; |
99 | 99 |
100 attributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, | 100 attributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, |
101 base::SysUTF8ToWide(sym_link).c_str()); | 101 base::SysUTF8ToWide(sym_link).c_str()); |
102 | 102 |
103 return SUCCEEDED(MFCreateDeviceSource(attributes.get(), source)); | 103 return SUCCEEDED(MFCreateDeviceSource(attributes.Get(), source)); |
104 } | 104 } |
105 | 105 |
106 static bool EnumerateVideoDevicesMediaFoundation(IMFActivate*** devices, | 106 static bool EnumerateVideoDevicesMediaFoundation(IMFActivate*** devices, |
107 UINT32* count) { | 107 UINT32* count) { |
108 ScopedComPtr<IMFAttributes> attributes; | 108 ScopedComPtr<IMFAttributes> attributes; |
109 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 1)) | 109 if (!PrepareVideoCaptureAttributesMediaFoundation(attributes.Receive(), 1)) |
110 return false; | 110 return false; |
111 | 111 |
112 return SUCCEEDED(MFEnumDeviceSources(attributes.get(), devices, count)); | 112 return SUCCEEDED(MFEnumDeviceSources(attributes.Get(), devices, count)); |
113 } | 113 } |
114 | 114 |
115 static bool IsDeviceBlackListed(const std::string& name) { | 115 static bool IsDeviceBlackListed(const std::string& name) { |
116 DCHECK_EQ(BLACKLISTED_CAMERA_MAX + 1, | 116 DCHECK_EQ(BLACKLISTED_CAMERA_MAX + 1, |
117 static_cast<int>(arraysize(kBlacklistedCameraNames))); | 117 static_cast<int>(arraysize(kBlacklistedCameraNames))); |
118 for (size_t i = 0; i < arraysize(kBlacklistedCameraNames); ++i) { | 118 for (size_t i = 0; i < arraysize(kBlacklistedCameraNames); ++i) { |
119 if (base::StartsWith(name, kBlacklistedCameraNames[i], | 119 if (base::StartsWith(name, kBlacklistedCameraNames[i], |
120 base::CompareCase::INSENSITIVE_ASCII)) { | 120 base::CompareCase::INSENSITIVE_ASCII)) { |
121 DVLOG(1) << "Enumerated blacklisted device: " << name; | 121 DVLOG(1) << "Enumerated blacklisted device: " << name; |
122 UMA_HISTOGRAM_ENUMERATION("Media.VideoCapture.BlacklistedDevice", i, | 122 UMA_HISTOGRAM_ENUMERATION("Media.VideoCapture.BlacklistedDevice", i, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // exists. Therefore the FAILED macro can't be used. | 255 // exists. Therefore the FAILED macro can't be used. |
256 if (hr != S_OK) | 256 if (hr != S_OK) |
257 return; | 257 return; |
258 | 258 |
259 // Walk the capture devices. No need to check for device presence again since | 259 // Walk the capture devices. No need to check for device presence again since |
260 // that is anyway needed in GetDeviceFilter(). "google camera adapter" and old | 260 // that is anyway needed in GetDeviceFilter(). "google camera adapter" and old |
261 // VFW devices are already skipped previously in GetDeviceNames() enumeration. | 261 // VFW devices are already skipped previously in GetDeviceNames() enumeration. |
262 base::win::ScopedComPtr<IBaseFilter> capture_filter; | 262 base::win::ScopedComPtr<IBaseFilter> capture_filter; |
263 hr = VideoCaptureDeviceWin::GetDeviceFilter(descriptor.device_id, | 263 hr = VideoCaptureDeviceWin::GetDeviceFilter(descriptor.device_id, |
264 capture_filter.Receive()); | 264 capture_filter.Receive()); |
265 if (!capture_filter.get()) { | 265 if (!capture_filter.Get()) { |
266 DLOG(ERROR) << "Failed to create capture filter: " | 266 DLOG(ERROR) << "Failed to create capture filter: " |
267 << logging::SystemErrorCodeToString(hr); | 267 << logging::SystemErrorCodeToString(hr); |
268 return; | 268 return; |
269 } | 269 } |
270 | 270 |
271 base::win::ScopedComPtr<IPin> output_capture_pin( | 271 base::win::ScopedComPtr<IPin> output_capture_pin( |
272 VideoCaptureDeviceWin::GetPin(capture_filter.get(), PINDIR_OUTPUT, | 272 VideoCaptureDeviceWin::GetPin(capture_filter.Get(), PINDIR_OUTPUT, |
273 PIN_CATEGORY_CAPTURE, GUID_NULL)); | 273 PIN_CATEGORY_CAPTURE, GUID_NULL)); |
274 if (!output_capture_pin.get()) { | 274 if (!output_capture_pin.Get()) { |
275 DLOG(ERROR) << "Failed to get capture output pin"; | 275 DLOG(ERROR) << "Failed to get capture output pin"; |
276 return; | 276 return; |
277 } | 277 } |
278 | 278 |
279 ScopedComPtr<IAMStreamConfig> stream_config; | 279 ScopedComPtr<IAMStreamConfig> stream_config; |
280 hr = output_capture_pin.QueryInterface(stream_config.Receive()); | 280 hr = output_capture_pin.QueryInterface(stream_config.Receive()); |
281 if (FAILED(hr)) { | 281 if (FAILED(hr)) { |
282 DLOG(ERROR) << "Failed to get IAMStreamConfig interface from " | 282 DLOG(ERROR) << "Failed to get IAMStreamConfig interface from " |
283 "capture device: " << logging::SystemErrorCodeToString(hr); | 283 "capture device: " << logging::SystemErrorCodeToString(hr); |
284 return; | 284 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " | 333 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " |
334 << descriptor.display_name; | 334 << descriptor.display_name; |
335 ScopedComPtr<IMFMediaSource> source; | 335 ScopedComPtr<IMFMediaSource> source; |
336 if (!CreateVideoCaptureDeviceMediaFoundation(descriptor.device_id.c_str(), | 336 if (!CreateVideoCaptureDeviceMediaFoundation(descriptor.device_id.c_str(), |
337 source.Receive())) { | 337 source.Receive())) { |
338 return; | 338 return; |
339 } | 339 } |
340 | 340 |
341 base::win::ScopedComPtr<IMFSourceReader> reader; | 341 base::win::ScopedComPtr<IMFSourceReader> reader; |
342 HRESULT hr = | 342 HRESULT hr = |
343 MFCreateSourceReaderFromMediaSource(source.get(), NULL, reader.Receive()); | 343 MFCreateSourceReaderFromMediaSource(source.Get(), NULL, reader.Receive()); |
344 if (FAILED(hr)) { | 344 if (FAILED(hr)) { |
345 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource failed: " | 345 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource failed: " |
346 << logging::SystemErrorCodeToString(hr); | 346 << logging::SystemErrorCodeToString(hr); |
347 return; | 347 return; |
348 } | 348 } |
349 | 349 |
350 DWORD stream_index = 0; | 350 DWORD stream_index = 0; |
351 ScopedComPtr<IMFMediaType> type; | 351 ScopedComPtr<IMFMediaType> type; |
352 while (SUCCEEDED(reader->GetNativeMediaType(kFirstVideoStream, stream_index, | 352 while (SUCCEEDED(reader->GetNativeMediaType(kFirstVideoStream, stream_index, |
353 type.Receive()))) { | 353 type.Receive()))) { |
354 UINT32 width, height; | 354 UINT32 width, height; |
355 hr = MFGetAttributeSize(type.get(), MF_MT_FRAME_SIZE, &width, &height); | 355 hr = MFGetAttributeSize(type.Get(), MF_MT_FRAME_SIZE, &width, &height); |
356 if (FAILED(hr)) { | 356 if (FAILED(hr)) { |
357 DLOG(ERROR) << "MFGetAttributeSize failed: " | 357 DLOG(ERROR) << "MFGetAttributeSize failed: " |
358 << logging::SystemErrorCodeToString(hr); | 358 << logging::SystemErrorCodeToString(hr); |
359 return; | 359 return; |
360 } | 360 } |
361 VideoCaptureFormat capture_format; | 361 VideoCaptureFormat capture_format; |
362 capture_format.frame_size.SetSize(width, height); | 362 capture_format.frame_size.SetSize(width, height); |
363 | 363 |
364 UINT32 numerator, denominator; | 364 UINT32 numerator, denominator; |
365 hr = MFGetAttributeRatio(type.get(), MF_MT_FRAME_RATE, &numerator, | 365 hr = MFGetAttributeRatio(type.Get(), MF_MT_FRAME_RATE, &numerator, |
366 &denominator); | 366 &denominator); |
367 if (FAILED(hr)) { | 367 if (FAILED(hr)) { |
368 DLOG(ERROR) << "MFGetAttributeSize failed: " | 368 DLOG(ERROR) << "MFGetAttributeSize failed: " |
369 << logging::SystemErrorCodeToString(hr); | 369 << logging::SystemErrorCodeToString(hr); |
370 return; | 370 return; |
371 } | 371 } |
372 capture_format.frame_rate = | 372 capture_format.frame_rate = |
373 denominator ? static_cast<float>(numerator) / denominator : 0.0f; | 373 denominator ? static_cast<float>(numerator) / denominator : 0.0f; |
374 | 374 |
375 GUID type_guid; | 375 GUID type_guid; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 460 } |
461 | 461 |
462 // static | 462 // static |
463 VideoCaptureDeviceFactory* | 463 VideoCaptureDeviceFactory* |
464 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 464 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
465 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 465 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
466 return new VideoCaptureDeviceFactoryWin(); | 466 return new VideoCaptureDeviceFactoryWin(); |
467 } | 467 } |
468 | 468 |
469 } // namespace media | 469 } // namespace media |
OLD | NEW |