chromium/third_party/blink/renderer/modules/webaudio/audio_context.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/webaudio/audio_context.h"

#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/mediastream/media_devices.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/public/platform/web_audio_latency_hint.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_context_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_timestamp.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_audiocontextlatencycategory_double.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream.h"
#include "third_party/blink/renderer/modules/peerconnection/peer_connection_dependency_factory.h"
#include "third_party/blink/renderer/modules/permissions/permission_utils.h"
#include "third_party/blink/renderer/modules/webaudio/audio_listener.h"
#include "third_party/blink/renderer/modules/webaudio/audio_playout_stats.h"
#include "third_party/blink/renderer/modules/webaudio/audio_sink_info.h"
#include "third_party/blink/renderer/modules/webaudio/media_element_audio_source_node.h"
#include "third_party/blink/renderer/modules/webaudio/media_stream_audio_destination_node.h"
#include "third_party/blink/renderer/modules/webaudio/media_stream_audio_source_node.h"
#include "third_party/blink/renderer/modules/webaudio/realtime_audio_destination_node.h"
#include "third_party/blink/renderer/modules/webrtc/webrtc_audio_device_impl.h"
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
#include "third_party/blink/renderer/platform/audio/vector_math.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

#if DEBUG_AUDIONODE_REFERENCES
#include <stdio.h>
#endif

