styleguide: Allow "= default" and "= delete"
[chromium-blink-merge.git] / media / midi / midi_manager_mac.h
blobf7179ec18a7494b3f1181481a59184053dc3d4f1
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 data.
46 // Each callback can contain multiple packets, each of which can contain
47 // multiple MIDI messages.
48 static void ReadMidiDispatch(
49 const MIDIPacketList *pktlist,
50 void *read_proc_refcon,
51 void *src_conn_refcon);
52 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist);
54 // An internal callback that runs on MidiSendThread.
55 void SendMidiData(MidiManagerClient* client,
56 uint32 port_index,
57 const std::vector<uint8>& data,
58 double timestamp);
60 // CoreMIDI
61 MIDIClientRef midi_client_;
62 MIDIPortRef coremidi_input_;
63 MIDIPortRef coremidi_output_;
65 enum{ kMaxPacketListSize = 512 };
66 char midi_buffer_[kMaxPacketListSize];
67 MIDIPacketList* packet_list_;
68 MIDIPacket* midi_packet_;
70 typedef std::map<MIDIEndpointRef, uint32> SourceMap;
72 // Keeps track of the index (0-based) for each of our sources.
73 SourceMap source_map_;
75 // Keeps track of all destinations.
76 std::vector<MIDIEndpointRef> destinations_;
78 // |client_thread_| is used to handle platform dependent operations.
79 base::Thread client_thread_;
81 // Sets true on destructing object to avoid starting |client_thread_| again.
82 bool shutdown_;
84 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac);
87 } // namespace media
89 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_