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