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

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

Issue 558623002: Video capture: Refactor GetBestMatchedFormat from Win to OS independent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove braces in if statement 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 | « media/video/capture/win/video_capture_device_mf_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/win/video_capture_device_win.cc
diff --git a/media/video/capture/win/video_capture_device_win.cc b/media/video/capture/win/video_capture_device_win.cc
index 7dfd834b2614e7c5c5e75953b5ba25d08459a944..d1ee6fc5e181e86cc2c9b7efe8fb785df9a16e34 100644
--- a/media/video/capture/win/video_capture_device_win.cc
+++ b/media/video/capture/win/video_capture_device_win.cc
@@ -318,18 +318,15 @@ void VideoCaptureDeviceWin::AllocateAndStart(
client_ = client.Pass();
- // Get the camera capability that best match the requested resolution.
- const VideoCaptureCapabilityWin& found_capability =
- capabilities_.GetBestMatchedFormat(
- params.requested_format.frame_size.width(),
- params.requested_format.frame_size.height(),
- params.requested_format.frame_rate);
+ // Get the camera capability that best match the requested format.
+ const CapabilityWin found_capability =
+ GetBestMatchedCapability(params.requested_format, capabilities_);
VideoCaptureFormat format = found_capability.supported_format;
// Reduce the frame rate if the requested frame rate is lower
// than the capability.
- if (format.frame_rate > params.requested_format.frame_rate)
- format.frame_rate = params.requested_format.frame_rate;
+ format.frame_rate =
+ std::min(format.frame_rate, params.requested_format.frame_rate);
ScopedComPtr<IAMStreamConfig> stream_config;
HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive());
@@ -501,9 +498,10 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() {
}
scoped_ptr<BYTE[]> caps(new BYTE[size]);
- for (int i = 0; i < count; ++i) {
+ for (int stream_index = 0; stream_index < count; ++stream_index) {
ScopedMediaType media_type;
- hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
+ hr = stream_config->GetStreamCaps(
+ stream_index, 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) {
@@ -514,53 +512,42 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() {
if (media_type->majortype == MEDIATYPE_Video &&
media_type->formattype == FORMAT_VideoInfo) {
- VideoCaptureCapabilityWin capability(i);
- capability.supported_format.pixel_format =
+ VideoCaptureFormat format;
+ format.pixel_format =
TranslateMediaSubtypeToPixelFormat(media_type->subtype);
- if (capability.supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN)
+ if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
continue;
VIDEOINFOHEADER* h =
reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat);
- capability.supported_format.frame_size.SetSize(h->bmiHeader.biWidth,
- h->bmiHeader.biHeight);
+ format.frame_size.SetSize(h->bmiHeader.biWidth, h->bmiHeader.biHeight);
- // Try to get a better |time_per_frame| from IAMVideoControl. If not, use
+ // Try to get a better |time_per_frame| from IAMVideoControl. If not, use
// the value from VIDEOINFOHEADER.
REFERENCE_TIME time_per_frame = h->AvgTimePerFrame;
if (video_control) {
ScopedCoMem<LONGLONG> max_fps;
LONG list_size = 0;
- SIZE size = {capability.supported_format.frame_size.width(),
- capability.supported_format.frame_size.height()};
-
- // GetFrameRateList doesn't return max frame rate always
- // eg: Logitech Notebook. This may be due to a bug in that API
- // because GetFrameRateList array is reversed in the above camera. So
- // a util method written. Can't assume the first value will return
- // the max fps.
- hr = video_control->GetFrameRateList(output_capture_pin_, i, size,
- &list_size, &max_fps);
- // Sometimes |list_size| will be > 0, but max_fps will be NULL. Some
+ const SIZE size = {format.frame_size.width(),
+ format.frame_size.height()};
+ hr = video_control->GetFrameRateList(
+ output_capture_pin_, stream_index, size, &list_size, &max_fps);
+ // Can't assume the first value will return the max fps.
+ // Sometimes |list_size| will be > 0, but max_fps will be NULL. Some
// drivers may return an HRESULT of S_FALSE which SUCCEEDED() translates
- // into success, so explicitly check S_OK. See http://crbug.com/306237.
+ // into success, so explicitly check S_OK. See http://crbug.com/306237.
if (hr == S_OK && list_size > 0 && max_fps) {
time_per_frame = *std::min_element(max_fps.get(),
max_fps.get() + list_size);
}
}
- capability.supported_format.frame_rate =
+ format.frame_rate =
(time_per_frame > 0)
? (kSecondsToReferenceTime / static_cast<float>(time_per_frame))
: 0.0;
- // DirectShow works at the moment only on integer frame_rate but the
- // best capability matching class works on rational frame rates.
- capability.frame_rate_numerator = capability.supported_format.frame_rate;
- capability.frame_rate_denominator = 1;
-
- capabilities_.Add(capability);
+ capabilities_.emplace_back(stream_index, format);
}
}
« no previous file with comments | « media/video/capture/win/video_capture_device_mf_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698