blob: 2a529bf908258e6916d488ffd93a6ce2a218bda1 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/optional.h"
#include "media/audio/audio_device_thread.h"
#include "media/base/audio_renderer_sink.h"
namespace media {
// Takes care of invoking the render callback on the audio thread.
// An instance of this class is created for each capture stream on output device
// stream created.
class MEDIA_EXPORT AudioOutputDeviceThreadCallback
: public media::AudioDeviceThread::Callback {
class Metrics {
void OnCreated();
void OnProcess();
void OnInitializePlayStartTime();
void OnDestroyed();
base::TimeTicks start_time_;
// If set, this is used to record the startup duration UMA stat.
base::Optional<base::TimeTicks> first_play_start_time_;
const media::AudioParameters& audio_parameters,
base::UnsafeSharedMemoryRegion shared_memory_region,
media::AudioRendererSink::RenderCallback* render_callback,
std::unique_ptr<Metrics> metrics = nullptr);
~AudioOutputDeviceThreadCallback() override;
void MapSharedMemory() override;
// Called whenever we receive notifications about pending data.
void Process(uint32_t control_signal) override;
// Returns whether the current thread is the audio device thread or not.
// Will always return true if DCHECKs are not enabled.
bool CurrentThreadIsAudioDeviceThread();
// Sets |first_play_start_time_| to the current time unless it's already set,
// in which case it's a no-op. The first call to this method MUST have
// completed by the time we recieve our first Process() callback to avoid
// data races.
void InitializePlayStartTime();
base::UnsafeSharedMemoryRegion shared_memory_region_;
base::WritableSharedMemoryMapping shared_memory_mapping_;
media::AudioRendererSink::RenderCallback* render_callback_;
std::unique_ptr<media::AudioBus> output_bus_;
uint64_t callback_num_;
std::unique_ptr<Metrics> metrics_;
} // namespace media