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_alsa.h" | 5 #include "media/midi/midi_manager_alsa.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 void MidiManagerAlsa::StartInitialization() { | 179 void MidiManagerAlsa::StartInitialization() { |
180 // TODO(agoode): Move off I/O thread. See http://crbug.com/374341. | 180 // TODO(agoode): Move off I/O thread. See http://crbug.com/374341. |
181 | 181 |
182 // Create client handles. | 182 // Create client handles. |
183 snd_seq_t* in_client; | 183 snd_seq_t* in_client; |
184 int err = | 184 int err = |
185 snd_seq_open(&in_client, kAlsaHw, SND_SEQ_OPEN_INPUT, SND_SEQ_NONBLOCK); | 185 snd_seq_open(&in_client, kAlsaHw, SND_SEQ_OPEN_INPUT, SND_SEQ_NONBLOCK); |
186 if (err != 0) { | 186 if (err != 0) { |
187 VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); | 187 VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); |
188 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 188 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
189 } | 189 } |
190 in_client_.reset(in_client); | 190 in_client_.reset(in_client); |
191 in_client_id_ = snd_seq_client_id(in_client_.get()); | 191 in_client_id_ = snd_seq_client_id(in_client_.get()); |
192 | 192 |
193 snd_seq_t* out_client; | 193 snd_seq_t* out_client; |
194 err = snd_seq_open(&out_client, kAlsaHw, SND_SEQ_OPEN_OUTPUT, 0); | 194 err = snd_seq_open(&out_client, kAlsaHw, SND_SEQ_OPEN_OUTPUT, 0); |
195 if (err != 0) { | 195 if (err != 0) { |
196 VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); | 196 VLOG(1) << "snd_seq_open fails: " << snd_strerror(err); |
197 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 197 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
198 } | 198 } |
199 out_client_.reset(out_client); | 199 out_client_.reset(out_client); |
200 out_client_id_ = snd_seq_client_id(out_client_.get()); | 200 out_client_id_ = snd_seq_client_id(out_client_.get()); |
201 | 201 |
202 // Name the clients. | 202 // Name the clients. |
203 err = snd_seq_set_client_name(in_client_.get(), "Chrome (input)"); | 203 err = snd_seq_set_client_name(in_client_.get(), "Chrome (input)"); |
204 if (err != 0) { | 204 if (err != 0) { |
205 VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); | 205 VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); |
206 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 206 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
207 } | 207 } |
208 err = snd_seq_set_client_name(out_client_.get(), "Chrome (output)"); | 208 err = snd_seq_set_client_name(out_client_.get(), "Chrome (output)"); |
209 if (err != 0) { | 209 if (err != 0) { |
210 VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); | 210 VLOG(1) << "snd_seq_set_client_name fails: " << snd_strerror(err); |
211 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 211 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
212 } | 212 } |
213 | 213 |
214 // Create input port. | 214 // Create input port. |
215 in_port_id_ = snd_seq_create_simple_port( | 215 in_port_id_ = snd_seq_create_simple_port( |
216 in_client_.get(), NULL, kCreateInputPortCaps, kCreatePortType); | 216 in_client_.get(), NULL, kCreateInputPortCaps, kCreatePortType); |
217 if (in_port_id_ < 0) { | 217 if (in_port_id_ < 0) { |
218 VLOG(1) << "snd_seq_create_simple_port fails: " | 218 VLOG(1) << "snd_seq_create_simple_port fails: " |
219 << snd_strerror(in_port_id_); | 219 << snd_strerror(in_port_id_); |
220 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 220 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
221 } | 221 } |
222 | 222 |
223 // Subscribe to the announce port. | 223 // Subscribe to the announce port. |
224 snd_seq_port_subscribe_t* subs; | 224 snd_seq_port_subscribe_t* subs; |
225 snd_seq_port_subscribe_alloca(&subs); | 225 snd_seq_port_subscribe_alloca(&subs); |
226 snd_seq_addr_t announce_sender; | 226 snd_seq_addr_t announce_sender; |
227 snd_seq_addr_t announce_dest; | 227 snd_seq_addr_t announce_dest; |
228 announce_sender.client = SND_SEQ_CLIENT_SYSTEM; | 228 announce_sender.client = SND_SEQ_CLIENT_SYSTEM; |
229 announce_sender.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE; | 229 announce_sender.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE; |
230 announce_dest.client = in_client_id_; | 230 announce_dest.client = in_client_id_; |
231 announce_dest.port = in_port_id_; | 231 announce_dest.port = in_port_id_; |
232 snd_seq_port_subscribe_set_sender(subs, &announce_sender); | 232 snd_seq_port_subscribe_set_sender(subs, &announce_sender); |
233 snd_seq_port_subscribe_set_dest(subs, &announce_dest); | 233 snd_seq_port_subscribe_set_dest(subs, &announce_dest); |
234 err = snd_seq_subscribe_port(in_client_.get(), subs); | 234 err = snd_seq_subscribe_port(in_client_.get(), subs); |
235 if (err != 0) { | 235 if (err != 0) { |
236 VLOG(1) << "snd_seq_subscribe_port on the announce port fails: " | 236 VLOG(1) << "snd_seq_subscribe_port on the announce port fails: " |
237 << snd_strerror(err); | 237 << snd_strerror(err); |
238 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 238 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
239 } | 239 } |
240 | 240 |
241 // Generate hotplug events for existing ports. | 241 // Generate hotplug events for existing ports. |
242 // TODO(agoode): Check the return value for failure. | 242 // TODO(agoode): Check the return value for failure. |
243 EnumerateAlsaPorts(); | 243 EnumerateAlsaPorts(); |
244 | 244 |
245 // Initialize udev monitor. | 245 // Initialize udev monitor. |
246 udev_monitor_.reset( | 246 udev_monitor_.reset( |
247 device::udev_monitor_new_from_netlink(udev_.get(), kUdev)); | 247 device::udev_monitor_new_from_netlink(udev_.get(), kUdev)); |
248 if (!udev_monitor_.get()) { | 248 if (!udev_monitor_.get()) { |
249 VLOG(1) << "udev_monitor_new_from_netlink fails"; | 249 VLOG(1) << "udev_monitor_new_from_netlink fails"; |
250 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 250 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
251 } | 251 } |
252 err = device::udev_monitor_filter_add_match_subsystem_devtype( | 252 err = device::udev_monitor_filter_add_match_subsystem_devtype( |
253 udev_monitor_.get(), kUdevSubsystemSound, nullptr); | 253 udev_monitor_.get(), kUdevSubsystemSound, nullptr); |
254 if (err != 0) { | 254 if (err != 0) { |
255 VLOG(1) << "udev_monitor_add_match_subsystem fails: " | 255 VLOG(1) << "udev_monitor_add_match_subsystem fails: " |
256 << base::safe_strerror(-err); | 256 << base::safe_strerror(-err); |
257 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 257 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
258 } | 258 } |
259 err = device::udev_monitor_enable_receiving(udev_monitor_.get()); | 259 err = device::udev_monitor_enable_receiving(udev_monitor_.get()); |
260 if (err != 0) { | 260 if (err != 0) { |
261 VLOG(1) << "udev_monitor_enable_receiving fails: " | 261 VLOG(1) << "udev_monitor_enable_receiving fails: " |
262 << base::safe_strerror(-err); | 262 << base::safe_strerror(-err); |
263 return CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 263 return CompleteInitialization(Result::INITIALIZATION_ERROR); |
264 } | 264 } |
265 | 265 |
266 // Generate hotplug events for existing udev devices. | 266 // Generate hotplug events for existing udev devices. |
267 EnumerateUdevCards(); | 267 EnumerateUdevCards(); |
268 | 268 |
269 // Start processing events. | 269 // Start processing events. |
270 event_thread_.Start(); | 270 event_thread_.Start(); |
271 event_thread_.message_loop()->PostTask( | 271 event_thread_.message_loop()->PostTask( |
272 FROM_HERE, | 272 FROM_HERE, |
273 base::Bind(&MidiManagerAlsa::ScheduleEventLoop, base::Unretained(this))); | 273 base::Bind(&MidiManagerAlsa::ScheduleEventLoop, base::Unretained(this))); |
274 | 274 |
275 CompleteInitialization(MIDI_OK); | 275 CompleteInitialization(Result::OK); |
276 } | 276 } |
277 | 277 |
278 void MidiManagerAlsa::DispatchSendMidiData(MidiManagerClient* client, | 278 void MidiManagerAlsa::DispatchSendMidiData(MidiManagerClient* client, |
279 uint32 port_index, | 279 uint32 port_index, |
280 const std::vector<uint8>& data, | 280 const std::vector<uint8>& data, |
281 double timestamp) { | 281 double timestamp) { |
282 // Not correct right now. http://crbug.com/374341. | 282 // Not correct right now. http://crbug.com/374341. |
283 if (!send_thread_.IsRunning()) | 283 if (!send_thread_.IsRunning()) |
284 send_thread_.Start(); | 284 send_thread_.Start(); |
285 | 285 |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 source_map_[AddrToInt(client_id, port_id)] = port_index; | 1341 source_map_[AddrToInt(client_id, port_id)] = port_index; |
1342 return true; | 1342 return true; |
1343 } | 1343 } |
1344 | 1344 |
1345 MidiManager* MidiManager::Create() { | 1345 MidiManager* MidiManager::Create() { |
1346 return new MidiManagerAlsa(); | 1346 return new MidiManagerAlsa(); |
1347 } | 1347 } |
1348 | 1348 |
1349 } // namespace midi | 1349 } // namespace midi |
1350 } // namespace media | 1350 } // namespace media |
OLD | NEW |