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 30 matching lines...) Expand all Loading... |
41 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 41 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
42 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ToMidiPortState); | 42 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ToMidiPortState); |
43 | 43 |
44 class AlsaCard; | 44 class AlsaCard; |
45 typedef std::map<int, AlsaCard*> AlsaCardMap; | 45 typedef std::map<int, AlsaCard*> AlsaCardMap; |
46 | 46 |
47 class MidiPort { | 47 class MidiPort { |
48 public: | 48 public: |
49 enum class Type { kInput, kOutput }; | 49 enum class Type { kInput, kOutput }; |
50 | 50 |
| 51 // The Id class is used to keep the multiple strings separate |
| 52 // but compare them all together for equality purposes. |
| 53 // The individual strings that make up the Id can theoretically contain |
| 54 // arbitrary characters, so unfortunately there is no simple way to |
| 55 // concatenate them into a single string. |
| 56 class Id final { |
| 57 public: |
| 58 Id(); |
| 59 Id(const std::string& bus, |
| 60 const std::string& vendor_id, |
| 61 const std::string& model_id, |
| 62 const std::string& usb_interface_num, |
| 63 const std::string& serial); |
| 64 Id(const Id&); |
| 65 ~Id(); |
| 66 bool operator==(const Id&) const; |
| 67 bool empty() const; |
| 68 |
| 69 std::string bus() const { return bus_; } |
| 70 std::string vendor_id() const { return vendor_id_; } |
| 71 std::string model_id() const { return model_id_; } |
| 72 std::string usb_interface_num() const { return usb_interface_num_; } |
| 73 std::string serial() const { return serial_; } |
| 74 |
| 75 private: |
| 76 std::string bus_; |
| 77 std::string vendor_id_; |
| 78 std::string model_id_; |
| 79 std::string usb_interface_num_; |
| 80 std::string serial_; |
| 81 }; |
| 82 |
51 MidiPort(const std::string& path, | 83 MidiPort(const std::string& path, |
52 const std::string& id, | 84 const Id& id, |
53 int client_id, | 85 int client_id, |
54 int port_id, | 86 int port_id, |
55 int midi_device, | 87 int midi_device, |
56 const std::string& client_name, | 88 const std::string& client_name, |
57 const std::string& port_name, | 89 const std::string& port_name, |
58 const std::string& manufacturer, | 90 const std::string& manufacturer, |
59 const std::string& version, | 91 const std::string& version, |
60 Type type); | 92 Type type); |
61 ~MidiPort(); | 93 ~MidiPort(); |
62 | 94 |
(...skipping 14 matching lines...) Expand all Loading... |
77 bool MatchCardPass1(const MidiPort& query) const; | 109 bool MatchCardPass1(const MidiPort& query) const; |
78 // Checks for equality for kernel cards with id, pass 2. | 110 // Checks for equality for kernel cards with id, pass 2. |
79 bool MatchCardPass2(const MidiPort& query) const; | 111 bool MatchCardPass2(const MidiPort& query) const; |
80 // Checks for equality for non-card clients, pass 1. | 112 // Checks for equality for non-card clients, pass 1. |
81 bool MatchNoCardPass1(const MidiPort& query) const; | 113 bool MatchNoCardPass1(const MidiPort& query) const; |
82 // Checks for equality for non-card clients, pass 2. | 114 // Checks for equality for non-card clients, pass 2. |
83 bool MatchNoCardPass2(const MidiPort& query) const; | 115 bool MatchNoCardPass2(const MidiPort& query) const; |
84 | 116 |
85 // accessors | 117 // accessors |
86 std::string path() const { return path_; } | 118 std::string path() const { return path_; } |
87 std::string id() const { return id_; } | 119 Id id() const { return id_; } |
88 std::string client_name() const { return client_name_; } | 120 std::string client_name() const { return client_name_; } |
89 std::string port_name() const { return port_name_; } | 121 std::string port_name() const { return port_name_; } |
90 std::string manufacturer() const { return manufacturer_; } | 122 std::string manufacturer() const { return manufacturer_; } |
91 std::string version() const { return version_; } | 123 std::string version() const { return version_; } |
92 int client_id() const { return client_id_; } | 124 int client_id() const { return client_id_; } |
93 int port_id() const { return port_id_; } | 125 int port_id() const { return port_id_; } |
94 int midi_device() const { return midi_device_; } | 126 int midi_device() const { return midi_device_; } |
95 Type type() const { return type_; } | 127 Type type() const { return type_; } |
96 uint32 web_port_index() const { return web_port_index_; } | 128 uint32 web_port_index() const { return web_port_index_; } |
97 bool connected() const { return connected_; } | 129 bool connected() const { return connected_; } |
(...skipping 14 matching lines...) Expand all Loading... |
112 client_id_ = client_id; | 144 client_id_ = client_id; |
113 port_id_ = port_id; | 145 port_id_ = port_id; |
114 client_name_ = client_name; | 146 client_name_ = client_name; |
115 port_name_ = port_name; | 147 port_name_ = port_name; |
116 manufacturer_ = manufacturer; | 148 manufacturer_ = manufacturer; |
117 version_ = version; | 149 version_ = version; |
118 } | 150 } |
119 | 151 |
120 private: | 152 private: |
121 // Immutable properties. | 153 // Immutable properties. |
122 const std::string id_; | 154 const Id id_; |
123 const int midi_device_; | 155 const int midi_device_; |
124 | 156 |
125 const Type type_; | 157 const Type type_; |
126 | 158 |
127 // Mutable properties. These will get updated as ports move around or | 159 // Mutable properties. These will get updated as ports move around or |
128 // drivers change. | 160 // drivers change. |
129 std::string path_; | 161 std::string path_; |
130 int client_id_; | 162 int client_id_; |
131 int port_id_; | 163 int port_id_; |
132 std::string client_name_; | 164 std::string client_name_; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // we are in sync between ALSA and udev. Until then, we cannot generate | 302 // we are in sync between ALSA and udev. Until then, we cannot generate |
271 // MIDIConnectionEvents to web clients. | 303 // MIDIConnectionEvents to web clients. |
272 int card_client_count_; | 304 int card_client_count_; |
273 | 305 |
274 DISALLOW_COPY_AND_ASSIGN(AlsaSeqState); | 306 DISALLOW_COPY_AND_ASSIGN(AlsaSeqState); |
275 }; | 307 }; |
276 | 308 |
277 class AlsaCard { | 309 class AlsaCard { |
278 public: | 310 public: |
279 AlsaCard(udev_device* dev, | 311 AlsaCard(udev_device* dev, |
280 const std::string& alsa_name, | 312 const std::string& name, |
281 const std::string& alsa_longname, | 313 const std::string& longname, |
282 const std::string& alsa_driver, | 314 const std::string& driver, |
283 int midi_device_count); | 315 int midi_device_count); |
284 ~AlsaCard(); | 316 ~AlsaCard(); |
285 const std::string alsa_name() const { return alsa_name_; } | 317 std::string name() const { return name_; } |
286 const std::string alsa_longname() const { return alsa_longname_; } | 318 std::string longname() const { return longname_; } |
287 const std::string manufacturer() const { return manufacturer_; } | 319 std::string driver() const { return driver_; } |
288 const std::string alsa_driver() const { return alsa_driver_; } | 320 std::string path() const { return path_; } |
| 321 std::string bus() const { return bus_; } |
| 322 std::string vendor_id() const { return vendor_id_; } |
| 323 std::string model_id() const { return model_id_; } |
| 324 std::string usb_interface_num() const { return usb_interface_num_; } |
| 325 std::string serial() const { return serial_; } |
289 int midi_device_count() const { return midi_device_count_; } | 326 int midi_device_count() const { return midi_device_count_; } |
290 // Returns hardware path. | 327 std::string manufacturer() const { return manufacturer_; } |
291 const std::string path() const; | |
292 // Returns the id we can use to try to match hardware across different | |
293 // paths. | |
294 const std::string id() const; | |
295 | 328 |
296 private: | 329 private: |
297 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); | 330 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer); |
298 | 331 |
299 // Extracts the manufacturer using heuristics and a variety of sources. | 332 // Extracts the manufacturer using heuristics and a variety of sources. |
300 static std::string ExtractManufacturerString( | 333 static std::string ExtractManufacturerString( |
301 const std::string& udev_id_vendor, | 334 const std::string& udev_id_vendor, |
302 const std::string& udev_id_vendor_id, | 335 const std::string& udev_id_vendor_id, |
303 const std::string& udev_id_vendor_from_database, | 336 const std::string& udev_id_vendor_from_database, |
304 const std::string& alsa_name, | 337 const std::string& name, |
305 const std::string& alsa_longname); | 338 const std::string& longname); |
306 | 339 |
307 std::string alsa_name_; | 340 const std::string name_; |
308 std::string alsa_longname_; | 341 const std::string longname_; |
309 std::string manufacturer_; | 342 const std::string driver_; |
310 std::string alsa_driver_; | 343 const std::string path_; |
311 std::string path_; | 344 const std::string bus_; |
312 std::string bus_; | 345 const std::string vendor_id_; |
313 std::string serial_; | 346 const std::string model_id_; |
314 std::string vendor_id_; | 347 const std::string usb_interface_num_; |
315 std::string model_id_; | 348 const std::string serial_; |
316 std::string usb_interface_num_; | 349 const int midi_device_count_; |
317 int midi_device_count_; | 350 const std::string manufacturer_; |
318 | 351 |
319 DISALLOW_COPY_AND_ASSIGN(AlsaCard); | 352 DISALLOW_COPY_AND_ASSIGN(AlsaCard); |
320 }; | 353 }; |
321 | 354 |
322 typedef base::hash_map<int, uint32> SourceMap; | 355 typedef base::hash_map<int, uint32> SourceMap; |
323 typedef base::hash_map<uint32, int> OutPortMap; | 356 typedef base::hash_map<uint32, int> OutPortMap; |
324 | 357 |
325 // An internal callback that runs on MidiSendThread. | 358 // An internal callback that runs on MidiSendThread. |
326 void SendMidiData(uint32 port_index, const std::vector<uint8>& data); | 359 void SendMidiData(uint32 port_index, const std::vector<uint8>& data); |
327 | 360 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 bool event_thread_shutdown_; // guarded by shutdown_lock_ | 422 bool event_thread_shutdown_; // guarded by shutdown_lock_ |
390 base::Lock shutdown_lock_; // guards event_thread_shutdown_ | 423 base::Lock shutdown_lock_; // guards event_thread_shutdown_ |
391 | 424 |
392 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); | 425 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); |
393 }; | 426 }; |
394 | 427 |
395 } // namespace midi | 428 } // namespace midi |
396 } // namespace media | 429 } // namespace media |
397 | 430 |
398 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ | 431 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ |
OLD | NEW |