diff options
author | Mike Lockwood <lockwood@google.com> | 2015-02-24 09:06:30 -0800 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2015-03-04 16:15:45 -0800 |
commit | 20821ecbe81ba52b260ae232096bc2bfb3e92ad0 (patch) | |
tree | ab847534d9d6aaaec135f0c1be6e23e804987550 /media | |
parent | 27b7c1f526b7b0e9dd97566ccf6cbd28bfeab285 (diff) | |
download | frameworks_base-20821ecbe81ba52b260ae232096bc2bfb3e92ad0.zip frameworks_base-20821ecbe81ba52b260ae232096bc2bfb3e92ad0.tar.gz frameworks_base-20821ecbe81ba52b260ae232096bc2bfb3e92ad0.tar.bz2 |
Eliminate MidiPort base class for MidiInputPort and MidiOutputPort
Change-Id: I628c0468ac980eee909add53a4d6e55e9b358603
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/midi/MidiInputPort.java | 25 | ||||
-rw-r--r-- | media/java/android/media/midi/MidiOutputPort.java | 25 | ||||
-rw-r--r-- | media/java/android/media/midi/MidiPortImpl.java (renamed from media/java/android/media/midi/MidiPort.java) | 50 |
3 files changed, 41 insertions, 59 deletions
diff --git a/media/java/android/media/midi/MidiInputPort.java b/media/java/android/media/midi/MidiInputPort.java index 730d364..9ded0b1 100644 --- a/media/java/android/media/midi/MidiInputPort.java +++ b/media/java/android/media/midi/MidiInputPort.java @@ -20,6 +20,7 @@ import android.os.ParcelFileDescriptor; import libcore.io.IoUtils; +import java.io.Closeable; import java.io.FileOutputStream; import java.io.IOException; @@ -29,19 +30,33 @@ import java.io.IOException; * CANDIDATE FOR PUBLIC API * @hide */ -public class MidiInputPort extends MidiPort implements MidiReceiver { +public class MidiInputPort implements MidiReceiver, Closeable { + private final int mPortNumber; private final FileOutputStream mOutputStream; // buffer to use for sending messages out our output stream - private final byte[] mBuffer = new byte[MAX_PACKET_SIZE]; + private final byte[] mBuffer = new byte[MidiPortImpl.MAX_PACKET_SIZE]; /* package */ MidiInputPort(ParcelFileDescriptor pfd, int portNumber) { - super(portNumber); + mPortNumber = portNumber; mOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pfd); } /** + * Returns the port number of this port + * + * @return the port's port number + */ + public final int getPortNumber() { + return mPortNumber; + } + + //FIXME + public void onIOException() { + } + + /** * Writes a MIDI message to the input port * * @param msg byte array containing the message @@ -56,9 +71,9 @@ public class MidiInputPort extends MidiPort implements MidiReceiver { synchronized (mBuffer) { try { while (count > 0) { - int length = packMessage(msg, offset, count, timestamp, mBuffer); + int length = MidiPortImpl.packMessage(msg, offset, count, timestamp, mBuffer); mOutputStream.write(mBuffer, 0, length); - int sent = getMessageSize(mBuffer, length); + int sent = MidiPortImpl.getMessageSize(mBuffer, length); assert(sent >= 0 && sent <= length); offset += sent; diff --git a/media/java/android/media/midi/MidiOutputPort.java b/media/java/android/media/midi/MidiOutputPort.java index c195603..3efd03f 100644 --- a/media/java/android/media/midi/MidiOutputPort.java +++ b/media/java/android/media/midi/MidiOutputPort.java @@ -21,6 +21,7 @@ import android.util.Log; import libcore.io.IoUtils; +import java.io.Closeable; import java.io.FileInputStream; import java.io.IOException; @@ -30,9 +31,10 @@ import java.io.IOException; * CANDIDATE FOR PUBLIC API * @hide */ -public class MidiOutputPort extends MidiPort implements MidiSender { +public class MidiOutputPort implements MidiSender, Closeable { private static final String TAG = "MidiOutputPort"; + private final int mPortNumber; private final FileInputStream mInputStream; private final MidiDispatcher mDispatcher = new MidiDispatcher(); @@ -41,7 +43,7 @@ public class MidiOutputPort extends MidiPort implements MidiSender { private final Thread mThread = new Thread() { @Override public void run() { - byte[] buffer = new byte[MAX_PACKET_SIZE]; + byte[] buffer = new byte[MidiPortImpl.MAX_PACKET_SIZE]; try { while (true) { @@ -52,9 +54,9 @@ public class MidiOutputPort extends MidiPort implements MidiSender { // FIXME - inform receivers here? } - int offset = getMessageOffset(buffer, count); - int size = getMessageSize(buffer, count); - long timestamp = getMessageTimeStamp(buffer, count); + int offset = MidiPortImpl.getMessageOffset(buffer, count); + int size = MidiPortImpl.getMessageSize(buffer, count); + long timestamp = MidiPortImpl.getMessageTimeStamp(buffer, count); // dispatch to all our receivers mDispatcher.post(buffer, offset, size, timestamp); @@ -68,12 +70,21 @@ public class MidiOutputPort extends MidiPort implements MidiSender { } }; - /* package */ MidiOutputPort(ParcelFileDescriptor pfd, int portNumber) { - super(portNumber); + /* package */ MidiOutputPort(ParcelFileDescriptor pfd, int portNumber) { + mPortNumber = portNumber; mInputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd); mThread.start(); } + /** + * Returns the port number of this port + * + * @return the port's port number + */ + public final int getPortNumber() { + return mPortNumber; + } + @Override public void connect(MidiReceiver receiver) { mDispatcher.getSender().connect(receiver); diff --git a/media/java/android/media/midi/MidiPort.java b/media/java/android/media/midi/MidiPortImpl.java index 3aa03f2..fcb23c1 100644 --- a/media/java/android/media/midi/MidiPort.java +++ b/media/java/android/media/midi/MidiPortImpl.java @@ -19,28 +19,19 @@ package android.media.midi; import java.io.Closeable; /** - * This class represents a MIDI input or output port. - * Base class for {@link MidiInputPort} and {@link MidiOutputPort} - * - * CANDIDATE FOR PUBLIC API - * @hide + * This class contains utilities for socket communication between a + * MidiInputPort and MidiOutputPort */ -abstract public class MidiPort implements Closeable { +/* package */ class MidiPortImpl { private static final String TAG = "MidiPort"; - private final int mPortNumber; - /** * Maximum size of a packet that can pass through our ParcelFileDescriptor. - * For internal use only. Implementation details may change in the future. - * @hide */ public static final int MAX_PACKET_SIZE = 1024; /** * size of message timestamp in bytes - * For internal use only. Implementation details may change in the future. - * @hide */ private static final int TIMESTAMP_SIZE = 8; @@ -49,29 +40,6 @@ abstract public class MidiPort implements Closeable { */ public static final int MAX_PACKET_DATA_SIZE = MAX_PACKET_SIZE - TIMESTAMP_SIZE; - - /* package */ MidiPort(int portNumber) { - mPortNumber = portNumber; - } - - /** - * Returns the port number of this port - * - * @return the port's port number - */ - public final int getPortNumber() { - return mPortNumber; - } - - /** - * Called when an IOExeption occurs while sending or receiving data. - * Subclasses can override to be notified of such errors - * - * @hide - */ - public void onIOException() { - } - /** * Utility function for packing a MIDI message to be sent through our ParcelFileDescriptor * @@ -80,9 +48,6 @@ abstract public class MidiPort implements Closeable { * timestamp is message timestamp to pack * dest is buffer to pack into * returns size of packed message - * - * For internal use only. Implementation details may change in the future. - * @hide */ public static int packMessage(byte[] message, int offset, int size, long timestamp, byte[] dest) { @@ -104,9 +69,6 @@ abstract public class MidiPort implements Closeable { /** * Utility function for unpacking a MIDI message received from our ParcelFileDescriptor * returns the offset of the MIDI message in packed buffer - * - * For internal use only. Implementation details may change in the future. - * @hide */ public static int getMessageOffset(byte[] buffer, int bufferLength) { // message is at the beginning @@ -116,9 +78,6 @@ abstract public class MidiPort implements Closeable { /** * Utility function for unpacking a MIDI message received from our ParcelFileDescriptor * returns size of MIDI data in packed buffer - * - * For internal use only. Implementation details may change in the future. - * @hide */ public static int getMessageSize(byte[] buffer, int bufferLength) { // message length is total buffer length minus size of the timestamp @@ -128,9 +87,6 @@ abstract public class MidiPort implements Closeable { /** * Utility function for unpacking a MIDI message received from our ParcelFileDescriptor * unpacks timestamp from packed buffer - * - * For internal use only. Implementation details may change in the future. - * @hide */ public static long getMessageTimeStamp(byte[] buffer, int bufferLength) { // timestamp is at end of the packet |