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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « media/midi/midi_input_port_android.h ('k') | media/midi/midi_jni_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/midi/midi_input_port_android.h"
6
7 #include "base/android/jni_array.h"
8 #include "base/time/time.h"
9 #include "jni/MidiInputPortAndroid_jni.h"
10
11 namespace media {
12 namespace midi {
13
14 MidiInputPortAndroid::MidiInputPortAndroid(JNIEnv* env,
15 jobject raw,
16 Delegate* delegate)
17 : raw_port_(env, raw), delegate_(delegate) {}
18
19 MidiInputPortAndroid::~MidiInputPortAndroid() {
20 Close();
21 }
22
23 bool MidiInputPortAndroid::Open() {
24 JNIEnv* env = base::android::AttachCurrentThread();
25 return Java_MidiInputPortAndroid_open(env, raw_port_.obj(),
26 reinterpret_cast<jlong>(this));
27 }
28
29 void MidiInputPortAndroid::Close() {
30 JNIEnv* env = base::android::AttachCurrentThread();
31 Java_MidiInputPortAndroid_close(env, raw_port_.obj());
32 }
33
34 void MidiInputPortAndroid::OnData(JNIEnv* env,
35 jobject caller,
36 jbyteArray data,
37 jint offset,
38 jint size,
39 jlong timestamp) {
40 std::vector<uint8> bytes;
41 base::android::JavaByteArrayToByteVector(env, data, &bytes);
42
43 if (size == 0) {
44 return;
45 }
46
47 // TimeTick's internal value is in microseconds, |timestamp| is in
48 // nanoseconds. Both are monotonic.
49 base::TimeTicks timestamp_to_pass = base::TimeTicks::FromInternalValue(
50 timestamp / base::TimeTicks::kNanosecondsPerMicrosecond);
51 delegate_->OnReceivedData(this, &bytes[offset], size, timestamp_to_pass);
52 }
53
54 bool MidiInputPortAndroid::Register(JNIEnv* env) {
55 return RegisterNativesImpl(env);
56 }
57
58 } // namespace midi
59 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_input_port_android.h ('k') | media/midi/midi_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698