blob: c523bb91f54f662f890c6cb6a01400ba6dc626d8 [file] [log] [blame]
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +00001// 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.
4
dnicoara@chromium.org9f2a6f02014-01-03 21:25:00 +00005#ifndef MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
6#define MEDIA_MIDI_MIDI_MANAGER_ALSA_H_
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +00007
agoode@chromium.org25227512014-06-08 05:12:05 +00008#include <alsa/asoundlib.h>
9#include <map>
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000010#include <vector>
11
12#include "base/basictypes.h"
13#include "base/memory/scoped_ptr.h"
agoode@chromium.org25227512014-06-08 05:12:05 +000014#include "base/synchronization/lock.h"
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000015#include "base/threading/thread.h"
16#include "media/midi/midi_manager.h"
17
18namespace media {
19
toyoshim@chromium.orgc82e66e2014-02-04 07:05:47 +000020class MidiManagerAlsa : public MidiManager {
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000021 public:
toyoshim@chromium.orgc82e66e2014-02-04 07:05:47 +000022 MidiManagerAlsa();
23 virtual ~MidiManagerAlsa();
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000024
toyoshim@chromium.orgc82e66e2014-02-04 07:05:47 +000025 // MidiManager implementation.
toyoshim@chromium.org51c7f532014-05-01 17:17:32 +000026 virtual void StartInitialization() OVERRIDE;
toyoshim@chromium.orgc82e66e2014-02-04 07:05:47 +000027 virtual void DispatchSendMidiData(MidiManagerClient* client,
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000028 uint32 port_index,
29 const std::vector<uint8>& data,
30 double timestamp) OVERRIDE;
31
32 private:
agoode@chromium.org25227512014-06-08 05:12:05 +000033 // An internal callback that runs on MidiSendThread.
34 void SendMidiData(uint32 port_index,
35 const std::vector<uint8>& data);
36
toyoshim@chromium.org4a8657c2014-02-06 11:23:09 +000037 void EventReset();
38 void EventLoop();
39
agoode@chromium.org25227512014-06-08 05:12:05 +000040 // Alsa seq handles.
41 snd_seq_t* in_client_;
42 snd_seq_t* out_client_;
43 int out_client_id_;
44
45 // One input port, many output ports.
46 int in_port_;
47 std::vector<int> out_ports_;
48
49 // Mapping from Alsa client:port to our index.
50 typedef std::map<int, uint32> SourceMap;
51 SourceMap source_map_;
52
53 // Alsa event <-> MIDI coders.
54 snd_midi_event_t* decoder_;
55 typedef std::vector<snd_midi_event_t*> EncoderList;
56 EncoderList encoders_;
57
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000058 base::Thread send_thread_;
toyoshim@chromium.org4a8657c2014-02-06 11:23:09 +000059 base::Thread event_thread_;
60
agoode@chromium.org25227512014-06-08 05:12:05 +000061 bool event_thread_shutdown_; // guarded by shutdown_lock_
62 base::Lock shutdown_lock_; // guards event_thread_shutdown_
toyoshim@chromium.org4a8657c2014-02-06 11:23:09 +000063
toyoshim@chromium.orgc82e66e2014-02-04 07:05:47 +000064 DISALLOW_COPY_AND_ASSIGN(MidiManagerAlsa);
toyoshim@chromium.orga97eebf2014-01-03 07:52:39 +000065};
66
67} // namespace media
68
dnicoara@chromium.org9f2a6f02014-01-03 21:25:00 +000069#endif // MEDIA_MIDI_MIDI_MANAGER_ALSA_H_