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/renderer/media/midi_message_filter.h" | 5 #include "content/renderer/media/midi_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // will be very few clients (usually one). Additionally, this lookup | 146 // will be very few clients (usually one). Additionally, this lookup |
147 // usually happens one time during page load. So the performance hit is | 147 // usually happens one time during page load. So the performance hit is |
148 // negligible. | 148 // negligible. |
149 for (ClientsMap::iterator i = clients_.begin(); i != clients_.end(); ++i) { | 149 for (ClientsMap::iterator i = clients_.begin(); i != clients_.end(); ++i) { |
150 if ((*i).second == client_id) | 150 if ((*i).second == client_id) |
151 return (*i).first; | 151 return (*i).first; |
152 } | 152 } |
153 return NULL; | 153 return NULL; |
154 } | 154 } |
155 | 155 |
156 void MIDIMessageFilter::OnDataReceived(int port, | 156 void MIDIMessageFilter::OnDataReceived(uint32 port, |
157 const std::vector<uint8>& data, | 157 const std::vector<uint8>& data, |
158 double timestamp) { | 158 double timestamp) { |
159 TRACE_EVENT0("midi", "MIDIMessageFilter::OnDataReceived"); | 159 TRACE_EVENT0("midi", "MIDIMessageFilter::OnDataReceived"); |
160 | 160 |
161 main_message_loop_->PostTask( | 161 main_message_loop_->PostTask( |
162 FROM_HERE, | 162 FROM_HERE, |
163 base::Bind(&MIDIMessageFilter::HandleDataReceived, this, | 163 base::Bind(&MIDIMessageFilter::HandleDataReceived, this, |
164 port, data, timestamp)); | 164 port, data, timestamp)); |
165 } | 165 } |
166 | 166 |
167 void MIDIMessageFilter::OnAcknowledgeSentData(size_t bytes_sent) { | 167 void MIDIMessageFilter::OnAcknowledgeSentData(size_t bytes_sent) { |
168 DCHECK_GE(unacknowledged_bytes_sent_, bytes_sent); | 168 DCHECK_GE(unacknowledged_bytes_sent_, bytes_sent); |
169 if (unacknowledged_bytes_sent_ >= bytes_sent) | 169 if (unacknowledged_bytes_sent_ >= bytes_sent) |
170 unacknowledged_bytes_sent_ -= bytes_sent; | 170 unacknowledged_bytes_sent_ -= bytes_sent; |
171 } | 171 } |
172 | 172 |
173 void MIDIMessageFilter::HandleDataReceived(int port, | 173 void MIDIMessageFilter::HandleDataReceived(uint32 port, |
174 const std::vector<uint8>& data, | 174 const std::vector<uint8>& data, |
175 double timestamp) { | 175 double timestamp) { |
176 TRACE_EVENT0("midi", "MIDIMessageFilter::HandleDataReceived"); | 176 TRACE_EVENT0("midi", "MIDIMessageFilter::HandleDataReceived"); |
177 | 177 |
178 #if defined(OS_ANDROID) | 178 #if defined(OS_ANDROID) |
179 // TODO(crogers): figure out why data() method does not compile on Android. | 179 // TODO(crogers): figure out why data() method does not compile on Android. |
180 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
181 #else | 181 #else |
182 for (ClientsMap::iterator i = clients_.begin(); i != clients_.end(); ++i) | 182 for (ClientsMap::iterator i = clients_.begin(); i != clients_.end(); ++i) |
183 (*i).first->didReceiveMIDIData(port, data.data(), data.size(), timestamp); | 183 (*i).first->didReceiveMIDIData(port, data.data(), data.size(), timestamp); |
184 #endif | 184 #endif |
185 } | 185 } |
186 | 186 |
187 void MIDIMessageFilter::SendMIDIData(int port, | 187 void MIDIMessageFilter::SendMIDIData(uint32 port, |
188 const uint8* data, | 188 const uint8* data, |
189 size_t length, | 189 size_t length, |
190 double timestamp) { | 190 double timestamp) { |
191 if (length > kMaxUnacknowledgedBytesSent) { | 191 if (length > kMaxUnacknowledgedBytesSent) { |
192 // TODO(crogers): buffer up the data to send at a later time. | 192 // TODO(crogers): buffer up the data to send at a later time. |
193 // For now we're just dropping these bytes on the floor. | 193 // For now we're just dropping these bytes on the floor. |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 std::vector<uint8> v(data, data + length); | 197 std::vector<uint8> v(data, data + length); |
198 io_message_loop_->PostTask(FROM_HERE, | 198 io_message_loop_->PostTask(FROM_HERE, |
199 base::Bind(&MIDIMessageFilter::SendMIDIDataOnIOThread, this, | 199 base::Bind(&MIDIMessageFilter::SendMIDIDataOnIOThread, this, |
200 port, v, timestamp)); | 200 port, v, timestamp)); |
201 } | 201 } |
202 | 202 |
203 void MIDIMessageFilter::SendMIDIDataOnIOThread(int port, | 203 void MIDIMessageFilter::SendMIDIDataOnIOThread(uint32 port, |
204 const std::vector<uint8>& data, | 204 const std::vector<uint8>& data, |
205 double timestamp) { | 205 double timestamp) { |
206 size_t n = data.size(); | 206 size_t n = data.size(); |
207 if (n > kMaxUnacknowledgedBytesSent || | 207 if (n > kMaxUnacknowledgedBytesSent || |
208 unacknowledged_bytes_sent_ > kMaxUnacknowledgedBytesSent || | 208 unacknowledged_bytes_sent_ > kMaxUnacknowledgedBytesSent || |
209 n + unacknowledged_bytes_sent_ > kMaxUnacknowledgedBytesSent) { | 209 n + unacknowledged_bytes_sent_ > kMaxUnacknowledgedBytesSent) { |
210 // TODO(crogers): buffer up the data to send at a later time. | 210 // TODO(crogers): buffer up the data to send at a later time. |
211 // For now we're just dropping these bytes on the floor. | 211 // For now we're just dropping these bytes on the floor. |
212 return; | 212 return; |
213 } | 213 } |
214 | 214 |
215 unacknowledged_bytes_sent_ += n; | 215 unacknowledged_bytes_sent_ += n; |
216 | 216 |
217 // Send to the browser. | 217 // Send to the browser. |
218 Send(new MIDIHostMsg_SendData(port, data, timestamp)); | 218 Send(new MIDIHostMsg_SendData(port, data, timestamp)); |
219 } | 219 } |
220 | 220 |
221 } // namespace content | 221 } // namespace content |
OLD | NEW |