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

Side by Side Diff: media/audio/win/audio_output_win_unittest.cc

Issue 155471: Refactoring to share MockAudioOutputStream implementations across 3 platforms... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/win/audio_output_win.cc ('k') | media/audio/win/waveout_output_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "media/audio/audio_output.h" 10 #include "media/audio/audio_output.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 EXPECT_TRUE(oas->Open(256)); 186 EXPECT_TRUE(oas->Open(256));
187 TestSourceBasic source; 187 TestSourceBasic source;
188 oas->Start(&source); 188 oas->Start(&source);
189 EXPECT_GT(source.callback_count(), 0); 189 EXPECT_GT(source.callback_count(), 0);
190 oas->Stop(); 190 oas->Stop();
191 oas->Close(); 191 oas->Close();
192 EXPECT_EQ(0, source.had_error()); 192 EXPECT_EQ(0, source.had_error());
193 EXPECT_EQ(1, source.was_closed()); 193 EXPECT_EQ(1, source.was_closed());
194 } 194 }
195 195
196 // Validate that the SineWaveAudioSource writes the expected values for
197 // the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues
198 // do not affect the result. We also test that AudioManager::GetLastMockBuffer
199 // works.
200 // TODO(hclam): move this test to SimpleSourcesTest once mock audio stream is
201 // implemented on other platform.
202 TEST(WinAudioTest, SineWaveAudio16MonoTest) {
203 const size_t samples = 1024;
204 const size_t bytes_per_sample = 2;
205 const int freq = 200;
206
207 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
208 freq, AudioManager::kTelephoneSampleRate);
209
210 AudioManager* audio_man = AudioManager::GetAudioManager();
211 ASSERT_TRUE(NULL != audio_man);
212 AudioOutputStream* oas =
213 audio_man->MakeAudioStream(AudioManager::AUDIO_MOCK, 1,
214 AudioManager::kTelephoneSampleRate,
215 bytes_per_sample * 2);
216 ASSERT_TRUE(NULL != oas);
217 EXPECT_TRUE(oas->Open(samples * bytes_per_sample));
218
219 oas->Start(&source);
220 oas->Stop();
221 oas->Close();
222
223 const int16* last_buffer =
224 reinterpret_cast<const int16*>(audio_man->GetLastMockBuffer());
225 ASSERT_TRUE(NULL != last_buffer);
226
227 size_t half_period = AudioManager::kTelephoneSampleRate / (freq * 2);
228
229 // Spot test positive incursion of sine wave.
230 EXPECT_EQ(0, last_buffer[0]);
231 EXPECT_EQ(5126, last_buffer[1]);
232 EXPECT_TRUE(last_buffer[1] < last_buffer[2]);
233 EXPECT_TRUE(last_buffer[2] < last_buffer[3]);
234 // Spot test negative incursion of sine wave.
235 EXPECT_EQ(0, last_buffer[half_period]);
236 EXPECT_EQ(-5126, last_buffer[half_period + 1]);
237 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]);
238 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]);
239 }
240
241 // =========================================================================== 196 // ===========================================================================
242 // Validation of AudioManager::AUDIO_PCM_LINEAR 197 // Validation of AudioManager::AUDIO_PCM_LINEAR
243 // 198 //
244 // The tests tend to fail in the build bots when somebody connects to them via 199 // The tests tend to fail in the build bots when somebody connects to them via
245 // via remote-desktop because it installs an audio device that fails to open 200 // via remote-desktop because it installs an audio device that fails to open
246 // at some point, possibly when the connection goes idle. So that is why we 201 // at some point, possibly when the connection goes idle. So that is why we
247 // skipped them in headless mode. 202 // skipped them in headless mode.
248 203
249 // Test that can it be created and closed. 204 // Test that can it be created and closed.
250 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { 205 TEST(WinAudioTest, PCMWaveStreamGetAndClose) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ::Sleep(500); 463 ::Sleep(500);
509 464
510 // Start again and play for 1.5 seconds. 465 // Start again and play for 1.5 seconds.
511 oas->Start(&source); 466 oas->Start(&source);
512 ::Sleep(1500); 467 ::Sleep(1500);
513 oas->Stop(); 468 oas->Stop();
514 469
515 oas->Close(); 470 oas->Close();
516 } 471 }
517 472
OLDNEW
« no previous file with comments | « media/audio/win/audio_output_win.cc ('k') | media/audio/win/waveout_output_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698