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 18 matching lines...) Expand all Loading... |
29 #include "modules/webaudio/AudioScheduledSourceNode.h" | 29 #include "modules/webaudio/AudioScheduledSourceNode.h" |
30 | 30 |
31 #include "bindings/v8/ExceptionState.h" | 31 #include "bindings/v8/ExceptionState.h" |
32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
33 #include "modules/EventModules.h" | 33 #include "modules/EventModules.h" |
34 #include "modules/webaudio/AudioContext.h" | 34 #include "modules/webaudio/AudioContext.h" |
35 #include "platform/audio/AudioUtilities.h" | 35 #include "platform/audio/AudioUtilities.h" |
36 #include <algorithm> | 36 #include <algorithm> |
37 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
38 | 38 |
39 using namespace std; | |
40 | |
41 namespace WebCore { | 39 namespace WebCore { |
42 | 40 |
43 const double AudioScheduledSourceNode::UnknownTime = -1; | 41 const double AudioScheduledSourceNode::UnknownTime = -1; |
44 | 42 |
45 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float
sampleRate) | 43 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float
sampleRate) |
46 : AudioSourceNode(context, sampleRate) | 44 : AudioSourceNode(context, sampleRate) |
47 , m_playbackState(UNSCHEDULED_STATE) | 45 , m_playbackState(UNSCHEDULED_STATE) |
48 , m_startTime(0) | 46 , m_startTime(0) |
49 , m_endTime(UnknownTime) | 47 , m_endTime(UnknownTime) |
50 , m_hasEndedListener(false) | 48 , m_hasEndedListener(false) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return; | 84 return; |
87 } | 85 } |
88 | 86 |
89 // Check if it's time to start playing. | 87 // Check if it's time to start playing. |
90 if (m_playbackState == SCHEDULED_STATE) { | 88 if (m_playbackState == SCHEDULED_STATE) { |
91 // Increment the active source count only if we're transitioning from SC
HEDULED_STATE to PLAYING_STATE. | 89 // Increment the active source count only if we're transitioning from SC
HEDULED_STATE to PLAYING_STATE. |
92 m_playbackState = PLAYING_STATE; | 90 m_playbackState = PLAYING_STATE; |
93 } | 91 } |
94 | 92 |
95 quantumFrameOffset = startFrame > quantumStartFrame ? startFrame - quantumSt
artFrame : 0; | 93 quantumFrameOffset = startFrame > quantumStartFrame ? startFrame - quantumSt
artFrame : 0; |
96 quantumFrameOffset = min(quantumFrameOffset, quantumFrameSize); // clamp to
valid range | 94 quantumFrameOffset = std::min(quantumFrameOffset, quantumFrameSize); // clam
p to valid range |
97 nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset; | 95 nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset; |
98 | 96 |
99 if (!nonSilentFramesToProcess) { | 97 if (!nonSilentFramesToProcess) { |
100 // Output silence. | 98 // Output silence. |
101 outputBus->zero(); | 99 outputBus->zero(); |
102 return; | 100 return; |
103 } | 101 } |
104 | 102 |
105 // Handle silence before we start playing. | 103 // Handle silence before we start playing. |
106 // Zero any initial frames representing silence leading up to a rendering st
art time in the middle of the quantum. | 104 // Zero any initial frames representing silence leading up to a rendering st
art time in the middle of the quantum. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 ASSERT(isMainThread()); | 153 ASSERT(isMainThread()); |
156 | 154 |
157 if (m_playbackState == UNSCHEDULED_STATE) { | 155 if (m_playbackState == UNSCHEDULED_STATE) { |
158 exceptionState.throwDOMException( | 156 exceptionState.throwDOMException( |
159 InvalidStateError, | 157 InvalidStateError, |
160 "cannot call stop without calling start first."); | 158 "cannot call stop without calling start first."); |
161 } else { | 159 } else { |
162 // stop() can be called more than once, with the last call to stop takin
g effect, unless the | 160 // stop() can be called more than once, with the last call to stop takin
g effect, unless the |
163 // source has already stopped due to earlier calls to stop. No exception
s are thrown in any | 161 // source has already stopped due to earlier calls to stop. No exception
s are thrown in any |
164 // case. | 162 // case. |
165 when = max(0.0, when); | 163 when = std::max(0.0, when); |
166 m_endTime = when; | 164 m_endTime = when; |
167 } | 165 } |
168 } | 166 } |
169 | 167 |
170 void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener) | 168 void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener) |
171 { | 169 { |
172 m_hasEndedListener = listener; | 170 m_hasEndedListener = listener; |
173 setAttributeEventListener(EventTypeNames::ended, listener); | 171 setAttributeEventListener(EventTypeNames::ended, listener); |
174 } | 172 } |
175 | 173 |
(...skipping 27 matching lines...) Expand all Loading... |
203 void AudioScheduledSourceNode::NotifyEndedTask::notifyEnded() | 201 void AudioScheduledSourceNode::NotifyEndedTask::notifyEnded() |
204 { | 202 { |
205 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::ended); | 203 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::ended); |
206 event->setTarget(m_scheduledNode.get()); | 204 event->setTarget(m_scheduledNode.get()); |
207 m_scheduledNode->dispatchEvent(event.get()); | 205 m_scheduledNode->dispatchEvent(event.get()); |
208 } | 206 } |
209 | 207 |
210 } // namespace WebCore | 208 } // namespace WebCore |
211 | 209 |
212 #endif // ENABLE(WEB_AUDIO) | 210 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |