OLD | NEW |
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/midi_manager_android.h" | 5 #include "media/midi/midi_manager_android.h" |
6 | 6 |
7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/context_utils.h" | 8 #include "base/android/context_utils.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 JNIEnv* env = base::android::AttachCurrentThread(); | 39 JNIEnv* env = base::android::AttachCurrentThread(); |
40 | 40 |
41 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); | 41 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); |
42 raw_manager_.Reset(Java_MidiManagerAndroid_create( | 42 raw_manager_.Reset(Java_MidiManagerAndroid_create( |
43 env, base::android::GetApplicationContext(), pointer)); | 43 env, base::android::GetApplicationContext(), pointer)); |
44 scheduler_.reset(new MidiScheduler(this)); | 44 scheduler_.reset(new MidiScheduler(this)); |
45 Java_MidiManagerAndroid_initialize(env, raw_manager_.obj()); | 45 Java_MidiManagerAndroid_initialize(env, raw_manager_.obj()); |
46 } | 46 } |
47 | 47 |
48 void MidiManagerAndroid::DispatchSendMidiData(MidiManagerClient* client, | 48 void MidiManagerAndroid::DispatchSendMidiData(MidiManagerClient* client, |
49 uint32 port_index, | 49 uint32_t port_index, |
50 const std::vector<uint8>& data, | 50 const std::vector<uint8_t>& data, |
51 double timestamp) { | 51 double timestamp) { |
52 if (port_index >= all_output_ports_.size()) { | 52 if (port_index >= all_output_ports_.size()) { |
53 // |port_index| is provided by a renderer so we can't believe that it is | 53 // |port_index| is provided by a renderer so we can't believe that it is |
54 // in the valid range. | 54 // in the valid range. |
55 return; | 55 return; |
56 } | 56 } |
57 DCHECK_EQ(output_ports().size(), all_output_ports_.size()); | 57 DCHECK_EQ(output_ports().size(), all_output_ports_.size()); |
58 if (output_ports()[port_index].state == MIDI_PORT_CONNECTED) { | 58 if (output_ports()[port_index].state == MIDI_PORT_CONNECTED) { |
59 // We treat send call as implicit open. | 59 // We treat send call as implicit open. |
60 // TODO(yhirano): Implement explicit open operation from the renderer. | 60 // TODO(yhirano): Implement explicit open operation from the renderer. |
61 if (all_output_ports_[port_index]->Open()) { | 61 if (all_output_ports_[port_index]->Open()) { |
62 SetOutputPortState(port_index, MIDI_PORT_OPENED); | 62 SetOutputPortState(port_index, MIDI_PORT_OPENED); |
63 } else { | 63 } else { |
64 // We cannot open the port. It's useless to send data to such a port. | 64 // We cannot open the port. It's useless to send data to such a port. |
65 return; | 65 return; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 // output_streams_[port_index] is alive unless MidiManagerUsb is deleted. | 69 // output_streams_[port_index] is alive unless MidiManagerUsb is deleted. |
70 // The task posted to the MidiScheduler will be disposed safely on deleting | 70 // The task posted to the MidiScheduler will be disposed safely on deleting |
71 // the scheduler. | 71 // the scheduler. |
72 scheduler_->PostSendDataTask( | 72 scheduler_->PostSendDataTask( |
73 client, data.size(), timestamp, | 73 client, data.size(), timestamp, |
74 base::Bind(&MidiOutputPortAndroid::Send, | 74 base::Bind(&MidiOutputPortAndroid::Send, |
75 base::Unretained(all_output_ports_[port_index]), data)); | 75 base::Unretained(all_output_ports_[port_index]), data)); |
76 } | 76 } |
77 | 77 |
78 void MidiManagerAndroid::OnReceivedData(MidiInputPortAndroid* port, | 78 void MidiManagerAndroid::OnReceivedData(MidiInputPortAndroid* port, |
79 const uint8* data, | 79 const uint8_t* data, |
80 size_t size, | 80 size_t size, |
81 base::TimeTicks timestamp) { | 81 base::TimeTicks timestamp) { |
82 const auto i = input_port_to_index_.find(port); | 82 const auto i = input_port_to_index_.find(port); |
83 DCHECK(input_port_to_index_.end() != i); | 83 DCHECK(input_port_to_index_.end() != i); |
84 ReceiveMidiData(i->second, data, size, timestamp); | 84 ReceiveMidiData(i->second, data, size, timestamp); |
85 } | 85 } |
86 | 86 |
87 void MidiManagerAndroid::OnInitialized( | 87 void MidiManagerAndroid::OnInitialized( |
88 JNIEnv* env, | 88 JNIEnv* env, |
89 const JavaParamRef<jobject>& caller, | 89 const JavaParamRef<jobject>& caller, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 devices_.push_back(device.release()); | 160 devices_.push_back(device.release()); |
161 } | 161 } |
162 | 162 |
163 bool MidiManagerAndroid::Register(JNIEnv* env) { | 163 bool MidiManagerAndroid::Register(JNIEnv* env) { |
164 return RegisterNativesImpl(env); | 164 return RegisterNativesImpl(env); |
165 } | 165 } |
166 | 166 |
167 } // namespace midi | 167 } // namespace midi |
168 } // namespace media | 168 } // namespace media |
OLD | NEW |