Commit f022b8fb authored by Hongchan Choi's avatar Hongchan Choi Committed by Commit Bot

Tidy up redundant call chain of CallbackBufferSize

CallbackBufferSize() were scattered around many classes for no specific
reason. This CL cleans them up and contains it to
DefaultAudioDestinationNode.

Bug: 854229
Change-Id: I9116cf8ecd9398108fcdcac89cbbfb8c42de957e
Reviewed-on: https://chromium-review.googlesource.com/1112072
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570081}
parent a212c946
...@@ -68,8 +68,6 @@ class AudioDestinationHandler : public AudioHandler, public AudioIOCallback { ...@@ -68,8 +68,6 @@ class AudioDestinationHandler : public AudioHandler, public AudioIOCallback {
// restart of the context. // restart of the context.
virtual void RestartRendering() = 0; virtual void RestartRendering() = 0;
// Returns the rendering callback buffer size.
size_t CallbackBufferSize() const override = 0;
virtual double SampleRate() const = 0; virtual double SampleRate() const = 0;
protected: protected:
...@@ -84,7 +82,6 @@ class AudioDestinationNode : public AudioNode { ...@@ -84,7 +82,6 @@ class AudioDestinationNode : public AudioNode {
AudioDestinationHandler& GetAudioDestinationHandler() const; AudioDestinationHandler& GetAudioDestinationHandler() const;
unsigned long maxChannelCount() const; unsigned long maxChannelCount() const;
size_t CallbackBufferSize() const { return Handler().CallbackBufferSize(); }
protected: protected:
AudioDestinationNode(BaseAudioContext&); AudioDestinationNode(BaseAudioContext&);
......
...@@ -238,11 +238,6 @@ class MODULES_EXPORT AudioHandler : public ThreadSafeRefCounted<AudioHandler> { ...@@ -238,11 +238,6 @@ class MODULES_EXPORT AudioHandler : public ThreadSafeRefCounted<AudioHandler> {
void UpdateChannelCountMode(); void UpdateChannelCountMode();
void UpdateChannelInterpretation(); void UpdateChannelInterpretation();
// Default callbackBufferSize should be the render quantum size
virtual size_t CallbackBufferSize() const {
return AudioUtilities::kRenderQuantumFrames;
}
protected: protected:
// Inputs and outputs must be created before the AudioHandler is // Inputs and outputs must be created before the AudioHandler is
// initialized. // initialized.
......
...@@ -147,11 +147,6 @@ class MODULES_EXPORT BaseAudioContext ...@@ -147,11 +147,6 @@ class MODULES_EXPORT BaseAudioContext
: ClosedContextSampleRate(); : ClosedContextSampleRate();
} }
size_t CallbackBufferSize() const {
return destination_node_ ? destination_node_->Handler().CallbackBufferSize()
: 0;
}
String state() const; String state() const;
AudioContextState ContextState() const { return context_state_; } AudioContextState ContextState() const { return context_state_; }
void ThrowExceptionForClosedState(ExceptionState&); void ThrowExceptionForClosedState(ExceptionState&);
......
...@@ -132,7 +132,7 @@ unsigned long DefaultAudioDestinationHandler::MaxChannelCount() const { ...@@ -132,7 +132,7 @@ unsigned long DefaultAudioDestinationHandler::MaxChannelCount() const {
return AudioDestination::MaxChannelCount(); return AudioDestination::MaxChannelCount();
} }
size_t DefaultAudioDestinationHandler::CallbackBufferSize() const { size_t DefaultAudioDestinationHandler::GetCallbackBufferSize() const {
return destination_->CallbackBufferSize(); return destination_->CallbackBufferSize();
} }
......
...@@ -55,10 +55,11 @@ class DefaultAudioDestinationHandler final : public AudioDestinationHandler { ...@@ -55,10 +55,11 @@ class DefaultAudioDestinationHandler final : public AudioDestinationHandler {
void StopRendering() override; void StopRendering() override;
void RestartRendering() override; void RestartRendering() override;
unsigned long MaxChannelCount() const override; unsigned long MaxChannelCount() const override;
// Returns the rendering callback buffer size.
size_t CallbackBufferSize() const override;
double SampleRate() const override; double SampleRate() const override;
// Returns a hadrware callback buffer size from audio infra.
size_t GetCallbackBufferSize() const;
// Returns a given frames-per-buffer size from audio infra. // Returns a given frames-per-buffer size from audio infra.
int GetFramesPerBuffer() const; int GetFramesPerBuffer() const;
...@@ -89,8 +90,6 @@ class DefaultAudioDestinationNode final : public AudioDestinationNode { ...@@ -89,8 +90,6 @@ class DefaultAudioDestinationNode final : public AudioDestinationNode {
static DefaultAudioDestinationNode* Create(BaseAudioContext*, static DefaultAudioDestinationNode* Create(BaseAudioContext*,
const WebAudioLatencyHint&); const WebAudioLatencyHint&);
size_t CallbackBufferSize() const { return Handler().CallbackBufferSize(); }
private: private:
explicit DefaultAudioDestinationNode(BaseAudioContext&, explicit DefaultAudioDestinationNode(BaseAudioContext&,
const WebAudioLatencyHint&); const WebAudioLatencyHint&);
......
...@@ -135,12 +135,6 @@ void OfflineAudioDestinationHandler::StopRendering() { ...@@ -135,12 +135,6 @@ void OfflineAudioDestinationHandler::StopRendering() {
NOTREACHED(); NOTREACHED();
} }
size_t OfflineAudioDestinationHandler::CallbackBufferSize() const {
// The callback buffer size has no meaning for an offline context.
NOTREACHED();
return 0;
}
void OfflineAudioDestinationHandler::InitializeOfflineRenderThread( void OfflineAudioDestinationHandler::InitializeOfflineRenderThread(
AudioBuffer* render_target) { AudioBuffer* render_target) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
......
...@@ -66,10 +66,6 @@ class OfflineAudioDestinationHandler final : public AudioDestinationHandler { ...@@ -66,10 +66,6 @@ class OfflineAudioDestinationHandler final : public AudioDestinationHandler {
void RestartRendering() override; void RestartRendering() override;
// Returns the rendering callback buffer size. This should never be
// called.
size_t CallbackBufferSize() const override;
double SampleRate() const override { return sample_rate_; } double SampleRate() const override { return sample_rate_; }
size_t RenderQuantumFrames() const { size_t RenderQuantumFrames() const {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "third_party/blink/renderer/modules/webaudio/audio_node_output.h" #include "third_party/blink/renderer/modules/webaudio/audio_node_output.h"
#include "third_party/blink/renderer/modules/webaudio/audio_processing_event.h" #include "third_party/blink/renderer/modules/webaudio/audio_processing_event.h"
#include "third_party/blink/renderer/modules/webaudio/base_audio_context.h" #include "third_party/blink/renderer/modules/webaudio/base_audio_context.h"
#include "third_party/blink/renderer/modules/webaudio/default_audio_destination_node.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/waitable_event.h" #include "third_party/blink/renderer/platform/waitable_event.h"
...@@ -373,7 +374,7 @@ static size_t ChooseBufferSize(size_t callback_buffer_size) { ...@@ -373,7 +374,7 @@ static size_t ChooseBufferSize(size_t callback_buffer_size) {
// Choose a buffer size based on the audio hardware buffer size. Arbitarily // Choose a buffer size based on the audio hardware buffer size. Arbitarily
// make it a power of two that is 4 times greater than the hardware buffer // make it a power of two that is 4 times greater than the hardware buffer
// size. // size.
// FIXME: What is the best way to choose this? // TODO(crbug.com/855758): What is the best way to choose this?
size_t buffer_size = size_t buffer_size =
1 << static_cast<unsigned>(log2(4 * callback_buffer_size) + 0.5); 1 << static_cast<unsigned>(log2(4 * callback_buffer_size) + 0.5);
...@@ -397,29 +398,29 @@ ScriptProcessorNode* ScriptProcessorNode::Create( ...@@ -397,29 +398,29 @@ ScriptProcessorNode* ScriptProcessorNode::Create(
ScriptProcessorNode* ScriptProcessorNode::Create( ScriptProcessorNode* ScriptProcessorNode::Create(
BaseAudioContext& context, BaseAudioContext& context,
size_t buffer_size, size_t requested_buffer_size,
ExceptionState& exception_state) { ExceptionState& exception_state) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
// Default is 2 inputs and 2 outputs. // Default is 2 inputs and 2 outputs.
return Create(context, buffer_size, 2, 2, exception_state); return Create(context, requested_buffer_size, 2, 2, exception_state);
} }
ScriptProcessorNode* ScriptProcessorNode::Create( ScriptProcessorNode* ScriptProcessorNode::Create(
BaseAudioContext& context, BaseAudioContext& context,
size_t buffer_size, size_t requested_buffer_size,
unsigned number_of_input_channels, unsigned number_of_input_channels,
ExceptionState& exception_state) { ExceptionState& exception_state) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
// Default is 2 outputs. // Default is 2 outputs.
return Create(context, buffer_size, number_of_input_channels, 2, return Create(context, requested_buffer_size, number_of_input_channels, 2,
exception_state); exception_state);
} }
ScriptProcessorNode* ScriptProcessorNode::Create( ScriptProcessorNode* ScriptProcessorNode::Create(
BaseAudioContext& context, BaseAudioContext& context,
size_t buffer_size, size_t requested_buffer_size,
unsigned number_of_input_channels, unsigned number_of_input_channels,
unsigned number_of_output_channels, unsigned number_of_output_channels,
ExceptionState& exception_state) { ExceptionState& exception_state) {
...@@ -455,17 +456,27 @@ ScriptProcessorNode* ScriptProcessorNode::Create( ...@@ -455,17 +456,27 @@ ScriptProcessorNode* ScriptProcessorNode::Create(
return nullptr; return nullptr;
} }
// Check for valid buffer size. // Sanitize user-supplied buffer size.
switch (buffer_size) { size_t buffer_size;
switch (requested_buffer_size) {
case 0: case 0:
// Choose an appropriate size. For an AudioContext, we need to // Choose an appropriate size. For an AudioContext, we need to
// choose an appropriate size based on the callback buffer size. // choose an appropriate size based on the callback buffer size.
// For OfflineAudioContext, there's no callback buffer size, so // For OfflineAudioContext, there's no callback buffer size, so
// just use the minimum valid buffer size. // just use the minimum valid buffer size.
if (context.HasRealtimeConstraint()) {
// TODO(crbug.com/854229): Due to the incompatible constructor between
// AudioDestinationNode and DefaultAudioDestinationNode, casting
// directly from |destination()| is impossible. This is a temporary
// workaround until the refactoring is completed.
DefaultAudioDestinationHandler& destination_handler =
static_cast<DefaultAudioDestinationHandler&>(
context.destination()->GetAudioDestinationHandler());
buffer_size = buffer_size =
context.HasRealtimeConstraint() ChooseBufferSize(destination_handler.GetCallbackBufferSize());
? ChooseBufferSize(context.destination()->CallbackBufferSize()) } else {
: 256; buffer_size = 256;
}
break; break;
case 256: case 256:
case 512: case 512:
...@@ -474,11 +485,12 @@ ScriptProcessorNode* ScriptProcessorNode::Create( ...@@ -474,11 +485,12 @@ ScriptProcessorNode* ScriptProcessorNode::Create(
case 4096: case 4096:
case 8192: case 8192:
case 16384: case 16384:
buffer_size = requested_buffer_size;
break; break;
default: default:
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kIndexSizeError, DOMExceptionCode::kIndexSizeError,
"buffer size (" + String::Number(buffer_size) + "buffer size (" + String::Number(requested_buffer_size) +
") must be 0 or a power of two between 256 and 16384."); ") must be 0 or a power of two between 256 and 16384.");
return nullptr; return nullptr;
} }
......
...@@ -126,14 +126,14 @@ class ScriptProcessorNode final ...@@ -126,14 +126,14 @@ class ScriptProcessorNode final
// The value chosen must carefully balance between latency and audio quality. // The value chosen must carefully balance between latency and audio quality.
static ScriptProcessorNode* Create(BaseAudioContext&, ExceptionState&); static ScriptProcessorNode* Create(BaseAudioContext&, ExceptionState&);
static ScriptProcessorNode* Create(BaseAudioContext&, static ScriptProcessorNode* Create(BaseAudioContext&,
size_t buffer_size, size_t requested_buffer_size,
ExceptionState&); ExceptionState&);
static ScriptProcessorNode* Create(BaseAudioContext&, static ScriptProcessorNode* Create(BaseAudioContext&,
size_t buffer_size, size_t requested_buffer_size,
unsigned number_of_input_channels, unsigned number_of_input_channels,
ExceptionState&); ExceptionState&);
static ScriptProcessorNode* Create(BaseAudioContext&, static ScriptProcessorNode* Create(BaseAudioContext&,
size_t buffer_size, size_t requested_buffer_size,
unsigned number_of_input_channels, unsigned number_of_input_channels,
unsigned number_of_output_channels, unsigned number_of_output_channels,
ExceptionState&); ExceptionState&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment