OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/media/midi_host.h" | 5 #include "content/browser/media/midi_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 midi_manager_->DispatchSendMidiData(this, port, data, timestamp); | 118 midi_manager_->DispatchSendMidiData(this, port, data, timestamp); |
119 } | 119 } |
120 | 120 |
121 void MidiHost::OnEndSession() { | 121 void MidiHost::OnEndSession() { |
122 is_session_requested_ = false; | 122 is_session_requested_ = false; |
123 midi_manager_->EndSession(this); | 123 midi_manager_->EndSession(this); |
124 } | 124 } |
125 | 125 |
126 void MidiHost::CompleteStartSession(media::MidiResult result) { | 126 void MidiHost::CompleteStartSession(media::MidiResult result) { |
127 DCHECK(is_session_requested_); | 127 DCHECK(is_session_requested_); |
128 MidiPortInfoList input_ports; | |
129 MidiPortInfoList output_ports; | |
130 | |
131 if (result == media::MIDI_OK) { | 128 if (result == media::MIDI_OK) { |
132 input_ports = midi_manager_->input_ports(); | |
133 output_ports = midi_manager_->output_ports(); | |
134 received_messages_queues_.clear(); | |
135 received_messages_queues_.resize(input_ports.size()); | |
136 // ChildSecurityPolicy is set just before OnStartSession by | 129 // ChildSecurityPolicy is set just before OnStartSession by |
137 // MidiDispatcherHost. So we can safely cache the policy. | 130 // MidiDispatcherHost. So we can safely cache the policy. |
138 has_sys_ex_permission_ = ChildProcessSecurityPolicyImpl::GetInstance()-> | 131 has_sys_ex_permission_ = ChildProcessSecurityPolicyImpl::GetInstance()-> |
139 CanSendMidiSysExMessage(renderer_process_id_); | 132 CanSendMidiSysExMessage(renderer_process_id_); |
140 } | 133 } |
134 Send(new MidiMsg_SessionStarted(result)); | |
135 } | |
141 | 136 |
142 Send(new MidiMsg_SessionStarted(result, | 137 void MidiHost::AddInputPort(const media::MidiPortInfo& info) { |
143 input_ports, | 138 base::AutoLock auto_lock(messages_queues_lock_); |
144 output_ports)); | 139 // MidiMessageQueue is created later in ReceiveMidiData(). |
140 received_messages_queues_.push_back(NULL); | |
yhirano
2014/10/23 08:24:13
You can use nullptr.
Takashi Toyoshima
2014/10/23 09:33:47
Done.
| |
141 Send(new MidiMsg_AddInputPort(info)); | |
142 } | |
143 | |
144 void MidiHost::AddOutputPort(const media::MidiPortInfo& info) { | |
145 Send(new MidiMsg_AddOutputPort(info)); | |
145 } | 146 } |
146 | 147 |
147 void MidiHost::ReceiveMidiData( | 148 void MidiHost::ReceiveMidiData( |
148 uint32 port, | 149 uint32 port, |
149 const uint8* data, | 150 const uint8* data, |
150 size_t length, | 151 size_t length, |
151 double timestamp) { | 152 double timestamp) { |
152 TRACE_EVENT0("midi", "MidiHost::ReceiveMidiData"); | 153 TRACE_EVENT0("midi", "MidiHost::ReceiveMidiData"); |
153 | 154 |
155 base::AutoLock auto_lock(messages_queues_lock_); | |
154 if (received_messages_queues_.size() <= port) | 156 if (received_messages_queues_.size() <= port) |
155 return; | 157 return; |
156 | 158 |
157 // Lazy initialization | 159 // Lazy initialization |
158 if (received_messages_queues_[port] == NULL) | 160 if (received_messages_queues_[port] == NULL) |
159 received_messages_queues_[port] = new media::MidiMessageQueue(true); | 161 received_messages_queues_[port] = new media::MidiMessageQueue(true); |
160 | 162 |
161 received_messages_queues_[port]->Add(data, length); | 163 received_messages_queues_[port]->Add(data, length); |
162 std::vector<uint8> message; | 164 std::vector<uint8> message; |
163 while (true) { | 165 while (true) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 } | 224 } |
223 waiting_data_length = media::GetMidiMessageLength(current); | 225 waiting_data_length = media::GetMidiMessageLength(current); |
224 if (waiting_data_length == 0) | 226 if (waiting_data_length == 0) |
225 return false; // Error: |current| should have been a valid status byte. | 227 return false; // Error: |current| should have been a valid status byte. |
226 --waiting_data_length; // Found status byte | 228 --waiting_data_length; // Found status byte |
227 } | 229 } |
228 return waiting_data_length == 0 && !in_sysex; | 230 return waiting_data_length == 0 && !in_sysex; |
229 } | 231 } |
230 | 232 |
231 } // namespace content | 233 } // namespace content |
OLD | NEW |