| 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 #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 <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // MidiManager implementation. | 30 // MidiManager implementation. |
| 31 void StartInitialization() override; | 31 void StartInitialization() override; |
| 32 void DispatchSendMidiData(MidiManagerClient* client, | 32 void DispatchSendMidiData(MidiManagerClient* client, |
| 33 uint32 port_index, | 33 uint32 port_index, |
| 34 const std::vector<uint8>& data, | 34 const std::vector<uint8>& data, |
| 35 double timestamp) override; | 35 double timestamp) override; |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 38 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
| 39 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, UdevEscape); | |
| 40 | 39 |
| 41 class CardInfo { | 40 class MidiDevice { |
| 42 public: | 41 public: |
| 43 CardInfo(const MidiManagerAlsa* outer, | 42 MidiDevice(const MidiManagerAlsa* outer, |
| 44 const std::string& alsa_name, const std::string& alsa_longname, | 43 const std::string& alsa_name, |
| 45 const std::string& alsa_driver, int card_index); | 44 const std::string& alsa_longname, |
| 46 ~CardInfo(); | 45 const std::string& alsa_driver, |
| 46 int card_index); |
| 47 ~MidiDevice(); |
| 47 | 48 |
| 48 const std::string alsa_name() const; | 49 const std::string alsa_name() const; |
| 49 const std::string manufacturer() const; | 50 const std::string manufacturer() const; |
| 50 const std::string alsa_driver() const; | 51 const std::string alsa_driver() const; |
| 51 const std::string udev_id_path() const; | 52 const std::string udev_id_path() const; |
| 52 const std::string udev_id_id() const; | 53 const std::string udev_id_id() const; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 56 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
| 56 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, UdevEscape); | |
| 57 | 57 |
| 58 // Extracts the manufacturer using heuristics and a variety of sources. | 58 // Extracts the manufacturer using heuristics and a variety of sources. |
| 59 static std::string ExtractManufacturerString( | 59 static std::string ExtractManufacturerString( |
| 60 const std::string& udev_id_vendor, | 60 const std::string& udev_id_vendor, |
| 61 const std::string& udev_id_vendor_id, | 61 const std::string& udev_id_vendor_id, |
| 62 const std::string& udev_id_vendor_from_database, | 62 const std::string& udev_id_vendor_from_database, |
| 63 const std::string& alsa_name, | 63 const std::string& alsa_name, |
| 64 const std::string& alsa_longname); | 64 const std::string& alsa_longname); |
| 65 | 65 |
| 66 std::string alsa_name_; | 66 std::string alsa_name_; |
| 67 std::string manufacturer_; | 67 std::string manufacturer_; |
| 68 std::string alsa_driver_; | 68 std::string alsa_driver_; |
| 69 std::string udev_id_path_; | 69 std::string udev_id_path_; |
| 70 std::string udev_id_id_; | 70 std::string udev_id_id_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(MidiDevice); |
| 71 }; | 73 }; |
| 72 | 74 |
| 75 // Returns an ordered vector of all the rawmidi devices on the system. |
| 76 ScopedVector<MidiDevice> AllMidiDevices(); |
| 77 |
| 78 // Enumerate all the ports for initial setup. |
| 79 void EnumeratePorts(); |
| 80 |
| 73 // An internal callback that runs on MidiSendThread. | 81 // An internal callback that runs on MidiSendThread. |
| 74 void SendMidiData(uint32 port_index, | 82 void SendMidiData(uint32 port_index, |
| 75 const std::vector<uint8>& data); | 83 const std::vector<uint8>& data); |
| 76 | 84 |
| 77 void EventReset(); | 85 void ScheduleEventLoop(); |
| 78 void EventLoop(); | 86 void EventLoop(); |
| 87 void ProcessSingleEvent(snd_seq_event_t* event, double timestamp); |
| 79 | 88 |
| 80 // Alsa seq handles. | 89 // ALSA seq handles. |
| 81 snd_seq_t* in_client_; | 90 snd_seq_t* in_client_; |
| 82 snd_seq_t* out_client_; | 91 snd_seq_t* out_client_; |
| 83 int out_client_id_; | 92 int out_client_id_; |
| 84 | 93 |
| 85 // One input port, many output ports. | 94 // One input port, many output ports. |
| 86 int in_port_; | 95 int in_port_; |
| 87 std::vector<int> out_ports_; | 96 std::vector<int> out_ports_; |
| 88 | 97 |
| 89 // Mapping from Alsa client:port to our index. | 98 // Mapping from ALSA client:port to our index. |
| 90 typedef std::map<int, uint32> SourceMap; | 99 typedef std::map<int, uint32> SourceMap; |
| 91 SourceMap source_map_; | 100 SourceMap source_map_; |
| 92 | 101 |
| 93 // Alsa event <-> MIDI coders. | 102 // ALSA event <-> MIDI coders. |
| 94 snd_midi_event_t* decoder_; | 103 snd_midi_event_t* decoder_; |
| 95 typedef std::vector<snd_midi_event_t*> EncoderList; | 104 typedef std::vector<snd_midi_event_t*> EncoderList; |
| 96 EncoderList encoders_; | 105 EncoderList encoders_; |
| 97 | 106 |
| 98 // udev, for querying hardware devices. | 107 // udev, for querying hardware devices. |
| 99 #if defined(USE_UDEV) | 108 #if defined(USE_UDEV) |
| 100 device::ScopedUdevPtr udev_; | 109 device::ScopedUdevPtr udev_; |
| 101 #endif // defined(USE_UDEV) | 110 #endif // defined(USE_UDEV) |
| 102 | 111 |
| 103 base::Thread send_thread_; | 112 base::Thread send_thread_; |
| 104 base::Thread event_thread_; | 113 base::Thread event_thread_; |
| 105 | 114 |
| 106 bool event_thread_shutdown_; // guarded by shutdown_lock_ | 115 bool event_thread_shutdown_; // guarded by shutdown_lock_ |
| 107 base::Lock shutdown_lock_; // guards event_thread_shutdown_ | 116 base::Lock shutdown_lock_; // guards event_thread_shutdown_ |
| 108 | 117 |
| 109 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); | 118 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); |
| 110 }; | 119 }; |
| 111 | 120 |
| 112 } // namespace media | 121 } // namespace media |
| 113 | 122 |
| 114 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ | 123 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ |
| OLD | NEW |