chromium/media/audio/wav_audio_handler.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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[] =;

// The size of a chunk header in wav file format. A chunk header consists of a
// tag ('fmt ' or 'data') and 4 bytes of chunk length.
const size_t kChunkHeaderSize =;

// The minimum size of 'fmt' chunk.
const size_t kFmtChunkMinimumSize =;
const size_t kFmtChunkExtensibleMinimumSize =;

// The offsets of 'fmt' fields.
const size_t kAudioFormatOffset =;
const size_t kChannelOffset =;
const size_t kSampleRateOffset =;
const size_t kBitsPerSampleOffset =;
const size_t kValidBitsPerSampleOffset =;
const size_t kSubFormatOffset =;

// A convenience struct for passing WAV parameters around. AudioParameters is
// too heavyweight for this. Keep this class internal to this implementation.
struct WavAudioParameters {};

bool ParamsAreValid(const WavAudioParameters& params) {}

// Parse a "fmt " chunk from wav data into its parameters. The `data` is in
// little endian encoding.
bool ParseFmtChunk(base::span<const uint8_t> data, WavAudioParameters* params) {}

// The `wav_data` is encoded in little endian, as will be `audio_data_out`.
bool ParseWavData(const std::string_view wav_data,
                  std::string_view* audio_data_out,
                  WavAudioParameters* params_out) {}

}  // namespace

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;

// static
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() {}

}  // namespace media