Index: media/midi/midi_input_port_android.cc |
diff --git a/media/midi/midi_input_port_android.cc b/media/midi/midi_input_port_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1f1a9557c84f0ed6e436d9135e36d64cd27d3e74 |
--- /dev/null |
+++ b/media/midi/midi_input_port_android.cc |
@@ -0,0 +1,41 @@ |
+// 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. |
+ |
+#include "media/midi/midi_input_port_android.h" |
+ |
+#include "base/android/jni_array.h" |
+#include "jni/MidiInputPortAndroid_jni.h" |
+ |
+namespace media { |
+namespace midi { |
+ |
+MidiInputPortAndroid::MidiInputPortAndroid(JNIEnv* env, |
+ jobject raw, |
+ Delegate* delegate) |
+ : delegate_(delegate) { |
+ Java_MidiInputPortAndroid_connect(env, raw, reinterpret_cast<jlong>(this)); |
+} |
+ |
+MidiInputPortAndroid::~MidiInputPortAndroid() {} |
+ |
+void MidiInputPortAndroid::OnData(JNIEnv* env, |
+ jobject caller, |
+ jbyteArray data, |
+ jint offset, |
+ jint size, |
+ jlong timestamp) { |
+ std::vector<uint8> bytes; |
+ base::android::JavaByteArrayToByteVector(env, data, &bytes); |
+ |
+ // We don't use |timestamp| because MidiManager wants base::TimeTicks. |
philburk
2015/08/19 01:40:15
Ignoring timestamp can cause rendering errors. Som
yhirano
2015/08/19 06:32:03
Done.
|
+ const uint8* head = bytes.size() ? &bytes[offset] : nullptr; |
+ delegate_->OnReceivedData(this, head, size, base::TimeTicks::Now()); |
+} |
+ |
+bool MidiInputPortAndroid::Register(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace midi |
+} // namespace media |