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

Side by Side Diff: media/midi/usb_midi_device_android.cc

Issue 1085843003: Revert of Web MIDI: split build rules for media/midi (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_unittests.isolate ('k') | media/midi/usb_midi_device_factory_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/usb_midi_device_android.h" 5 #include "media/midi/usb_midi_device_android.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "jni/UsbMidiDeviceAndroid_jni.h" 12 #include "jni/UsbMidiDeviceAndroid_jni.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 UsbMidiDeviceAndroid::UsbMidiDeviceAndroid(ObjectRef raw_device, 16 UsbMidiDeviceAndroid::UsbMidiDeviceAndroid(ObjectRef raw_device,
17 UsbMidiDeviceDelegate* delegate) 17 UsbMidiDeviceDelegate* delegate)
18 : raw_device_(raw_device), delegate_(delegate) { 18 : raw_device_(raw_device), delegate_(delegate) {
19 JNIEnv* env = base::android::AttachCurrentThread(); 19 JNIEnv* env = base::android::AttachCurrentThread();
20 midi::Java_UsbMidiDeviceAndroid_registerSelf( 20 Java_UsbMidiDeviceAndroid_registerSelf(
21 env, raw_device_.obj(), reinterpret_cast<jlong>(this)); 21 env, raw_device_.obj(), reinterpret_cast<jlong>(this));
22 } 22 }
23 23
24 UsbMidiDeviceAndroid::~UsbMidiDeviceAndroid() { 24 UsbMidiDeviceAndroid::~UsbMidiDeviceAndroid() {
25 JNIEnv* env = base::android::AttachCurrentThread(); 25 JNIEnv* env = base::android::AttachCurrentThread();
26 midi::Java_UsbMidiDeviceAndroid_close(env, raw_device_.obj()); 26 Java_UsbMidiDeviceAndroid_close(env, raw_device_.obj());
27 } 27 }
28 28
29 std::vector<uint8> UsbMidiDeviceAndroid::GetDescriptor() { 29 std::vector<uint8> UsbMidiDeviceAndroid::GetDescriptor() {
30 JNIEnv* env = base::android::AttachCurrentThread(); 30 JNIEnv* env = base::android::AttachCurrentThread();
31 base::android::ScopedJavaLocalRef<jbyteArray> descriptors = 31 base::android::ScopedJavaLocalRef<jbyteArray> descriptors =
32 midi::Java_UsbMidiDeviceAndroid_getDescriptors(env, raw_device_.obj()); 32 Java_UsbMidiDeviceAndroid_getDescriptors(env, raw_device_.obj());
33 33
34 std::vector<uint8> ret; 34 std::vector<uint8> ret;
35 base::android::JavaByteArrayToByteVector(env, descriptors.obj(), &ret); 35 base::android::JavaByteArrayToByteVector(env, descriptors.obj(), &ret);
36 return ret; 36 return ret;
37 } 37 }
38 38
39 void UsbMidiDeviceAndroid::Send(int endpoint_number, 39 void UsbMidiDeviceAndroid::Send(int endpoint_number,
40 const std::vector<uint8>& data) { 40 const std::vector<uint8>& data) {
41 JNIEnv* env = base::android::AttachCurrentThread(); 41 JNIEnv* env = base::android::AttachCurrentThread();
42 const uint8* head = data.size() ? &data[0] : NULL; 42 const uint8* head = data.size() ? &data[0] : NULL;
43 ScopedJavaLocalRef<jbyteArray> data_to_pass = 43 ScopedJavaLocalRef<jbyteArray> data_to_pass =
44 base::android::ToJavaByteArray(env, head, data.size()); 44 base::android::ToJavaByteArray(env, head, data.size());
45 45
46 midi::Java_UsbMidiDeviceAndroid_send( 46 Java_UsbMidiDeviceAndroid_send(
47 env, raw_device_.obj(), endpoint_number, data_to_pass.obj()); 47 env, raw_device_.obj(), endpoint_number, data_to_pass.obj());
48 } 48 }
49 49
50 void UsbMidiDeviceAndroid::OnData(JNIEnv* env, 50 void UsbMidiDeviceAndroid::OnData(JNIEnv* env,
51 jobject caller, 51 jobject caller,
52 jint endpoint_number, 52 jint endpoint_number,
53 jbyteArray data) { 53 jbyteArray data) {
54 std::vector<uint8> bytes; 54 std::vector<uint8> bytes;
55 base::android::JavaByteArrayToByteVector(env, data, &bytes); 55 base::android::JavaByteArrayToByteVector(env, data, &bytes);
56 56
57 const uint8* head = bytes.size() ? &bytes[0] : NULL; 57 const uint8* head = bytes.size() ? &bytes[0] : NULL;
58 delegate_->ReceiveUsbMidiData(this, endpoint_number, head, bytes.size(), 58 delegate_->ReceiveUsbMidiData(this, endpoint_number, head, bytes.size(),
59 base::TimeTicks::Now()); 59 base::TimeTicks::Now());
60 } 60 }
61 61
62 bool UsbMidiDeviceAndroid::RegisterUsbMidiDevice(JNIEnv* env) { 62 bool UsbMidiDeviceAndroid::RegisterUsbMidiDevice(JNIEnv* env) {
63 return midi::RegisterNativesImpl(env); 63 return RegisterNativesImpl(env);
64 } 64 }
65 65
66 } // namespace media 66 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_unittests.isolate ('k') | media/midi/usb_midi_device_factory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698