Chromium Code Reviews| 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..6a988fd312b217b21bfefa9db88df2c122d9cab9 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. |
| + // Get the camera capability that best match the requested format. |
| const VideoCaptureCapabilityWin& found_capability = |
| - capabilities_.GetBestMatchedFormat( |
| - params.requested_format.frame_size.width(), |
| - params.requested_format.frame_size.height(), |
| - params.requested_format.frame_rate); |
| + *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. |
|
mcasas
2014/10/13 08:18:47
I think this comment is superfluous.
|
| - 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_.push_back(VideoCaptureCapabilityWin(stream_index, format)); |
| } |
| } |