#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/webcodecs/audio_data.h"
#include "base/compiler_specific.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "media/base/audio_buffer.h"
#include "media/base/audio_bus.h"
#include "media/base/limits.h"
#include "media/base/sample_format.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data_copy_to_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data_init.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink {
namespace {
std::optional<V8AudioSampleFormat> MediaFormatToBlinkFormat(
media::SampleFormat media_format) { … }
media::SampleFormat BlinkFormatToMediaFormat(V8AudioSampleFormat blink_format) { … }
template <typename SampleType>
void CopyToInterleaved(uint8_t* dest_data,
const std::vector<uint8_t*>& src_channels_data,
const int frame_offset,
const int frames_to_copy) { … }
template <typename SampleType>
void CopyToPlanar(uint8_t* dest_data,
const uint8_t* src_data,
const int src_channel_count,
const int dest_channel_index,
const int frame_offset,
const int frames_to_copy,
ExceptionState& exception_state) { … }
media::SampleFormat RemovePlanar(media::SampleFormat format) { … }
class ArrayBufferContentsAsAudioExternalMemory
: public media::AudioBuffer::ExternalMemory { … };
}
AudioData* AudioData::Create(ScriptState* script_state,
AudioDataInit* init,
ExceptionState& exception_state) { … }
AudioData::AudioData(ScriptState* script_state,
AudioDataInit* init,
ExceptionState& exception_state)
: … { … }
AudioData::AudioData(scoped_refptr<media::AudioBuffer> buffer)
: … { … }
AudioData::~AudioData() = default;
AudioData* AudioData::clone(ExceptionState& exception_state) { … }
void AudioData::close() { … }
int64_t AudioData::timestamp() const { … }
std::optional<V8AudioSampleFormat> AudioData::format() const { … }
float AudioData::sampleRate() const { … }
uint32_t AudioData::numberOfFrames() const { … }
uint32_t AudioData::numberOfChannels() const { … }
uint64_t AudioData::duration() const { … }
uint32_t AudioData::allocationSize(AudioDataCopyToOptions* copy_to_options,
ExceptionState& exception_state) { … }
void AudioData::copyTo(const AllowSharedBufferSource* destination,
AudioDataCopyToOptions* copy_to_options,
ExceptionState& exception_state) { … }
void AudioData::CopyConvert(base::span<uint8_t> dest,
AudioDataCopyToOptions* copy_to_options) { … }
void AudioData::CopyToInterleaved(base::span<uint8_t> dest,
AudioDataCopyToOptions* copy_to_options) { … }
void AudioData::CopyToPlanar(base::span<uint8_t> dest,
AudioDataCopyToOptions* copy_to_options,
ExceptionState& exception_state) { … }
void AudioData::Trace(Visitor* visitor) const { … }
}