| 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/renderer_host/media/midi_host.h" | 5 #include "content/browser/renderer_host/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 Send(new MIDIMsg_SessionStarted( | 84 Send(new MIDIMsg_SessionStarted( |
| 85 client_id, | 85 client_id, |
| 86 success, | 86 success, |
| 87 input_ports, | 87 input_ports, |
| 88 output_ports)); | 88 output_ports)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void MIDIHost::OnSendData(int port, | 91 void MIDIHost::OnSendData(uint32 port, |
| 92 const std::vector<uint8>& data, | 92 const std::vector<uint8>& data, |
| 93 double timestamp) { | 93 double timestamp) { |
| 94 if (!midi_manager_) | 94 if (!midi_manager_) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 if (data.empty()) | 97 if (data.empty()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 base::AutoLock auto_lock(in_flight_lock_); | 100 base::AutoLock auto_lock(in_flight_lock_); |
| 101 | 101 |
| 102 // Sanity check that we won't send too much. | 102 // Sanity check that we won't send too much. |
| 103 if (sent_bytes_in_flight_ > kMaxInFlightBytes || | 103 if (sent_bytes_in_flight_ > kMaxInFlightBytes || |
| 104 data.size() > kMaxInFlightBytes || | 104 data.size() > kMaxInFlightBytes || |
| 105 data.size() + sent_bytes_in_flight_ > kMaxInFlightBytes) | 105 data.size() + sent_bytes_in_flight_ > kMaxInFlightBytes) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 // For now disallow all System Exclusive messages even if we | 108 // For now disallow all System Exclusive messages even if we |
| 109 // have permission. | 109 // have permission. |
| 110 // TODO(toyoshim): allow System Exclusive if browser has granted | 110 // TODO(toyoshim): allow System Exclusive if browser has granted |
| 111 // this client access. We'll likely need to pass a GURL | 111 // this client access. We'll likely need to pass a GURL |
| 112 // here to compare against our permissions. | 112 // here to compare against our permissions. |
| 113 if (data[0] >= kSysExMessage) | 113 if (data[0] >= kSysExMessage) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 midi_manager_->DispatchSendMIDIData( | 116 midi_manager_->DispatchSendMIDIData( |
| 117 this, | 117 this, |
| 118 port, | 118 port, |
| 119 &data[0], | 119 data, |
| 120 data.size(), | |
| 121 timestamp); | 120 timestamp); |
| 122 | 121 |
| 123 sent_bytes_in_flight_ += data.size(); | 122 sent_bytes_in_flight_ += data.size(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void MIDIHost::ReceiveMIDIData( | 125 void MIDIHost::ReceiveMIDIData( |
| 127 int port_index, | 126 uint32 port, |
| 128 const uint8* data, | 127 const uint8* data, |
| 129 size_t length, | 128 size_t length, |
| 130 double timestamp) { | 129 double timestamp) { |
| 131 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData"); | 130 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData"); |
| 132 | 131 |
| 133 // For now disallow all System Exclusive messages even if we | 132 // For now disallow all System Exclusive messages even if we |
| 134 // have permission. | 133 // have permission. |
| 135 // TODO(toyoshim): allow System Exclusive if browser has granted | 134 // TODO(toyoshim): allow System Exclusive if browser has granted |
| 136 // this client access. We'll likely need to pass a GURL | 135 // this client access. We'll likely need to pass a GURL |
| 137 // here to compare against our permissions. | 136 // here to compare against our permissions. |
| 138 if (length > 0 && data[0] >= kSysExMessage) | 137 if (length > 0 && data[0] >= kSysExMessage) |
| 139 return; | 138 return; |
| 140 | 139 |
| 141 // Send to the renderer. | 140 // Send to the renderer. |
| 142 std::vector<uint8> v(data, data + length); | 141 std::vector<uint8> v(data, data + length); |
| 143 Send(new MIDIMsg_DataReceived(port_index, v, timestamp)); | 142 Send(new MIDIMsg_DataReceived(port, v, timestamp)); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void MIDIHost::AccumulateMIDIBytesSent(size_t n) { | 145 void MIDIHost::AccumulateMIDIBytesSent(size_t n) { |
| 147 { | 146 { |
| 148 base::AutoLock auto_lock(in_flight_lock_); | 147 base::AutoLock auto_lock(in_flight_lock_); |
| 149 if (n <= sent_bytes_in_flight_) | 148 if (n <= sent_bytes_in_flight_) |
| 150 sent_bytes_in_flight_ -= n; | 149 sent_bytes_in_flight_ -= n; |
| 151 } | 150 } |
| 152 | 151 |
| 153 if (bytes_sent_since_last_acknowledgement_ + n >= | 152 if (bytes_sent_since_last_acknowledgement_ + n >= |
| 154 bytes_sent_since_last_acknowledgement_) | 153 bytes_sent_since_last_acknowledgement_) |
| 155 bytes_sent_since_last_acknowledgement_ += n; | 154 bytes_sent_since_last_acknowledgement_ += n; |
| 156 | 155 |
| 157 if (bytes_sent_since_last_acknowledgement_ >= | 156 if (bytes_sent_since_last_acknowledgement_ >= |
| 158 kAcknowledgementThresholdBytes) { | 157 kAcknowledgementThresholdBytes) { |
| 159 Send(new MIDIMsg_AcknowledgeSentData( | 158 Send(new MIDIMsg_AcknowledgeSentData( |
| 160 bytes_sent_since_last_acknowledgement_)); | 159 bytes_sent_since_last_acknowledgement_)); |
| 161 bytes_sent_since_last_acknowledgement_ = 0; | 160 bytes_sent_since_last_acknowledgement_ = 0; |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 } // namespace content | 164 } // namespace content |
| OLD | NEW |