| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_win.h" | 5 #include "media/midi/midi_manager_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <ks.h> | 8 #include <ks.h> |
| 9 #include <ksmedia.h> | 9 #include <ksmedia.h> |
| 10 #include <mmreg.h> | 10 #include <mmreg.h> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 << " midiOutGetErrorText error: " << get_result; | 82 << " midiOutGetErrorText error: " << get_result; |
| 83 return std::string(); | 83 return std::string(); |
| 84 } | 84 } |
| 85 return base::WideToUTF8(text); | 85 return base::WideToUTF8(text); |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string MmversionToString(MMVERSION version) { | 88 std::string MmversionToString(MMVERSION version) { |
| 89 return base::StringPrintf("%d.%d", HIBYTE(version), LOBYTE(version)); | 89 return base::StringPrintf("%d.%d", HIBYTE(version), LOBYTE(version)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void CloseOutputPortOnTaskThread(HMIDIOUT midi_out_handle) { |
| 93 midiOutClose(midi_out_handle); |
| 94 } |
| 95 |
| 92 class MIDIHDRDeleter { | 96 class MIDIHDRDeleter { |
| 93 public: | 97 public: |
| 94 void operator()(MIDIHDR* header) { | 98 void operator()(MIDIHDR* header) { |
| 95 if (!header) | 99 if (!header) |
| 96 return; | 100 return; |
| 97 delete[] static_cast<char*>(header->lpData); | 101 delete[] static_cast<char*>(header->lpData); |
| 98 header->lpData = NULL; | 102 header->lpData = NULL; |
| 99 header->dwBufferLength = 0; | 103 header->dwBufferLength = 0; |
| 100 delete header; | 104 delete header; |
| 101 } | 105 } |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 result = midiOutGetDevCaps( | 825 result = midiOutGetDevCaps( |
| 822 device_id, reinterpret_cast<LPMIDIOUTCAPSW>(&caps), sizeof(caps)); | 826 device_id, reinterpret_cast<LPMIDIOUTCAPSW>(&caps), sizeof(caps)); |
| 823 if (result != MMSYSERR_NOERROR) { | 827 if (result != MMSYSERR_NOERROR) { |
| 824 DLOG(ERROR) << "midiInGetDevCaps failed: " << GetOutErrorMessage(result); | 828 DLOG(ERROR) << "midiInGetDevCaps failed: " << GetOutErrorMessage(result); |
| 825 return; | 829 return; |
| 826 } | 830 } |
| 827 auto state = | 831 auto state = |
| 828 make_scoped_refptr(new MidiOutputDeviceState(MidiDeviceInfo(caps))); | 832 make_scoped_refptr(new MidiOutputDeviceState(MidiDeviceInfo(caps))); |
| 829 state->midi_handle = midi_out_handle; | 833 state->midi_handle = midi_out_handle; |
| 830 const auto& state_device_info = state->device_info; | 834 const auto& state_device_info = state->device_info; |
| 831 if (IsUnsupportedDevice(state_device_info)) | 835 if (IsUnsupportedDevice(state_device_info)) { |
| 836 task_thread_.task_runner()->PostTask( |
| 837 FROM_HERE, base::Bind(&CloseOutputPortOnTaskThread, midi_out_handle)); |
| 832 return; | 838 return; |
| 839 } |
| 833 bool add_new_port = false; | 840 bool add_new_port = false; |
| 834 uint32_t port_number = 0; | 841 uint32_t port_number = 0; |
| 835 { | 842 { |
| 836 base::AutoLock auto_lock(output_ports_lock_); | 843 base::AutoLock auto_lock(output_ports_lock_); |
| 837 const auto it = unused_output_ports_.find(state_device_info); | 844 const auto it = unused_output_ports_.find(state_device_info); |
| 838 if (it == unused_output_ports_.end()) { | 845 if (it == unused_output_ports_.end()) { |
| 839 port_number = static_cast<uint32_t>(output_ports_.size()); | 846 port_number = static_cast<uint32_t>(output_ports_.size()); |
| 840 add_new_port = true; | 847 add_new_port = true; |
| 841 output_ports_.push_back(nullptr); | 848 output_ports_.push_back(nullptr); |
| 842 output_ports_ages_.push_back(0); | 849 output_ports_ages_.push_back(0); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 } | 1201 } |
| 1195 | 1202 |
| 1196 MidiManager* MidiManager::Create() { | 1203 MidiManager* MidiManager::Create() { |
| 1197 if (base::FeatureList::IsEnabled(features::kMidiManagerWinrt) && | 1204 if (base::FeatureList::IsEnabled(features::kMidiManagerWinrt) && |
| 1198 base::win::GetVersion() >= base::win::VERSION_WIN10) | 1205 base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 1199 return new MidiManagerWinrt(); | 1206 return new MidiManagerWinrt(); |
| 1200 return new MidiManagerWin(); | 1207 return new MidiManagerWin(); |
| 1201 } | 1208 } |
| 1202 | 1209 |
| 1203 } // namespace midi | 1210 } // namespace midi |
| OLD | NEW |