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

Side by Side Diff: media/midi/midi_manager_win.cc

Issue 2485903002: Web MIDI: do not keep virtual synth open (Closed)
Patch Set: fix deadlock Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 result = midiOutGetDevCaps( 821 result = midiOutGetDevCaps(
822 device_id, reinterpret_cast<LPMIDIOUTCAPSW>(&caps), sizeof(caps)); 822 device_id, reinterpret_cast<LPMIDIOUTCAPSW>(&caps), sizeof(caps));
823 if (result != MMSYSERR_NOERROR) { 823 if (result != MMSYSERR_NOERROR) {
824 DLOG(ERROR) << "midiInGetDevCaps failed: " << GetOutErrorMessage(result); 824 DLOG(ERROR) << "midiInGetDevCaps failed: " << GetOutErrorMessage(result);
825 return; 825 return;
826 } 826 }
827 auto state = 827 auto state =
828 make_scoped_refptr(new MidiOutputDeviceState(MidiDeviceInfo(caps))); 828 make_scoped_refptr(new MidiOutputDeviceState(MidiDeviceInfo(caps)));
829 state->midi_handle = midi_out_handle; 829 state->midi_handle = midi_out_handle;
830 const auto& state_device_info = state->device_info; 830 const auto& state_device_info = state->device_info;
831 if (IsUnsupportedDevice(state_device_info)) 831 bool unsupported = IsUnsupportedDevice(state_device_info);
Takashi Toyoshima 2016/11/10 08:12:26 Note: I tried to close handle here so to just retu
832 return;
833 bool add_new_port = false; 832 bool add_new_port = false;
834 uint32_t port_number = 0; 833 uint32_t port_number = 0;
835 { 834 {
836 base::AutoLock auto_lock(output_ports_lock_); 835 base::AutoLock auto_lock(output_ports_lock_);
837 const auto it = unused_output_ports_.find(state_device_info); 836 const auto it = unused_output_ports_.find(state_device_info);
838 if (it == unused_output_ports_.end()) { 837 if (it == unused_output_ports_.end()) {
839 port_number = static_cast<uint32_t>(output_ports_.size()); 838 port_number = static_cast<uint32_t>(output_ports_.size());
840 add_new_port = true; 839 add_new_port = true;
841 output_ports_.push_back(nullptr); 840 output_ports_.push_back(nullptr);
842 output_ports_ages_.push_back(0); 841 output_ports_ages_.push_back(0);
(...skipping 10 matching lines...) Expand all
853 output_ports_[port_number]->port_index = port_number; 852 output_ports_[port_number]->port_index = port_number;
854 output_ports_[port_number]->port_age = output_ports_ages_[port_number]; 853 output_ports_[port_number]->port_age = output_ports_ages_[port_number];
855 } 854 }
856 if (add_new_port) { 855 if (add_new_port) {
857 const MidiPortInfo port_info( 856 const MidiPortInfo port_info(
858 // TODO(toyoshim): Use a hash ID insted. crbug.com/467448 857 // TODO(toyoshim): Use a hash ID insted. crbug.com/467448
859 base::IntToString(static_cast<int>(port_number)), 858 base::IntToString(static_cast<int>(port_number)),
860 GetManufacturerName(state_device_info), 859 GetManufacturerName(state_device_info),
861 base::WideToUTF8(state_device_info.product_name), 860 base::WideToUTF8(state_device_info.product_name),
862 MmversionToString(state_device_info.driver_version), 861 MmversionToString(state_device_info.driver_version),
863 PortState::OPENED); 862 unsupported ? PortState::DISCONNECTED : PortState::OPENED);
864 task_thread_.task_runner()->PostTask( 863 task_thread_.task_runner()->PostTask(
865 FROM_HERE, base::Bind(&MidiServiceWinImpl::AddOutputPortOnTaskThread, 864 FROM_HERE,
866 base::Unretained(this), port_info)); 865 base::Bind(&MidiServiceWinImpl::AddOutputPortOnTaskThread,
866 base::Unretained(this), port_number, port_info));
867 } else { 867 } else {
868 task_thread_.task_runner()->PostTask( 868 task_thread_.task_runner()->PostTask(
869 FROM_HERE, 869 FROM_HERE,
870 base::Bind(&MidiServiceWinImpl::SetOutputPortStateOnTaskThread, 870 base::Bind(
871 base::Unretained(this), port_number, 871 &MidiServiceWinImpl::SetOutputPortStateOnTaskThread,
872 PortState::CONNECTED)); 872 base::Unretained(this), port_number,
873 unsupported ? PortState::DISCONNECTED : PortState::CONNECTED));
873 } 874 }
874 } 875 }
875 876
876 void OnMidiOutDoneOnMultimediaThread(HMIDIOUT midi_out_handle, 877 void OnMidiOutDoneOnMultimediaThread(HMIDIOUT midi_out_handle,
877 DWORD_PTR param1) { 878 DWORD_PTR param1) {
878 auto state = GetOutputDeviceFromHandle(midi_out_handle); 879 auto state = GetOutputDeviceFromHandle(midi_out_handle);
879 if (!state) 880 if (!state)
880 return; 881 return;
881 // Take ownership of the MIDIHDR object. 882 // Take ownership of the MIDIHDR object.
882 ScopedMIDIHDR header(reinterpret_cast<MIDIHDR*>(param1)); 883 ScopedMIDIHDR header(reinterpret_cast<MIDIHDR*>(param1));
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 base::TimeTicks time) { 1068 base::TimeTicks time) {
1068 AssertOnTaskThread(); 1069 AssertOnTaskThread();
1069 delegate_->OnReceiveMidiData(port_index, data, time); 1070 delegate_->OnReceiveMidiData(port_index, data, time);
1070 } 1071 }
1071 1072
1072 void AddInputPortOnTaskThread(MidiPortInfo info) { 1073 void AddInputPortOnTaskThread(MidiPortInfo info) {
1073 AssertOnTaskThread(); 1074 AssertOnTaskThread();
1074 delegate_->OnAddInputPort(info); 1075 delegate_->OnAddInputPort(info);
1075 } 1076 }
1076 1077
1077 void AddOutputPortOnTaskThread(MidiPortInfo info) { 1078 void AddOutputPortOnTaskThread(uint32_t port_index, MidiPortInfo info) {
1078 AssertOnTaskThread(); 1079 AssertOnTaskThread();
1080 if (info.state == PortState::DISCONNECTED) {
yukawa 2016/11/10 08:13:13 Fine as long as this is a short-term fix. Ideally
1081 // Close immediately if the device is unsupported one. Device information
1082 // should be updated inside MOM_CLOSE callback.
1083 HMIDIOUT midi_handle = kInvalidMidiOutHandle;
1084 {
1085 base::AutoLock auto_lock(output_ports_lock_);
1086 scoped_refptr<MidiOutputDeviceState> device_state =
1087 output_ports_[port_index];
1088 if (device_state)
1089 midi_handle = device_state->midi_handle;
1090 }
1091 if (midi_handle != kInvalidMidiOutHandle)
1092 midiOutClose(midi_handle);
1093 }
1079 delegate_->OnAddOutputPort(info); 1094 delegate_->OnAddOutputPort(info);
1080 } 1095 }
1081 1096
1082 void SetInputPortStateOnTaskThread(uint32_t port_index, PortState state) { 1097 void SetInputPortStateOnTaskThread(uint32_t port_index, PortState state) {
1083 AssertOnTaskThread(); 1098 AssertOnTaskThread();
1084 delegate_->OnSetInputPortState(port_index, state); 1099 delegate_->OnSetInputPortState(port_index, state);
1085 } 1100 }
1086 1101
1087 void SetOutputPortStateOnTaskThread(uint32_t port_index, PortState state) { 1102 void SetOutputPortStateOnTaskThread(uint32_t port_index, PortState state) {
1088 AssertOnTaskThread(); 1103 AssertOnTaskThread();
1104 if (state == PortState::DISCONNECTED) {
yukawa 2016/11/10 08:13:13 Ditto.
1105 // Close immediately if the device is unsupported one and still opened.
1106 // Device information should be updated inside MOM_CLOSE callback.
1107 HMIDIOUT midi_handle = kInvalidMidiOutHandle;
1108 {
1109 base::AutoLock auto_lock(output_ports_lock_);
1110 scoped_refptr<MidiOutputDeviceState> device_state =
1111 output_ports_[port_index];
1112 if (device_state && device_state->midi_handle != kInvalidMidiOutHandle)
1113 midi_handle = device_state->midi_handle;
1114 }
1115 if (midi_handle != kInvalidMidiOutHandle)
1116 midiOutClose(midi_handle);
1117 }
1089 delegate_->OnSetOutputPortState(port_index, state); 1118 delegate_->OnSetOutputPortState(port_index, state);
1090 } 1119 }
1091 1120
1092 ///////////////////////////////////////////////////////////////////////////// 1121 /////////////////////////////////////////////////////////////////////////////
1093 // Fields: 1122 // Fields:
1094 ///////////////////////////////////////////////////////////////////////////// 1123 /////////////////////////////////////////////////////////////////////////////
1095 1124
1096 // Does not take ownership. 1125 // Does not take ownership.
1097 MidiServiceWinDelegate* delegate_; 1126 MidiServiceWinDelegate* delegate_;
1098 1127
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 } 1223 }
1195 1224
1196 MidiManager* MidiManager::Create() { 1225 MidiManager* MidiManager::Create() {
1197 if (base::FeatureList::IsEnabled(features::kMidiManagerWinrt) && 1226 if (base::FeatureList::IsEnabled(features::kMidiManagerWinrt) &&
1198 base::win::GetVersion() >= base::win::VERSION_WIN10) 1227 base::win::GetVersion() >= base::win::VERSION_WIN10)
1199 return new MidiManagerWinrt(); 1228 return new MidiManagerWinrt();
1200 return new MidiManagerWin(); 1229 return new MidiManagerWin();
1201 } 1230 }
1202 1231
1203 } // namespace midi 1232 } // namespace midi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698