#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/audio/wav_audio_handler.h"
#include <algorithm>
#include <cstring>
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/containers/span_reader.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/numerics/byte_conversions.h"
#include "build/build_config.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_timestamp_helper.h"
#include "media/base/limits.h"
namespace media {
namespace {
const uint8_t kChunkId[] = …;
const uint8_t kFormat[] = …;
const uint8_t kFmtSubchunkId[] = …;
const uint8_t kDataSubchunkId[] = …;
const size_t kChunkHeaderSize = …;
const size_t kFmtChunkMinimumSize = …;
const size_t kFmtChunkExtensibleMinimumSize = …;
const size_t kAudioFormatOffset = …;
const size_t kChannelOffset = …;
const size_t kSampleRateOffset = …;
const size_t kBitsPerSampleOffset = …;
const size_t kValidBitsPerSampleOffset = …;
const size_t kSubFormatOffset = …;
struct WavAudioParameters { … };
bool ParamsAreValid(const WavAudioParameters& params) { … }
bool ParseFmtChunk(base::span<const uint8_t> data, WavAudioParameters* params) { … }
bool ParseWavData(const std::string_view wav_data,
std::string_view* audio_data_out,
WavAudioParameters* params_out) { … }
}
WavAudioHandler::WavAudioHandler(std::string_view audio_data,
uint16_t num_channels,
uint32_t sample_rate,
uint16_t bits_per_sample,
AudioFormat audio_format)
: … { … }
WavAudioHandler::~WavAudioHandler() = default;
std::unique_ptr<WavAudioHandler> WavAudioHandler::Create(
std::string_view wav_data) { … }
bool WavAudioHandler::Initialize() { … }
int WavAudioHandler::GetNumChannels() const { … }
int WavAudioHandler::GetSampleRate() const { … }
bool WavAudioHandler::AtEnd() const { … }
bool WavAudioHandler::CopyTo(AudioBus* bus, size_t* frames_written) { … }
base::TimeDelta WavAudioHandler::GetDuration() const { … }
void WavAudioHandler::Reset() { … }
}