#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/audio/input_sync_writer.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/check.h"
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "media/base/audio_glitch_info.h"
#include "services/audio/input_glitch_counter.h"
namespace audio {
namespace {
enum class AudioGlitchResult { … };
}
InputSyncWriter::OverflowData::OverflowData(
double volume,
bool key_pressed,
base::TimeTicks capture_time,
const media::AudioGlitchInfo& glitch_info,
std::unique_ptr<media::AudioBus> audio_bus)
: … { … }
InputSyncWriter::OverflowData::~OverflowData() { … }
InputSyncWriter::OverflowData::OverflowData(InputSyncWriter::OverflowData&&) =
default;
InputSyncWriter::OverflowData& InputSyncWriter::OverflowData::operator=(
InputSyncWriter::OverflowData&& other) = default;
InputSyncWriter::InputSyncWriter(
base::RepeatingCallback<void(const std::string&)> log_callback,
base::MappedReadOnlyRegion shared_memory,
std::unique_ptr<base::CancelableSyncSocket> socket,
uint32_t shared_memory_segment_count,
const media::AudioParameters& params,
std::unique_ptr<InputGlitchCounter> glitch_counter)
: … { … }
InputSyncWriter::~InputSyncWriter() = default;
std::unique_ptr<InputSyncWriter> InputSyncWriter::Create(
base::RepeatingCallback<void(const std::string&)> log_callback,
uint32_t shared_memory_segment_count,
const media::AudioParameters& params,
base::CancelableSyncSocket* foreign_socket) { … }
base::ReadOnlySharedMemoryRegion InputSyncWriter::TakeSharedMemoryRegion() { … }
void InputSyncWriter::Write(const media::AudioBus* data,
double volume,
bool key_pressed,
base::TimeTicks capture_time,
const media::AudioGlitchInfo& glitch_info) { … }
void InputSyncWriter::Close() { … }
void InputSyncWriter::CheckTimeSinceLastWrite() { … }
bool InputSyncWriter::PushDataToFifo(
const media::AudioBus& data,
double volume,
bool key_pressed,
base::TimeTicks capture_time,
const media::AudioGlitchInfo& glitch_info) { … }
bool InputSyncWriter::WriteDataToCurrentSegment(
const media::AudioBus& data,
double volume,
bool key_pressed,
base::TimeTicks capture_time,
const media::AudioGlitchInfo& glitch_info) { … }
bool InputSyncWriter::SignalDataWrittenAndUpdateCounters() { … }
media::AudioInputBuffer* InputSyncWriter::GetSharedInputBuffer(
uint32_t segment_id) const { … }
}