Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Unified Diff: media/midi/midi_input_port_android.cc

Issue 1177973003: [Web MIDI] Use Android MIDI API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698