summaryrefslogtreecommitdiffstats
path: root/services/usb/java/com
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2015-01-27 11:47:43 -0800
committerMike Lockwood <lockwood@google.com>2015-01-29 09:09:00 -0800
commitcb096273734d96f4676014fa9030b57ea48b58d8 (patch)
tree76a89d12a0faa79fe49d285312d12d67a0bc97c1 /services/usb/java/com
parentab75f637878ce3237e675cf3e1a5a43c3c009b09 (diff)
downloadframeworks_base-cb096273734d96f4676014fa9030b57ea48b58d8.zip
frameworks_base-cb096273734d96f4676014fa9030b57ea48b58d8.tar.gz
frameworks_base-cb096273734d96f4676014fa9030b57ea48b58d8.tar.bz2
MIDI Manager: Remove message packetization from MIDI transport
Instead of attempting to package exactly one MIDI message in each call to MidiReceiver.onPost(), we now pass messages as a raw stream of bytes. This means we may now receive multiple MIDI messages in MidiReceiver.onPost(). We make this change to avoid the complexity of taking the single message approach with SysEx and realtime messages. This shifts some of the burden of parsing MIDI messages to the client application. But the parsing is best handled in the application anyway, rather than having the framework impose its own policy on how the messages are parsed. Change-Id: Idb6c200037f827cc618bc7d9455a7aa864b494a7
Diffstat (limited to 'services/usb/java/com')
-rw-r--r--services/usb/java/com/android/server/usb/UsbMidiDevice.java31
1 files changed, 7 insertions, 24 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbMidiDevice.java b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
index 01b2df9..0ca52f6 100644
--- a/services/usb/java/com/android/server/usb/UsbMidiDevice.java
+++ b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
@@ -21,9 +21,9 @@ import android.hardware.usb.UsbDevice;
import android.midi.MidiDeviceInfo;
import android.midi.MidiDeviceServer;
import android.midi.MidiManager;
+import android.midi.MidiPort;
import android.midi.MidiReceiver;
import android.midi.MidiSender;
-import android.midi.MidiUtils;
import android.os.Bundle;
import android.system.ErrnoException;
import android.system.Os;
@@ -45,7 +45,9 @@ public final class UsbMidiDevice implements Closeable {
// for polling multiple FileDescriptors for MIDI events
private final StructPollfd[] mPollFDs;
+ // streams for reading from ALSA driver
private final FileInputStream[] mInputStreams;
+ // streams for writing to ALSA driver
private final FileOutputStream[] mOutputStreams;
public static UsbMidiDevice create(Context context, UsbDevice usbDevice, int card, int device) {
@@ -131,7 +133,7 @@ public final class UsbMidiDevice implements Closeable {
new Thread() {
@Override
public void run() {
- byte[] buffer = new byte[3];
+ byte[] buffer = new byte[MidiPort.MAX_PACKET_DATA_SIZE];
try {
boolean done = false;
while (!done) {
@@ -141,7 +143,8 @@ public final class UsbMidiDevice implements Closeable {
if ((pfd.revents & OsConstants.POLLIN) != 0) {
// clear readable flag
pfd.revents = 0;
- int count = readMessage(buffer, index);
+
+ int count = mInputStreams[index].read(buffer);
mOutputPortReceivers[index].onPost(buffer, 0, count,
System.nanoTime());
} else if ((pfd.revents & (OsConstants.POLLERR
@@ -150,7 +153,7 @@ public final class UsbMidiDevice implements Closeable {
}
}
- // poll if none are readable
+ // wait until we have a readable port
Os.poll(mPollFDs, -1 /* infinite timeout */);
}
} catch (IOException e) {
@@ -174,26 +177,6 @@ public final class UsbMidiDevice implements Closeable {
}
}
- private int readMessage(byte[] buffer, int index) throws IOException {
- FileInputStream inputStream = mInputStreams[index];
-
- if (inputStream.read(buffer, 0, 1) != 1) {
- Log.e(TAG, "could not read command byte");
- return -1;
- }
- int dataSize = MidiUtils.getMessageDataSize(buffer[0]);
- if (dataSize < 0) {
- return -1;
- }
- if (dataSize > 0) {
- if (inputStream.read(buffer, 1, dataSize) != dataSize) {
- Log.e(TAG, "could not read command data");
- return -1;
- }
- }
- return dataSize + 1;
- }
-
private static native int nativeGetSubdeviceCount(int card, int device);
private static native FileDescriptor[] nativeOpen(int card, int device, int subdeviceCount);
}