#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/base/audio_buffer.h"
#include <cmath>
#include "base/bits.h"
#include "base/containers/heap_array.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "media/base/audio_bus.h"
#include "media/base/limits.h"
#include "media/base/timestamp_constants.h"
namespace media {
AudioBuffer::ExternalMemory::ExternalMemory() = default;
AudioBuffer::ExternalMemory::ExternalMemory(base::span<uint8_t> span)
: … { … }
AudioBuffer::ExternalMemory::~ExternalMemory() = default;
AudioBuffer::ExternalMemory::ExternalMemory(const ExternalMemory&) = default;
AudioBuffer::ExternalMemory::ExternalMemory(ExternalMemory&&) = default;
namespace {
template <class SourceSampleTypeTraits>
void CopyConvertFromInterleaved(
const typename SourceSampleTypeTraits::ValueType* source_buffer,
int num_frames_to_write,
const std::vector<float*> dest) { … }
class SelfOwnedMemory : public AudioBuffer::ExternalMemory { … };
std::unique_ptr<AudioBuffer::ExternalMemory> AllocateMemory(size_t size) { … }
}
static base::TimeDelta CalculateDuration(int frames, double sample_rate) { … }
AudioBufferMemoryPool::AudioBufferMemoryPool(int alignment)
: … { … }
AudioBufferMemoryPool::~AudioBufferMemoryPool() = default;
AudioBufferMemoryPool::ExternalMemoryFromPool::ExternalMemoryFromPool(
ExternalMemoryFromPool&& am) = default;
AudioBufferMemoryPool::ExternalMemoryFromPool::ExternalMemoryFromPool(
scoped_refptr<AudioBufferMemoryPool> pool,
std::unique_ptr<uint8_t, base::AlignedFreeDeleter> memory,
size_t size)
: … { … }
AudioBufferMemoryPool::ExternalMemoryFromPool::~ExternalMemoryFromPool() { … }
size_t AudioBufferMemoryPool::GetPoolSizeForTesting() { … }
std::unique_ptr<AudioBufferMemoryPool::ExternalMemoryFromPool>
AudioBufferMemoryPool::CreateBuffer(size_t size) { … }
void AudioBufferMemoryPool::ReturnBuffer(ExternalMemoryFromPool memory) { … }
AudioBuffer::AudioBuffer(SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
bool create_buffer,
const uint8_t* const* data,
const size_t data_size,
const base::TimeDelta timestamp,
scoped_refptr<AudioBufferMemoryPool> pool)
: … { … }
AudioBuffer::AudioBuffer(SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
const base::TimeDelta timestamp,
std::unique_ptr<ExternalMemory> external_memory)
: … { … }
AudioBuffer::~AudioBuffer() = default;
scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom(
SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
const uint8_t* const* data,
const base::TimeDelta timestamp,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom(
ChannelLayout channel_layout,
int sample_rate,
const base::TimeDelta timestamp,
const AudioBus* audio_bus,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom(
int sample_rate,
const base::TimeDelta timestamp,
const AudioBus* audio_bus,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CopyBitstreamFrom(
SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
const uint8_t* const* data,
const size_t data_size,
const base::TimeDelta timestamp,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CreateBuffer(
SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CreateBitstreamBuffer(
SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
size_t data_size,
scoped_refptr<AudioBufferMemoryPool> pool) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CreateEmptyBuffer(
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
const base::TimeDelta timestamp) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CreateFromExternalMemory(
SampleFormat sample_format,
ChannelLayout channel_layout,
int channel_count,
int sample_rate,
int frame_count,
const base::TimeDelta timestamp,
std::unique_ptr<AudioBuffer::ExternalMemory> external_memory) { … }
scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() { … }
std::unique_ptr<AudioBus> AudioBuffer::WrapOrCopyToAudioBus(
scoped_refptr<AudioBuffer> buffer) { … }
void AudioBuffer::AdjustSampleRate(int sample_rate) { … }
void AudioBuffer::ReadFrames(int frames_to_copy,
int source_frame_offset,
int dest_frame_offset,
AudioBus* dest) const { … }
void AudioBuffer::TrimStart(int frames_to_trim) { … }
void AudioBuffer::TrimEnd(int frames_to_trim) { … }
void AudioBuffer::TrimRange(int start, int end) { … }
bool AudioBuffer::IsBitstreamFormat() const { … }
}