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

Side by Side Diff: media/midi/midi_manager_alsa.h

Issue 2673423002: Web MIDI: add dynamic MidiManager instantiation support for Linux (Closed)
Patch Set: hope try compile this on all Created 3 years, 10 months 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
OLDNEW
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 #ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 6 #define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
7 7
8 #include <alsa/asoundlib.h> 8 #include <alsa/asoundlib.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "media/midi/midi_manager.h" 24 #include "media/midi/midi_manager.h"
25 25
26 namespace base { 26 namespace base {
27 class ThreadChecker; 27 class ThreadChecker;
28 } 28 }
29 29
30 namespace midi { 30 namespace midi {
31 31
32 class MIDI_EXPORT MidiManagerAlsa final : public MidiManager { 32 class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
33 public: 33 public:
34 MidiManagerAlsa(); 34 MidiManagerAlsa(MidiService* service);
yhirano 2017/02/08 10:04:37 +explicit
Takashi Toyoshima 2017/02/08 11:08:55 Done.
35 ~MidiManagerAlsa() override; 35 ~MidiManagerAlsa() override;
36 36
37 // MidiManager implementation. 37 // MidiManager implementation.
38 void StartInitialization() override; 38 void StartInitialization() override;
39 void Finalize() override; 39 void Finalize() override;
40 void DispatchSendMidiData(MidiManagerClient* client, 40 void DispatchSendMidiData(MidiManagerClient* client,
41 uint32_t port_index, 41 uint32_t port_index,
42 const std::vector<uint8_t>& data, 42 const std::vector<uint8_t>& data,
43 double timestamp) override; 43 double timestamp) override;
44 44
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 }; 366 };
367 }; 367 };
368 368
369 using SourceMap = base::hash_map<int, uint32_t>; 369 using SourceMap = base::hash_map<int, uint32_t>;
370 using OutPortMap = base::hash_map<uint32_t, int>; 370 using OutPortMap = base::hash_map<uint32_t, int>;
371 using ScopedSndSeqPtr = std::unique_ptr<snd_seq_t, SndSeqDeleter>; 371 using ScopedSndSeqPtr = std::unique_ptr<snd_seq_t, SndSeqDeleter>;
372 using ScopedSndMidiEventPtr = 372 using ScopedSndMidiEventPtr =
373 std::unique_ptr<snd_midi_event_t, SndMidiEventDeleter>; 373 std::unique_ptr<snd_midi_event_t, SndMidiEventDeleter>;
374 374
375 // An internal callback that runs on MidiSendThread. 375 // An internal callback that runs on MidiSendThread.
376 void SendMidiData(uint32_t port_index, const std::vector<uint8_t>& data); 376 void SendMidiData(int instance_id,
377 MidiManagerClient* client,
378 uint32_t port_index,
379 const std::vector<uint8_t>& data);
377 380
378 void ScheduleEventLoop(); 381 void EventLoop(int instance_id);
379 void EventLoop();
380 void ProcessSingleEvent(snd_seq_event_t* event, double timestamp); 382 void ProcessSingleEvent(snd_seq_event_t* event, double timestamp);
381 void ProcessClientStartEvent(int client_id); 383 void ProcessClientStartEvent(int client_id);
382 void ProcessPortStartEvent(const snd_seq_addr_t& addr); 384 void ProcessPortStartEvent(const snd_seq_addr_t& addr);
383 void ProcessClientExitEvent(const snd_seq_addr_t& addr); 385 void ProcessClientExitEvent(const snd_seq_addr_t& addr);
384 void ProcessPortExitEvent(const snd_seq_addr_t& addr); 386 void ProcessPortExitEvent(const snd_seq_addr_t& addr);
385 void ProcessUdevEvent(udev_device* dev); 387 void ProcessUdevEvent(udev_device* dev);
386 void AddCard(udev_device* dev); 388 void AddCard(udev_device* dev);
387 void RemoveCard(int number); 389 void RemoveCard(int number);
388 390
389 // Updates port_state_ and Web MIDI state from alsa_seq_state_. 391 // Updates port_state_ and Web MIDI state from alsa_seq_state_.
(...skipping 23 matching lines...) Expand all
413 415
414 // Mapping from card to devices. 416 // Mapping from card to devices.
415 AlsaCardMap alsa_cards_; 417 AlsaCardMap alsa_cards_;
416 418
417 // This is the current count of midi devices across all cards we know 419 // This is the current count of midi devices across all cards we know
418 // about. When this number matches card_client_count_ in AlsaSeqState, 420 // about. When this number matches card_client_count_ in AlsaSeqState,
419 // we are safe to generate MIDIConnectionEvents. Otherwise we need to 421 // we are safe to generate MIDIConnectionEvents. Otherwise we need to
420 // wait for our information from ALSA and udev to get back in sync. 422 // wait for our information from ALSA and udev to get back in sync.
421 int alsa_card_midi_count_ = 0; 423 int alsa_card_midi_count_ = 0;
422 424
423 base::Lock shutdown_lock_; // guards event_thread_shutdown_
424 bool event_thread_shutdown_ = false; // guarded by shutdown_lock_
425
426 // This lock is needed to ensure that members destroyed in Finalize 425 // This lock is needed to ensure that members destroyed in Finalize
427 // will be visibly destroyed before the destructor is run in the 426 // will be visibly destroyed before the destructor is run in the
428 // other thread. Otherwise, the same objects may have their destructors 427 // other thread. Otherwise, the same objects may have their destructors
429 // run multiple times in different threads. 428 // run multiple times in different threads.
430 base::Lock lazy_init_member_lock_; // guards members below 429 base::Lock lazy_init_member_lock_; // guards members below
431 430
432 // Members initialized in StartInitialization() are below. 431 // Members initialized in StartInitialization() are below.
433 // Make sure to destroy these in Finalize()! 432 // Make sure to destroy these in Finalize()!
434 std::unique_ptr<base::ThreadChecker> initialization_thread_checker_; 433 std::unique_ptr<base::ThreadChecker> initialization_thread_checker_;
435 434
436 // ALSA seq handles and ids. 435 // ALSA seq handles and ids.
437 ScopedSndSeqPtr in_client_; 436 ScopedSndSeqPtr in_client_;
438 int in_client_id_; 437 int in_client_id_;
439 ScopedSndSeqPtr out_client_; 438 ScopedSndSeqPtr out_client_;
440 int out_client_id_; 439 int out_client_id_;
441 int in_port_id_; 440 int in_port_id_;
442 441
443 // ALSA event -> MIDI coder. 442 // ALSA event -> MIDI coder.
444 ScopedSndMidiEventPtr decoder_; 443 ScopedSndMidiEventPtr decoder_;
445 444
446 // udev, for querying hardware devices. 445 // udev, for querying hardware devices.
447 device::ScopedUdevPtr udev_; 446 device::ScopedUdevPtr udev_;
448 device::ScopedUdevMonitorPtr udev_monitor_; 447 device::ScopedUdevMonitorPtr udev_monitor_;
449 448
450 // Threads for sending and receiving. These are initialized in the 449 int instance_id_;
451 // constructor, but are started at the end of StartInitialization.
452 base::Thread event_thread_;
453 base::Thread send_thread_;
454 450
455 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); 451 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa);
456 }; 452 };
457 453
458 } // namespace midi 454 } // namespace midi
459 455
460 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 456 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698