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.
5 #include "media/midi/midi_input_port_android.h"
7 #include "base/android/jni_array.h"
8 #include "base/time/time.h"
9 #include "jni/MidiInputPortAndroid_jni.h"
14 MidiInputPortAndroid::MidiInputPortAndroid(JNIEnv
* env
,
17 : raw_port_(env
, raw
), delegate_(delegate
) {}
19 MidiInputPortAndroid::~MidiInputPortAndroid() {
23 bool MidiInputPortAndroid::Open() {
24 JNIEnv
* env
= base::android::AttachCurrentThread();
25 return Java_MidiInputPortAndroid_open(env
, raw_port_
.obj(),
26 reinterpret_cast<jlong
>(this));
29 void MidiInputPortAndroid::Close() {
30 JNIEnv
* env
= base::android::AttachCurrentThread();
31 Java_MidiInputPortAndroid_close(env
, raw_port_
.obj());
34 void MidiInputPortAndroid::OnData(JNIEnv
* env
,
40 std::vector
<uint8
> bytes
;
41 base::android::JavaByteArrayToByteVector(env
, data
, &bytes
);
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
);
54 bool MidiInputPortAndroid::Register(JNIEnv
* env
) {
55 return RegisterNativesImpl(env
);