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
3 // found in the LICENSE file.
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
8 #include <alsa/asoundlib.h>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h"
16 #include "media/midi/midi_manager.h"
20 class MidiManagerAlsa : public MidiManager {
23 virtual ~MidiManagerAlsa();
25 // MidiManager implementation.
26 virtual void StartInitialization() OVERRIDE;
27 virtual void DispatchSendMidiData(MidiManagerClient* client,
29 const std::vector<uint8>& data,
30 double timestamp) OVERRIDE;
33 // An internal callback that runs on MidiSendThread.
34 void SendMidiData(uint32 port_index,
35 const std::vector<uint8>& data);
41 snd_seq_t* in_client_;
42 snd_seq_t* out_client_;
45 // One input port, many output ports.
47 std::vector<int> out_ports_;
49 // Mapping from Alsa client:port to our index.
50 typedef std::map<int, uint32> SourceMap;
51 SourceMap source_map_;
53 // Alsa event <-> MIDI coders.
54 snd_midi_event_t* decoder_;
55 typedef std::vector<snd_midi_event_t*> EncoderList;
56 EncoderList encoders_;
58 base::Thread send_thread_;
59 base::Thread event_thread_;
61 bool event_thread_shutdown_; // guarded by shutdown_lock_
62 base::Lock shutdown_lock_; // guards event_thread_shutdown_
64 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa);
69 #endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_