Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioContext.cpp

Issue 1865583002: Implement BaseAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp b/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
index e45fbf22d878e21d2aca2e1e491cee4fa2fc6e2d..1e8d4473423300f28b22f2fa2e9e4b142c518abf 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
@@ -9,7 +9,12 @@
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
+#include "core/html/HTMLMediaElement.h"
+#include "modules/mediastream/MediaStream.h"
#include "modules/webaudio/AudioBufferCallback.h"
+#include "modules/webaudio/MediaElementAudioSourceNode.h"
+#include "modules/webaudio/MediaStreamAudioDestinationNode.h"
+#include "modules/webaudio/MediaStreamAudioSourceNode.h"
#include "platform/audio/AudioUtilities.h"
#if DEBUG_AUDIONODE_REFERENCES
@@ -24,7 +29,7 @@ const unsigned MaxHardwareContexts = 6;
static unsigned s_hardwareContextCount = 0;
static unsigned s_contextId = 0;
-AbstractAudioContext* AudioContext::create(Document& document, ExceptionState& exceptionState)
+AudioContext* AudioContext::create(Document& document, ExceptionState& exceptionState)
{
ASSERT(isMainThread());
if (s_hardwareContextCount >= MaxHardwareContexts) {
@@ -70,7 +75,7 @@ AbstractAudioContext* AudioContext::create(Document& document, ExceptionState& e
}
AudioContext::AudioContext(Document& document)
- : AbstractAudioContext(&document)
+ : BaseAudioContext(&document)
, m_contextId(s_contextId++)
{
}
@@ -85,7 +90,72 @@ AudioContext::~AudioContext()
DEFINE_TRACE(AudioContext)
{
visitor->trace(m_closeResolver);
- AbstractAudioContext::trace(visitor);
+ BaseAudioContext::trace(visitor);
+}
+
+MediaElementAudioSourceNode* AudioContext::createMediaElementSource(HTMLMediaElement* mediaElement, ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
+
+ if (isContextClosed()) {
+ throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ // First check if this media element already has a source node.
+ if (mediaElement->audioSourceNode()) {
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "HTMLMediaElement already connected previously to a different MediaElementSourceNode.");
+ return nullptr;
+ }
+
+ MediaElementAudioSourceNode* node = MediaElementAudioSourceNode::create(*this, *mediaElement);
+
+ mediaElement->setAudioSourceNode(node);
+
+ notifySourceNodeStartedProcessing(node); // context keeps reference until node is disconnected
+ return node;
+}
+
+MediaStreamAudioSourceNode* AudioContext::createMediaStreamSource(MediaStream* mediaStream, ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
+
+ if (isContextClosed()) {
+ throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ MediaStreamTrackVector audioTracks = mediaStream->getAudioTracks();
+ if (audioTracks.isEmpty()) {
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "MediaStream has no audio track");
+ return nullptr;
+ }
+
+ // Use the first audio track in the media stream.
+ MediaStreamTrack* audioTrack = audioTracks[0];
+ OwnPtr<AudioSourceProvider> provider = audioTrack->createWebAudioSource();
+ MediaStreamAudioSourceNode* node = MediaStreamAudioSourceNode::create(*this, *mediaStream, audioTrack, provider.release());
+
+ // FIXME: Only stereo streams are supported right now. We should be able to accept multi-channel streams.
+ node->setFormat(2, sampleRate());
+
+ notifySourceNodeStartedProcessing(node); // context keeps reference until node is disconnected
+ return node;
+}
+
+MediaStreamAudioDestinationNode* AudioContext::createMediaStreamDestination(ExceptionState& exceptionState)
+{
+ if (isContextClosed()) {
+ throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ // Set number of output channels to stereo by default.
+ return MediaStreamAudioDestinationNode::create(*this, 2);
}
ScriptPromise AudioContext::suspendContext(ScriptState* scriptState)
@@ -182,7 +252,7 @@ void AudioContext::didClose()
bool AudioContext::isContextClosed() const
{
- return m_closeResolver || AbstractAudioContext::isContextClosed();
+ return m_closeResolver || BaseAudioContext::isContextClosed();
}
void AudioContext::stopRendering()

Powered by Google App Engine
This is Rietveld 408576698