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

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

Issue 6776024: Fix Linux audio playback for short files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright Created 9 years, 8 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
« no previous file with comments | « no previous file | media/audio/linux/alsa_output_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/linux/alsa_output.cc
diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc
index d8e502cf7699b60b49c794be0faa2c289f8b0408..8c5762b643e1a92248acfde4cb64a7d827cd34b6 100644
--- a/media/audio/linux/alsa_output.cc
+++ b/media/audio/linux/alsa_output.cc
@@ -395,6 +395,14 @@ void AlsaPcmOutputStream::StartTask() {
return;
}
+ if (shared_data_.state() != kIsPlaying) {
+ return;
+ }
+
+ // Before starting, the buffer might have audio from previous user of this
+ // device.
+ buffer_->Clear();
+
// When starting again, drop all packets in the device and prepare it again
// incase we are restarting from a pause state and need to flush old data.
int error = wrapper_->PcmDrop(playback_handle_);
@@ -538,6 +546,10 @@ void AlsaPcmOutputStream::WritePacket() {
return;
}
+ if (shared_data_.state() == kIsStopped) {
+ return;
+ }
+
CHECK_EQ(buffer_->forward_bytes() % bytes_per_output_frame_, 0u);
const uint8* buffer_data;
@@ -579,6 +591,14 @@ void AlsaPcmOutputStream::WritePacket() {
// Seek forward in the buffer after we've written some data to ALSA.
buffer_->Seek(frames_written * bytes_per_output_frame_);
}
+ } else {
+ // If nothing left to write and playback hasn't started yet, start it now.
+ // This ensures that shorter sounds will still play.
+ if (playback_handle_ &&
+ (wrapper_->PcmState(playback_handle_) == SND_PCM_STATE_PREPARED) &&
+ GetCurrentDelay() > 0) {
+ wrapper_->PcmStart(playback_handle_);
+ }
}
}
@@ -589,6 +609,10 @@ void AlsaPcmOutputStream::WriteTask() {
return;
}
+ if (shared_data_.state() == kIsStopped) {
+ return;
+ }
+
bool source_exhausted;
BufferPacket(&source_exhausted);
WritePacket();
« no previous file with comments | « no previous file | media/audio/linux/alsa_output_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698