diff options
author | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 01:01:37 +0000 |
---|---|---|
committer | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-05 01:01:37 +0000 |
commit | 1c6893e13f60b3e458e88d3b181a6448c4d79192 (patch) | |
tree | 7899527ec1e2445c7627bbbe1bbf7cc2b668aaf7 /media/audio/linux/alsa_output_unittest.cc | |
parent | babed2e690d3880c9a0e39a92ee68e6dfde9ba95 (diff) | |
download | chromium_src-1c6893e13f60b3e458e88d3b181a6448c4d79192.zip chromium_src-1c6893e13f60b3e458e88d3b181a6448c4d79192.tar.gz chromium_src-1c6893e13f60b3e458e88d3b181a6448c4d79192.tar.bz2 |
Re-write the alsa polling scheduling to make it work with low buffer audio, for example, 10ms for playout.
Before this patch, the alsa scheme sets a frame_avail_wanted as half of the ALSA buffer size, then it checks if the available_frame buffer slot in ALSA is smaller than frame_avail_wanted, if it is, which means that ALSA has more buffer than we need, then it schedule the next time to be FrameToMills(frame_avail_wanted - available_frame). Otherwise, we invoke the next write immediately.
But this scheduling scheme doesn't handle the following cases well:
#1, It has a chance running into a dead lock that we always have less than half of the buffer filled, where it runs
into a busy looping. This happens mostly when the buffer size is small.
#2, We can write more data to ALSA than what it needs.
This patch fixes the problems by initiating the next time for the moment when half of packet is played out. Then it checks with ALSA on how many frames are available,
and do a re-scheduling: if the available frames are not enough for a packet, it schedules the next write for the moment when the buffer for a packet becomes available, if the next write happens in less than 10ms, then it will use 10ms in order to avoid back to back writing; if the existing frames are less than half packet, it make next write
to be immediate.
Review URL: http://codereview.chromium.org/7976047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/linux/alsa_output_unittest.cc')
-rw-r--r-- | media/audio/linux/alsa_output_unittest.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/media/audio/linux/alsa_output_unittest.cc b/media/audio/linux/alsa_output_unittest.cc index 9fe2b92..875814b 100644 --- a/media/audio/linux/alsa_output_unittest.cc +++ b/media/audio/linux/alsa_output_unittest.cc @@ -436,13 +436,6 @@ TEST_F(AlsaPcmOutputStreamTest, StartStop) { EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _)) .Times(2) .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0))); - EXPECT_CALL(mock_callback, - OnMoreData(test_stream_.get(), _, kTestPacketSize, _)) - .Times(2) - .WillOnce(Return(kTestPacketSize)) - .WillOnce(Return(0)); - EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) - .WillOnce(Return(kTestFramesPerPacket)); // Expect scheduling. EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) @@ -451,7 +444,15 @@ TEST_F(AlsaPcmOutputStreamTest, StartStop) { .WillOnce(Return(kTestFramesPerPacket)) .WillRepeatedly(DoAll(InvokeWithoutArgs(&message_loop_, &MessageLoop::QuitNow), - Return(0))); // Buffer is full. + Return(0))); // Buffer is full. + + EXPECT_CALL(mock_callback, + OnMoreData(test_stream_.get(), _, kTestPacketSize, _)) + .Times(2) + .WillOnce(Return(kTestPacketSize)) + .WillOnce(Return(0)); + EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) + .WillOnce(Return(kTestFramesPerPacket)); test_stream_->Start(&mock_callback); message_loop_.RunAllPending(); |