| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (portIndex >= m_inputs.size()) | 191 if (portIndex >= m_inputs.size()) |
| 192 return; | 192 return; |
| 193 | 193 |
| 194 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStamp); | 194 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStamp); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void MIDIAccess::sendMIDIData(unsigned portIndex, | 197 void MIDIAccess::sendMIDIData(unsigned portIndex, |
| 198 const unsigned char* data, | 198 const unsigned char* data, |
| 199 size_t length, | 199 size_t length, |
| 200 double timeStampInMilliseconds) { | 200 double timeStampInMilliseconds) { |
| 201 // Do not continue sending when document is going to be closed. |
| 202 Document* document = toDocument(getExecutionContext()); |
| 203 DCHECK(document); |
| 204 DocumentLoader* loader = document->loader(); |
| 205 if (!loader) |
| 206 return; |
| 207 |
| 201 if (!data || !length || portIndex >= m_outputs.size()) | 208 if (!data || !length || portIndex >= m_outputs.size()) |
| 202 return; | 209 return; |
| 210 |
| 203 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to | 211 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to |
| 204 // the same time coordinate system as performance.now() into a time in seconds | 212 // the same time coordinate system as performance.now() into a time in seconds |
| 205 // which is based on the time coordinate system of | 213 // which is based on the time coordinate system of |
| 206 // monotonicallyIncreasingTime(). | 214 // monotonicallyIncreasingTime(). |
| 207 double timeStamp; | 215 double timeStamp; |
| 208 | 216 |
| 209 if (!timeStampInMilliseconds) { | 217 if (!timeStampInMilliseconds) { |
| 210 // We treat a value of 0 (which is the default value) as special, meaning | 218 // We treat a value of 0 (which is the default value) as special, meaning |
| 211 // "now". We need to translate it exactly to 0 seconds. | 219 // "now". We need to translate it exactly to 0 seconds. |
| 212 timeStamp = 0; | 220 timeStamp = 0; |
| 213 } else { | 221 } else { |
| 214 Document* document = toDocument(getExecutionContext()); | 222 double documentStartTime = loader->timing().referenceMonotonicTime(); |
| 215 DCHECK(document); | |
| 216 double documentStartTime = | |
| 217 document->loader()->timing().referenceMonotonicTime(); | |
| 218 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; | 223 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; |
| 219 } | 224 } |
| 220 | 225 |
| 221 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); | 226 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); |
| 222 } | 227 } |
| 223 | 228 |
| 224 void MIDIAccess::contextDestroyed() { | 229 void MIDIAccess::contextDestroyed() { |
| 225 m_accessor.reset(); | 230 m_accessor.reset(); |
| 226 } | 231 } |
| 227 | 232 |
| 228 DEFINE_TRACE(MIDIAccess) { | 233 DEFINE_TRACE(MIDIAccess) { |
| 229 visitor->trace(m_inputs); | 234 visitor->trace(m_inputs); |
| 230 visitor->trace(m_outputs); | 235 visitor->trace(m_outputs); |
| 231 EventTargetWithInlineData::trace(visitor); | 236 EventTargetWithInlineData::trace(visitor); |
| 232 SuspendableObject::trace(visitor); | 237 SuspendableObject::trace(visitor); |
| 233 } | 238 } |
| 234 | 239 |
| 235 } // namespace blink | 240 } // namespace blink |
| OLD | NEW |