| Index: media/audio/alsa/alsa_output.cc
|
| diff --git a/media/audio/alsa/alsa_output.cc b/media/audio/alsa/alsa_output.cc
|
| index 27ab0d1fd2002cd7d38ba86de355a1f8abd6f1f2..967e4a4b05ec2c446008158e6df90034eaa7a6ed 100644
|
| --- a/media/audio/alsa/alsa_output.cc
|
| +++ b/media/audio/alsa/alsa_output.cc
|
| @@ -37,12 +37,14 @@
|
| #include <stddef.h>
|
|
|
| #include <algorithm>
|
| +#include <utility>
|
|
|
| #include "base/bind.h"
|
| #include "base/logging.h"
|
| #include "base/memory/free_deleter.h"
|
| #include "base/stl_util.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| +#include "base/time/default_tick_clock.h"
|
| #include "base/trace_event/trace_event.h"
|
| #include "media/audio/alsa/alsa_util.h"
|
| #include "media/audio/alsa/alsa_wrapper.h"
|
| @@ -125,7 +127,7 @@ std::ostream& operator<<(std::ostream& os,
|
| case AlsaPcmOutputStream::kIsClosed:
|
| os << "kIsClosed";
|
| break;
|
| - };
|
| + }
|
| return os;
|
| }
|
|
|
| @@ -164,6 +166,7 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name,
|
| volume_(1.0f),
|
| source_callback_(NULL),
|
| audio_bus_(AudioBus::Create(params)),
|
| + tick_clock_(new base::DefaultTickClock()),
|
| weak_factory_(this) {
|
| DCHECK(manager_->GetTaskRunner()->BelongsToCurrentThread());
|
| DCHECK_EQ(audio_bus_->frames() * bytes_per_frame_, packet_size_);
|
| @@ -345,6 +348,12 @@ void AlsaPcmOutputStream::GetVolume(double* volume) {
|
| *volume = volume_;
|
| }
|
|
|
| +void AlsaPcmOutputStream::SetTickClockForTesting(
|
| + std::unique_ptr<base::TickClock> tick_clock) {
|
| + DCHECK(tick_clock);
|
| + tick_clock_ = std::move(tick_clock);
|
| +}
|
| +
|
| void AlsaPcmOutputStream::BufferPacket(bool* source_exhausted) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| @@ -361,13 +370,14 @@ void AlsaPcmOutputStream::BufferPacket(bool* source_exhausted) {
|
| // WritePacket() consumes only the current chunk of data.
|
| if (!buffer_->forward_bytes()) {
|
| // Before making a request to source for data we need to determine the
|
| - // delay (in bytes) for the requested data to be played.
|
| - const uint32_t hardware_delay = GetCurrentDelay() * bytes_per_frame_;
|
| + // delay for the requested data to be played.
|
| + const base::TimeDelta delay =
|
| + FramesToTimeDelta(GetCurrentDelay(), sample_rate_);
|
|
|
| scoped_refptr<media::DataBuffer> packet =
|
| new media::DataBuffer(packet_size_);
|
| - int frames_filled = RunDataCallback(
|
| - audio_bus_.get(), hardware_delay);
|
| + int frames_filled =
|
| + RunDataCallback(delay, tick_clock_->NowTicks(), audio_bus_.get());
|
|
|
| size_t packet_size = frames_filled * bytes_per_frame_;
|
| DCHECK_LE(packet_size, packet_size_);
|
| @@ -777,12 +787,13 @@ AlsaPcmOutputStream::InternalState AlsaPcmOutputStream::state() {
|
| return state_;
|
| }
|
|
|
| -int AlsaPcmOutputStream::RunDataCallback(AudioBus* audio_bus,
|
| - uint32_t total_bytes_delay) {
|
| +int AlsaPcmOutputStream::RunDataCallback(base::TimeDelta delay,
|
| + base::TimeTicks delay_timestamp,
|
| + AudioBus* audio_bus) {
|
| TRACE_EVENT0("audio", "AlsaPcmOutputStream::RunDataCallback");
|
|
|
| if (source_callback_)
|
| - return source_callback_->OnMoreData(audio_bus, total_bytes_delay, 0);
|
| + return source_callback_->OnMoreData(delay, delay_timestamp, 0, audio_bus);
|
|
|
| return 0;
|
| }
|
|
|