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

Side by Side Diff: media/video/capture/win/video_capture_device_mf_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: fix mac syntax error Created 6 years, 3 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 unified diff | Download patch
OLDNEW
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
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) {
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
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 FillCapabilitiesFromType(IMFMediaType* type,
mcasas 2014/09/10 16:52:28 s/FillCapabilities/FillFormat/ const IMFMediaType
52 VideoCaptureCapabilityWin* capability) { 49 VideoCaptureFormat* format) {
53 GUID type_guid; 50 GUID type_guid;
54 if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) || 51 if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) ||
55 !GetFrameSize(type, &capability->supported_format.frame_size) || 52 !GetFrameSize(type, &format->frame_size) ||
56 !GetFrameRate(type, 53 !GetFrameRate(type, &format->frame_rate) ||
57 &capability->frame_rate_numerator,
58 &capability->frame_rate_denominator) ||
59 !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 54 !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
60 &capability->supported_format.pixel_format)) { 55 &format->pixel_format)) {
61 return false; 56 return false;
62 } 57 }
63 capability->supported_format.frame_rate =
64 capability->frame_rate_numerator / capability->frame_rate_denominator;
65 58
66 return true; 59 return true;
67 } 60 }
68 61
69 HRESULT FillCapabilities(IMFSourceReader* source, 62 HRESULT FillCapabilities(IMFSourceReader* source,
70 CapabilityList* capabilities) { 63 CapabilityList* capabilities) {
71 DWORD stream_index = 0; 64 DWORD stream_index = 0;
72 ScopedComPtr<IMFMediaType> type; 65 ScopedComPtr<IMFMediaType> type;
73 HRESULT hr; 66 HRESULT hr;
74 for (hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, 67 while (SUCCEEDED(hr = source->GetNativeMediaType(
75 type.Receive()); 68 kFirstVideoStream, stream_index, type.Receive()))) {
76 SUCCEEDED(hr); 69 VideoCaptureFormat format;
77 hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, 70 if (FillCapabilitiesFromType(type, &format))
78 type.Receive())) { 71 capabilities->push_back(VideoCaptureCapabilityWin(stream_index, format));
79 VideoCaptureCapabilityWin capability(stream_index++);
80 if (FillCapabilitiesFromType(type, &capability))
81 capabilities->Add(capability);
82 type.Release(); 72 type.Release();
73 stream_index++;
tommi (sloooow) - chröme 2014/09/09 20:11:11 ++stream_index;
magjed_chromium 2014/09/10 18:34:21 Done.
83 } 74 }
84 75
85 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) 76 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES))
86 hr = HRESULT_FROM_WIN32(ERROR_EMPTY); 77 hr = HRESULT_FROM_WIN32(ERROR_EMPTY);
87 78
88 return (hr == MF_E_NO_MORE_TYPES) ? S_OK : hr; 79 return (hr == MF_E_NO_MORE_TYPES) ? S_OK : hr;
89 } 80 }
90 81
91 82
92 class MFReaderCallback FINAL 83 class MFReaderCallback FINAL
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 base::AutoLock lock(lock_); 235 base::AutoLock lock(lock_);
245 236
246 client_ = client.Pass(); 237 client_ = client.Pass();
247 DCHECK_EQ(capture_, false); 238 DCHECK_EQ(capture_, false);
248 239
249 CapabilityList capabilities; 240 CapabilityList capabilities;
250 HRESULT hr = S_OK; 241 HRESULT hr = S_OK;
251 if (reader_) { 242 if (reader_) {
252 hr = FillCapabilities(reader_, &capabilities); 243 hr = FillCapabilities(reader_, &capabilities);
253 if (SUCCEEDED(hr)) { 244 if (SUCCEEDED(hr)) {
254 VideoCaptureCapabilityWin found_capability = 245 const VideoCaptureCapabilityWin& found_capability =
255 capabilities.GetBestMatchedFormat( 246 *GetBestMatchedFormat(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; 247 ScopedComPtr<IMFMediaType> type;
261 hr = reader_->GetNativeMediaType( 248 hr = reader_->GetNativeMediaType(
262 kFirstVideoStream, found_capability.stream_index, type.Receive()); 249 kFirstVideoStream, found_capability.first, type.Receive());
263 if (SUCCEEDED(hr)) { 250 if (SUCCEEDED(hr)) {
264 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type); 251 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type);
265 if (SUCCEEDED(hr)) { 252 if (SUCCEEDED(hr)) {
266 hr = reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, 253 hr = reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL,
267 NULL); 254 NULL);
268 if (SUCCEEDED(hr)) { 255 if (SUCCEEDED(hr)) {
269 capture_format_ = found_capability.supported_format; 256 capture_format_ = found_capability.second;
270 capture_ = true; 257 capture_ = true;
271 return; 258 return;
272 } 259 }
273 } 260 }
274 } 261 }
275 } 262 }
276 } 263 }
277 264
278 OnError(hr); 265 OnError(hr);
279 } 266 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 320
334 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { 321 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) {
335 if (client_.get()) { 322 if (client_.get()) {
336 client_->OnError( 323 client_->OnError(
337 base::StringPrintf("VideoCaptureDeviceMFWin: %s", 324 base::StringPrintf("VideoCaptureDeviceMFWin: %s",
338 logging::SystemErrorCodeToString(hr).c_str())); 325 logging::SystemErrorCodeToString(hr).c_str()));
339 } 326 }
340 } 327 }
341 328
342 } // namespace media 329 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698