OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 package org.chromium.media.midi; | 5 package org.chromium.midi; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.media.midi.MidiDevice; | 8 import android.media.midi.MidiDevice; |
9 import android.media.midi.MidiOutputPort; | 9 import android.media.midi.MidiOutputPort; |
10 import android.media.midi.MidiReceiver; | 10 import android.media.midi.MidiReceiver; |
11 import android.os.Build; | 11 import android.os.Build; |
12 | 12 |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
15 | 15 |
16 import java.io.IOException; | 16 import java.io.IOException; |
17 | 17 |
18 // Note "InputPort" is named in the Web MIDI manner. It corresponds to MidiOutpu
tPort class in the | 18 // Note "InputPort" is named in the Web MIDI manner. It corresponds to MidiOutpu
tPort class in the |
19 // Android API. | 19 // Android API. |
20 /** | 20 /** |
21 * A MidiInputPortAndroid provides data to the associated media::midi::MidiInput
PortAndroid object. | 21 * A MidiInputPortAndroid provides data to the associated midi::MidiInputPortAnd
roid object. |
22 */ | 22 */ |
23 @JNINamespace("media::midi") | 23 @JNINamespace("midi") |
24 @TargetApi(Build.VERSION_CODES.M) | 24 @TargetApi(Build.VERSION_CODES.M) |
25 class MidiInputPortAndroid { | 25 class MidiInputPortAndroid { |
26 /** | 26 /** |
27 * The underlying port. | 27 * The underlying port. |
28 */ | 28 */ |
29 private MidiOutputPort mPort; | 29 private MidiOutputPort mPort; |
30 /** | 30 /** |
31 * A pointer to a media::midi::MidiInputPortAndroid object. | 31 * A pointer to a midi::MidiInputPortAndroid object. |
32 */ | 32 */ |
33 private long mNativeReceiverPointer; | 33 private long mNativeReceiverPointer; |
34 /** | 34 /** |
35 * The device this port belongs to. | 35 * The device this port belongs to. |
36 */ | 36 */ |
37 private final MidiDevice mDevice; | 37 private final MidiDevice mDevice; |
38 /** | 38 /** |
39 * The index of the port in the associated device. | 39 * The index of the port in the associated device. |
40 */ | 40 */ |
41 private final int mIndex; | 41 private final int mIndex; |
42 | 42 |
43 /** | 43 /** |
44 * constructor | 44 * constructor |
45 * @param device the device this port belongs to. | 45 * @param device the device this port belongs to. |
46 * @param index the index of the port in the associated device. | 46 * @param index the index of the port in the associated device. |
47 */ | 47 */ |
48 MidiInputPortAndroid(MidiDevice device, int index) { | 48 MidiInputPortAndroid(MidiDevice device, int index) { |
49 mDevice = device; | 49 mDevice = device; |
50 mIndex = index; | 50 mIndex = index; |
51 } | 51 } |
52 | 52 |
53 /** | 53 /** |
54 * Registers this object to the underlying port so as to the C++ function wi
ll be called with | 54 * Registers this object to the underlying port so as to the C++ function wi
ll be called with |
55 * the given C++ object when data arrives. | 55 * the given C++ object when data arrives. |
56 * @param nativeReceiverPointer a pointer to a media::midi::MidiInputPortAnd
roid object. | 56 * @param nativeReceiverPointer a pointer to a midi::MidiInputPortAndroid ob
ject. |
57 * @return true if this operation succeeds or the port is already open. | 57 * @return true if this operation succeeds or the port is already open. |
58 */ | 58 */ |
59 @CalledByNative | 59 @CalledByNative |
60 boolean open(long nativeReceiverPointer) { | 60 boolean open(long nativeReceiverPointer) { |
61 if (mPort != null) { | 61 if (mPort != null) { |
62 return true; | 62 return true; |
63 } | 63 } |
64 mPort = mDevice.openOutputPort(mIndex); | 64 mPort = mDevice.openOutputPort(mIndex); |
65 if (mPort == null) { | 65 if (mPort == null) { |
66 return false; | 66 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
88 } catch (IOException e) { | 88 } catch (IOException e) { |
89 // We can do nothing here. Just ignore the error. | 89 // We can do nothing here. Just ignore the error. |
90 } | 90 } |
91 mNativeReceiverPointer = 0; | 91 mNativeReceiverPointer = 0; |
92 mPort = null; | 92 mPort = null; |
93 } | 93 } |
94 | 94 |
95 private static native void nativeOnData( | 95 private static native void nativeOnData( |
96 long nativeMidiInputPortAndroid, byte[] bs, int offset, int count, l
ong timestamp); | 96 long nativeMidiInputPortAndroid, byte[] bs, int offset, int count, l
ong timestamp); |
97 } | 97 } |
OLD | NEW |