Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Unified Diff: media/audio/alsa/alsa_output.cc

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Changes based on comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..93c29213599230d0367ba283a12d694d438cab95 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_;
+ // time when the requested data will be played.
+ const base::TimeTicks target_playout_time =
+ tick_clock_->NowTicks() +
+ 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(target_playout_time, audio_bus_.get());
size_t packet_size = frames_filled * bytes_per_frame_;
DCHECK_LE(packet_size, packet_size_);
@@ -777,12 +787,12 @@ AlsaPcmOutputStream::InternalState AlsaPcmOutputStream::state() {
return state_;
}
-int AlsaPcmOutputStream::RunDataCallback(AudioBus* audio_bus,
- uint32_t total_bytes_delay) {
+int AlsaPcmOutputStream::RunDataCallback(base::TimeTicks target_playout_time,
+ 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(target_playout_time, 0, audio_bus);
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698