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

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

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/win/audio_low_latency_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <mmsystem.h> 8 #include <mmsystem.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/environment.h" 14 #include "base/environment.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/run_loop.h"
19 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
20 #include "base/win/scoped_com_initializer.h" 21 #include "base/win/scoped_com_initializer.h"
21 #include "media/audio/audio_device_description.h" 22 #include "media/audio/audio_device_description.h"
22 #include "media/audio/audio_io.h" 23 #include "media/audio/audio_io.h"
23 #include "media/audio/audio_manager.h" 24 #include "media/audio/audio_manager.h"
24 #include "media/audio/audio_unittest_util.h" 25 #include "media/audio/audio_unittest_util.h"
25 #include "media/audio/win/core_audio_util_win.h" 26 #include "media/audio/win/core_audio_util_win.h"
26 #include "media/base/seekable_buffer.h" 27 #include "media/base/seekable_buffer.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 using ::testing::_; 31 using ::testing::_;
31 using ::testing::AnyNumber; 32 using ::testing::AnyNumber;
32 using ::testing::AtLeast; 33 using ::testing::AtLeast;
33 using ::testing::Gt; 34 using ::testing::Gt;
34 using ::testing::NotNull; 35 using ::testing::NotNull;
35 36
36 namespace media { 37 namespace media {
37 38
38 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop) { 39 ACTION_P3(CheckCountAndPostQuitTask, count, limit, run_loop) {
39 if (++*count >= limit) { 40 if (++*count >= limit)
40 loop->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 41 run_loop->QuitWhenIdle();
41 }
42 } 42 }
43 43
44 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { 44 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback {
45 public: 45 public:
46 MOCK_METHOD4(OnData, 46 MOCK_METHOD4(OnData,
47 void(AudioInputStream* stream, 47 void(AudioInputStream* stream,
48 const AudioBus* src, 48 const AudioBus* src,
49 uint32_t hardware_delay_bytes, 49 uint32_t hardware_delay_bytes,
50 double volume)); 50 double volume));
51 MOCK_METHOD1(OnError, void(AudioInputStream* stream)); 51 MOCK_METHOD1(OnError, void(AudioInputStream* stream));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 AudioInputStream* stream_; 253 AudioInputStream* stream_;
254 254
255 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream); 255 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream);
256 }; 256 };
257 257
258 class WinAudioInputTest : public ::testing::Test { 258 class WinAudioInputTest : public ::testing::Test {
259 public: 259 public:
260 WinAudioInputTest() { 260 WinAudioInputTest() {
261 audio_manager_ = 261 audio_manager_ =
262 AudioManager::CreateForTesting(message_loop_.task_runner()); 262 AudioManager::CreateForTesting(message_loop_.task_runner());
263 message_loop_.RunUntilIdle(); 263 base::RunLoop().RunUntilIdle();
264 } 264 }
265 ~WinAudioInputTest() override { 265 ~WinAudioInputTest() override {
266 audio_manager_.reset(); 266 audio_manager_.reset();
267 message_loop_.RunUntilIdle(); 267 base::RunLoop().RunUntilIdle();
268 } 268 }
269 269
270 protected: 270 protected:
271 base::MessageLoop message_loop_; 271 base::MessageLoop message_loop_;
272 ScopedAudioManagerPtr audio_manager_; 272 ScopedAudioManagerPtr audio_manager_;
273 }; 273 };
274 274
275 // Verify that we can retrieve the current hardware/mixing sample rate 275 // Verify that we can retrieve the current hardware/mixing sample rate
276 // for all available input devices. 276 // for all available input devices.
277 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { 277 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 AudioInputStreamWrapper aisw(audio_manager_.get()); 372 AudioInputStreamWrapper aisw(audio_manager_.get());
373 ScopedAudioInputStream ais(aisw.Create()); 373 ScopedAudioInputStream ais(aisw.Create());
374 EXPECT_TRUE(ais->Open()); 374 EXPECT_TRUE(ais->Open());
375 375
376 MockAudioInputCallback sink; 376 MockAudioInputCallback sink;
377 377
378 // Derive the expected size in bytes of each recorded packet. 378 // Derive the expected size in bytes of each recorded packet.
379 uint32_t bytes_per_packet = 379 uint32_t bytes_per_packet =
380 aisw.channels() * aisw.frames_per_buffer() * (aisw.bits_per_sample() / 8); 380 aisw.channels() * aisw.frames_per_buffer() * (aisw.bits_per_sample() / 8);
381 381
382 // We use 10ms packets and will run the test until ten packets are received. 382 {
383 // All should contain valid packets of the same size and a valid delay 383 // We use 10ms packets and will run the test until ten packets are received.
384 // estimate. 384 // All should contain valid packets of the same size and a valid delay
385 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _)) 385 // estimate.
386 .Times(AtLeast(10)) 386 base::RunLoop run_loop;
387 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &message_loop_)); 387 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _))
388 ais->Start(&sink); 388 .Times(AtLeast(10))
389 message_loop_.Run(); 389 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &run_loop));
390 ais->Stop(); 390 ais->Start(&sink);
391 run_loop.Run();
392 ais->Stop();
393 }
391 394
392 // Store current packet size (to be used in the subsequent tests). 395 // Store current packet size (to be used in the subsequent tests).
393 int frames_per_buffer_10ms = aisw.frames_per_buffer(); 396 int frames_per_buffer_10ms = aisw.frames_per_buffer();
394 397
395 ais.Close(); 398 ais.Close();
396 399
397 // 20 ms packet size. 400 // 20 ms packet size.
398 401
399 count = 0; 402 count = 0;
400 ais.Reset(aisw.Create(2 * frames_per_buffer_10ms)); 403 ais.Reset(aisw.Create(2 * frames_per_buffer_10ms));
401 EXPECT_TRUE(ais->Open()); 404 EXPECT_TRUE(ais->Open());
402 bytes_per_packet = aisw.channels() * aisw.frames_per_buffer() * 405 bytes_per_packet = aisw.channels() * aisw.frames_per_buffer() *
403 (aisw.bits_per_sample() / 8); 406 (aisw.bits_per_sample() / 8);
404 407
405 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _)) 408 {
406 .Times(AtLeast(10)) 409 base::RunLoop run_loop;
407 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &message_loop_)); 410 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _))
408 ais->Start(&sink); 411 .Times(AtLeast(10))
409 message_loop_.Run(); 412 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &run_loop));
410 ais->Stop(); 413 ais->Start(&sink);
411 ais.Close(); 414 run_loop.Run();
415 ais->Stop();
416 ais.Close();
417 }
412 418
413 // 5 ms packet size. 419 // 5 ms packet size.
414 420
415 count = 0; 421 count = 0;
416 ais.Reset(aisw.Create(frames_per_buffer_10ms / 2)); 422 ais.Reset(aisw.Create(frames_per_buffer_10ms / 2));
417 EXPECT_TRUE(ais->Open()); 423 EXPECT_TRUE(ais->Open());
418 bytes_per_packet = aisw.channels() * aisw.frames_per_buffer() * 424 bytes_per_packet = aisw.channels() * aisw.frames_per_buffer() *
419 (aisw.bits_per_sample() / 8); 425 (aisw.bits_per_sample() / 8);
420 426
421 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _)) 427 {
422 .Times(AtLeast(10)) 428 base::RunLoop run_loop;
423 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &message_loop_)); 429 EXPECT_CALL(sink, OnData(ais.get(), NotNull(), _, _))
424 ais->Start(&sink); 430 .Times(AtLeast(10))
425 message_loop_.Run(); 431 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, &run_loop));
426 ais->Stop(); 432 ais->Start(&sink);
427 ais.Close(); 433 run_loop.Run();
434 ais->Stop();
435 ais.Close();
436 }
428 } 437 }
429 438
430 // Test that we can capture a stream in loopback. 439 // Test that we can capture a stream in loopback.
431 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamLoopback) { 440 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamLoopback) {
432 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices() && 441 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices() &&
433 CoreAudioUtil::IsSupported()); 442 CoreAudioUtil::IsSupported());
434 443
435 AudioParameters params = audio_manager_->GetInputStreamParameters( 444 AudioParameters params = audio_manager_->GetInputStreamParameters(
436 AudioDeviceDescription::kLoopbackInputDeviceId); 445 AudioDeviceDescription::kLoopbackInputDeviceId);
437 EXPECT_EQ(params.effects(), 0); 446 EXPECT_EQ(params.effects(), 0);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample()); 487 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample());
479 VLOG(0) << ">> Speak into the default microphone while recording."; 488 VLOG(0) << ">> Speak into the default microphone while recording.";
480 ais->Start(&file_sink); 489 ais->Start(&file_sink);
481 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 490 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
482 ais->Stop(); 491 ais->Stop();
483 VLOG(0) << ">> Recording has stopped."; 492 VLOG(0) << ">> Recording has stopped.";
484 ais.Close(); 493 ais.Close();
485 } 494 }
486 495
487 } // namespace media 496 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_device_unittest.cc ('k') | media/audio/win/audio_low_latency_output_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698