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

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

Issue 968663004: Improve MidiManagerAlsa manufacturer reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@udev
Patch Set: Fix embarrassing mistake that broke driver and manufacturer Created 5 years, 9 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
« no previous file with comments | « media/media.gyp ('k') | media/midi/midi_manager_alsa.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "media/midi/midi_manager.h" 17 #include "media/midi/midi_manager.h"
17 18
19 #if defined(USE_UDEV)
20 #include "device/udev_linux/scoped_udev.h"
21 #endif // defined(USE_UDEV)
22
18 namespace media { 23 namespace media {
19 24
20 class MidiManagerAlsa : public MidiManager { 25 class MEDIA_EXPORT MidiManagerAlsa : public MidiManager {
21 public: 26 public:
22 MidiManagerAlsa(); 27 MidiManagerAlsa();
23 ~MidiManagerAlsa() override; 28 ~MidiManagerAlsa() override;
24 29
25 // MidiManager implementation. 30 // MidiManager implementation.
26 void StartInitialization() override; 31 void StartInitialization() override;
27 void DispatchSendMidiData(MidiManagerClient* client, 32 void DispatchSendMidiData(MidiManagerClient* client,
28 uint32 port_index, 33 uint32 port_index,
29 const std::vector<uint8>& data, 34 const std::vector<uint8>& data,
30 double timestamp) override; 35 double timestamp) override;
31 36
32 private: 37 private:
38 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer);
39 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, UdevEscape);
40
41 class CardInfo {
42 public:
43 CardInfo(const MidiManagerAlsa* outer,
44 const std::string& alsa_name, const std::string& alsa_longname,
45 const std::string& alsa_driver, int card_index);
46 ~CardInfo();
47
48 const std::string alsa_name() const;
49 const std::string manufacturer() const;
50 const std::string alsa_driver() const;
51 const std::string udev_id_path() const;
52 const std::string udev_id_id() const;
53
54 private:
55 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer);
56 FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, UdevEscape);
57
58 // Extracts the manufacturer using heuristics and a variety of sources.
59 static std::string ExtractManufacturerString(
60 const std::string& udev_id_vendor_enc,
61 const std::string& udev_id_vendor_id,
62 const std::string& udev_id_vendor_from_database,
63 const std::string& alsa_name,
64 const std::string& alsa_longname);
65
66 // TODO(agoode): Move this into a common place. Maybe device/udev_linux?
67 // Decodes just \xXX in strings.
68 static std::string UnescapeUdev(const std::string& s);
69
70 std::string alsa_name_;
71 std::string manufacturer_;
72 std::string alsa_driver_;
73 std::string udev_id_path_;
74 std::string udev_id_id_;
75 };
76
33 // An internal callback that runs on MidiSendThread. 77 // An internal callback that runs on MidiSendThread.
34 void SendMidiData(uint32 port_index, 78 void SendMidiData(uint32 port_index,
35 const std::vector<uint8>& data); 79 const std::vector<uint8>& data);
36 80
37 void EventReset(); 81 void EventReset();
38 void EventLoop(); 82 void EventLoop();
39 83
40 // Alsa seq handles. 84 // Alsa seq handles.
41 snd_seq_t* in_client_; 85 snd_seq_t* in_client_;
42 snd_seq_t* out_client_; 86 snd_seq_t* out_client_;
43 int out_client_id_; 87 int out_client_id_;
44 88
45 // One input port, many output ports. 89 // One input port, many output ports.
46 int in_port_; 90 int in_port_;
47 std::vector<int> out_ports_; 91 std::vector<int> out_ports_;
48 92
49 // Mapping from Alsa client:port to our index. 93 // Mapping from Alsa client:port to our index.
50 typedef std::map<int, uint32> SourceMap; 94 typedef std::map<int, uint32> SourceMap;
51 SourceMap source_map_; 95 SourceMap source_map_;
52 96
53 // Alsa event <-> MIDI coders. 97 // Alsa event <-> MIDI coders.
54 snd_midi_event_t* decoder_; 98 snd_midi_event_t* decoder_;
55 typedef std::vector<snd_midi_event_t*> EncoderList; 99 typedef std::vector<snd_midi_event_t*> EncoderList;
56 EncoderList encoders_; 100 EncoderList encoders_;
57 101
102 // udev, for querying hardware devices.
103 #if defined(USE_UDEV)
104 device::ScopedUdevPtr udev_;
105 #endif // defined(USE_UDEV)
106
58 base::Thread send_thread_; 107 base::Thread send_thread_;
59 base::Thread event_thread_; 108 base::Thread event_thread_;
60 109
61 bool event_thread_shutdown_; // guarded by shutdown_lock_ 110 bool event_thread_shutdown_; // guarded by shutdown_lock_
62 base::Lock shutdown_lock_; // guards event_thread_shutdown_ 111 base::Lock shutdown_lock_; // guards event_thread_shutdown_
63 112
64 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa); 113 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa);
65 }; 114 };
66 115
67 } // namespace media 116 } // namespace media
68 117
69 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_ 118 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
OLDNEW
« no previous file with comments | « media/media.gyp ('k') | media/midi/midi_manager_alsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698