Index: media/audio/alsa/alsa_output.cc |
diff --git a/media/audio/alsa/alsa_output.cc b/media/audio/alsa/alsa_output.cc |
index c127fb4c2e93a9c6bfd000e41b9717bd181681e1..dbac2a624008499d18812c8aafa37e9a491b2586 100644 |
--- a/media/audio/alsa/alsa_output.cc |
+++ b/media/audio/alsa/alsa_output.cc |
@@ -161,6 +161,7 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name, |
frames_per_packet_(packet_size_ / bytes_per_frame_), |
state_(kCreated), |
volume_(1.0f), |
+ elapsed_written_frames_(0), |
source_callback_(NULL), |
audio_bus_(AudioBus::Create(params)), |
weak_factory_(this) { |
@@ -289,6 +290,9 @@ void AlsaPcmOutputStream::Start(AudioSourceCallback* callback) { |
// device. |
buffer_->Clear(); |
+ // Invalidate written frames count. |
+ elapsed_written_frames_ = 0; |
+ |
// When starting again, drop all packets in the device and prepare it again |
// in case we are restarting from a pause state and need to flush old data. |
int error = wrapper_->PcmDrop(playback_handle_); |
@@ -466,6 +470,8 @@ void AlsaPcmOutputStream::WritePacket() { |
// Seek forward in the buffer after we've written some data to ALSA. |
buffer_->Seek(frames_written * bytes_per_output_frame_); |
} |
+ if (frames_written) |
+ elapsed_written_frames_ += frames_written; |
} else { |
// If nothing left to write and playback hasn't started yet, start it now. |
// This ensures that shorter sounds will still play. |
@@ -783,8 +789,16 @@ int AlsaPcmOutputStream::RunDataCallback(AudioBus* audio_bus, |
uint32_t total_bytes_delay) { |
TRACE_EVENT0("audio", "AlsaPcmOutputStream::RunDataCallback"); |
+ AudioTimestamp output_timestamp; |
+ // This is quite a raugh estimation, we need to consider using |
+ // snd_pcm_status_get_audio* API when it is accessible. |
+ output_timestamp.frames = elapsed_written_frames_ - GetCurrentDelay(); |
+ output_timestamp.ticks = base::TimeTicks::Now().ToInternalValue(); |
+ DCHECK(output_timestamp.frames >= 0); |
+ |
if (source_callback_) |
- return source_callback_->OnMoreData(audio_bus, total_bytes_delay, 0); |
+ return source_callback_->OnMoreData(audio_bus, total_bytes_delay, 0, |
+ output_timestamp); |
return 0; |
} |