| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/video/capture/win/video_capture_device_mf_win.h" | 5 #include "media/video/capture/win/video_capture_device_mf_win.h" |
| 6 | 6 |
| 7 #include <mfapi.h> | 7 #include <mfapi.h> |
| 8 #include <mferror.h> | 8 #include <mferror.h> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const size_t kVidPidSize = 4; | 27 const size_t kVidPidSize = 4; |
| 28 | 28 |
| 29 static bool GetFrameSize(IMFMediaType* type, gfx::Size* frame_size) { | 29 static bool GetFrameSize(IMFMediaType* type, gfx::Size* frame_size) { |
| 30 UINT32 width32, height32; | 30 UINT32 width32, height32; |
| 31 if (FAILED(MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width32, &height32))) | 31 if (FAILED(MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width32, &height32))) |
| 32 return false; | 32 return false; |
| 33 frame_size->SetSize(width32, height32); | 33 frame_size->SetSize(width32, height32); |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 static bool GetFrameRate(IMFMediaType* type, | 37 static bool GetFrameRate(IMFMediaType* type, float* frame_rate) { |
| 38 int* frame_rate_numerator, | |
| 39 int* frame_rate_denominator) { | |
| 40 UINT32 numerator, denominator; | 38 UINT32 numerator, denominator; |
| 41 if (FAILED(MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, | 39 if (FAILED(MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, |
| 42 &denominator))|| | 40 &denominator))|| |
| 43 !denominator) { | 41 !denominator) { |
| 44 return false; | 42 return false; |
| 45 } | 43 } |
| 46 *frame_rate_numerator = numerator; | 44 *frame_rate = static_cast<float>(numerator) / denominator; |
| 47 *frame_rate_denominator = denominator; | |
| 48 return true; | 45 return true; |
| 49 } | 46 } |
| 50 | 47 |
| 51 static bool FillCapabilitiesFromType(IMFMediaType* type, | 48 static bool FillFormat(IMFMediaType* type, VideoCaptureFormat* format) { |
| 52 VideoCaptureCapabilityWin* capability) { | |
| 53 GUID type_guid; | 49 GUID type_guid; |
| 54 if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) || | 50 if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) || |
| 55 !GetFrameSize(type, &capability->supported_format.frame_size) || | 51 !GetFrameSize(type, &format->frame_size) || |
| 56 !GetFrameRate(type, | 52 !GetFrameRate(type, &format->frame_rate) || |
| 57 &capability->frame_rate_numerator, | |
| 58 &capability->frame_rate_denominator) || | |
| 59 !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, | 53 !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, |
| 60 &capability->supported_format.pixel_format)) { | 54 &format->pixel_format)) { |
| 61 return false; | 55 return false; |
| 62 } | 56 } |
| 63 capability->supported_format.frame_rate = | |
| 64 capability->frame_rate_numerator / capability->frame_rate_denominator; | |
| 65 | 57 |
| 66 return true; | 58 return true; |
| 67 } | 59 } |
| 68 | 60 |
| 69 HRESULT FillCapabilities(IMFSourceReader* source, | 61 HRESULT FillCapabilities(IMFSourceReader* source, |
| 70 CapabilityList* capabilities) { | 62 CapabilityList* capabilities) { |
| 71 DWORD stream_index = 0; | 63 DWORD stream_index = 0; |
| 72 ScopedComPtr<IMFMediaType> type; | 64 ScopedComPtr<IMFMediaType> type; |
| 73 HRESULT hr; | 65 HRESULT hr; |
| 74 for (hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, | 66 while (SUCCEEDED(hr = source->GetNativeMediaType( |
| 75 type.Receive()); | 67 kFirstVideoStream, stream_index, type.Receive()))) { |
| 76 SUCCEEDED(hr); | 68 VideoCaptureFormat format; |
| 77 hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, | 69 if (FillFormat(type, &format)) |
| 78 type.Receive())) { | 70 capabilities->push_back(VideoCaptureCapabilityWin(stream_index, format)); |
| 79 VideoCaptureCapabilityWin capability(stream_index++); | |
| 80 if (FillCapabilitiesFromType(type, &capability)) | |
| 81 capabilities->Add(capability); | |
| 82 type.Release(); | 71 type.Release(); |
| 72 ++stream_index; |
| 83 } | 73 } |
| 84 | 74 |
| 85 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) | 75 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) |
| 86 hr = HRESULT_FROM_WIN32(ERROR_EMPTY); | 76 hr = HRESULT_FROM_WIN32(ERROR_EMPTY); |
| 87 | 77 |
| 88 return (hr == MF_E_NO_MORE_TYPES) ? S_OK : hr; | 78 return (hr == MF_E_NO_MORE_TYPES) ? S_OK : hr; |
| 89 } | 79 } |
| 90 | 80 |
| 91 | 81 |
| 92 class MFReaderCallback FINAL | 82 class MFReaderCallback FINAL |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 base::AutoLock lock(lock_); | 234 base::AutoLock lock(lock_); |
| 245 | 235 |
| 246 client_ = client.Pass(); | 236 client_ = client.Pass(); |
| 247 DCHECK_EQ(capture_, false); | 237 DCHECK_EQ(capture_, false); |
| 248 | 238 |
| 249 CapabilityList capabilities; | 239 CapabilityList capabilities; |
| 250 HRESULT hr = S_OK; | 240 HRESULT hr = S_OK; |
| 251 if (reader_) { | 241 if (reader_) { |
| 252 hr = FillCapabilities(reader_, &capabilities); | 242 hr = FillCapabilities(reader_, &capabilities); |
| 253 if (SUCCEEDED(hr)) { | 243 if (SUCCEEDED(hr)) { |
| 254 VideoCaptureCapabilityWin found_capability = | 244 const VideoCaptureCapabilityWin& found_capability = |
| 255 capabilities.GetBestMatchedFormat( | 245 *GetBestMatchedCapability(params.requested_format, capabilities); |
| 256 params.requested_format.frame_size.width(), | |
| 257 params.requested_format.frame_size.height(), | |
| 258 params.requested_format.frame_rate); | |
| 259 | |
| 260 ScopedComPtr<IMFMediaType> type; | 246 ScopedComPtr<IMFMediaType> type; |
| 261 hr = reader_->GetNativeMediaType( | 247 hr = reader_->GetNativeMediaType( |
| 262 kFirstVideoStream, found_capability.stream_index, type.Receive()); | 248 kFirstVideoStream, found_capability.stream_index, type.Receive()); |
| 263 if (SUCCEEDED(hr)) { | 249 if (SUCCEEDED(hr)) { |
| 264 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type); | 250 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type); |
| 265 if (SUCCEEDED(hr)) { | 251 if (SUCCEEDED(hr)) { |
| 266 hr = reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, | 252 hr = reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, |
| 267 NULL); | 253 NULL); |
| 268 if (SUCCEEDED(hr)) { | 254 if (SUCCEEDED(hr)) { |
| 269 capture_format_ = found_capability.supported_format; | 255 capture_format_ = found_capability.supported_format; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 319 |
| 334 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { | 320 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { |
| 335 if (client_.get()) { | 321 if (client_.get()) { |
| 336 client_->OnError( | 322 client_->OnError( |
| 337 base::StringPrintf("VideoCaptureDeviceMFWin: %s", | 323 base::StringPrintf("VideoCaptureDeviceMFWin: %s", |
| 338 logging::SystemErrorCodeToString(hr).c_str())); | 324 logging::SystemErrorCodeToString(hr).c_str())); |
| 339 } | 325 } |
| 340 } | 326 } |
| 341 | 327 |
| 342 } // namespace media | 328 } // namespace media |
| OLD | NEW |