summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhenrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 18:01:34 +0000
committerhenrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 18:01:34 +0000
commitd216b454cb9db9c6650f1258b3f2e10731e36454 (patch)
tree09186c2c02b5308a504968715719e3fa1b6ef2ba /media
parenta3bf8f623165996166376de7aeb5987143502021 (diff)
downloadchromium_src-d216b454cb9db9c6650f1258b3f2e10731e36454.zip
chromium_src-d216b454cb9db9c6650f1258b3f2e10731e36454.tar.gz
chromium_src-d216b454cb9db9c6650f1258b3f2e10731e36454.tar.bz2
Fixes a bug related to Start/Stop/Start/Stop calling sequences in WASAPIAudioOutputStream.
BUG=132956 TEST=media_unittests --gtest_also_run_disabled_tests --gtest_filter=WinAudioOutputTest* It is also possible to play out the file in segments where each segment start with a call to Start() and stops with a call to Stop(). To do so, modify the kNumFileSegments (defaults to 1) to a suitable integer number (e.g 10). It will ensure that the 20s file is played out in 2 seconds long segments with a fresh Stop(), Start() calling sequence between each sequence. Review URL: https://chromiumcodereview.appspot.com/10556006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/win/audio_low_latency_output_win.cc18
-rw-r--r--media/audio/win/audio_low_latency_output_win_unittest.cc37
2 files changed, 45 insertions, 10 deletions
diff --git a/media/audio/win/audio_low_latency_output_win.cc b/media/audio/win/audio_low_latency_output_win.cc
index 0ac8e17..b3f7dfe 100644
--- a/media/audio/win/audio_low_latency_output_win.cc
+++ b/media/audio/win/audio_low_latency_output_win.cc
@@ -219,6 +219,24 @@ void WASAPIAudioOutputStream::Stop() {
render_thread_ = NULL;
}
+ // Flush all pending data and reset the audio clock stream position to 0.
+ hr = audio_client_->Reset();
+ if (FAILED(hr)) {
+ DLOG_IF(ERROR, hr != AUDCLNT_E_NOT_INITIALIZED)
+ << "Failed to reset streaming: " << std::hex << hr;
+ }
+
+ // Extra safety check to ensure that the buffers are cleared.
+ // If the buffers are not cleared correctly, the next call to Start()
+ // would fail with AUDCLNT_E_BUFFER_ERROR at IAudioRenderClient::GetBuffer().
+ UINT32 num_queued_frames = 0;
+ audio_client_->GetCurrentPadding(&num_queued_frames);
+ DCHECK_EQ(0u, num_queued_frames);
+
+ // Ensure that we don't quit the main thread loop immediately next
+ // time Start() is called.
+ ResetEvent(stop_render_event_.Get());
+
started_ = false;
}
diff --git a/media/audio/win/audio_low_latency_output_win_unittest.cc b/media/audio/win/audio_low_latency_output_win_unittest.cc
index c7e4ab5..f764834 100644
--- a/media/audio/win/audio_low_latency_output_win_unittest.cc
+++ b/media/audio/win/audio_low_latency_output_win_unittest.cc
@@ -41,6 +41,7 @@ namespace media {
static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw";
static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw";
static const size_t kFileDurationMs = 20000;
+static const size_t kNumFileSegments = 1;
static const size_t kMaxDeltaSamples = 1000;
static const char* kDeltaTimeMsFileName = "delta_times_ms.txt";
@@ -69,8 +70,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
previous_call_time_(base::Time::Now()),
text_file_(NULL),
elements_to_write_(0) {
- // Reads a test file from media/test/data directory and stores it in
- // a scoped_array.
+ // Reads a test file from media/test/data directory.
file_ = ReadTestDataFile(name);
// Creates an array that will store delta times between callbacks.
@@ -119,7 +119,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
if (pos_ + static_cast<int>(max_size) > file_size())
max_size = file_size() - pos_;
if (max_size) {
- memcpy(dest, &file_[pos_], max_size);
+ memcpy(dest, file_->GetData() + pos_, max_size);
pos_ += max_size;
}
return max_size;
@@ -369,6 +369,16 @@ TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMiscCallingSequences) {
aos->Stop();
EXPECT_FALSE(waos->started());
+ // Start(), Stop(), Start(), Stop().
+ aos->Start(&source);
+ EXPECT_TRUE(waos->started());
+ aos->Stop();
+ EXPECT_FALSE(waos->started());
+ aos->Start(&source);
+ EXPECT_TRUE(waos->started());
+ aos->Stop();
+ EXPECT_FALSE(waos->started());
+
aos->Close();
}
@@ -531,15 +541,22 @@ TEST(WinAudioOutputTest, DISABLED_WASAPIAudioOutputStreamReadFromFile) {
}
ReadFromFileAudioSource file_source(file_name);
- LOG(INFO) << "File name : " << file_name.c_str();
- LOG(INFO) << "Sample rate: " << aosw.sample_rate();
- LOG(INFO) << "File size : " << file_source.file_size();
+ LOG(INFO) << "File name : " << file_name.c_str();
+ LOG(INFO) << "Sample rate : " << aosw.sample_rate();
+ LOG(INFO) << "File size : " << file_source.file_size();
+ LOG(INFO) << "#file segments: " << kNumFileSegments;
LOG(INFO) << ">> Listen to the file while playing...";
- aos->Start(&file_source);
- base::PlatformThread::Sleep(
- base::TimeDelta::FromMilliseconds(kFileDurationMs));
- aos->Stop();
+ for (int i = 0; i < kNumFileSegments; i++) {
+ // Each segment will start with a short (~20ms) block of zeros, hence
+ // some short glitches might be heard in this test if kNumFileSegments
+ // is larger than one. The exact length of the silence period depends on
+ // the selected sample rate.
+ aos->Start(&file_source);
+ base::PlatformThread::Sleep(
+ base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments));
+ aos->Stop();
+ }
LOG(INFO) << ">> File playout has stopped.";
aos->Close();