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

Unified Diff: Source/modules/webaudio/AudioBufferSourceNode.cpp

Issue 190953005: Support nullable buffer for AudioBufferSourceNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/modules/webaudio/AudioBufferSourceNode.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/AudioBufferSourceNode.cpp
diff --git a/Source/modules/webaudio/AudioBufferSourceNode.cpp b/Source/modules/webaudio/AudioBufferSourceNode.cpp
index 9541cdb3377d309e529c88ff0a06cc5ef854c8e7..37437a2e3072ea6aea496f20b309a33f44832dac 100644
--- a/Source/modules/webaudio/AudioBufferSourceNode.cpp
+++ b/Source/modules/webaudio/AudioBufferSourceNode.cpp
@@ -58,6 +58,7 @@ PassRefPtr<AudioBufferSourceNode> AudioBufferSourceNode::create(AudioContext* co
AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* context, float sampleRate)
: AudioScheduledSourceNode(context, sampleRate)
, m_buffer(nullptr)
+ , m_nullableBuffer(nullptr)
, m_isLooping(false)
, m_loopStart(0)
, m_loopEnd(0)
@@ -156,7 +157,10 @@ bool AudioBufferSourceNode::renderSilenceAndFinishIfNotLooping(AudioBus*, unsign
memset(m_destinationChannels[i] + index, 0, sizeof(float) * framesToProcess);
}
- finish();
+ // If buffer was set to null, it sould keep to render slience to ready rendering with proper buffer with setBuffer().
+ if (m_buffer != m_nullableBuffer)
+ finish();
+
return true;
}
return false;
@@ -334,11 +338,19 @@ bool AudioBufferSourceNode::renderFromBuffer(AudioBus* bus, unsigned destination
void AudioBufferSourceNode::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionState)
{
ASSERT(isMainThread());
- // FIXME: It does not look like we should throw if the buffer is null as
- // the attribute is nullable in the specification.
+
+ // If a buffer is null, it is one channel of silence according to specification.
if (!buffer) {
- exceptionState.throwTypeError("buffer cannot be null");
- return;
+ // Set mono channel, default frame = 512 and destination's sampleRate.
+ if (!m_nullableBuffer)
+ m_nullableBuffer = context()->createBuffer(1, 512, context()->sampleRate(), exceptionState);
+
+ if (!m_nullableBuffer) {
+ exceptionState.throwTypeError("failed creation of nullable buffer");
+ return;
+ }
+
+ buffer = m_nullableBuffer.get();
}
// The context must be locked since changing the buffer can re-configure the number of channels that are output.
« no previous file with comments | « Source/modules/webaudio/AudioBufferSourceNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698