Chromium Code Reviews| Index: media/midi/java/src/org/chromium/media/midi/MidiOutputPortAndroid.java |
| diff --git a/media/midi/java/src/org/chromium/media/midi/MidiOutputPortAndroid.java b/media/midi/java/src/org/chromium/media/midi/MidiOutputPortAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4763ba09f71fa62b3c2108a4c9fafdd2ea157e08 |
| --- /dev/null |
| +++ b/media/midi/java/src/org/chromium/media/midi/MidiOutputPortAndroid.java |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.media.midi; |
| + |
| +import android.media.midi.MidiDevice; |
| +import android.media.midi.MidiInputPort; |
| + |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| + |
| +import java.io.IOException; |
| + |
| +/** |
| + * A class implementing media::midi::MidiOutputPortAndroid functionality. |
| + */ |
| +// Note "OutputPort" is named in the WebMIDI manner. It corresponds to MidiInputPort class in the |
|
Takashi Toyoshima
2015/09/07 16:42:20
s/WebMIDI/Web MIDI/
yhirano
2015/09/10 11:43:50
Done.
|
| +// Android API. |
| +@JNINamespace("media::midi") |
| +class MidiOutputPortAndroid { |
| + /** |
| + * The underlying port. |
| + */ |
| + private MidiInputPort mPort; |
| + /** |
| + * The device this port belongs to. |
| + */ |
| + private MidiDevice mDevice; |
| + /** |
| + * The index of the port in the associated device. |
| + */ |
| + private int mIndex; |
| + |
| + /** |
| + * constructor |
| + * @param device The device this port belongs to. |
| + * @param index The index of the port in the associated device. |
| + */ |
| + MidiOutputPortAndroid(MidiDevice device, int index) { |
| + mDevice = device; |
| + mIndex = index; |
| + } |
| + |
| + /** |
| + * Opens this port. |
| + * @return true when the operation succeeds or the port is already open. |
| + */ |
| + @CalledByNative |
| + boolean open() { |
| + if (mPort != null) { |
| + return true; |
| + } |
| + mPort = mDevice.openInputPort(mIndex); |
| + return mPort != null; |
| + } |
| + |
| + /** |
| + * Sends the data to the underlying output port. |
| + */ |
| + @CalledByNative |
| + void send(byte[] bs) { |
| + if (mPort == null) { |
| + return; |
| + } |
| + try { |
| + mPort.send(bs, 0, bs.length); |
| + } catch (IOException e) { |
| + // We can do nothing here. Just ignore the error. |
|
Takashi Toyoshima
2015/09/07 16:42:19
It's nice to log the error.
yhirano
2015/09/10 11:43:50
Done.
|
| + } |
| + } |
| + |
| + /** |
| + * Closes the port. |
| + */ |
| + @CalledByNative |
| + void close() { |
| + if (mPort == null) { |
| + return; |
| + } |
| + try { |
| + mPort.close(); |
| + } catch (IOException e) { |
| + // We can do nothing here. Just ignore the error. |
| + } |
| + mPort = null; |
| + } |
| +} |