#include "third_party/blink/renderer/modules/webcodecs/audio_encoder.h"
#include <cinttypes>
#include <limits>
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "media/audio/audio_opus_encoder.h"
#include "media/base/audio_parameters.h"
#include "media/base/limits.h"
#include "media/base/mime_util.h"
#include "media/base/offloading_audio_encoder.h"
#include "media/mojo/clients/mojo_audio_encoder.h"
#include "media/mojo/mojom/interface_factory.mojom.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_aac_encoder_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_decoder_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_support.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_encoded_audio_chunk_metadata.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_opus_application.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_opus_encoder_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_opus_signal.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
#include "third_party/blink/renderer/modules/webcodecs/array_buffer_util.h"
#include "third_party/blink/renderer/modules/webcodecs/encoded_audio_chunk.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
namespace blink {
namespace {
constexpr const char kCategory[] = …;
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
constexpr uint32_t kDefaultOpusComplexity = 5;
#else
constexpr uint32_t kDefaultOpusComplexity = …;
#endif
template <typename T>
bool VerifyParameterValues(const T& value,
String error_message_base_base,
WTF::Vector<T> supported_values,
String* js_error_message) { … }
AudioEncoderTraits::ParsedConfig* ParseAacConfigStatic(
const AacEncoderConfig* aac_config,
AudioEncoderTraits::ParsedConfig* result,
ExceptionState& exception_state) { … }
AudioEncoderTraits::ParsedConfig* ParseOpusConfigStatic(
const OpusEncoderConfig* opus_config,
AudioEncoderTraits::ParsedConfig* result,
ExceptionState& exception_state) { … }
AudioEncoderTraits::ParsedConfig* ParseConfigStatic(
const AudioEncoderConfig* config,
ExceptionState& exception_state) { … }
bool VerifyCodecSupportStatic(AudioEncoderTraits::ParsedConfig* config,
String* js_error_message) { … }
AacEncoderConfig* CopyAacConfig(const AacEncoderConfig& config) { … }
OpusEncoderConfig* CopyOpusConfig(const OpusEncoderConfig& config) { … }
AudioEncoderConfig* CopyConfig(const AudioEncoderConfig& config) { … }
std::unique_ptr<media::AudioEncoder> CreateSoftwareAudioEncoder(
media::AudioCodec codec) { … }
std::unique_ptr<media::AudioEncoder> CreatePlatformAudioEncoder(
media::AudioCodec codec) { … }
}
const char* AudioEncoderTraits::GetName() { … }
AudioEncoder* AudioEncoder::Create(ScriptState* script_state,
const AudioEncoderInit* init,
ExceptionState& exception_state) { … }
AudioEncoder::AudioEncoder(ScriptState* script_state,
const AudioEncoderInit* init,
ExceptionState& exception_state)
: … { … }
AudioEncoder::~AudioEncoder() = default;
std::unique_ptr<media::AudioEncoder> AudioEncoder::CreateMediaAudioEncoder(
const ParsedConfig& config) { … }
void AudioEncoder::ProcessConfigure(Request* request) { … }
void AudioEncoder::ProcessEncode(Request* request) { … }
void AudioEncoder::ProcessReconfigure(Request* request) { … }
AudioEncoder::ParsedConfig* AudioEncoder::ParseConfig(
const AudioEncoderConfig* opts,
ExceptionState& exception_state) { … }
bool AudioEncoder::CanReconfigure(ParsedConfig& original_config,
ParsedConfig& new_config) { … }
bool AudioEncoder::VerifyCodecSupport(ParsedConfig* config,
String* js_error_message) { … }
void AudioEncoder::CallOutputCallback(
ParsedConfig* active_config,
uint32_t reset_count,
media::EncodedAudioBuffer encoded_buffer,
std::optional<media::AudioEncoder::CodecDescription> codec_desc) { … }
ScriptPromise<AudioEncoderSupport> AudioEncoder::isConfigSupported(
ScriptState* script_state,
const AudioEncoderConfig* config,
ExceptionState& exception_state) { … }
const AtomicString& AudioEncoder::InterfaceName() const { … }
DOMException* AudioEncoder::MakeOperationError(std::string error_msg,
media::EncoderStatus status) { … }
DOMException* AudioEncoder::MakeEncodingError(std::string error_msg,
media::EncoderStatus status) { … }
}