#include "third_party/blink/renderer/platform/audio/audio_destination.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/feature_list.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_glitch_info.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_audio_latency_hint.h"
#include "third_party/blink/public/platform/web_audio_sink_descriptor.h"
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
#include "third_party/blink/renderer/platform/audio/push_pull_fifo.h"
#include "third_party/blink/renderer/platform/audio/vector_math.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_media.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
namespace blink {
namespace {
constexpr uint32_t kFIFOSize = …;
const char* DeviceStateToString(AudioDestination::DeviceState state) { … }
}
scoped_refptr<AudioDestination> AudioDestination::Create(
AudioIOCallback& callback,
const WebAudioSinkDescriptor& sink_descriptor,
unsigned number_of_output_channels,
const WebAudioLatencyHint& latency_hint,
std::optional<float> context_sample_rate,
unsigned render_quantum_frames) { … }
AudioDestination::~AudioDestination() { … }
int AudioDestination::Render(base::TimeDelta delay,
base::TimeTicks delay_timestamp,
const media::AudioGlitchInfo& glitch_info,
media::AudioBus* dest) { … }
void AudioDestination::OnRenderError() { … }
void AudioDestination::Start() { … }
void AudioDestination::Stop() { … }
void AudioDestination::Pause() { … }
void AudioDestination::Resume() { … }
void AudioDestination::SetWorkletTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> worklet_task_runner) { … }
void AudioDestination::StartWithWorkletTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> worklet_task_runner) { … }
bool AudioDestination::IsPlaying() { … }
double AudioDestination::SampleRate() const { … }
uint32_t AudioDestination::CallbackBufferSize() const { … }
int AudioDestination::FramesPerBuffer() const { … }
base::TimeDelta AudioDestination::GetPlatformBufferDuration() const { … }
uint32_t AudioDestination::MaxChannelCount() const { … }
void AudioDestination::SetDetectSilence(bool detect_silence) { … }
AudioDestination::AudioDestination(
AudioIOCallback& callback,
const WebAudioSinkDescriptor& sink_descriptor,
unsigned number_of_output_channels,
const WebAudioLatencyHint& latency_hint,
std::optional<float> context_sample_rate,
unsigned render_quantum_frames)
: … { … }
void AudioDestination::SetDeviceState(DeviceState state) { … }
void AudioDestination::RequestRenderWait(
size_t frames_requested,
size_t frames_to_render,
base::TimeDelta delay,
base::TimeTicks delay_timestamp,
const media::AudioGlitchInfo& glitch_info) { … }
void AudioDestination::RequestRender(
size_t frames_requested,
size_t frames_to_render,
base::TimeDelta delay,
base::TimeTicks delay_timestamp,
const media::AudioGlitchInfo& glitch_info) { … }
void AudioDestination::ProvideResamplerInput(int resampler_frame_delay,
AudioBus* dest) { … }
void AudioDestination::SendLogMessage(const String& message) const { … }
void AudioDestination::PullFromCallback(AudioBus* destination_bus,
base::TimeDelta delay) { … }
media::OutputDeviceStatus AudioDestination::MaybeCreateSinkAndGetStatus() { … }
}