summaryrefslogtreecommitdiffstats
path: root/media/audio/win/audio_output_win_unittest.cc
diff options
context:
space:
mode:
authorenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 18:30:27 +0000
committerenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 18:30:27 +0000
commitbcb01e9dbad7e7a31b61f6ca87eb7abc1b1ca1a3 (patch)
treebd4b461aea2c75b3ce4f9597a6d84f7bb3ef5564 /media/audio/win/audio_output_win_unittest.cc
parent318bc95a682f2ae4a35d393aa4e43779eea8627f (diff)
downloadchromium_src-bcb01e9dbad7e7a31b61f6ca87eb7abc1b1ca1a3.zip
chromium_src-bcb01e9dbad7e7a31b61f6ca87eb7abc1b1ca1a3.tar.gz
chromium_src-bcb01e9dbad7e7a31b61f6ca87eb7abc1b1ca1a3.tar.bz2
Do not stop audio physical stream immediately after logical one had stopped.
Wait some time. We are still stopping/closing the stream, as (1) it is better for battery life, and (2) some people can hear active device even when it is playing silence. That increased audio startup latency, especially on Windows, because we are using 3 buffers on Windows. To fix that I changed the code to use 2 buffers on presumable good Windows boxes -- i.e. running non-Vista and having more than single core. Changed unit tests as well. That CL finishes work on browser-side audio mixer. Not sure how important it is, though -- hopefully it will provide some time while implementing renderer-side mixer. That CL also fixes bug 131720. Looks that it was caused by timing change, and starting stream earlier causes less dropped frames. (I still cannot understand why on modern system we should have even single dropped frame, and why slight timing change caused us to drop frame, but that is different question...) BUG=114701 BUG=129190 BUG=131720 BUG=132009 TEST=Should not be noticeable difference in behavior. TEST=Startup of 2nd stream should become somewhat faster. TEST=Run tests on Win7 and XP myself. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=141770 Review URL: https://chromiumcodereview.appspot.com/10540034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142430 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/win/audio_output_win_unittest.cc')
-rw-r--r--media/audio/win/audio_output_win_unittest.cc53
1 files changed, 31 insertions, 22 deletions
diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc
index 4066643..d954093 100644
--- a/media/audio/win/audio_output_win_unittest.cc
+++ b/media/audio/win/audio_output_win_unittest.cc
@@ -76,7 +76,7 @@ class TestSourceBasic : public AudioOutputStream::AudioSourceCallback {
int had_error_;
};
-const int kNumBuffers = 3;
+const int kMaxNumBuffers = 3;
// Specializes TestSourceBasic to detect that the AudioStream is using
// triple buffering correctly.
class TestSourceTripleBuffer : public TestSourceBasic {
@@ -92,14 +92,14 @@ class TestSourceTripleBuffer : public TestSourceBasic {
AudioBuffersState buffers_state) {
// Call the base, which increments the callback_count_.
TestSourceBasic::OnMoreData(dest, max_size, buffers_state);
- if (callback_count() % kNumBuffers == 2) {
+ if (callback_count() % NumberOfWaveOutBuffers() == 2) {
set_error(!CompareExistingIfNotNULL(2, dest));
- } else if (callback_count() % kNumBuffers == 1) {
+ } else if (callback_count() % NumberOfWaveOutBuffers() == 1) {
set_error(!CompareExistingIfNotNULL(1, dest));
} else {
set_error(!CompareExistingIfNotNULL(0, dest));
}
- if (callback_count() > kNumBuffers) {
+ if (callback_count() > kMaxNumBuffers) {
set_error(buffer_address_[0] == buffer_address_[1]);
set_error(buffer_address_[1] == buffer_address_[2]);
}
@@ -114,7 +114,7 @@ class TestSourceTripleBuffer : public TestSourceBasic {
return (entry == address);
}
- void* buffer_address_[kNumBuffers];
+ void* buffer_address_[kMaxNumBuffers];
};
// Specializes TestSourceBasic to simulate a source that blocks for some time
@@ -129,7 +129,7 @@ class TestSourceLaggy : public TestSourceBasic {
AudioBuffersState buffers_state) {
// Call the base, which increments the callback_count_.
TestSourceBasic::OnMoreData(dest, max_size, buffers_state);
- if (callback_count() > kNumBuffers) {
+ if (callback_count() > kMaxNumBuffers) {
::Sleep(lag_in_ms_);
}
return max_size;
@@ -312,7 +312,7 @@ TEST(WinAudioTest, PCMWaveStreamTripleBuffer) {
EXPECT_TRUE(oas->Open());
oas->Start(&test_triple_buffer);
::Sleep(300);
- EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers);
+ EXPECT_GT(test_triple_buffer.callback_count(), kMaxNumBuffers);
EXPECT_FALSE(test_triple_buffer.had_error());
oas->Stop();
::Sleep(500);
@@ -600,28 +600,37 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) {
uint32 bytes_100_ms = samples_100_ms * 2;
- // We expect the amount of pending bytes will reaching 2 times of
- // |bytes_100_ms| because the audio output stream has a triple buffer scheme.
+ // Audio output stream has either a double or triple buffer scheme.
+ // We expect the amount of pending bytes will reaching up to 2 times of
+ // |bytes_100_ms| depending on number of buffers used.
// From that it would decrease as we are playing the data but not providing
// new one. And then we will try to provide zero data so the amount of
// pending bytes will go down and eventually read zero.
InSequence s;
+
EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
Field(&AudioBuffersState::pending_bytes, 0)))
.WillOnce(Return(bytes_100_ms));
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
- Field(&AudioBuffersState::pending_bytes,
- bytes_100_ms)))
- .WillOnce(Return(bytes_100_ms));
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
- Field(&AudioBuffersState::pending_bytes,
- 2 * bytes_100_ms)))
- .WillOnce(Return(bytes_100_ms));
- EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
- Field(&AudioBuffersState::pending_bytes,
- 2 * bytes_100_ms)))
- .Times(AnyNumber())
- .WillRepeatedly(Return(0));
+ switch (NumberOfWaveOutBuffers()) {
+ case 2:
+ break; // Calls are the same as at end of 3-buffer scheme.
+ case 3:
+ EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
+ Field(&AudioBuffersState::pending_bytes,
+ bytes_100_ms)))
+ .WillOnce(Return(bytes_100_ms));
+ EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
+ Field(&AudioBuffersState::pending_bytes,
+ 2 * bytes_100_ms)))
+ .WillOnce(Return(bytes_100_ms));
+ EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
+ Field(&AudioBuffersState::pending_bytes,
+ 2 * bytes_100_ms)))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(0));
+ default:
+ ASSERT_TRUE(false) << "Unexpected number of buffers";
+ }
EXPECT_CALL(source, OnMoreData(NotNull(), bytes_100_ms,
Field(&AudioBuffersState::pending_bytes,
bytes_100_ms)))