Roll src/third_party/WebKit 3529d49:06e8485 (svn 202554:202555)
[chromium-blink-merge.git] / media / midi / midi_output_port_android.cc
blobf82ad51d63bdc140f9c29744e55037d3315872c3
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_output_port_android.h"
7 #include "base/android/jni_array.h"
8 #include "jni/MidiOutputPortAndroid_jni.h"
10 namespace media {
11 namespace midi {
13 MidiOutputPortAndroid::MidiOutputPortAndroid(JNIEnv* env, jobject raw)
14 : raw_port_(env, raw) {}
15 MidiOutputPortAndroid::~MidiOutputPortAndroid() {
16 Close();
19 bool MidiOutputPortAndroid::Open() {
20 JNIEnv* env = base::android::AttachCurrentThread();
21 return Java_MidiOutputPortAndroid_open(env, raw_port_.obj());
24 void MidiOutputPortAndroid::Close() {
25 JNIEnv* env = base::android::AttachCurrentThread();
26 Java_MidiOutputPortAndroid_close(env, raw_port_.obj());
29 void MidiOutputPortAndroid::Send(const std::vector<uint8>& data) {
30 if (data.size() == 0) {
31 return;
34 JNIEnv* env = base::android::AttachCurrentThread();
35 ScopedJavaLocalRef<jbyteArray> data_to_pass =
36 base::android::ToJavaByteArray(env, &data[0], data.size());
38 Java_MidiOutputPortAndroid_send(env, raw_port_.obj(), data_to_pass.obj());
41 bool MidiOutputPortAndroid::Register(JNIEnv* env) {
42 return RegisterNativesImpl(env);
45 } // namespace midi
46 } // namespace media