Fix some potential after free errors on TestCompletionCallback
[chromium-blink-merge.git] / media / midi / midi_manager_mac.h
blobf513e119c0e0551cc2e9d945a9e8362bcf8442a9
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>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "media/midi/midi_manager.h"
15 #include "media/midi/midi_port_info.h"
17 namespace media {
19 class MEDIA_EXPORT MIDIManagerMac : public MIDIManager {
20 public:
21 MIDIManagerMac();
22 virtual ~MIDIManagerMac();
24 // MIDIManager implementation.
25 virtual bool Initialize() OVERRIDE;
26 virtual void SendMIDIData(int port_index,
27 const uint8* data,
28 size_t length,
29 double timestamp) OVERRIDE;
31 private:
32 // CoreMIDI callback for MIDI data.
33 // Each callback can contain multiple packets, each of which can contain
34 // multiple MIDI messages.
35 static void ReadMidiDispatch(
36 const MIDIPacketList *pktlist,
37 void *read_proc_refcon,
38 void *src_conn_refcon);
39 virtual void ReadMidi(MIDIEndpointRef source, const MIDIPacketList *pktlist);
41 // Helper
42 static media::MIDIPortInfo GetPortInfoFromEndpoint(MIDIEndpointRef endpoint);
43 static double MIDITimeStampToSeconds(MIDITimeStamp timestamp);
44 static MIDITimeStamp SecondsToMIDITimeStamp(double seconds);
46 // CoreMIDI
47 MIDIClientRef midi_client_;
48 MIDIPortRef coremidi_input_;
49 MIDIPortRef coremidi_output_;
51 enum{ kMaxPacketListSize = 512 };
52 char midi_buffer_[kMaxPacketListSize];
53 MIDIPacketList* packet_list_;
54 MIDIPacket* midi_packet_;
56 typedef std::map<MIDIEndpointRef, int> SourceMap;
58 // Keeps track of the index (0-based) for each of our sources.
59 SourceMap source_map_;
61 // Keeps track of all destinations.
62 std::vector<MIDIEndpointRef> destinations_;
64 DISALLOW_COPY_AND_ASSIGN(MIDIManagerMac);
67 } // namespace media
69 #endif // MEDIA_MIDI_MIDI_MANAGER_MAC_H_