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 #pragma warning(disable : 4467) | 7 #pragma warning(disable : 4467) |
8 | 8 |
9 #include <initguid.h> // Required by <devpkey.h> | 9 #include <initguid.h> // Required by <devpkey.h> |
10 | 10 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return false; | 380 return false; |
381 } | 381 } |
382 | 382 |
383 auto dev_info_statics = WrlStaticsFactory< | 383 auto dev_info_statics = WrlStaticsFactory< |
384 IDeviceInformationStatics, | 384 IDeviceInformationStatics, |
385 RuntimeClass_Windows_Devices_Enumeration_DeviceInformation>(); | 385 RuntimeClass_Windows_Devices_Enumeration_DeviceInformation>(); |
386 if (!dev_info_statics) | 386 if (!dev_info_statics) |
387 return false; | 387 return false; |
388 | 388 |
389 hr = dev_info_statics->CreateWatcherAqsFilter(device_selector, | 389 hr = dev_info_statics->CreateWatcherAqsFilter(device_selector, |
390 watcher_.Receive()); | 390 watcher_.GetAddressOf()); |
391 if (FAILED(hr)) { | 391 if (FAILED(hr)) { |
392 VLOG(1) << "CreateWatcherAqsFilter failed: " << PrintHr(hr); | 392 VLOG(1) << "CreateWatcherAqsFilter failed: " << PrintHr(hr); |
393 return false; | 393 return false; |
394 } | 394 } |
395 | 395 |
396 // Register callbacks to WinRT that post state-modifying jobs back to COM | 396 // Register callbacks to WinRT that post state-modifying jobs back to COM |
397 // thread. |weak_ptr| and |task_runner| are captured by lambda callbacks for | 397 // thread. |weak_ptr| and |task_runner| are captured by lambda callbacks for |
398 // posting jobs. Note that WinRT callback arguments should not be passed | 398 // posting jobs. Note that WinRT callback arguments should not be passed |
399 // outside the callback since the pointers may be unavailable afterwards. | 399 // outside the callback since the pointers may be unavailable afterwards. |
400 base::WeakPtr<MidiPortManager> weak_ptr = GetWeakPtrFromFactory(); | 400 base::WeakPtr<MidiPortManager> weak_ptr = GetWeakPtrFromFactory(); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 HRESULT hr = handle->add_MessageReceived( | 787 HRESULT hr = handle->add_MessageReceived( |
788 WRL::Callback< | 788 WRL::Callback< |
789 ITypedEventHandler<MidiInPort*, MidiMessageReceivedEventArgs*>>( | 789 ITypedEventHandler<MidiInPort*, MidiMessageReceivedEventArgs*>>( |
790 [weak_ptr, task_runner](IMidiInPort* handle, | 790 [weak_ptr, task_runner](IMidiInPort* handle, |
791 IMidiMessageReceivedEventArgs* args) { | 791 IMidiMessageReceivedEventArgs* args) { |
792 const base::TimeTicks now = base::TimeTicks::Now(); | 792 const base::TimeTicks now = base::TimeTicks::Now(); |
793 | 793 |
794 std::string dev_id = GetDeviceIdString(handle); | 794 std::string dev_id = GetDeviceIdString(handle); |
795 | 795 |
796 ScopedComPtr<IMidiMessage> message; | 796 ScopedComPtr<IMidiMessage> message; |
797 HRESULT hr = args->get_Message(message.Receive()); | 797 HRESULT hr = args->get_Message(message.GetAddressOf()); |
798 if (FAILED(hr)) { | 798 if (FAILED(hr)) { |
799 VLOG(1) << "get_Message failed: " << PrintHr(hr); | 799 VLOG(1) << "get_Message failed: " << PrintHr(hr); |
800 return hr; | 800 return hr; |
801 } | 801 } |
802 | 802 |
803 ScopedComPtr<IBuffer> buffer; | 803 ScopedComPtr<IBuffer> buffer; |
804 hr = message->get_RawData(buffer.Receive()); | 804 hr = message->get_RawData(buffer.GetAddressOf()); |
805 if (FAILED(hr)) { | 805 if (FAILED(hr)) { |
806 VLOG(1) << "get_RawData failed: " << PrintHr(hr); | 806 VLOG(1) << "get_RawData failed: " << PrintHr(hr); |
807 return hr; | 807 return hr; |
808 } | 808 } |
809 | 809 |
810 uint8_t* p_buffer_data = nullptr; | 810 uint8_t* p_buffer_data = nullptr; |
811 hr = GetPointerToBufferData(buffer.Get(), &p_buffer_data); | 811 hr = GetPointerToBufferData(buffer.Get(), &p_buffer_data); |
812 if (FAILED(hr)) | 812 if (FAILED(hr)) |
813 return hr; | 813 return hr; |
814 | 814 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 } | 1007 } |
1008 | 1008 |
1009 auto buffer_factory = | 1009 auto buffer_factory = |
1010 WrlStaticsFactory<IBufferFactory, | 1010 WrlStaticsFactory<IBufferFactory, |
1011 RuntimeClass_Windows_Storage_Streams_Buffer>(); | 1011 RuntimeClass_Windows_Storage_Streams_Buffer>(); |
1012 if (!buffer_factory) | 1012 if (!buffer_factory) |
1013 return; | 1013 return; |
1014 | 1014 |
1015 ScopedComPtr<IBuffer> buffer; | 1015 ScopedComPtr<IBuffer> buffer; |
1016 HRESULT hr = buffer_factory->Create(static_cast<UINT32>(data.size()), | 1016 HRESULT hr = buffer_factory->Create(static_cast<UINT32>(data.size()), |
1017 buffer.Receive()); | 1017 buffer.GetAddressOf()); |
1018 if (FAILED(hr)) { | 1018 if (FAILED(hr)) { |
1019 VLOG(1) << "Create failed: " << PrintHr(hr); | 1019 VLOG(1) << "Create failed: " << PrintHr(hr); |
1020 return; | 1020 return; |
1021 } | 1021 } |
1022 | 1022 |
1023 hr = buffer->put_Length(static_cast<UINT32>(data.size())); | 1023 hr = buffer->put_Length(static_cast<UINT32>(data.size())); |
1024 if (FAILED(hr)) { | 1024 if (FAILED(hr)) { |
1025 VLOG(1) << "put_Length failed: " << PrintHr(hr); | 1025 VLOG(1) << "put_Length failed: " << PrintHr(hr); |
1026 return; | 1026 return; |
1027 } | 1027 } |
(...skipping 14 matching lines...) Expand all Loading... |
1042 | 1042 |
1043 void MidiManagerWinrt::OnPortManagerReady() { | 1043 void MidiManagerWinrt::OnPortManagerReady() { |
1044 DCHECK(com_thread_checker_->CalledOnValidThread()); | 1044 DCHECK(com_thread_checker_->CalledOnValidThread()); |
1045 DCHECK(port_manager_ready_count_ < 2); | 1045 DCHECK(port_manager_ready_count_ < 2); |
1046 | 1046 |
1047 if (++port_manager_ready_count_ == 2) | 1047 if (++port_manager_ready_count_ == 2) |
1048 CompleteInitialization(Result::OK); | 1048 CompleteInitialization(Result::OK); |
1049 } | 1049 } |
1050 | 1050 |
1051 } // namespace midi | 1051 } // namespace midi |
OLD | NEW |