1 // Copyright 2015 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_ANDROID_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_ANDROID_H_
11 #include "base/android/scoped_java_ref.h"
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/time/time.h"
17 #include "media/midi/midi_input_port_android.h"
18 #include "media/midi/midi_manager.h"
19 #include "media/midi/midi_scheduler.h"
24 class MidiDeviceAndroid
;
25 class MidiOutputPortAndroid
;
27 // MidiManagerAndroid is a MidiManager subclass for Android M or newer. For
28 // older android OSes, we use MidiManagerUsb.
29 class MidiManagerAndroid final
: public MidiManager
,
30 public MidiInputPortAndroid::Delegate
{
33 ~MidiManagerAndroid() override
;
35 // MidiManager implementation.
36 void StartInitialization() override
;
37 void DispatchSendMidiData(MidiManagerClient
* client
,
39 const std::vector
<uint8
>& data
,
40 double timestamp
) override
;
42 // MidiInputPortAndroid::Delegate implementation.
43 void OnReceivedData(MidiInputPortAndroid
*,
46 base::TimeTicks timestamp
) override
;
48 // Called from the Java world.
49 void OnInitialized(JNIEnv
* env
, jobject caller
, jobjectArray devices
);
50 void OnAttached(JNIEnv
* env
, jobject caller
, jobject device
);
51 void OnDetached(JNIEnv
* env
, jobject caller
, jobject device
);
53 static bool Register(JNIEnv
* env
);
56 void AddDevice(scoped_ptr
<MidiDeviceAndroid
> device
);
57 void AddInputPortAndroid(MidiInputPortAndroid
* port
,
58 MidiDeviceAndroid
* device
);
59 void AddOutputPortAndroid(MidiOutputPortAndroid
* port
,
60 MidiDeviceAndroid
* device
);
62 ScopedVector
<MidiDeviceAndroid
> devices_
;
63 // All ports held in |devices_|. Each device has ownership of ports, but we
64 // can store pointers here because a device will keep its ports while it is
66 std::vector
<MidiInputPortAndroid
*> all_input_ports_
;
67 // A dictionary from a port to its index.
68 // input_port_to_index_[all_input_ports_[i]] == i for each valid |i|.
69 base::hash_map
<MidiInputPortAndroid
*, size_t> input_port_to_index_
;
71 // Ditto for output ports.
72 std::vector
<MidiOutputPortAndroid
*> all_output_ports_
;
73 base::hash_map
<MidiOutputPortAndroid
*, size_t> output_port_to_index_
;
75 base::android::ScopedJavaGlobalRef
<jobject
> raw_manager_
;
76 scoped_ptr
<MidiScheduler
> scheduler_
;
82 #endif // MEDIA_MIDI_MIDI_MANAGER_ANDROID_H_