summaryrefslogtreecommitdiffstats
path: root/services/usb
diff options
context:
space:
mode:
authorPhil Burk <philburk@google.com>2015-07-29 15:55:00 -0700
committerPhil Burk <philburk@google.com>2015-07-29 15:55:00 -0700
commit6456a65afed66819b73df7eb605037402b91fc3f (patch)
tree40b979be985e80c2b587eb3725d52bdc5e6a21cb /services/usb
parentb83b5fa641847ee1d533253ba5e1a3e13913b9d9 (diff)
downloadframeworks_base-6456a65afed66819b73df7eb605037402b91fc3f.zip
frameworks_base-6456a65afed66819b73df7eb605037402b91fc3f.tar.gz
frameworks_base-6456a65afed66819b73df7eb605037402b91fc3f.tar.bz2
UsbMidiDevice: add timestamps for input events
This will improve the accuracy of recorded MIDI performances. Bug: 22801515 Change-Id: Ib78bc929224f2f27938c83a815eaa62f6b5f9560 Signed-off-by: Phil Burk <philburk@google.com>
Diffstat (limited to 'services/usb')
-rw-r--r--services/usb/java/com/android/server/usb/UsbMidiDevice.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbMidiDevice.java b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
index 97bf505..38ede87 100644
--- a/services/usb/java/com/android/server/usb/UsbMidiDevice.java
+++ b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
@@ -128,7 +128,7 @@ public final class UsbMidiDevice implements Closeable {
mReceiver = receiver;
}
}
-
+
public static UsbMidiDevice create(Context context, Bundle properties, int card, int device) {
// FIXME - support devices with different number of input and output ports
int subDeviceCount = nativeGetSubdeviceCount(card, device);
@@ -203,6 +203,8 @@ public final class UsbMidiDevice implements Closeable {
byte[] buffer = new byte[BUFFER_SIZE];
try {
while (true) {
+ // Record time of event immediately after waking.
+ long timestamp = System.nanoTime();
synchronized (mLock) {
if (!mIsOpen) break;
@@ -215,14 +217,14 @@ public final class UsbMidiDevice implements Closeable {
} else if ((pfd.revents & OsConstants.POLLIN) != 0) {
// clear readable flag
pfd.revents = 0;
-
+
if (index == mInputStreams.length - 1) {
// last file descriptor is used only for unblocking Os.poll()
break;
}
int count = mInputStreams[index].read(buffer);
- outputReceivers[index].send(buffer, 0, count);
+ outputReceivers[index].send(buffer, 0, count, timestamp);
}
}
}