Chromium Code Reviews| Index: media/video/capture/win/video_capture_device_mf_win.cc |
| diff --git a/media/video/capture/win/video_capture_device_mf_win.cc b/media/video/capture/win/video_capture_device_mf_win.cc |
| index 0e199da26dd0dd56efe10dcc9d418f8b011a3761..3fe53fc09311441d8f3cf3248fcce5933f7b1539 100644 |
| --- a/media/video/capture/win/video_capture_device_mf_win.cc |
| +++ b/media/video/capture/win/video_capture_device_mf_win.cc |
| @@ -34,34 +34,27 @@ static bool GetFrameSize(IMFMediaType* type, gfx::Size* frame_size) { |
| return true; |
| } |
| -static bool GetFrameRate(IMFMediaType* type, |
| - int* frame_rate_numerator, |
| - int* frame_rate_denominator) { |
| +static bool GetFrameRate(IMFMediaType* type, float* frame_rate) { |
|
mcasas
2014/09/10 16:52:28
const IMFMediaType* type ?
tommi (sloooow) - chröme
2014/09/10 17:41:09
COM doesn't have a concept of 'const' for objects
|
| UINT32 numerator, denominator; |
| if (FAILED(MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, |
| &denominator))|| |
| !denominator) { |
| return false; |
| } |
| - *frame_rate_numerator = numerator; |
| - *frame_rate_denominator = denominator; |
| + *frame_rate = static_cast<float>(numerator) / denominator; |
| return true; |
| } |
| static bool FillCapabilitiesFromType(IMFMediaType* type, |
|
mcasas
2014/09/10 16:52:28
s/FillCapabilities/FillFormat/
const IMFMediaType
|
| - VideoCaptureCapabilityWin* capability) { |
| + VideoCaptureFormat* format) { |
| GUID type_guid; |
| if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) || |
| - !GetFrameSize(type, &capability->supported_format.frame_size) || |
| - !GetFrameRate(type, |
| - &capability->frame_rate_numerator, |
| - &capability->frame_rate_denominator) || |
| + !GetFrameSize(type, &format->frame_size) || |
| + !GetFrameRate(type, &format->frame_rate) || |
| !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, |
| - &capability->supported_format.pixel_format)) { |
| + &format->pixel_format)) { |
| return false; |
| } |
| - capability->supported_format.frame_rate = |
| - capability->frame_rate_numerator / capability->frame_rate_denominator; |
| return true; |
| } |
| @@ -71,15 +64,13 @@ HRESULT FillCapabilities(IMFSourceReader* source, |
| DWORD stream_index = 0; |
| ScopedComPtr<IMFMediaType> type; |
| HRESULT hr; |
| - for (hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, |
| - type.Receive()); |
| - SUCCEEDED(hr); |
| - hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, |
| - type.Receive())) { |
| - VideoCaptureCapabilityWin capability(stream_index++); |
| - if (FillCapabilitiesFromType(type, &capability)) |
| - capabilities->Add(capability); |
| + while (SUCCEEDED(hr = source->GetNativeMediaType( |
| + kFirstVideoStream, stream_index, type.Receive()))) { |
| + VideoCaptureFormat format; |
| + if (FillCapabilitiesFromType(type, &format)) |
| + capabilities->push_back(VideoCaptureCapabilityWin(stream_index, format)); |
| type.Release(); |
| + stream_index++; |
|
tommi (sloooow) - chröme
2014/09/09 20:11:11
++stream_index;
magjed_chromium
2014/09/10 18:34:21
Done.
|
| } |
| if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) |
| @@ -251,22 +242,18 @@ void VideoCaptureDeviceMFWin::AllocateAndStart( |
| if (reader_) { |
| hr = FillCapabilities(reader_, &capabilities); |
| if (SUCCEEDED(hr)) { |
| - VideoCaptureCapabilityWin found_capability = |
| - capabilities.GetBestMatchedFormat( |
| - params.requested_format.frame_size.width(), |
| - params.requested_format.frame_size.height(), |
| - params.requested_format.frame_rate); |
| - |
| + const VideoCaptureCapabilityWin& found_capability = |
| + *GetBestMatchedFormat(params.requested_format, capabilities); |
| ScopedComPtr<IMFMediaType> type; |
| hr = reader_->GetNativeMediaType( |
| - kFirstVideoStream, found_capability.stream_index, type.Receive()); |
| + kFirstVideoStream, found_capability.first, type.Receive()); |
| if (SUCCEEDED(hr)) { |
| hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type); |
| if (SUCCEEDED(hr)) { |
| hr = reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, |
| NULL); |
| if (SUCCEEDED(hr)) { |
| - capture_format_ = found_capability.supported_format; |
| + capture_format_ = found_capability.second; |
| capture_ = true; |
| return; |
| } |