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

Unified Diff: media/video/capture/win/video_capture_device_factory_win.cc

Issue 558503003: Windows video capture: Remove duplicated code from GetDeviceSupportedFormats* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/video/capture/win/video_capture_device_mf_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/win/video_capture_device_factory_win.cc
diff --git a/media/video/capture/win/video_capture_device_factory_win.cc b/media/video/capture/win/video_capture_device_factory_win.cc
index fee96b8ef72c98da5f94567fffa95e3e7113ca79..127e352ba14e27b80d77e0d56203c87f3db7ab61 100644
--- a/media/video/capture/win/video_capture_device_factory_win.cc
+++ b/media/video/capture/win/video_capture_device_factory_win.cc
@@ -216,91 +216,10 @@ static void GetDeviceNamesMediaFoundation(Names* device_names) {
static void GetDeviceSupportedFormatsDirectShow(const Name& device,
VideoCaptureFormats* formats) {
DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name();
- ScopedComPtr<ICreateDevEnum> dev_enum;
- HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL,
- CLSCTX_INPROC);
- if (FAILED(hr))
+ VideoCaptureDeviceWin capture_device(device);
+ if (!capture_device.Init())
return;
-
- ScopedComPtr<IEnumMoniker> enum_moniker;
- hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
- enum_moniker.Receive(), 0);
- // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera
- // exists. Therefore the FAILED macro can't be used.
- if (hr != S_OK)
- return;
-
- // Walk the capture devices. No need to check for device presence again since
- // that is anyway needed in GetDeviceFilter(). "google camera adapter" and old
- // VFW devices are already skipped previously in GetDeviceNames() enumeration.
- base::win::ScopedComPtr<IBaseFilter> capture_filter;
- hr = VideoCaptureDeviceWin::GetDeviceFilter(device.capabilities_id(),
- CLSID_VideoInputDeviceCategory,
- capture_filter.Receive());
- if (!capture_filter) {
- DLOG(ERROR) << "Failed to create capture filter: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
-
- base::win::ScopedComPtr<IPin> output_capture_pin(
- VideoCaptureDeviceWin::GetPin(capture_filter,
- PINDIR_OUTPUT,
- PIN_CATEGORY_CAPTURE,
- GUID_NULL));
- if (!output_capture_pin) {
- DLOG(ERROR) << "Failed to get capture output pin";
- return;
- }
-
- ScopedComPtr<IAMStreamConfig> stream_config;
- hr = output_capture_pin.QueryInterface(stream_config.Receive());
- if (FAILED(hr)) {
- DLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
- "capture device: " << logging::SystemErrorCodeToString(hr);
- return;
- }
-
- int count = 0, size = 0;
- hr = stream_config->GetNumberOfCapabilities(&count, &size);
- if (FAILED(hr)) {
- DLOG(ERROR) << "GetNumberOfCapabilities failed: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
-
- scoped_ptr<BYTE[]> caps(new BYTE[size]);
- for (int i = 0; i < count; ++i) {
- VideoCaptureDeviceWin::ScopedMediaType media_type;
- hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
- // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
- // macros here since they'll trigger incorrectly.
- if (hr != S_OK || !media_type.get()) {
- DLOG(ERROR) << "GetStreamCaps failed: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
-
- if (media_type->majortype == MEDIATYPE_Video &&
- media_type->formattype == FORMAT_VideoInfo) {
- VideoCaptureFormat format;
- format.pixel_format =
- VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
- media_type->subtype);
- if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
- continue;
- VIDEOINFOHEADER* h =
- reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat);
- format.frame_size.SetSize(h->bmiHeader.biWidth,
- h->bmiHeader.biHeight);
- // Trust the frame rate from the VIDEOINFOHEADER.
- format.frame_rate = (h->AvgTimePerFrame > 0) ?
- kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame) :
- 0.0f;
- formats->push_back(format);
- DVLOG(1) << device.name() << " " << format.ToString();
- }
- }
+ capture_device.GetDeviceSupportedFormats(formats);
}
static void GetDeviceSupportedFormatsMediaFoundation(
@@ -322,45 +241,11 @@ static void GetDeviceSupportedFormatsMediaFoundation(
return;
}
- DWORD stream_index = 0;
- ScopedComPtr<IMFMediaType> type;
- while (SUCCEEDED(reader->GetNativeMediaType(
- kFirstVideoStream, stream_index, type.Receive()))) {
- UINT32 width, height;
- hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
- if (FAILED(hr)) {
- DLOG(ERROR) << "MFGetAttributeSize failed: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
- VideoCaptureFormat capture_format;
- capture_format.frame_size.SetSize(width, height);
-
- UINT32 numerator, denominator;
- hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
- if (FAILED(hr)) {
- DLOG(ERROR) << "MFGetAttributeSize failed: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
- capture_format.frame_rate = denominator
- ? static_cast<float>(numerator) / denominator : 0.0f;
-
- GUID type_guid;
- hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
- if (FAILED(hr)) {
- DLOG(ERROR) << "GetGUID failed: "
- << logging::SystemErrorCodeToString(hr);
- return;
- }
- VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
- &capture_format.pixel_format);
- type.Release();
- formats->push_back(capture_format);
- ++stream_index;
+ CapabilityList capabilities;
+ VideoCaptureDeviceMFWin::FillCapabilities(reader, &capabilities);
- DVLOG(1) << device.name() << " " << capture_format.ToString();
- }
+ for (const CapabilityWin& capability : capabilities)
+ formats->push_back(capability.supported_format);
}
// Returns true iff the current platform supports the Media Foundation API
@@ -457,6 +342,8 @@ void VideoCaptureDeviceFactoryWin::GetDeviceSupportedFormats(
GetDeviceSupportedFormatsMediaFoundation(device, formats);
else
GetDeviceSupportedFormatsDirectShow(device, formats);
+ for (const VideoCaptureFormat& format : *formats)
mcasas 2014/10/23 08:25:09 indent
+ DVLOG(1) << device.name() << " " << format.ToString();
}
} // namespace media
« no previous file with comments | « no previous file | media/video/capture/win/video_capture_device_mf_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698