summaryrefslogtreecommitdiffstats
path: root/media/audio/linux
diff options
context:
space:
mode:
authordavej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 23:31:33 +0000
committerdavej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 23:31:33 +0000
commitfb930c854c9d3d984411eb6be45242af793943b3 (patch)
treebf244c99a6323d417354d0397edfb6b2fe3f6940 /media/audio/linux
parent72cd998240b90ceb9f6fb6f412c8e24acb0fecf8 (diff)
downloadchromium_src-fb930c854c9d3d984411eb6be45242af793943b3.zip
chromium_src-fb930c854c9d3d984411eb6be45242af793943b3.tar.gz
chromium_src-fb930c854c9d3d984411eb6be45242af793943b3.tar.bz2
Fix Linux audio playback
Playing audio files shorter than about 11000 samples on Linux was either not working at all, or re-playing (starting and stopping on the same audio object) was working only intermittently. It was possible to stop audio playback before the first buffer was played, resulting in no sound at all. Also, if replaying, the buffer may have been dirty from the previous playback on the same device. So on Linux at least, these issues appear fixed. BUG=73045,47761,59367,59369,59370,65618 TEST=Manual, quickly playing short audio files on Linux should work Review URL: http://codereview.chromium.org/6776024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/linux')
-rw-r--r--media/audio/linux/alsa_output.cc24
-rw-r--r--media/audio/linux/alsa_output_unittest.cc4
2 files changed, 26 insertions, 2 deletions
diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc
index d8e502c..8c5762b 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();
diff --git a/media/audio/linux/alsa_output_unittest.cc b/media/audio/linux/alsa_output_unittest.cc
index 832aa5f..911a8c8 100644
--- a/media/audio/linux/alsa_output_unittest.cc
+++ b/media/audio/linux/alsa_output_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -437,7 +437,7 @@ TEST_F(AlsaPcmOutputStreamTest, StartStop) {
// Expect the pre-roll.
MockAudioSourceCallback mock_callback;
EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle))
- .Times(2)
+ .Times(3)
.WillRepeatedly(Return(SND_PCM_STATE_RUNNING));
EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _))
.Times(2)