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" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/win/scoped_co_mem.h" | 14 #include "base/win/scoped_co_mem.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "media/video/capture/win/capability_list_win.h" | 16 #include "media/video/capture/win/capability_list_win.h" |
17 | 17 |
18 using base::win::ScopedCoMem; | 18 using base::win::ScopedCoMem; |
19 using base::win::ScopedComPtr; | 19 using base::win::ScopedComPtr; |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 // In Windows device identifiers, the USB VID and PID are preceded by the string | 23 // In Windows device identifiers, the USB VID and PID are preceded by the string |
24 // "vid_" or "pid_". The identifiers are each 4 bytes long. | 24 // "vid_" or "pid_". The identifiers are each 4 bytes long. |
25 const char kVidPrefix[] = "vid_"; // Also contains '\0'. | 25 const char kVidPrefix[] = "vid_"; // Also contains '\0'. |
26 const char kPidPrefix[] = "pid_"; // Also contains '\0'. | 26 const char kPidPrefix[] = "pid_"; // Also contains '\0'. |
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 FillCapabilitiesFromType(IMFMediaType* type, |
30 UINT32 width32, height32; | 30 VideoCaptureFormat* format) { |
31 if (FAILED(MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width32, &height32))) | 31 UINT32 width, height; |
32 HRESULT hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); | |
33 if (FAILED(hr)) { | |
34 DLOG(ERROR) << "MFGetAttributeSize failed: " | |
35 << logging::SystemErrorCodeToString(hr); | |
32 return false; | 36 return false; |
33 frame_size->SetSize(width32, height32); | 37 } |
38 | |
39 UINT32 numerator, denominator; | |
40 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); | |
41 if (FAILED(hr)) { | |
42 DLOG(ERROR) << "MFGetAttributeSize failed: " | |
43 << logging::SystemErrorCodeToString(hr); | |
44 return false; | |
45 } | |
46 | |
47 GUID type_guid; | |
48 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); | |
49 if (FAILED(hr)) { | |
50 DLOG(ERROR) << "GetGUID failed: " << logging::SystemErrorCodeToString(hr); | |
51 return false; | |
52 } | |
53 | |
54 format->frame_size.SetSize(width, height); | |
55 format->frame_rate = | |
56 denominator ? static_cast<float>(numerator) / denominator : 0.0f; | |
57 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, &format->pixel_format); | |
34 return true; | 58 return true; |
35 } | 59 } |
36 | 60 |
37 static bool GetFrameRate(IMFMediaType* type, | 61 // static |
38 int* frame_rate_numerator, | 62 HRESULT VideoCaptureDeviceMFWin::FillCapabilities( |
39 int* frame_rate_denominator) { | 63 IMFSourceReader* source, |
40 UINT32 numerator, denominator; | 64 CapabilityList* capabilities) { |
41 if (FAILED(MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, | |
42 &denominator))|| | |
43 !denominator) { | |
44 return false; | |
45 } | |
46 *frame_rate_numerator = numerator; | |
47 *frame_rate_denominator = denominator; | |
48 return true; | |
49 } | |
50 | |
51 static bool FillCapabilitiesFromType(IMFMediaType* type, | |
52 VideoCaptureCapabilityWin* capability) { | |
53 GUID type_guid; | |
54 if (FAILED(type->GetGUID(MF_MT_SUBTYPE, &type_guid)) || | |
55 !GetFrameSize(type, &capability->supported_format.frame_size) || | |
56 !GetFrameRate(type, | |
57 &capability->frame_rate_numerator, | |
58 &capability->frame_rate_denominator) || | |
59 !VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, | |
60 &capability->supported_format.pixel_format)) { | |
61 return false; | |
62 } | |
63 capability->supported_format.frame_rate = | |
64 capability->frame_rate_numerator / capability->frame_rate_denominator; | |
65 | |
66 return true; | |
67 } | |
68 | |
69 HRESULT FillCapabilities(IMFSourceReader* source, | |
70 CapabilityList* capabilities) { | |
71 DWORD stream_index = 0; | 65 DWORD stream_index = 0; |
72 ScopedComPtr<IMFMediaType> type; | 66 ScopedComPtr<IMFMediaType> type; |
73 HRESULT hr; | 67 HRESULT hr; |
74 for (hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, | 68 while (SUCCEEDED(hr = source->GetNativeMediaType( |
75 type.Receive()); | 69 kFirstVideoStream, stream_index, type.Receive()))) { |
perkj_chrome
2014/09/19 10:04:55
indentation.
while (SUCCEEDED(hr = source->GetNati
| |
76 SUCCEEDED(hr); | |
77 hr = source->GetNativeMediaType(kFirstVideoStream, stream_index, | |
78 type.Receive())) { | |
79 VideoCaptureCapabilityWin capability(stream_index++); | 70 VideoCaptureCapabilityWin capability(stream_index++); |
80 if (FillCapabilitiesFromType(type, &capability)) | 71 if (FillCapabilitiesFromType(type, &capability.supported_format)) |
81 capabilities->Add(capability); | 72 capabilities->Add(capability); |
82 type.Release(); | 73 type.Release(); |
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 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 | 324 |
334 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { | 325 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { |
335 if (client_.get()) { | 326 if (client_.get()) { |
336 client_->OnError( | 327 client_->OnError( |
337 base::StringPrintf("VideoCaptureDeviceMFWin: %s", | 328 base::StringPrintf("VideoCaptureDeviceMFWin: %s", |
338 logging::SystemErrorCodeToString(hr).c_str())); | 329 logging::SystemErrorCodeToString(hr).c_str())); |
339 } | 330 } |
340 } | 331 } |
341 | 332 |
342 } // namespace media | 333 } // namespace media |
OLD | NEW |