namespace blink {

namespace {

// Number of AudioContexts still alive.  It's incremented when an
// AudioContext is created and decremented when the context is closed.
unsigned hardware_context_count =;

// A context ID that is incremented for each context that is created.
// This initializes the internal id for the context.
unsigned context_id =;

// When the client does not have enough permission, the outputLatency property
// is quantized by 8ms to reduce the precision for privacy concerns.
constexpr double kOutputLatencyQuatizingFactor =;

// When the client has enough permission, the outputLatency property gets
// 1ms precision.
constexpr double kOutputLatencyMaxPrecisionFactor =;

// Operations tracked in the WebAudio.AudioContext.Operation histogram.
enum class AudioContextOperation {};

void RecordAudioContextOperation(AudioContextOperation operation) {}

const char* LatencyCategoryToString(
    WebAudioLatencyHint::AudioContextLatencyCategory category) {}

String GetAudioContextLogString(const WebAudioLatencyHint& latency_hint,
                                std::optional<float> sample_rate) {}

bool IsAudible(const AudioBus* rendered_data) {}

SetSinkIdResolver;

}  // namespace

AudioContext* AudioContext::Create(ExecutionContext* context,
                                   const AudioContextOptions* context_options,
                                   ExceptionState& exception_state) {}

AudioContext::AudioContext(LocalDOMWindow& window,
                           const WebAudioLatencyHint& latency_hint,
                           std::optional<float> sample_rate,
                           WebAudioSinkDescriptor sink_descriptor,
                           bool update_echo_cancellation_on_first_start)
    :{}

void AudioContext::Uninitialize() {}

AudioContext::~AudioContext() {}

void AudioContext::Trace(Visitor* visitor) const {}

ScriptPromise<IDLUndefined> AudioContext::suspendContext(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> AudioContext::resumeContext(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

bool AudioContext::IsPullingAudioGraph() const {}

AudioTimestamp* AudioContext::getOutputTimestamp(
    ScriptState* script_state) const {}

ScriptPromise<IDLUndefined> AudioContext::closeContext(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

void AudioContext::DidClose() {}

bool AudioContext::IsContextCleared() const {}

void AudioContext::StartRendering() {}

void AudioContext::StopRendering() {}

void AudioContext::SuspendRendering() {}

double AudioContext::baseLatency() const {}

double AudioContext::outputLatency() const {}

AudioPlayoutStats* AudioContext::playoutStats() {}

ScriptPromise<IDLUndefined> AudioContext::setSinkId(
    ScriptState* script_state,
    const V8UnionAudioSinkOptionsOrString* v8_sink_id,
    ExceptionState& exception_state) {}

MediaElementAudioSourceNode* AudioContext::createMediaElementSource(
    HTMLMediaElement* media_element,
    ExceptionState& exception_state) {}

MediaStreamAudioSourceNode* AudioContext::createMediaStreamSource(
    MediaStream* media_stream,
    ExceptionState& exception_state) {}

MediaStreamAudioDestinationNode* AudioContext::createMediaStreamDestination(
    ExceptionState& exception_state) {}

void AudioContext::NotifySourceNodeStart() {}

AutoplayPolicy::Type AudioContext::GetAutoplayPolicy() const {}

bool AudioContext::AreAutoplayRequirementsFulfilled() const {}

void AudioContext::MaybeAllowAutoplayWithUnlockType(AutoplayUnlockType type) {}

bool AudioContext::IsAllowedToStart() const {}

void AudioContext::RecordAutoplayMetrics() {}

void AudioContext::ContextDestroyed() {}

bool AudioContext::HasPendingActivity() const {}

RealtimeAudioDestinationNode* AudioContext::GetRealtimeAudioDestinationNode()
    const {}

bool AudioContext::HandlePreRenderTasks(
    uint32_t frames_to_process,
    const AudioIOPosition* output_position,
    const AudioCallbackMetric* metric,
    base::TimeDelta playout_delay,
    const media::AudioGlitchInfo& glitch_info) {}

void AudioContext::NotifyAudibleAudioStarted() {}

void AudioContext::HandlePostRenderTasks() {}

void AudioContext::HandleAudibility(AudioBus* destination_bus) {}

void AudioContext::ResolvePromisesForUnpause() {}

AudioIOPosition AudioContext::OutputPosition() const {}

void AudioContext::NotifyAudibleAudioStopped() {}

void AudioContext::EnsureAudioContextManagerService() {}

void AudioContext::OnAudioContextManagerServiceConnectionError() {}

void AudioContext::SendLogMessage(const String& message) {}

AudioCallbackMetric AudioContext::GetCallbackMetric() const {}

base::TimeDelta AudioContext::PlatformBufferDuration() const {}

void AudioContext::OnPermissionStatusChange(
    mojom::blink::PermissionStatus status) {}

void AudioContext::DidInitialPermissionCheck(
    mojom::blink::PermissionDescriptorPtr descriptor,
    mojom::blink::PermissionStatus status) {}

double AudioContext::GetOutputLatencyQuantizingFactor() const {}

void AudioContext::NotifySetSinkIdBegins() {}

void AudioContext::NotifySetSinkIdIsDone(
    WebAudioSinkDescriptor pending_sink_descriptor) {}

void AudioContext::InitializeMediaDeviceService() {}

void AudioContext::DevicesEnumerated(
    const Vector<Vector<WebMediaDeviceInfo>>& enumeration,
    Vector<mojom::blink::VideoInputDeviceCapabilitiesPtr>
        video_input_capabilities,
    Vector<mojom::blink::AudioInputDeviceCapabilitiesPtr>
        audio_input_capabilities) {}

void AudioContext::OnDevicesChanged(mojom::blink::MediaDeviceType device_type,
                                    const Vector<WebMediaDeviceInfo>& devices) {}

void AudioContext::UninitializeMediaDeviceService() {}

void AudioContext::UpdateV8SinkId() {}

bool AudioContext::IsValidSinkDescriptor(
    const WebAudioSinkDescriptor& sink_descriptor) {}

void AudioContext::OnRenderError() {}

void AudioContext::ResumeOnPrerenderActivation() {}

void AudioContext::TransferAudioFrameStatsTo(
    AudioFrameStatsAccumulator& receiver) {}

void AudioContext::HandleRenderError() {}

void AudioContext::invoke_onrendererror_from_platform_for_testing() {}

}  // namespace blink