Merge "Merge "USB MIDI: Null check for mUsbMidiPacketConverter" into tm-dev am: 0559661c13 am: 63a301c819" into tm-d1-dev-plus-aosp
This commit is contained in:
committed by
Android (Google) Code Review
commit
a00896eaf3
@@ -81,7 +81,7 @@ public final class UsbDirectMidiDevice implements Closeable {
|
|||||||
private static final int BULK_TRANSFER_TIMEOUT_MILLISECONDS = 10;
|
private static final int BULK_TRANSFER_TIMEOUT_MILLISECONDS = 10;
|
||||||
|
|
||||||
// Arbitrary number for timeout when closing a thread
|
// Arbitrary number for timeout when closing a thread
|
||||||
private static final int THREAD_JOIN_TIMEOUT_MILLISECONDS = 50;
|
private static final int THREAD_JOIN_TIMEOUT_MILLISECONDS = 200;
|
||||||
|
|
||||||
private ArrayList<UsbDeviceConnection> mUsbDeviceConnections;
|
private ArrayList<UsbDeviceConnection> mUsbDeviceConnections;
|
||||||
private ArrayList<ArrayList<UsbEndpoint>> mInputUsbEndpoints;
|
private ArrayList<ArrayList<UsbEndpoint>> mInputUsbEndpoints;
|
||||||
@@ -370,6 +370,10 @@ public final class UsbDirectMidiDevice implements Closeable {
|
|||||||
convertedArray = swapEndiannessPerWord(inputBuffer,
|
convertedArray = swapEndiannessPerWord(inputBuffer,
|
||||||
bytesRead);
|
bytesRead);
|
||||||
} else {
|
} else {
|
||||||
|
if (mUsbMidiPacketConverter == null) {
|
||||||
|
Log.w(TAG, "mUsbMidiPacketConverter is null");
|
||||||
|
break;
|
||||||
|
}
|
||||||
convertedArray =
|
convertedArray =
|
||||||
mUsbMidiPacketConverter.usbMidiToRawMidi(
|
mUsbMidiPacketConverter.usbMidiToRawMidi(
|
||||||
inputBuffer, bytesRead);
|
inputBuffer, bytesRead);
|
||||||
@@ -379,12 +383,20 @@ public final class UsbDirectMidiDevice implements Closeable {
|
|||||||
logByteArray("Input after conversion ", convertedArray,
|
logByteArray("Input after conversion ", convertedArray,
|
||||||
0, convertedArray.length);
|
0, convertedArray.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((outputReceivers == null)
|
||||||
|
|| (outputReceivers[portFinal] == null)) {
|
||||||
|
Log.w(TAG, "outputReceivers is null");
|
||||||
|
break;
|
||||||
|
}
|
||||||
outputReceivers[portFinal].send(convertedArray, 0,
|
outputReceivers[portFinal].send(convertedArray, 0,
|
||||||
convertedArray.length, timestamp);
|
convertedArray.length, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, "reader thread exiting");
|
Log.d(TAG, "reader thread exiting");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.e(TAG, "input thread: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
request.close();
|
request.close();
|
||||||
}
|
}
|
||||||
@@ -414,49 +426,57 @@ public final class UsbDirectMidiDevice implements Closeable {
|
|||||||
Thread newThread = new Thread("UsbDirectMidiDevice output thread " + portFinal) {
|
Thread newThread = new Thread("UsbDirectMidiDevice output thread " + portFinal) {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
try {
|
||||||
if (Thread.currentThread().interrupted()) {
|
while (true) {
|
||||||
Log.w(TAG, "output thread interrupted");
|
if (Thread.currentThread().interrupted()) {
|
||||||
break;
|
Log.w(TAG, "output thread interrupted");
|
||||||
}
|
break;
|
||||||
MidiEvent event;
|
}
|
||||||
try {
|
MidiEvent event;
|
||||||
event = (MidiEvent) eventSchedulerFinal.waitNextEvent();
|
try {
|
||||||
} catch (InterruptedException e) {
|
event = (MidiEvent) eventSchedulerFinal.waitNextEvent();
|
||||||
Log.w(TAG, "event scheduler interrupted");
|
} catch (InterruptedException e) {
|
||||||
break;
|
Log.w(TAG, "event scheduler interrupted");
|
||||||
}
|
break;
|
||||||
if (event == null) {
|
}
|
||||||
Log.w(TAG, "event is null");
|
if (event == null) {
|
||||||
break;
|
Log.w(TAG, "event is null");
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
logByteArray("Output before conversion ", event.data, 0,
|
logByteArray("Output before conversion ", event.data, 0,
|
||||||
event.count);
|
event.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] convertedArray;
|
byte[] convertedArray;
|
||||||
if (mIsUniversalMidiDevice) {
|
if (mIsUniversalMidiDevice) {
|
||||||
// For USB, each 32 bit word of a UMP is
|
// For USB, each 32 bit word of a UMP is
|
||||||
// sent with the least significant byte first.
|
// sent with the least significant byte first.
|
||||||
convertedArray = swapEndiannessPerWord(event.data,
|
convertedArray = swapEndiannessPerWord(event.data,
|
||||||
event.count);
|
event.count);
|
||||||
} else {
|
} else {
|
||||||
convertedArray =
|
if (mUsbMidiPacketConverter == null) {
|
||||||
mUsbMidiPacketConverter.rawMidiToUsbMidi(
|
Log.w(TAG, "mUsbMidiPacketConverter is null");
|
||||||
event.data, event.count, portFinal);
|
break;
|
||||||
}
|
}
|
||||||
|
convertedArray =
|
||||||
|
mUsbMidiPacketConverter.rawMidiToUsbMidi(
|
||||||
|
event.data, event.count, portFinal);
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
logByteArray("Output after conversion ", convertedArray, 0,
|
logByteArray("Output after conversion ", convertedArray, 0,
|
||||||
convertedArray.length);
|
convertedArray.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionFinal.bulkTransfer(endpointFinal, convertedArray,
|
connectionFinal.bulkTransfer(endpointFinal, convertedArray,
|
||||||
convertedArray.length,
|
convertedArray.length,
|
||||||
BULK_TRANSFER_TIMEOUT_MILLISECONDS);
|
BULK_TRANSFER_TIMEOUT_MILLISECONDS);
|
||||||
eventSchedulerFinal.addEventToPool(event);
|
eventSchedulerFinal.addEventToPool(event);
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.e(TAG, "output thread: ", e);
|
||||||
}
|
}
|
||||||
Log.d(TAG, "output thread exit");
|
Log.d(TAG, "output thread exit");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user