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 21 matching lines...) Expand all Loading... |
32 void StartInitialization() override; | 32 void StartInitialization() override; |
33 void DispatchSendMidiData(MidiManagerClient* client, | 33 void DispatchSendMidiData(MidiManagerClient* client, |
34 uint32 port_index, | 34 uint32 port_index, |
35 const std::vector<uint8>& data, | 35 const std::vector<uint8>& data, |
36 double timestamp) override; | 36 double timestamp) override; |
37 | 37 |
38 private: | 38 private: |
39 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 39 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
40 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, JSONPortMetadata); | 40 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, JSONPortMetadata); |
41 | 41 |
42 class AlsaRawmidi { | 42 class AlsaCard { |
43 public: | 43 public: |
44 AlsaRawmidi(const MidiManagerAlsa* outer, | 44 AlsaCard(const MidiManagerAlsa* outer, |
45 const std::string& alsa_name, | 45 const std::string& alsa_name, |
46 const std::string& alsa_longname, | 46 const std::string& alsa_longname, |
47 const std::string& alsa_driver, | 47 const std::string& alsa_driver, |
48 int card_index); | 48 int card_index, |
49 ~AlsaRawmidi(); | 49 int midi_count); |
| 50 ~AlsaCard(); |
50 | 51 |
51 const std::string alsa_name() const; | 52 const std::string alsa_name() const; |
52 const std::string alsa_longname() const; | 53 const std::string alsa_longname() const; |
53 const std::string manufacturer() const; | 54 const std::string manufacturer() const; |
54 const std::string alsa_driver() const; | 55 const std::string alsa_driver() const; |
55 const std::string path() const; | 56 const std::string path() const; |
56 const std::string bus() const; | 57 const std::string bus() const; |
57 const std::string vendor_id() const; | 58 const std::string vendor_id() const; |
58 const std::string id() const; | 59 const std::string id() const; |
| 60 const int midi_count() const; |
59 | 61 |
60 private: | 62 private: |
61 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 63 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
62 | 64 |
63 // Extracts the manufacturer using heuristics and a variety of sources. | 65 // Extracts the manufacturer using heuristics and a variety of sources. |
64 static std::string ExtractManufacturerString( | 66 static std::string ExtractManufacturerString( |
65 const std::string& udev_id_vendor, | 67 const std::string& udev_id_vendor, |
66 const std::string& udev_id_vendor_id, | 68 const std::string& udev_id_vendor_id, |
67 const std::string& udev_id_vendor_from_database, | 69 const std::string& udev_id_vendor_from_database, |
68 const std::string& alsa_name, | 70 const std::string& alsa_name, |
69 const std::string& alsa_longname); | 71 const std::string& alsa_longname); |
70 | 72 |
71 std::string alsa_name_; | 73 std::string alsa_name_; |
72 std::string alsa_longname_; | 74 std::string alsa_longname_; |
73 std::string manufacturer_; | 75 std::string manufacturer_; |
74 std::string alsa_driver_; | 76 std::string alsa_driver_; |
75 std::string path_; | 77 std::string path_; |
76 std::string bus_; | 78 std::string bus_; |
77 std::string vendor_id_; | 79 std::string vendor_id_; |
78 std::string model_id_; | 80 std::string model_id_; |
79 std::string usb_interface_num_; | 81 std::string usb_interface_num_; |
| 82 int midi_count_; |
80 | 83 |
81 DISALLOW_COPY_AND_ASSIGN(AlsaRawmidi); | 84 DISALLOW_COPY_AND_ASSIGN(AlsaCard); |
82 }; | 85 }; |
83 | 86 |
84 class AlsaPortMetadata { | 87 class AlsaPortMetadata { |
85 public: | 88 public: |
86 enum class Type { kInput, kOutput }; | 89 enum class Type { kInput, kOutput }; |
87 | 90 |
88 AlsaPortMetadata(const std::string& path, | 91 AlsaPortMetadata(const std::string& path, |
89 const std::string& bus, | 92 const std::string& bus, |
90 const std::string& id, | 93 const std::string& id, |
91 const snd_seq_addr_t* address, | 94 const snd_seq_addr_t* address, |
(...skipping 25 matching lines...) Expand all Loading... |
117 const int port_addr_; | 120 const int port_addr_; |
118 const std::string client_name_; | 121 const std::string client_name_; |
119 const std::string port_name_; | 122 const std::string port_name_; |
120 const std::string card_name_; | 123 const std::string card_name_; |
121 const std::string card_longname_; | 124 const std::string card_longname_; |
122 const Type type_; | 125 const Type type_; |
123 | 126 |
124 DISALLOW_COPY_AND_ASSIGN(AlsaPortMetadata); | 127 DISALLOW_COPY_AND_ASSIGN(AlsaPortMetadata); |
125 }; | 128 }; |
126 | 129 |
127 // Returns an ordered vector of all the rawmidi devices on the system. | 130 // Returns an ordered vector of all the cards with MIDI capabilities. |
128 ScopedVector<AlsaRawmidi> AllAlsaRawmidis(); | 131 ScopedVector<AlsaCard> AllMidiCards(); |
129 | 132 |
130 // Enumerate all the ports for initial setup. | 133 // Enumerate all the ports for initial setup. |
131 void EnumeratePorts(); | 134 void EnumeratePorts(); |
132 | 135 |
133 // An internal callback that runs on MidiSendThread. | 136 // An internal callback that runs on MidiSendThread. |
134 void SendMidiData(uint32 port_index, | 137 void SendMidiData(uint32 port_index, |
135 const std::vector<uint8>& data); | 138 const std::vector<uint8>& data); |
136 | 139 |
137 void ScheduleEventLoop(); | 140 void ScheduleEventLoop(); |
138 void EventLoop(); | 141 void EventLoop(); |
(...skipping 25 matching lines...) Expand all Loading... |
164 | 167 |
165 bool event_thread_shutdown_; // guarded by shutdown_lock_ | 168 bool event_thread_shutdown_; // guarded by shutdown_lock_ |
166 base::Lock shutdown_lock_; // guards event_thread_shutdown_ | 169 base::Lock shutdown_lock_; // guards event_thread_shutdown_ |
167 | 170 |
168 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); | 171 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); |
169 }; | 172 }; |
170 | 173 |
171 } // namespace media | 174 } // namespace media |
172 | 175 |
173 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ | 176 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ |
OLD | NEW |