| 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 "device/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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/win/scoped_co_mem.h" | 16 #include "base/win/scoped_co_mem.h" |
| 17 #include "base/win/scoped_variant.h" | 17 #include "base/win/scoped_variant.h" |
| 18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 19 #include "device/capture/video/win/video_capture_device_mf_win.h" |
| 20 #include "device/capture/video/win/video_capture_device_win.h" |
| 19 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
| 20 #include "media/base/win/mf_initializer.h" | 22 #include "media/base/win/mf_initializer.h" |
| 21 #include "media/capture/video/win/video_capture_device_mf_win.h" | |
| 22 #include "media/capture/video/win/video_capture_device_win.h" | |
| 23 | 23 |
| 24 using base::win::ScopedCoMem; | 24 using base::win::ScopedCoMem; |
| 25 using base::win::ScopedComPtr; | 25 using base::win::ScopedComPtr; |
| 26 using base::win::ScopedVariant; | 26 using base::win::ScopedVariant; |
| 27 using Descriptor = media::VideoCaptureDeviceDescriptor; | 27 using media::VideoCaptureFormat; |
| 28 using Descriptors = media::VideoCaptureDeviceDescriptors; | 28 using media::VideoCaptureFormats; |
| 29 using Descriptor = device::VideoCaptureDeviceDescriptor; |
| 30 using Descriptors = device::VideoCaptureDeviceDescriptors; |
| 29 | 31 |
| 30 namespace media { | 32 namespace device { |
| 31 | 33 |
| 32 // In Windows device identifiers, the USB VID and PID are preceded by the string | 34 // In Windows device identifiers, the USB VID and PID are preceded by the string |
| 33 // "vid_" or "pid_". The identifiers are each 4 bytes long. | 35 // "vid_" or "pid_". The identifiers are each 4 bytes long. |
| 34 const char kVidPrefix[] = "vid_"; // Also contains '\0'. | 36 const char kVidPrefix[] = "vid_"; // Also contains '\0'. |
| 35 const char kPidPrefix[] = "pid_"; // Also contains '\0'. | 37 const char kPidPrefix[] = "pid_"; // Also contains '\0'. |
| 36 const size_t kVidPidSize = 4; | 38 const size_t kVidPidSize = 4; |
| 37 | 39 |
| 38 // Avoid enumerating and/or using certain devices due to they provoking crashes | 40 // Avoid enumerating and/or using certain devices due to they provoking crashes |
| 39 // or any other reason (http://crbug.com/378494). This enum is defined for the | 41 // or any other reason (http://crbug.com/378494). This enum is defined for the |
| 40 // purposes of UMA collection. Existing entries cannot be removed. | 42 // purposes of UMA collection. Existing entries cannot be removed. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ExpandEnvironmentStringsW(kMfDLL, path, arraysize(path)); | 74 ExpandEnvironmentStringsW(kMfDLL, path, arraysize(path)); |
| 73 if (!LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) | 75 if (!LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) |
| 74 return false; | 76 return false; |
| 75 } | 77 } |
| 76 return true; | 78 return true; |
| 77 } | 79 } |
| 78 | 80 |
| 79 static bool PrepareVideoCaptureAttributesMediaFoundation( | 81 static bool PrepareVideoCaptureAttributesMediaFoundation( |
| 80 IMFAttributes** attributes, | 82 IMFAttributes** attributes, |
| 81 int count) { | 83 int count) { |
| 82 InitializeMediaFoundation(); | 84 media::InitializeMediaFoundation(); |
| 83 | 85 |
| 84 if (FAILED(MFCreateAttributes(attributes, count))) | 86 if (FAILED(MFCreateAttributes(attributes, count))) |
| 85 return false; | 87 return false; |
| 86 | 88 |
| 87 return SUCCEEDED( | 89 return SUCCEEDED( |
| 88 (*attributes) | 90 (*attributes) |
| 89 ->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, | 91 ->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, |
| 90 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID)); | 92 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID)); |
| 91 } | 93 } |
| 92 | 94 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 << logging::SystemErrorCodeToString(hr); | 304 << logging::SystemErrorCodeToString(hr); |
| 303 return; | 305 return; |
| 304 } | 306 } |
| 305 | 307 |
| 306 if (media_type->majortype == MEDIATYPE_Video && | 308 if (media_type->majortype == MEDIATYPE_Video && |
| 307 media_type->formattype == FORMAT_VideoInfo) { | 309 media_type->formattype == FORMAT_VideoInfo) { |
| 308 VideoCaptureFormat format; | 310 VideoCaptureFormat format; |
| 309 format.pixel_format = | 311 format.pixel_format = |
| 310 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( | 312 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( |
| 311 media_type->subtype); | 313 media_type->subtype); |
| 312 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) | 314 if (format.pixel_format == media::PIXEL_FORMAT_UNKNOWN) |
| 313 continue; | 315 continue; |
| 314 VIDEOINFOHEADER* h = | 316 VIDEOINFOHEADER* h = |
| 315 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 317 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 316 format.frame_size.SetSize(h->bmiHeader.biWidth, h->bmiHeader.biHeight); | 318 format.frame_size.SetSize(h->bmiHeader.biWidth, h->bmiHeader.biHeight); |
| 317 // Trust the frame rate from the VIDEOINFOHEADER. | 319 // Trust the frame rate from the VIDEOINFOHEADER. |
| 318 format.frame_rate = | 320 format.frame_rate = |
| 319 (h->AvgTimePerFrame > 0) | 321 (h->AvgTimePerFrame > 0) |
| 320 ? kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame) | 322 ? kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame) |
| 321 : 0.0f; | 323 : 0.0f; |
| 322 formats->push_back(format); | 324 formats->push_back(format); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 GetDeviceSupportedFormatsDirectShow(device, formats); | 458 GetDeviceSupportedFormatsDirectShow(device, formats); |
| 457 } | 459 } |
| 458 | 460 |
| 459 // static | 461 // static |
| 460 VideoCaptureDeviceFactory* | 462 VideoCaptureDeviceFactory* |
| 461 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 463 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
| 462 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 464 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 463 return new VideoCaptureDeviceFactoryWin(); | 465 return new VideoCaptureDeviceFactoryWin(); |
| 464 } | 466 } |
| 465 | 467 |
| 466 } // namespace media | 468 } // namespace device |
| OLD | NEW |