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

Unified Diff: media/midi/midi_manager_alsa.h

Issue 1126983007: MidiManagerAlsa: Enable manufacturer again, now with hotplug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@magical-sound-furnace
Patch Set: Rename and clarify variables associated with ALSA <-> udev synchronized state Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/midi/midi_manager_alsa.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_manager_alsa.h
diff --git a/media/midi/midi_manager_alsa.h b/media/midi/midi_manager_alsa.h
index db78dff300fcfa188028674457838aaff7c22d55..e8b2f6b631f8fc9555bf33b10fc2094761772462 100644
--- a/media/midi/midi_manager_alsa.h
+++ b/media/midi/midi_manager_alsa.h
@@ -41,6 +41,9 @@ class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer);
FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ToMidiPortState);
+ class AlsaCard;
+ typedef std::map<int, AlsaCard*> AlsaCardMap;
+
class MidiPort {
public:
enum class Type { kInput, kOutput };
@@ -210,7 +213,10 @@ class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
bool midi);
void PortExit(int client_id, int port_id);
snd_seq_client_type_t ClientType(int client_id) const;
- scoped_ptr<TemporaryMidiPortState> ToMidiPortState();
+ scoped_ptr<TemporaryMidiPortState> ToMidiPortState(
+ const AlsaCardMap& alsa_cards);
+
+ int card_client_count() { return card_client_count_; }
private:
class Port {
@@ -259,20 +265,63 @@ class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
ClientMap clients_;
STLValueDeleter<ClientMap> clients_deleter_;
+ // This is the current number of clients we know about that have
+ // cards. When this number matches alsa_card_midi_count_, we know
+ // we are in sync between ALSA and udev. Until then, we cannot generate
+ // MIDIConnectionEvents to web clients.
+ int card_client_count_;
+
DISALLOW_COPY_AND_ASSIGN(AlsaSeqState);
};
+ class AlsaCard {
+ public:
+ AlsaCard(udev_device* dev,
+ const std::string& alsa_name,
+ const std::string& alsa_longname,
+ const std::string& alsa_driver,
+ int midi_device_count);
+ ~AlsaCard();
+ const std::string alsa_name() const { return alsa_name_; }
+ const std::string alsa_longname() const { return alsa_longname_; }
+ const std::string manufacturer() const { return manufacturer_; }
+ const std::string alsa_driver() const { return alsa_driver_; }
+ int midi_device_count() const { return midi_device_count_; }
+ // Returns hardware path.
+ const std::string path() const;
+ // Returns the id we can use to try to match hardware across different
+ // paths.
+ const std::string id() const;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(MidiManagerAlsaTest, ExtractManufacturer);
+
+ // Extracts the manufacturer using heuristics and a variety of sources.
+ static std::string ExtractManufacturerString(
+ const std::string& udev_id_vendor,
+ const std::string& udev_id_vendor_id,
+ const std::string& udev_id_vendor_from_database,
+ const std::string& alsa_name,
+ const std::string& alsa_longname);
+
+ std::string alsa_name_;
+ std::string alsa_longname_;
+ std::string manufacturer_;
+ std::string alsa_driver_;
+ std::string path_;
+ std::string bus_;
+ std::string serial_;
+ std::string vendor_id_;
+ std::string model_id_;
+ std::string usb_interface_num_;
+ int midi_device_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(AlsaCard);
+ };
+
typedef base::hash_map<int, uint32> SourceMap;
typedef base::hash_map<uint32, int> OutPortMap;
- // Extracts the manufacturer using heuristics and a variety of sources.
- static std::string ExtractManufacturerString(
- const std::string& udev_id_vendor,
- const std::string& udev_id_vendor_id,
- const std::string& udev_id_vendor_from_database,
- const std::string& alsa_name,
- const std::string& alsa_longname);
-
// An internal callback that runs on MidiSendThread.
void SendMidiData(uint32 port_index, const std::vector<uint8>& data);
@@ -284,6 +333,8 @@ class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
void ProcessClientExitEvent(const snd_seq_addr_t& addr);
void ProcessPortExitEvent(const snd_seq_addr_t& addr);
void ProcessUdevEvent(udev_device* dev);
+ void AddCard(udev_device* dev);
+ void RemoveCard(int number);
// Updates port_state_ and Web MIDI state from alsa_seq_state_.
void UpdatePortStateAndGenerateEvents();
@@ -315,6 +366,16 @@ class MIDI_EXPORT MidiManagerAlsa final : public MidiManager {
// Mapping from ALSA client:port to our index.
SourceMap source_map_;
+ // Mapping from card to devices.
+ AlsaCardMap alsa_cards_;
+ STLValueDeleter<AlsaCardMap> alsa_cards_deleter_;
+
+ // This is the current count of midi devices across all cards we know
+ // about. When this number matches card_client_count_ in AlsaSeqState,
+ // we are safe to generate MIDIConnectionEvents. Otherwise we need to
+ // wait for our information from ALSA and udev to get back in sync.
+ int alsa_card_midi_count_;
+
// ALSA event -> MIDI coder.
snd_midi_event_t* decoder_;
« no previous file with comments | « no previous file | media/midi/midi_manager_alsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698