#include "modules/webaudio/AudioScheduledSourceNode.h"
-#include "bindings/v8/ExceptionState.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/CrossThreadTask.h"
#include "core/dom/ExceptionCode.h"
-#include "core/events/Event.h"
-#include "platform/audio/AudioUtilities.h"
+#include "modules/EventModules.h"
#include "modules/webaudio/AudioContext.h"
-#include <algorithm>
+#include "platform/audio/AudioUtilities.h"
#include "wtf/MathExtras.h"
+#include <algorithm>
-using namespace std;
-
-namespace WebCore {
+namespace blink {
const double AudioScheduledSourceNode::UnknownTime = -1;
if (m_playbackState == SCHEDULED_STATE) {
// Increment the active source count only if we're transitioning from SCHEDULED_STATE to PLAYING_STATE.
m_playbackState = PLAYING_STATE;
- context()->incrementActiveSourceCount();
}
quantumFrameOffset = startFrame > quantumStartFrame ? startFrame - quantumStartFrame : 0;
- quantumFrameOffset = min(quantumFrameOffset, quantumFrameSize); // clamp to valid range
+ quantumFrameOffset = std::min(quantumFrameOffset, quantumFrameSize); // clamp to valid range
nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset;
if (!nonSilentFramesToProcess) {
return;
}
-
void AudioScheduledSourceNode::start(double when, ExceptionState& exceptionState)
{
ASSERT(isMainThread());
return;
}
+ if (!std::isfinite(when) || (when < 0)) {
+ exceptionState.throwDOMException(
+ InvalidAccessError,
+ "Start time must be a finite non-negative number: " + String::number(when));
+ return;
+ }
+
m_startTime = when;
m_playbackState = SCHEDULED_STATE;
}
exceptionState.throwDOMException(
InvalidStateError,
"cannot call stop without calling start first.");
- } else {
- // stop() can be called more than once, with the last call to stop taking effect, unless the
- // source has already stopped due to earlier calls to stop. No exceptions are thrown in any
- // case.
- when = max(0.0, when);
- m_endTime = when;
+ return;
}
+
+ if (!std::isfinite(when) || (when < 0)) {
+ exceptionState.throwDOMException(
+ InvalidAccessError,
+ "Stop time must be a finite non-negative number: " + String::number(when));
+ return;
+ }
+
+ // stop() can be called more than once, with the last call to stop taking effect, unless the
+ // source has already stopped due to earlier calls to stop. No exceptions are thrown in any
+ // case.
+ when = std::max(0.0, when);
+ m_endTime = when;
}
-void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld)
+void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener)
{
m_hasEndedListener = listener;
- setAttributeEventListener(EventTypeNames::ended, listener, isolatedWorld);
+ setAttributeEventListener(EventTypeNames::ended, listener);
}
void AudioScheduledSourceNode::finish()
// Let the context dereference this AudioNode.
context()->notifyNodeFinishedProcessing(this);
m_playbackState = FINISHED_STATE;
- context()->decrementActiveSourceCount();
}
- if (m_hasEndedListener) {
- // |task| will keep the AudioScheduledSourceNode alive until the listener has been handled.
- OwnPtr<NotifyEndedTask> task = adoptPtr(new NotifyEndedTask(this));
- callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, task.leakPtr());
+ if (m_hasEndedListener && context()->executionContext()) {
+ context()->executionContext()->postTask(createCrossThreadTask(&AudioScheduledSourceNode::notifyEnded, this));
}
}
-void AudioScheduledSourceNode::notifyEndedDispatch(void* userData)
-{
- OwnPtr<NotifyEndedTask> task = adoptPtr(static_cast<NotifyEndedTask*>(userData));
-
- task->notifyEnded();
-}
-
-AudioScheduledSourceNode::NotifyEndedTask::NotifyEndedTask(PassRefPtr<AudioScheduledSourceNode> sourceNode)
- : m_scheduledNode(sourceNode)
-{
-}
-
-void AudioScheduledSourceNode::NotifyEndedTask::notifyEnded()
+void AudioScheduledSourceNode::notifyEnded()
{
- RefPtr<Event> event = Event::create(EventTypeNames::ended);
- event->setTarget(m_scheduledNode);
- m_scheduledNode->dispatchEvent(event.get());
+ dispatchEvent(Event::create(EventTypeNames::ended));
}
-} // namespace WebCore
+} // namespace blink
#endif // ENABLE(WEB_AUDIO)