Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / media / midi / midi_manager_mac.h
blobe034fbae6ef5d17b14c4e0b3e4f79aa3dadb1ab7
1 // Copyright (c) 2013 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_MAC_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_MAC_H_
8 #include <CoreMIDI/MIDIServices.h>
9 #include <map>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/compiler_specific.h"
16 #include "base/threading/thread.h"
17 #include "media/midi/midi_manager.h"
18 #include "media/midi/midi_port_info.h"
20 namespace media {
22 class MEDIA_EXPORT MidiManagerMac : public MidiManager {
23 public:
24 MidiManagerMac();
25 ~MidiManagerMac() override;
27 // MidiManager implementation.
28 void StartInitialization() override;
29 void DispatchSendMidiData(MidiManagerClient* client,
30 uint32 port_index,
31 const std::vector<uint8>& data,
32 double timestamp) override;
34 private:
35 // Runs a closure on |client_thread_|. It starts the thread if it isn't
36 // running and the destructor isn't called.
37 // Caller can bind base::Unretained(this) to |closure| since we join
38 // |client_thread_| in the destructor.
39 void RunOnClientThread(const base::Closure& closure);
41 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from
42 // StartInitialization().
43 void InitializeCoreMIDI();
45 // CoreMIDI callback for MIDI notification.
46 // Receives MIDI related event notifications from CoreMIDI.
47 static void ReceiveMidiNotifyDispatch(const MIDINotification* message,
48 void* refcon);
49 void ReceiveMidiNotify(const MIDINotification* message);
51 // CoreMIDI callback for MIDI data.
52 // Each callback can contain multiple packets, each of which can contain
53 // multiple MIDI messages.
54 static void ReadMidiDispatch(const MIDIPacketList* packet_list,
55 void* read_proc_refcon,
56 void* src_conn_refcon);
57 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist);
59 // An internal callback that runs on MidiSendThread.
60 void SendMidiData(MidiManagerClient* client,
61 uint32 port_index,
62 const std::vector<uint8>& data,
63 double timestamp);
65 // CoreMIDI
66 MIDIClientRef midi_client_;
67 MIDIPortRef coremidi_input_;
68 MIDIPortRef coremidi_output_;
69 std::vector<uint8> midi_buffer_;
71 // Keeps track of the index (0-based) for each of our sources.
72 typedef std::map<MIDIEndpointRef, uint32> SourceMap;
73 SourceMap source_map_;
75 // Keeps track of all destinations.
76 typedef std::vector<MIDIEndpointRef> DestinationVector;
77 DestinationVector destinations_;
79 // |client_thread_| is used to handle platform dependent operations.
80 base::Thread client_thread_;
82 // Sets true on destructing object to avoid starting |client_thread_| again.
83 bool shutdown_;
85 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac);
88 } // namespace media
90 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_