Commit cec6c171 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Fuchsia: Move AudioOutputStreamFuchsia to AudioRenderer2.

Previously AudioOutputStreamFuchsia was using media_client library,
which is deprecated now. Update //media to use AudioRenderer2 FIDL
interface directly.

Bug: 851733
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I356a0ae08798c2eb62d4cb42355aff4c47fbb360
Reviewed-on: https://chromium-review.googlesource.com/1096414
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567376}
parent c6b80124
......@@ -317,7 +317,7 @@ source_set("audio") {
"fuchsia/audio_output_stream_fuchsia.cc",
"fuchsia/audio_output_stream_fuchsia.h",
]
libs += [ "media_client" ]
deps += [ "//third_party/fuchsia-sdk:media" ]
}
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
......
......@@ -53,7 +53,7 @@ class AudioOutputTest : public ::testing::Test {
}
protected:
base::MessageLoop message_loop_;
base::MessageLoopForIO message_loop_;
std::unique_ptr<AudioManager> audio_manager_;
std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_;
AudioParameters stream_params_;
......
......@@ -10,10 +10,14 @@
namespace media {
AudioThreadImpl::AudioThreadImpl() : thread_("AudioThread") {
base::Thread::Options thread_options;
#if defined(OS_WIN)
thread_.init_com_with_mta(true);
#elif defined(OS_FUCHSIA)
// FIDL-based APIs require async_t, which is initialized on IO thread.
thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
#endif
CHECK(thread_.Start());
CHECK(thread_.StartWithOptions(thread_options));
#if defined(OS_MACOSX)
// On Mac, the audio task runner must belong to the main thread.
......
......@@ -15,16 +15,14 @@ namespace media {
AudioManagerFuchsia::AudioManagerFuchsia(
std::unique_ptr<AudioThread> audio_thread,
AudioLogFactory* audio_log_factory)
: AudioManagerBase(std::move(audio_thread), audio_log_factory),
fuchsia_audio_manager_(fuchsia_audio_manager_create()) {}
: AudioManagerBase(std::move(audio_thread), audio_log_factory) {}
AudioManagerFuchsia::~AudioManagerFuchsia() {
fuchsia_audio_manager_free(fuchsia_audio_manager_);
}
AudioManagerFuchsia::~AudioManagerFuchsia() = default;
bool AudioManagerFuchsia::HasAudioOutputDevices() {
return fuchsia_audio_manager_get_output_devices(fuchsia_audio_manager_,
nullptr, 0) > 0;
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API for device
// enumeration. Update this method when that functionality is implemented.
return true;
}
bool AudioManagerFuchsia::HasAudioInputDevices() {
......@@ -40,33 +38,9 @@ void AudioManagerFuchsia::GetAudioInputDeviceNames(
void AudioManagerFuchsia::GetAudioOutputDeviceNames(
AudioDeviceNames* device_names) {
device_names->clear();
std::vector<fuchsia_audio_device_description> descriptions;
descriptions.resize(16);
bool try_again = true;
while (try_again) {
int result = fuchsia_audio_manager_get_output_devices(
fuchsia_audio_manager_, descriptions.data(), descriptions.size());
if (result < 0) {
LOG(ERROR) << "fuchsia_audio_manager_get_output_devices() returned "
<< result;
device_names->clear();
return;
}
// Try again if the buffer was too small.
try_again = static_cast<size_t>(result) > descriptions.size();
descriptions.resize(result);
}
// Create default device if we have any output devices present.
if (!descriptions.empty())
device_names->push_back(AudioDeviceName::CreateDefault());
for (auto& desc : descriptions) {
device_names->push_back(AudioDeviceName(desc.name, desc.id));
}
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API for device
// enumeration. Update this method when that functionality is implemented.
*device_names = {AudioDeviceName::CreateDefault()};
}
AudioParameters AudioManagerFuchsia::GetInputStreamParameters(
......@@ -78,32 +52,11 @@ AudioParameters AudioManagerFuchsia::GetInputStreamParameters(
AudioParameters AudioManagerFuchsia::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
fuchsia_audio_parameters device_params;
int result = fuchsia_audio_manager_get_output_device_default_parameters(
fuchsia_audio_manager_,
output_device_id == AudioDeviceDescription::kDefaultDeviceId
? nullptr
: const_cast<char*>(output_device_id.c_str()),
&device_params);
if (result < 0) {
LOG(ERROR) << "fuchsia_audio_manager_get_default_output_device_parameters()"
" returned "
<< result;
return AudioParameters();
}
int user_buffer_size = GetUserBufferSize();
if (user_buffer_size > 0)
device_params.buffer_size = user_buffer_size;
int sample_rate = input_params.sample_rate();
if (sample_rate < 8000 || sample_rate > 96000)
sample_rate = device_params.sample_rate;
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API to get
// device configuration. Update this method when that functionality is
// implemented.
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
GuessChannelLayout(device_params.num_channels),
sample_rate, device_params.buffer_size);
CHANNEL_LAYOUT_STEREO, 48000, 480);
}
const char* AudioManagerFuchsia::GetName() {
......@@ -122,7 +75,13 @@ AudioOutputStream* AudioManagerFuchsia::MakeLowLatencyOutputStream(
const std::string& device_id,
const LogCallback& log_callback) {
DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
return new AudioOutputStreamFuchsia(this, device_id, params);
if (!device_id.empty() &&
device_id != AudioDeviceDescription::kDefaultDeviceId) {
return nullptr;
}
return new AudioOutputStreamFuchsia(this, params);
}
AudioInputStream* AudioManagerFuchsia::MakeLinearInputStream(
......
......@@ -5,8 +5,6 @@
#ifndef MEDIA_AUDIO_FUCHSIA_AUDIO_MANAGER_FUCHSIA_H_
#define MEDIA_AUDIO_FUCHSIA_AUDIO_MANAGER_FUCHSIA_H_
#include <media/audio.h>
#include "media/audio/audio_manager_base.h"
namespace media {
......@@ -43,18 +41,12 @@ class AudioManagerFuchsia : public AudioManagerBase {
const std::string& device_id,
const LogCallback& log_callback) override;
fuchsia_audio_manager* GetFuchsiaAudioManager() const {
return fuchsia_audio_manager_;
}
protected:
AudioParameters GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) override;
private:
fuchsia_audio_manager* fuchsia_audio_manager_;
DISALLOW_COPY_AND_ASSIGN(AudioManagerFuchsia);
};
......
......@@ -5,8 +5,9 @@
#ifndef MEDIA_AUDIO_FUCHSIA_AUDIO_OUTPUT_STREAM_FUCHSIA_H_
#define MEDIA_AUDIO_FUCHSIA_AUDIO_OUTPUT_STREAM_FUCHSIA_H_
#include <media/audio.h>
#include <fuchsia/media/cpp/fidl.h>
#include "base/memory/shared_memory.h"
#include "base/timer/timer.h"
#include "media/audio/audio_io.h"
#include "media/base/audio_parameters.h"
......@@ -19,7 +20,6 @@ class AudioOutputStreamFuchsia : public AudioOutputStream {
public:
// Caller must ensure that manager outlives the stream.
AudioOutputStreamFuchsia(AudioManagerFuchsia* manager,
const std::string& device_id,
const AudioParameters& parameters);
// AudioOutputStream interface.
......@@ -33,35 +33,53 @@ class AudioOutputStreamFuchsia : public AudioOutputStream {
private:
~AudioOutputStreamFuchsia() override;
// Returns minimum |payload_buffer_| size for the current |min_lead_time_|.
size_t GetMinBufferSize();
// Allocates and maps |payload_buffer_|.
bool InitializePayloadBuffer();
base::TimeTicks GetCurrentStreamTime();
// Updates |presentation_delay_ns_|.
bool UpdatePresentationDelay();
// Event handler for |audio_renderer_|.
void OnMinLeadTimeChanged(int64_t min_lead_time);
// Error handler for |audio_renderer_|.
void OnRendererError();
// Requests data from AudioSourceCallback, passes it to the mixer and
// schedules |timer_| for the next call.
void PumpSamples();
// Schedules |timer_| to call PumpSamples() when appropriate for the next
// packet.
void SchedulePumpSamples(base::TimeTicks now);
AudioManagerFuchsia* manager_;
std::string device_id_;
AudioParameters parameters_;
// These are used only in PumpSamples(). They are kept here to avoid
// Audio renderer connection.
fuchsia::media::AudioRenderer2Ptr audio_renderer_;
// |audio_bus_| is used only in PumpSamples(). It is kept here to avoid
// reallocating the memory every time.
std::unique_ptr<AudioBus> audio_bus_;
std::vector<float> buffer_;
fuchsia_audio_output_stream* stream_ = nullptr;
base::SharedMemory payload_buffer_;
size_t payload_buffer_pos_ = 0;
AudioSourceCallback* callback_ = nullptr;
double volume_ = 1.0;
base::TimeTicks started_time_;
int64_t stream_position_samples_ = 0;
base::TimeTicks reference_time_;
int64_t stream_position_samples_;
// Total presentation delay for the stream. This value is returned by
// fuchsia_audio_output_stream_get_min_delay()
zx_duration_t presentation_delay_ns_ = 0;
// Current min lead time for the stream. This value is updated by
// AudioRenderer::OnMinLeadTimeChanged event. Assume 50ms until we get the
// first OnMinLeadTimeChanged event.
base::TimeDelta min_lead_time_ = base::TimeDelta::FromMilliseconds(50);
// Timer that's scheduled to call PumpSamples().
base::OneShotTimer timer_;
......
......@@ -206,6 +206,7 @@ fuchsia_sdk_fidl_pkg("media") {
namespace_path = "fuchsia"
sources = [
"audio.fidl",
"audio_capturer.fidl",
"audio_renderer.fidl",
"media_renderer.fidl",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment