OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/midi/midi_manager_winrt.h" | 5 #include "media/midi/midi_manager_winrt.h" |
6 | 6 |
7 #include <comdef.h> | 7 #include <comdef.h> |
8 #include <robuffer.h> | 8 #include <robuffer.h> |
9 #include <windows.devices.enumeration.h> | 9 #include <windows.devices.enumeration.h> |
10 #include <windows.devices.midi.h> | 10 #include <windows.devices.midi.h> |
11 #include <wrl/event.h> | 11 #include <wrl/event.h> |
12 | 12 |
13 #include <iomanip> | 13 #include <iomanip> |
14 #include <unordered_map> | 14 #include <unordered_map> |
15 #include <unordered_set> | 15 #include <unordered_set> |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
19 #include "base/scoped_generic.h" | 19 #include "base/scoped_generic.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
24 #include "base/win/scoped_comptr.h" | 24 #include "base/win/scoped_comptr.h" |
25 #include "base/win/windows_version.h" | |
26 #include "media/midi/midi_scheduler.h" | 25 #include "media/midi/midi_scheduler.h" |
27 | 26 |
28 namespace media { | 27 namespace media { |
29 namespace midi { | 28 namespace midi { |
30 namespace { | 29 namespace { |
31 | 30 |
32 namespace WRL = Microsoft::WRL; | 31 namespace WRL = Microsoft::WRL; |
33 | 32 |
34 using namespace ABI::Windows::Devices::Enumeration; | 33 using namespace ABI::Windows::Devices::Enumeration; |
35 using namespace ABI::Windows::Devices::Midi; | 34 using namespace ABI::Windows::Devices::Midi; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // std::string with nullptr (in base::WideToUTF8) is undefined behavior. | 189 // std::string with nullptr (in base::WideToUTF8) is undefined behavior. |
191 const base::char16* buffer = | 190 const base::char16* buffer = |
192 g_combase_functions.Get().WindowsGetStringRawBuffer(result, nullptr); | 191 g_combase_functions.Get().WindowsGetStringRawBuffer(result, nullptr); |
193 if (buffer) | 192 if (buffer) |
194 return base::WideToUTF8(buffer); | 193 return base::WideToUTF8(buffer); |
195 return std::string(); | 194 return std::string(); |
196 } | 195 } |
197 | 196 |
198 template <typename T> | 197 template <typename T> |
199 std::string GetIdString(T* obj) { | 198 std::string GetIdString(T* obj) { |
200 return GetStringFromObjectMethod<T, &T::get_Id>(obj); | 199 return GetStringFromObjectMethod<T, &T::get_Id>(obj); |
Shao-Chuan Lee
2016/09/01 09:48:20
This triggers error C2893 and C2672 in amd64_x86 M
| |
201 } | 200 } |
202 | 201 |
203 template <typename T> | 202 template <typename T> |
204 std::string GetDeviceIdString(T* obj) { | 203 std::string GetDeviceIdString(T* obj) { |
205 return GetStringFromObjectMethod<T, &T::get_DeviceId>(obj); | 204 return GetStringFromObjectMethod<T, &T::get_DeviceId>(obj); |
Shao-Chuan Lee
2016/09/01 09:48:20
ditto
| |
206 } | 205 } |
207 | 206 |
208 std::string GetNameString(IDeviceInformation* info) { | 207 std::string GetNameString(IDeviceInformation* info) { |
209 return GetStringFromObjectMethod<IDeviceInformation, | 208 return GetStringFromObjectMethod<IDeviceInformation, |
210 &IDeviceInformation::get_Name>(info); | 209 &IDeviceInformation::get_Name>(info); |
Shao-Chuan Lee
2016/09/01 09:48:20
ditto
| |
211 } | 210 } |
212 | 211 |
213 HRESULT GetPointerToBufferData(IBuffer* buffer, uint8_t** out) { | 212 HRESULT GetPointerToBufferData(IBuffer* buffer, uint8_t** out) { |
214 ScopedComPtr<Windows::Storage::Streams::IBufferByteAccess> buffer_byte_access; | 213 ScopedComPtr<Windows::Storage::Streams::IBufferByteAccess> buffer_byte_access; |
215 | 214 |
216 HRESULT hr = buffer_byte_access.QueryFrom(buffer); | 215 HRESULT hr = buffer_byte_access.QueryFrom(buffer); |
217 if (FAILED(hr)) { | 216 if (FAILED(hr)) { |
218 VLOG(1) << "QueryInterface failed: " << PrintHr(hr); | 217 VLOG(1) << "QueryInterface failed: " << PrintHr(hr); |
219 return hr; | 218 return hr; |
220 } | 219 } |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 MidiManagerWinrt::~MidiManagerWinrt() { | 802 MidiManagerWinrt::~MidiManagerWinrt() { |
804 base::AutoLock auto_lock(lazy_init_member_lock_); | 803 base::AutoLock auto_lock(lazy_init_member_lock_); |
805 | 804 |
806 CHECK(!com_thread_checker_); | 805 CHECK(!com_thread_checker_); |
807 CHECK(!port_manager_in_); | 806 CHECK(!port_manager_in_); |
808 CHECK(!port_manager_out_); | 807 CHECK(!port_manager_out_); |
809 CHECK(!scheduler_); | 808 CHECK(!scheduler_); |
810 } | 809 } |
811 | 810 |
812 void MidiManagerWinrt::StartInitialization() { | 811 void MidiManagerWinrt::StartInitialization() { |
813 if (base::win::GetVersion() < base::win::VERSION_WIN10) { | |
814 VLOG(1) << "WinRT MIDI backend is only supported on Windows 10 or later."; | |
815 CompleteInitialization(Result::INITIALIZATION_ERROR); | |
816 return; | |
817 } | |
818 | |
819 com_thread_.init_com_with_mta(true); | 812 com_thread_.init_com_with_mta(true); |
820 com_thread_.Start(); | 813 com_thread_.Start(); |
821 | 814 |
822 com_thread_.task_runner()->PostTask( | 815 com_thread_.task_runner()->PostTask( |
823 FROM_HERE, base::Bind(&MidiManagerWinrt::InitializeOnComThread, | 816 FROM_HERE, base::Bind(&MidiManagerWinrt::InitializeOnComThread, |
824 base::Unretained(this))); | 817 base::Unretained(this))); |
825 } | 818 } |
826 | 819 |
827 void MidiManagerWinrt::Finalize() { | 820 void MidiManagerWinrt::Finalize() { |
828 com_thread_.task_runner()->PostTask( | 821 com_thread_.task_runner()->PostTask( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
936 } | 929 } |
937 | 930 |
938 void MidiManagerWinrt::OnPortManagerReady() { | 931 void MidiManagerWinrt::OnPortManagerReady() { |
939 DCHECK(com_thread_checker_->CalledOnValidThread()); | 932 DCHECK(com_thread_checker_->CalledOnValidThread()); |
940 DCHECK(port_manager_ready_count_ < 2); | 933 DCHECK(port_manager_ready_count_ < 2); |
941 | 934 |
942 if (++port_manager_ready_count_ == 2) | 935 if (++port_manager_ready_count_ == 2) |
943 CompleteInitialization(Result::OK); | 936 CompleteInitialization(Result::OK); |
944 } | 937 } |
945 | 938 |
946 MidiManager* MidiManager::Create() { | |
947 return new MidiManagerWinrt(); | |
948 } | |
949 | |
950 } // namespace midi | 939 } // namespace midi |
951 } // namespace media | 940 } // namespace media |
OLD | NEW |