OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_android.h" | 5 #include "media/midi/midi_manager_android.h" |
6 | 6 |
7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/context_utils.h" | 8 #include "base/android/context_utils.h" |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 void MidiManagerAndroid::OnAttached(JNIEnv* env, | 149 void MidiManagerAndroid::OnAttached(JNIEnv* env, |
150 const JavaParamRef<jobject>& caller, | 150 const JavaParamRef<jobject>& caller, |
151 const JavaParamRef<jobject>& raw_device) { | 151 const JavaParamRef<jobject>& raw_device) { |
152 AddDevice(base::MakeUnique<MidiDeviceAndroid>(env, raw_device, this)); | 152 AddDevice(base::MakeUnique<MidiDeviceAndroid>(env, raw_device, this)); |
153 } | 153 } |
154 | 154 |
155 void MidiManagerAndroid::OnDetached(JNIEnv* env, | 155 void MidiManagerAndroid::OnDetached(JNIEnv* env, |
156 const JavaParamRef<jobject>& caller, | 156 const JavaParamRef<jobject>& caller, |
157 const JavaParamRef<jobject>& raw_device) { | 157 const JavaParamRef<jobject>& raw_device) { |
158 for (auto* device : devices_) { | 158 for (auto& device : devices_) { |
159 if (device->HasRawDevice(env, raw_device)) { | 159 if (device->HasRawDevice(env, raw_device)) { |
160 for (auto* port : device->input_ports()) { | 160 for (auto& port : device->input_ports()) { |
161 DCHECK(input_port_to_index_.end() != input_port_to_index_.find(port)); | 161 DCHECK(input_port_to_index_.end() != |
162 size_t index = input_port_to_index_[port]; | 162 input_port_to_index_.find(port.get())); |
| 163 size_t index = input_port_to_index_[port.get()]; |
163 SetInputPortState(index, PortState::DISCONNECTED); | 164 SetInputPortState(index, PortState::DISCONNECTED); |
164 } | 165 } |
165 for (auto* port : device->output_ports()) { | 166 for (auto& port : device->output_ports()) { |
166 DCHECK(output_port_to_index_.end() != output_port_to_index_.find(port)); | 167 DCHECK(output_port_to_index_.end() != |
167 size_t index = output_port_to_index_[port]; | 168 output_port_to_index_.find(port.get())); |
| 169 size_t index = output_port_to_index_[port.get()]; |
168 SetOutputPortState(index, PortState::DISCONNECTED); | 170 SetOutputPortState(index, PortState::DISCONNECTED); |
169 } | 171 } |
170 } | 172 } |
171 } | 173 } |
172 } | 174 } |
173 | 175 |
174 void MidiManagerAndroid::AddDevice(std::unique_ptr<MidiDeviceAndroid> device) { | 176 void MidiManagerAndroid::AddDevice(std::unique_ptr<MidiDeviceAndroid> device) { |
175 for (auto* port : device->input_ports()) { | 177 for (auto& port : device->input_ports()) { |
176 // We implicitly open input ports here, because there are no signal | 178 // We implicitly open input ports here, because there are no signal |
177 // from the renderer when to open. | 179 // from the renderer when to open. |
178 // TODO(yhirano): Implement open operation in Blink. | 180 // TODO(yhirano): Implement open operation in Blink. |
179 PortState state = port->Open() ? PortState::OPENED : PortState::CONNECTED; | 181 PortState state = port->Open() ? PortState::OPENED : PortState::CONNECTED; |
180 | 182 |
181 const size_t index = all_input_ports_.size(); | 183 const size_t index = all_input_ports_.size(); |
182 all_input_ports_.push_back(port); | 184 all_input_ports_.push_back(port.get()); |
183 // Port ID must be unique in a MIDI manager. This ID setting is | 185 // Port ID must be unique in a MIDI manager. This ID setting is |
184 // sufficiently unique although there is no user-friendly meaning. | 186 // sufficiently unique although there is no user-friendly meaning. |
185 // TODO(yhirano): Use a hashed string as ID. | 187 // TODO(yhirano): Use a hashed string as ID. |
186 const std::string id( | 188 const std::string id( |
187 base::StringPrintf("native:port-in-%ld", static_cast<long>(index))); | 189 base::StringPrintf("native:port-in-%ld", static_cast<long>(index))); |
188 | 190 |
189 input_port_to_index_.insert(std::make_pair(port, index)); | 191 input_port_to_index_.insert(std::make_pair(port.get(), index)); |
190 AddInputPort(MidiPortInfo(id, device->GetManufacturer(), | 192 AddInputPort(MidiPortInfo(id, device->GetManufacturer(), |
191 device->GetProductName(), | 193 device->GetProductName(), |
192 device->GetDeviceVersion(), state)); | 194 device->GetDeviceVersion(), state)); |
193 } | 195 } |
194 for (auto* port : device->output_ports()) { | 196 for (auto& port : device->output_ports()) { |
195 const size_t index = all_output_ports_.size(); | 197 const size_t index = all_output_ports_.size(); |
196 all_output_ports_.push_back(port); | 198 all_output_ports_.push_back(port.get()); |
197 | 199 |
198 // Port ID must be unique in a MIDI manager. This ID setting is | 200 // Port ID must be unique in a MIDI manager. This ID setting is |
199 // sufficiently unique although there is no user-friendly meaning. | 201 // sufficiently unique although there is no user-friendly meaning. |
200 // TODO(yhirano): Use a hashed string as ID. | 202 // TODO(yhirano): Use a hashed string as ID. |
201 const std::string id( | 203 const std::string id( |
202 base::StringPrintf("native:port-out-%ld", static_cast<long>(index))); | 204 base::StringPrintf("native:port-out-%ld", static_cast<long>(index))); |
203 | 205 |
204 output_port_to_index_.insert(std::make_pair(port, index)); | 206 output_port_to_index_.insert(std::make_pair(port.get(), index)); |
205 AddOutputPort( | 207 AddOutputPort( |
206 MidiPortInfo(id, device->GetManufacturer(), device->GetProductName(), | 208 MidiPortInfo(id, device->GetManufacturer(), device->GetProductName(), |
207 device->GetDeviceVersion(), PortState::CONNECTED)); | 209 device->GetDeviceVersion(), PortState::CONNECTED)); |
208 } | 210 } |
209 devices_.push_back(device.release()); | 211 devices_.push_back(std::move(device)); |
210 } | 212 } |
211 | 213 |
212 bool MidiManagerAndroid::Register(JNIEnv* env) { | 214 bool MidiManagerAndroid::Register(JNIEnv* env) { |
213 return RegisterNativesImpl(env); | 215 return RegisterNativesImpl(env); |
214 } | 216 } |
215 | 217 |
216 } // namespace midi | 218 } // namespace midi |
OLD | NEW |