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

Side by Side Diff: content/browser/media/midi_host.cc

Issue 664843002: Web MIDI: distributes MIDIPort information asynchronously (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lifecycle
Patch Set: . => -> Created 6 years, 1 month 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 | « content/browser/media/midi_host.h ('k') | content/common/media/midi_messages.h » ('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 (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
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(nullptr);
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] == nullptr)
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) {
164 received_messages_queues_[port]->Get(&message); 166 received_messages_queues_[port]->Get(&message);
165 if (message.empty()) 167 if (message.empty())
166 break; 168 break;
167 169
168 // MIDI devices may send a system exclusive messages even if the renderer 170 // MIDI devices may send a system exclusive messages even if the renderer
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « content/browser/media/midi_host.h ('k') | content/common/media/midi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698