| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 : AudioHandler(nodeType, node, sampleRate) | 40 : AudioHandler(nodeType, node, sampleRate) |
| 41 , m_startTime(0) | 41 , m_startTime(0) |
| 42 , m_endTime(UnknownTime) | 42 , m_endTime(UnknownTime) |
| 43 , m_playbackState(UNSCHEDULED_STATE) | 43 , m_playbackState(UNSCHEDULED_STATE) |
| 44 { | 44 { |
| 45 } | 45 } |
| 46 | 46 |
| 47 void AudioScheduledSourceHandler::updateSchedulingInfo( | 47 void AudioScheduledSourceHandler::updateSchedulingInfo( |
| 48 size_t quantumFrameSize, AudioBus* outputBus, size_t& quantumFrameOffset, si
ze_t& nonSilentFramesToProcess) | 48 size_t quantumFrameSize, AudioBus* outputBus, size_t& quantumFrameOffset, si
ze_t& nonSilentFramesToProcess) |
| 49 { | 49 { |
| 50 ASSERT(outputBus); | 50 DCHECK(outputBus); |
| 51 if (!outputBus) | 51 if (!outputBus) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 ASSERT(quantumFrameSize == ProcessingSizeInFrames); | 54 DCHECK_EQ(quantumFrameSize, ProcessingSizeInFrames); |
| 55 if (quantumFrameSize != ProcessingSizeInFrames) | 55 if (quantumFrameSize != ProcessingSizeInFrames) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 double sampleRate = this->sampleRate(); | 58 double sampleRate = this->sampleRate(); |
| 59 | 59 |
| 60 // quantumStartFrame : Start frame of the current time quantum. | 60 // quantumStartFrame : Start frame of the current time quantum. |
| 61 // quantumEndFrame : End frame of the current time quantum. | 61 // quantumEndFrame : End frame of the current time quantum. |
| 62 // startFrame : Start frame for this source. | 62 // startFrame : Start frame for this source. |
| 63 // endFrame : End frame for this source. | 63 // endFrame : End frame for this source. |
| 64 size_t quantumStartFrame = context()->currentSampleFrame(); | 64 size_t quantumStartFrame = context()->currentSampleFrame(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Handle silence after we're done playing. | 105 // Handle silence after we're done playing. |
| 106 // If the end time is somewhere in the middle of this time quantum, then zer
o out the | 106 // If the end time is somewhere in the middle of this time quantum, then zer
o out the |
| 107 // frames from the end time to the very end of the quantum. | 107 // frames from the end time to the very end of the quantum. |
| 108 if (m_endTime != UnknownTime && endFrame >= quantumStartFrame && endFrame <
quantumEndFrame) { | 108 if (m_endTime != UnknownTime && endFrame >= quantumStartFrame && endFrame <
quantumEndFrame) { |
| 109 size_t zeroStartFrame = endFrame - quantumStartFrame; | 109 size_t zeroStartFrame = endFrame - quantumStartFrame; |
| 110 size_t framesToZero = quantumFrameSize - zeroStartFrame; | 110 size_t framesToZero = quantumFrameSize - zeroStartFrame; |
| 111 | 111 |
| 112 bool isSafe = zeroStartFrame < quantumFrameSize && framesToZero <= quant
umFrameSize && zeroStartFrame + framesToZero <= quantumFrameSize; | 112 bool isSafe = zeroStartFrame < quantumFrameSize && framesToZero <= quant
umFrameSize && zeroStartFrame + framesToZero <= quantumFrameSize; |
| 113 ASSERT(isSafe); | 113 DCHECK(isSafe); |
| 114 | 114 |
| 115 if (isSafe) { | 115 if (isSafe) { |
| 116 if (framesToZero > nonSilentFramesToProcess) | 116 if (framesToZero > nonSilentFramesToProcess) |
| 117 nonSilentFramesToProcess = 0; | 117 nonSilentFramesToProcess = 0; |
| 118 else | 118 else |
| 119 nonSilentFramesToProcess -= framesToZero; | 119 nonSilentFramesToProcess -= framesToZero; |
| 120 | 120 |
| 121 for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i) | 121 for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i) |
| 122 memset(outputBus->channel(i)->mutableData() + zeroStartFrame, 0,
sizeof(float) * framesToZero); | 122 memset(outputBus->channel(i)->mutableData() + zeroStartFrame, 0,
sizeof(float) * framesToZero); |
| 123 } | 123 } |
| 124 | 124 |
| 125 finish(); | 125 finish(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void AudioScheduledSourceHandler::start(double when, ExceptionState& exceptionSt
ate) | 131 void AudioScheduledSourceHandler::start(double when, ExceptionState& exceptionSt
ate) |
| 132 { | 132 { |
| 133 ASSERT(isMainThread()); | 133 DCHECK(isMainThread()); |
| 134 | 134 |
| 135 context()->recordUserGestureState(); | 135 context()->recordUserGestureState(); |
| 136 | 136 |
| 137 if (playbackState() != UNSCHEDULED_STATE) { | 137 if (playbackState() != UNSCHEDULED_STATE) { |
| 138 exceptionState.throwDOMException( | 138 exceptionState.throwDOMException( |
| 139 InvalidStateError, | 139 InvalidStateError, |
| 140 "cannot call start more than once."); | 140 "cannot call start more than once."); |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 | 143 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 162 | 162 |
| 163 // If |when| < currentTime, the source must start now according to the spec. | 163 // If |when| < currentTime, the source must start now according to the spec. |
| 164 // So just set startTime to currentTime in this case to start the source now
. | 164 // So just set startTime to currentTime in this case to start the source now
. |
| 165 m_startTime = std::max(when, context()->currentTime()); | 165 m_startTime = std::max(when, context()->currentTime()); |
| 166 | 166 |
| 167 setPlaybackState(SCHEDULED_STATE); | 167 setPlaybackState(SCHEDULED_STATE); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void AudioScheduledSourceHandler::stop(double when, ExceptionState& exceptionSta
te) | 170 void AudioScheduledSourceHandler::stop(double when, ExceptionState& exceptionSta
te) |
| 171 { | 171 { |
| 172 ASSERT(isMainThread()); | 172 DCHECK(isMainThread()); |
| 173 | 173 |
| 174 if (playbackState() == UNSCHEDULED_STATE) { | 174 if (playbackState() == UNSCHEDULED_STATE) { |
| 175 exceptionState.throwDOMException( | 175 exceptionState.throwDOMException( |
| 176 InvalidStateError, | 176 InvalidStateError, |
| 177 "cannot call stop without calling start first."); | 177 "cannot call stop without calling start first."); |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 | 180 |
| 181 if (when < 0) { | 181 if (when < 0) { |
| 182 exceptionState.throwDOMException( | 182 exceptionState.throwDOMException( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 211 { | 211 { |
| 212 finishWithoutOnEnded(); | 212 finishWithoutOnEnded(); |
| 213 | 213 |
| 214 if (context()->getExecutionContext()) { | 214 if (context()->getExecutionContext()) { |
| 215 context()->getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossT
hreadTask(&AudioScheduledSourceHandler::notifyEnded, PassRefPtr<AudioScheduledSo
urceHandler>(this))); | 215 context()->getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossT
hreadTask(&AudioScheduledSourceHandler::notifyEnded, PassRefPtr<AudioScheduledSo
urceHandler>(this))); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 void AudioScheduledSourceHandler::notifyEnded() | 219 void AudioScheduledSourceHandler::notifyEnded() |
| 220 { | 220 { |
| 221 ASSERT(isMainThread()); | 221 DCHECK(isMainThread()); |
| 222 if (node()) | 222 if (node()) |
| 223 node()->dispatchEvent(Event::create(EventTypeNames::ended)); | 223 node()->dispatchEvent(Event::create(EventTypeNames::ended)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // ---------------------------------------------------------------- | 226 // ---------------------------------------------------------------- |
| 227 | 227 |
| 228 AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext& context) | 228 AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext& context) |
| 229 : AudioSourceNode(context) | 229 : AudioSourceNode(context) |
| 230 , ActiveScriptWrappable(this) | 230 , ActiveScriptWrappable(this) |
| 231 { | 231 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // playback state if the context is closed. | 272 // playback state if the context is closed. |
| 273 if (context()->isContextClosed()) | 273 if (context()->isContextClosed()) |
| 274 return false; | 274 return false; |
| 275 | 275 |
| 276 // If a node is scheduled or playing, do not collect the node prematurely | 276 // If a node is scheduled or playing, do not collect the node prematurely |
| 277 // even its reference is out of scope. Then fire onended event if assigned. | 277 // even its reference is out of scope. Then fire onended event if assigned. |
| 278 return audioScheduledSourceHandler().isPlayingOrScheduled(); | 278 return audioScheduledSourceHandler().isPlayingOrScheduled(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace blink | 281 } // namespace blink |
| OLD | NEW |