OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_MAC_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_MAC_H_ |
6 #define MEDIA_MIDI_MIDI_MANAGER_MAC_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_MAC_H_ |
7 | 7 |
8 #include <CoreMIDI/MIDIServices.h> | 8 #include <CoreMIDI/MIDIServices.h> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | |
14 #include "base/callback.h" | 13 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
16 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
17 #include "media/midi/midi_export.h" | 16 #include "media/midi/midi_export.h" |
18 #include "media/midi/midi_manager.h" | 17 #include "media/midi/midi_manager.h" |
19 #include "media/midi/midi_port_info.h" | 18 #include "media/midi/midi_port_info.h" |
20 | 19 |
21 namespace media { | 20 namespace media { |
22 namespace midi { | 21 namespace midi { |
23 | 22 |
24 class MIDI_EXPORT MidiManagerMac final : public MidiManager { | 23 class MIDI_EXPORT MidiManagerMac final : public MidiManager { |
25 public: | 24 public: |
26 MidiManagerMac(); | 25 MidiManagerMac(); |
27 ~MidiManagerMac() override; | 26 ~MidiManagerMac() override; |
28 | 27 |
29 // MidiManager implementation. | 28 // MidiManager implementation. |
30 void StartInitialization() override; | 29 void StartInitialization() override; |
31 void Finalize() override; | 30 void Finalize() override; |
32 void DispatchSendMidiData(MidiManagerClient* client, | 31 void DispatchSendMidiData(MidiManagerClient* client, |
33 uint32 port_index, | 32 uint32_t port_index, |
34 const std::vector<uint8>& data, | 33 const std::vector<uint8_t>& data, |
35 double timestamp) override; | 34 double timestamp) override; |
36 | 35 |
37 private: | 36 private: |
38 // Runs a closure on |client_thread_|. It starts the thread if it isn't | 37 // Runs a closure on |client_thread_|. It starts the thread if it isn't |
39 // running and the destructor isn't called. | 38 // running and the destructor isn't called. |
40 // Caller can bind base::Unretained(this) to |closure| since we join | 39 // Caller can bind base::Unretained(this) to |closure| since we join |
41 // |client_thread_| in the destructor. | 40 // |client_thread_| in the destructor. |
42 void RunOnClientThread(const base::Closure& closure); | 41 void RunOnClientThread(const base::Closure& closure); |
43 | 42 |
44 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from | 43 // Initializes CoreMIDI on |client_thread_| asynchronously. Called from |
45 // StartInitialization(). | 44 // StartInitialization(). |
46 void InitializeCoreMIDI(); | 45 void InitializeCoreMIDI(); |
47 | 46 |
48 // CoreMIDI callback for MIDI notification. | 47 // CoreMIDI callback for MIDI notification. |
49 // Receives MIDI related event notifications from CoreMIDI. | 48 // Receives MIDI related event notifications from CoreMIDI. |
50 static void ReceiveMidiNotifyDispatch(const MIDINotification* message, | 49 static void ReceiveMidiNotifyDispatch(const MIDINotification* message, |
51 void* refcon); | 50 void* refcon); |
52 void ReceiveMidiNotify(const MIDINotification* message); | 51 void ReceiveMidiNotify(const MIDINotification* message); |
53 | 52 |
54 // CoreMIDI callback for MIDI data. | 53 // CoreMIDI callback for MIDI data. |
55 // Each callback can contain multiple packets, each of which can contain | 54 // Each callback can contain multiple packets, each of which can contain |
56 // multiple MIDI messages. | 55 // multiple MIDI messages. |
57 static void ReadMidiDispatch(const MIDIPacketList* packet_list, | 56 static void ReadMidiDispatch(const MIDIPacketList* packet_list, |
58 void* read_proc_refcon, | 57 void* read_proc_refcon, |
59 void* src_conn_refcon); | 58 void* src_conn_refcon); |
60 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist); | 59 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist); |
61 | 60 |
62 // An internal callback that runs on MidiSendThread. | 61 // An internal callback that runs on MidiSendThread. |
63 void SendMidiData(MidiManagerClient* client, | 62 void SendMidiData(MidiManagerClient* client, |
64 uint32 port_index, | 63 uint32_t port_index, |
65 const std::vector<uint8>& data, | 64 const std::vector<uint8_t>& data, |
66 double timestamp); | 65 double timestamp); |
67 | 66 |
68 // CoreMIDI | 67 // CoreMIDI |
69 MIDIClientRef midi_client_; | 68 MIDIClientRef midi_client_; |
70 MIDIPortRef coremidi_input_; | 69 MIDIPortRef coremidi_input_; |
71 MIDIPortRef coremidi_output_; | 70 MIDIPortRef coremidi_output_; |
72 std::vector<uint8> midi_buffer_; | 71 std::vector<uint8_t> midi_buffer_; |
73 | 72 |
74 // Keeps track of the index (0-based) for each of our sources. | 73 // Keeps track of the index (0-based) for each of our sources. |
75 typedef std::map<MIDIEndpointRef, uint32> SourceMap; | 74 typedef std::map<MIDIEndpointRef, uint32_t> SourceMap; |
76 SourceMap source_map_; | 75 SourceMap source_map_; |
77 | 76 |
78 // Keeps track of all destinations. | 77 // Keeps track of all destinations. |
79 typedef std::vector<MIDIEndpointRef> DestinationVector; | 78 typedef std::vector<MIDIEndpointRef> DestinationVector; |
80 DestinationVector destinations_; | 79 DestinationVector destinations_; |
81 | 80 |
82 // |client_thread_| is used to handle platform dependent operations. | 81 // |client_thread_| is used to handle platform dependent operations. |
83 base::Thread client_thread_; | 82 base::Thread client_thread_; |
84 | 83 |
85 // Sets true on destructing object to avoid starting |client_thread_| again. | 84 // Sets true on destructing object to avoid starting |client_thread_| again. |
86 bool shutdown_; | 85 bool shutdown_; |
87 | 86 |
88 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac); | 87 DISALLOW_COPY_AND_ASSIGN(MidiManagerMac); |
89 }; | 88 }; |
90 | 89 |
91 } // namespace midi | 90 } // namespace midi |
92 } // namespace media | 91 } // namespace media |
93 | 92 |
94 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_ | 93 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_ |
OLD | NEW |