| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/android/build_info.h" | |
| 6 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 7 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 11 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 12 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 using namespace std; | 88 using namespace std; |
| 90 os << endl << "format: " << FormatToString(params.format()) << endl | 89 os << endl << "format: " << FormatToString(params.format()) << endl |
| 91 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 90 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
| 92 << "sample rate: " << params.sample_rate() << endl | 91 << "sample rate: " << params.sample_rate() << endl |
| 93 << "bits per sample: " << params.bits_per_sample() << endl | 92 << "bits per sample: " << params.bits_per_sample() << endl |
| 94 << "frames per buffer: " << params.frames_per_buffer() << endl | 93 << "frames per buffer: " << params.frames_per_buffer() << endl |
| 95 << "channels: " << params.channels() << endl | 94 << "channels: " << params.channels() << endl |
| 96 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl | 95 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl |
| 97 << "bytes per second: " << params.GetBytesPerSecond() << endl | 96 << "bytes per second: " << params.GetBytesPerSecond() << endl |
| 98 << "bytes per frame: " << params.GetBytesPerFrame() << endl | 97 << "bytes per frame: " << params.GetBytesPerFrame() << endl |
| 99 << "chunk size in ms: " << ExpectedTimeBetweenCallbacks(params) << endl | 98 << "frame size in ms: " << ExpectedTimeBetweenCallbacks(params); |
| 100 << "echo_canceller: " | |
| 101 << (params.effects() & AudioParameters::ECHO_CANCELLER); | |
| 102 return os; | 99 return os; |
| 103 } | 100 } |
| 104 | 101 |
| 105 // Gmock implementation of AudioInputStream::AudioInputCallback. | 102 // Gmock implementation of AudioInputStream::AudioInputCallback. |
| 106 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { | 103 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
| 107 public: | 104 public: |
| 108 MOCK_METHOD5(OnData, | 105 MOCK_METHOD5(OnData, |
| 109 void(AudioInputStream* stream, | 106 void(AudioInputStream* stream, |
| 110 const uint8* src, | 107 const uint8* src, |
| 111 uint32 size, | 108 uint32 size, |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 AudioParameters params_; | 376 AudioParameters params_; |
| 380 base::TimeTicks previous_time_; | 377 base::TimeTicks previous_time_; |
| 381 base::Lock lock_; | 378 base::Lock lock_; |
| 382 scoped_ptr<media::SeekableBuffer> fifo_; | 379 scoped_ptr<media::SeekableBuffer> fifo_; |
| 383 scoped_ptr<uint8[]> buffer_; | 380 scoped_ptr<uint8[]> buffer_; |
| 384 bool started_; | 381 bool started_; |
| 385 | 382 |
| 386 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); | 383 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); |
| 387 }; | 384 }; |
| 388 | 385 |
| 389 // Test fixture class for tests which only exercise the output path. | 386 // Test fixture class. |
| 390 class AudioAndroidOutputTest : public testing::Test { | 387 class AudioAndroidTest : public testing::Test { |
| 391 public: | 388 public: |
| 392 AudioAndroidOutputTest() {} | 389 AudioAndroidTest() {} |
| 393 | 390 |
| 394 protected: | 391 protected: |
| 395 virtual void SetUp() { | 392 virtual void SetUp() { |
| 396 audio_manager_.reset(AudioManager::CreateForTesting()); | 393 audio_manager_.reset(AudioManager::CreateForTesting()); |
| 397 loop_.reset(new base::MessageLoopForUI()); | 394 loop_.reset(new base::MessageLoopForUI()); |
| 398 } | 395 } |
| 399 | 396 |
| 400 virtual void TearDown() {} | 397 virtual void TearDown() {} |
| 401 | 398 |
| 402 AudioManager* audio_manager() { return audio_manager_.get(); } | 399 AudioManager* audio_manager() { return audio_manager_.get(); } |
| 403 base::MessageLoopForUI* loop() { return loop_.get(); } | 400 base::MessageLoopForUI* loop() { return loop_.get(); } |
| 404 | 401 |
| 402 AudioParameters GetDefaultInputStreamParameters() { |
| 403 return audio_manager()->GetInputStreamParameters( |
| 404 AudioManagerBase::kDefaultDeviceId); |
| 405 } |
| 406 |
| 405 AudioParameters GetDefaultOutputStreamParameters() { | 407 AudioParameters GetDefaultOutputStreamParameters() { |
| 406 return audio_manager()->GetDefaultOutputStreamParameters(); | 408 return audio_manager()->GetDefaultOutputStreamParameters(); |
| 407 } | 409 } |
| 408 | 410 |
| 409 double AverageTimeBetweenCallbacks(int num_callbacks) const { | 411 double AverageTimeBetweenCallbacks(int num_callbacks) const { |
| 410 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) | 412 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) |
| 411 .InMillisecondsF(); | 413 .InMillisecondsF(); |
| 412 } | 414 } |
| 413 | 415 |
| 414 void StartOutputStreamCallbacks(const AudioParameters& params) { | 416 void StartInputStreamCallbacks(const AudioParameters& params) { |
| 415 double expected_time_between_callbacks_ms = | 417 double expected_time_between_callbacks_ms = |
| 416 ExpectedTimeBetweenCallbacks(params); | 418 ExpectedTimeBetweenCallbacks(params); |
| 417 const int num_callbacks = | 419 const int num_callbacks = |
| 418 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 420 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
| 419 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( | 421 AudioInputStream* stream = audio_manager()->MakeAudioInputStream( |
| 420 params, std::string(), std::string()); | 422 params, AudioManagerBase::kDefaultDeviceId); |
| 421 EXPECT_TRUE(stream); | 423 EXPECT_TRUE(stream); |
| 422 | 424 |
| 423 int count = 0; | 425 int count = 0; |
| 424 MockAudioOutputCallback source; | 426 MockAudioInputCallback sink; |
| 425 | 427 |
| 426 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 428 EXPECT_CALL(sink, |
| 429 OnData(stream, NotNull(), params.GetBytesPerBuffer(), _, _)) |
| 427 .Times(AtLeast(num_callbacks)) | 430 .Times(AtLeast(num_callbacks)) |
| 428 .WillRepeatedly( | 431 .WillRepeatedly( |
| 429 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 432 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); |
| 430 Invoke(&source, &MockAudioOutputCallback::RealOnMoreData))); | 433 EXPECT_CALL(sink, OnError(stream)).Times(0); |
| 431 EXPECT_CALL(source, OnError(stream)).Times(0); | 434 EXPECT_CALL(sink, OnClose(stream)).Times(1); |
| 432 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | |
| 433 | 435 |
| 434 EXPECT_TRUE(stream->Open()); | 436 EXPECT_TRUE(stream->Open()); |
| 435 stream->Start(&source); | 437 stream->Start(&sink); |
| 436 start_time_ = base::TimeTicks::Now(); | 438 start_time_ = base::TimeTicks::Now(); |
| 437 loop()->Run(); | 439 loop()->Run(); |
| 438 end_time_ = base::TimeTicks::Now(); | 440 end_time_ = base::TimeTicks::Now(); |
| 439 stream->Stop(); | 441 stream->Stop(); |
| 440 stream->Close(); | 442 stream->Close(); |
| 441 | 443 |
| 442 double average_time_between_callbacks_ms = | 444 double average_time_between_callbacks_ms = |
| 443 AverageTimeBetweenCallbacks(num_callbacks); | 445 AverageTimeBetweenCallbacks(num_callbacks); |
| 444 VLOG(0) << "expected time between callbacks: " | 446 VLOG(0) << "expected time between callbacks: " |
| 445 << expected_time_between_callbacks_ms << " ms"; | 447 << expected_time_between_callbacks_ms << " ms"; |
| 446 VLOG(0) << "average time between callbacks: " | 448 VLOG(0) << "average time between callbacks: " |
| 447 << average_time_between_callbacks_ms << " ms"; | 449 << average_time_between_callbacks_ms << " ms"; |
| 448 EXPECT_GE(average_time_between_callbacks_ms, | 450 EXPECT_GE(average_time_between_callbacks_ms, |
| 449 0.70 * expected_time_between_callbacks_ms); | 451 0.70 * expected_time_between_callbacks_ms); |
| 450 EXPECT_LE(average_time_between_callbacks_ms, | 452 EXPECT_LE(average_time_between_callbacks_ms, |
| 451 1.30 * expected_time_between_callbacks_ms); | 453 1.30 * expected_time_between_callbacks_ms); |
| 452 } | 454 } |
| 453 | 455 |
| 454 scoped_ptr<base::MessageLoopForUI> loop_; | 456 void StartOutputStreamCallbacks(const AudioParameters& params) { |
| 455 scoped_ptr<AudioManager> audio_manager_; | |
| 456 base::TimeTicks start_time_; | |
| 457 base::TimeTicks end_time_; | |
| 458 | |
| 459 private: | |
| 460 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); | |
| 461 }; | |
| 462 | |
| 463 // AudioRecordInputStream should only be created on Jelly Bean and higher. This | |
| 464 // ensures we only test against the AudioRecord path when that is satisfied. | |
| 465 std::vector<bool> RunAudioRecordInputPathTests() { | |
| 466 std::vector<bool> tests; | |
| 467 tests.push_back(false); | |
| 468 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) | |
| 469 tests.push_back(true); | |
| 470 return tests; | |
| 471 } | |
| 472 | |
| 473 // Test fixture class for tests which exercise the input path, or both input and | |
| 474 // output paths. It is value-parameterized to test against both the Java | |
| 475 // AudioRecord (when true) and native OpenSLES (when false) input paths. | |
| 476 class AudioAndroidInputTest : public AudioAndroidOutputTest, | |
| 477 public testing::WithParamInterface<bool> { | |
| 478 public: | |
| 479 AudioAndroidInputTest() {} | |
| 480 | |
| 481 protected: | |
| 482 AudioParameters GetInputStreamParameters() { | |
| 483 AudioParameters input_params = audio_manager()->GetInputStreamParameters( | |
| 484 AudioManagerBase::kDefaultDeviceId); | |
| 485 // Override the platform effects setting to use the AudioRecord or OpenSLES | |
| 486 // path as requested. | |
| 487 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : | |
| 488 AudioParameters::NO_EFFECTS; | |
| 489 AudioParameters params(input_params.format(), | |
| 490 input_params.channel_layout(), | |
| 491 input_params.input_channels(), | |
| 492 input_params.sample_rate(), | |
| 493 input_params.bits_per_sample(), | |
| 494 input_params.frames_per_buffer(), | |
| 495 effects); | |
| 496 return params; | |
| 497 } | |
| 498 | |
| 499 void StartInputStreamCallbacks(const AudioParameters& params) { | |
| 500 double expected_time_between_callbacks_ms = | 457 double expected_time_between_callbacks_ms = |
| 501 ExpectedTimeBetweenCallbacks(params); | 458 ExpectedTimeBetweenCallbacks(params); |
| 502 const int num_callbacks = | 459 const int num_callbacks = |
| 503 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 460 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
| 504 AudioInputStream* stream = audio_manager()->MakeAudioInputStream( | 461 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( |
| 505 params, AudioManagerBase::kDefaultDeviceId); | 462 params, std::string(), std::string()); |
| 506 EXPECT_TRUE(stream); | 463 EXPECT_TRUE(stream); |
| 507 | 464 |
| 508 int count = 0; | 465 int count = 0; |
| 509 MockAudioInputCallback sink; | 466 MockAudioOutputCallback source; |
| 510 | 467 |
| 511 EXPECT_CALL(sink, | 468 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
| 512 OnData(stream, NotNull(), params.GetBytesPerBuffer(), _, _)) | |
| 513 .Times(AtLeast(num_callbacks)) | 469 .Times(AtLeast(num_callbacks)) |
| 514 .WillRepeatedly( | 470 .WillRepeatedly( |
| 515 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); | 471 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
| 516 EXPECT_CALL(sink, OnError(stream)).Times(0); | 472 Invoke(&source, &MockAudioOutputCallback::RealOnMoreData))); |
| 517 EXPECT_CALL(sink, OnClose(stream)).Times(1); | 473 EXPECT_CALL(source, OnError(stream)).Times(0); |
| 474 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); |
| 518 | 475 |
| 519 EXPECT_TRUE(stream->Open()); | 476 EXPECT_TRUE(stream->Open()); |
| 520 stream->Start(&sink); | 477 stream->Start(&source); |
| 521 start_time_ = base::TimeTicks::Now(); | 478 start_time_ = base::TimeTicks::Now(); |
| 522 loop()->Run(); | 479 loop()->Run(); |
| 523 end_time_ = base::TimeTicks::Now(); | 480 end_time_ = base::TimeTicks::Now(); |
| 524 stream->Stop(); | 481 stream->Stop(); |
| 525 stream->Close(); | 482 stream->Close(); |
| 526 | 483 |
| 527 double average_time_between_callbacks_ms = | 484 double average_time_between_callbacks_ms = |
| 528 AverageTimeBetweenCallbacks(num_callbacks); | 485 AverageTimeBetweenCallbacks(num_callbacks); |
| 529 VLOG(0) << "expected time between callbacks: " | 486 VLOG(0) << "expected time between callbacks: " |
| 530 << expected_time_between_callbacks_ms << " ms"; | 487 << expected_time_between_callbacks_ms << " ms"; |
| 531 VLOG(0) << "average time between callbacks: " | 488 VLOG(0) << "average time between callbacks: " |
| 532 << average_time_between_callbacks_ms << " ms"; | 489 << average_time_between_callbacks_ms << " ms"; |
| 533 EXPECT_GE(average_time_between_callbacks_ms, | 490 EXPECT_GE(average_time_between_callbacks_ms, |
| 534 0.70 * expected_time_between_callbacks_ms); | 491 0.70 * expected_time_between_callbacks_ms); |
| 535 EXPECT_LE(average_time_between_callbacks_ms, | 492 EXPECT_LE(average_time_between_callbacks_ms, |
| 536 1.30 * expected_time_between_callbacks_ms); | 493 1.30 * expected_time_between_callbacks_ms); |
| 537 } | 494 } |
| 538 | 495 |
| 496 scoped_ptr<base::MessageLoopForUI> loop_; |
| 497 scoped_ptr<AudioManager> audio_manager_; |
| 498 base::TimeTicks start_time_; |
| 499 base::TimeTicks end_time_; |
| 539 | 500 |
| 540 private: | 501 DISALLOW_COPY_AND_ASSIGN(AudioAndroidTest); |
| 541 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | |
| 542 }; | 502 }; |
| 543 | 503 |
| 544 // Get the default audio input parameters and log the result. | 504 // Get the default audio input parameters and log the result. |
| 545 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { | 505 TEST_F(AudioAndroidTest, GetInputStreamParameters) { |
| 546 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here | 506 AudioParameters params = GetDefaultInputStreamParameters(); |
| 547 // so that we can log the real (non-overridden) values of the effects. | |
| 548 AudioParameters params = audio_manager()->GetInputStreamParameters( | |
| 549 AudioManagerBase::kDefaultDeviceId); | |
| 550 EXPECT_TRUE(params.IsValid()); | 507 EXPECT_TRUE(params.IsValid()); |
| 551 VLOG(1) << params; | 508 VLOG(1) << params; |
| 552 } | 509 } |
| 553 | 510 |
| 554 // Get the default audio output parameters and log the result. | 511 // Get the default audio output parameters and log the result. |
| 555 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { | 512 TEST_F(AudioAndroidTest, GetDefaultOutputStreamParameters) { |
| 556 AudioParameters params = GetDefaultOutputStreamParameters(); | 513 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 557 EXPECT_TRUE(params.IsValid()); | 514 EXPECT_TRUE(params.IsValid()); |
| 558 VLOG(1) << params; | 515 VLOG(1) << params; |
| 559 } | 516 } |
| 560 | 517 |
| 561 // Check if low-latency output is supported and log the result as output. | 518 // Check if low-latency output is supported and log the result as output. |
| 562 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { | 519 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { |
| 563 AudioManagerAndroid* manager = | 520 AudioManagerAndroid* manager = |
| 564 static_cast<AudioManagerAndroid*>(audio_manager()); | 521 static_cast<AudioManagerAndroid*>(audio_manager()); |
| 565 bool low_latency = manager->IsAudioLowLatencySupported(); | 522 bool low_latency = manager->IsAudioLowLatencySupported(); |
| 566 low_latency ? VLOG(0) << "Low latency output is supported" | 523 low_latency ? VLOG(0) << "Low latency output is supported" |
| 567 : VLOG(0) << "Low latency output is *not* supported"; | 524 : VLOG(0) << "Low latency output is *not* supported"; |
| 568 } | 525 } |
| 569 | 526 |
| 570 // Ensure that a default input stream can be created and closed. | 527 // Ensure that a default input stream can be created and closed. |
| 571 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 528 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { |
| 572 AudioParameters params = GetInputStreamParameters(); | 529 AudioParameters params = GetDefaultInputStreamParameters(); |
| 573 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 530 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 574 params, AudioManagerBase::kDefaultDeviceId); | 531 params, AudioManagerBase::kDefaultDeviceId); |
| 575 EXPECT_TRUE(ais); | 532 EXPECT_TRUE(ais); |
| 576 ais->Close(); | 533 ais->Close(); |
| 577 } | 534 } |
| 578 | 535 |
| 579 // Ensure that a default output stream can be created and closed. | 536 // Ensure that a default output stream can be created and closed. |
| 580 // TODO(henrika): should we also verify that this API changes the audio mode | 537 // TODO(henrika): should we also verify that this API changes the audio mode |
| 581 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 538 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 582 // it is called? | 539 // it is called? |
| 583 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 540 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { |
| 584 AudioParameters params = GetDefaultOutputStreamParameters(); | 541 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 585 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 542 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 586 params, std::string(), std::string()); | 543 params, std::string(), std::string()); |
| 587 EXPECT_TRUE(aos); | 544 EXPECT_TRUE(aos); |
| 588 aos->Close(); | 545 aos->Close(); |
| 589 } | 546 } |
| 590 | 547 |
| 591 // Ensure that a default input stream can be opened and closed. | 548 // Ensure that a default input stream can be opened and closed. |
| 592 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { | 549 TEST_F(AudioAndroidTest, OpenAndCloseInputStream) { |
| 593 AudioParameters params = GetInputStreamParameters(); | 550 AudioParameters params = GetDefaultInputStreamParameters(); |
| 594 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 551 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 595 params, AudioManagerBase::kDefaultDeviceId); | 552 params, AudioManagerBase::kDefaultDeviceId); |
| 596 EXPECT_TRUE(ais); | 553 EXPECT_TRUE(ais); |
| 597 EXPECT_TRUE(ais->Open()); | 554 EXPECT_TRUE(ais->Open()); |
| 598 ais->Close(); | 555 ais->Close(); |
| 599 } | 556 } |
| 600 | 557 |
| 601 // Ensure that a default output stream can be opened and closed. | 558 // Ensure that a default output stream can be opened and closed. |
| 602 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { | 559 TEST_F(AudioAndroidTest, OpenAndCloseOutputStream) { |
| 603 AudioParameters params = GetDefaultOutputStreamParameters(); | 560 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 604 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 561 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 605 params, std::string(), std::string()); | 562 params, std::string(), std::string()); |
| 606 EXPECT_TRUE(aos); | 563 EXPECT_TRUE(aos); |
| 607 EXPECT_TRUE(aos->Open()); | 564 EXPECT_TRUE(aos->Open()); |
| 608 aos->Close(); | 565 aos->Close(); |
| 609 } | 566 } |
| 610 | 567 |
| 611 // Start input streaming using default input parameters and ensure that the | 568 // Start input streaming using default input parameters and ensure that the |
| 612 // callback sequence is sane. | 569 // callback sequence is sane. |
| 613 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacks) { | 570 TEST_F(AudioAndroidTest, StartInputStreamCallbacks) { |
| 614 AudioParameters params = GetInputStreamParameters(); | 571 AudioParameters params = GetDefaultInputStreamParameters(); |
| 615 StartInputStreamCallbacks(params); | 572 StartInputStreamCallbacks(params); |
| 616 } | 573 } |
| 617 | 574 |
| 618 // Start input streaming using non default input parameters and ensure that the | 575 // Start input streaming using non default input parameters and ensure that the |
| 619 // callback sequence is sane. The only change we make in this test is to select | 576 // callback sequence is sane. The only change we make in this test is to select |
| 620 // a 10ms buffer size instead of the default size. | 577 // a 10ms buffer size instead of the default size. |
| 621 // TODO(henrika): possibly add support for more variations. | 578 // TODO(henrika): possibly add support for more variations. |
| 622 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacksNonDefaultParameters) { | 579 TEST_F(AudioAndroidTest, StartInputStreamCallbacksNonDefaultParameters) { |
| 623 AudioParameters native_params = GetInputStreamParameters(); | 580 AudioParameters native_params = GetDefaultInputStreamParameters(); |
| 624 AudioParameters params(native_params.format(), | 581 AudioParameters params(native_params.format(), |
| 625 native_params.channel_layout(), | 582 native_params.channel_layout(), |
| 626 native_params.input_channels(), | |
| 627 native_params.sample_rate(), | 583 native_params.sample_rate(), |
| 628 native_params.bits_per_sample(), | 584 native_params.bits_per_sample(), |
| 629 native_params.sample_rate() / 100, | 585 native_params.sample_rate() / 100); |
| 630 native_params.effects()); | |
| 631 StartInputStreamCallbacks(params); | 586 StartInputStreamCallbacks(params); |
| 632 } | 587 } |
| 633 | 588 |
| 634 // Start output streaming using default output parameters and ensure that the | 589 // Start output streaming using default output parameters and ensure that the |
| 635 // callback sequence is sane. | 590 // callback sequence is sane. |
| 636 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) { | 591 TEST_F(AudioAndroidTest, StartOutputStreamCallbacks) { |
| 637 AudioParameters params = GetDefaultOutputStreamParameters(); | 592 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 638 StartOutputStreamCallbacks(params); | 593 StartOutputStreamCallbacks(params); |
| 639 } | 594 } |
| 640 | 595 |
| 641 // Start output streaming using non default output parameters and ensure that | 596 // Start output streaming using non default output parameters and ensure that |
| 642 // the callback sequence is sane. The only change we make in this test is to | 597 // the callback sequence is sane. The only change we make in this test is to |
| 643 // select a 10ms buffer size instead of the default size and to open up the | 598 // select a 10ms buffer size instead of the default size and to open up the |
| 644 // device in mono. | 599 // device in mono. |
| 645 // TODO(henrika): possibly add support for more variations. | 600 // TODO(henrika): possibly add support for more variations. |
| 646 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacksNonDefaultParameters) { | 601 TEST_F(AudioAndroidTest, StartOutputStreamCallbacksNonDefaultParameters) { |
| 647 AudioParameters native_params = GetDefaultOutputStreamParameters(); | 602 AudioParameters native_params = GetDefaultOutputStreamParameters(); |
| 648 AudioParameters params(native_params.format(), | 603 AudioParameters params(native_params.format(), |
| 649 CHANNEL_LAYOUT_MONO, | 604 CHANNEL_LAYOUT_MONO, |
| 650 native_params.sample_rate(), | 605 native_params.sample_rate(), |
| 651 native_params.bits_per_sample(), | 606 native_params.bits_per_sample(), |
| 652 native_params.sample_rate() / 100); | 607 native_params.sample_rate() / 100); |
| 653 StartOutputStreamCallbacks(params); | 608 StartOutputStreamCallbacks(params); |
| 654 } | 609 } |
| 655 | 610 |
| 656 // Play out a PCM file segment in real time and allow the user to verify that | 611 // Play out a PCM file segment in real time and allow the user to verify that |
| 657 // the rendered audio sounds OK. | 612 // the rendered audio sounds OK. |
| 658 // NOTE: this test requires user interaction and is not designed to run as an | 613 // NOTE: this test requires user interaction and is not designed to run as an |
| 659 // automatized test on bots. | 614 // automatized test on bots. |
| 660 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { | 615 TEST_F(AudioAndroidTest, DISABLED_RunOutputStreamWithFileAsSource) { |
| 661 AudioParameters params = GetDefaultOutputStreamParameters(); | 616 AudioParameters params = GetDefaultOutputStreamParameters(); |
| 662 VLOG(1) << params; | 617 VLOG(1) << params; |
| 663 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 618 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 664 params, std::string(), std::string()); | 619 params, std::string(), std::string()); |
| 665 EXPECT_TRUE(aos); | 620 EXPECT_TRUE(aos); |
| 666 | 621 |
| 667 std::string file_name; | 622 std::string file_name; |
| 668 if (params.sample_rate() == 48000 && params.channels() == 2) { | 623 if (params.sample_rate() == 48000 && params.channels() == 2) { |
| 669 file_name = kSpeechFile_16b_s_48k; | 624 file_name = kSpeechFile_16b_s_48k; |
| 670 } else if (params.sample_rate() == 48000 && params.channels() == 1) { | 625 } else if (params.sample_rate() == 48000 && params.channels() == 1) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 687 VLOG(0) << ">> Verify that the file is played out correctly..."; | 642 VLOG(0) << ">> Verify that the file is played out correctly..."; |
| 688 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 643 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 689 aos->Stop(); | 644 aos->Stop(); |
| 690 aos->Close(); | 645 aos->Close(); |
| 691 } | 646 } |
| 692 | 647 |
| 693 // Start input streaming and run it for ten seconds while recording to a | 648 // Start input streaming and run it for ten seconds while recording to a |
| 694 // local audio file. | 649 // local audio file. |
| 695 // NOTE: this test requires user interaction and is not designed to run as an | 650 // NOTE: this test requires user interaction and is not designed to run as an |
| 696 // automatized test on bots. | 651 // automatized test on bots. |
| 697 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { | 652 TEST_F(AudioAndroidTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { |
| 698 AudioParameters params = GetInputStreamParameters(); | 653 AudioParameters params = GetDefaultInputStreamParameters(); |
| 699 VLOG(1) << params; | 654 VLOG(1) << params; |
| 700 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 655 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 701 params, AudioManagerBase::kDefaultDeviceId); | 656 params, AudioManagerBase::kDefaultDeviceId); |
| 702 EXPECT_TRUE(ais); | 657 EXPECT_TRUE(ais); |
| 703 | 658 |
| 704 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", | 659 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", |
| 705 params.sample_rate(), | 660 params.sample_rate(), |
| 706 params.frames_per_buffer(), | 661 params.frames_per_buffer(), |
| 707 params.channels()); | 662 params.channels()); |
| 708 | 663 |
| 709 base::WaitableEvent event(false, false); | 664 base::WaitableEvent event(false, false); |
| 710 FileAudioSink sink(&event, params, file_name); | 665 FileAudioSink sink(&event, params, file_name); |
| 711 | 666 |
| 712 EXPECT_TRUE(ais->Open()); | 667 EXPECT_TRUE(ais->Open()); |
| 713 ais->Start(&sink); | 668 ais->Start(&sink); |
| 714 VLOG(0) << ">> Speak into the microphone to record audio..."; | 669 VLOG(0) << ">> Speak into the microphone to record audio..."; |
| 715 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 670 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 716 ais->Stop(); | 671 ais->Stop(); |
| 717 ais->Close(); | 672 ais->Close(); |
| 718 } | 673 } |
| 719 | 674 |
| 720 // Same test as RunSimplexInputStreamWithFileAsSink but this time output | 675 // Same test as RunSimplexInputStreamWithFileAsSink but this time output |
| 721 // streaming is active as well (reads zeros only). | 676 // streaming is active as well (reads zeros only). |
| 722 // NOTE: this test requires user interaction and is not designed to run as an | 677 // NOTE: this test requires user interaction and is not designed to run as an |
| 723 // automatized test on bots. | 678 // automatized test on bots. |
| 724 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { | 679 TEST_F(AudioAndroidTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { |
| 725 AudioParameters in_params = GetInputStreamParameters(); | 680 AudioParameters in_params = GetDefaultInputStreamParameters(); |
| 726 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 681 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 727 in_params, AudioManagerBase::kDefaultDeviceId); | 682 in_params, AudioManagerBase::kDefaultDeviceId); |
| 728 EXPECT_TRUE(ais); | 683 EXPECT_TRUE(ais); |
| 729 | 684 |
| 730 AudioParameters out_params = | 685 AudioParameters out_params = |
| 731 audio_manager()->GetDefaultOutputStreamParameters(); | 686 audio_manager()->GetDefaultOutputStreamParameters(); |
| 732 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 687 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
| 733 out_params, std::string(), std::string()); | 688 out_params, std::string(), std::string()); |
| 734 EXPECT_TRUE(aos); | 689 EXPECT_TRUE(aos); |
| 735 | 690 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 758 aos->Close(); | 713 aos->Close(); |
| 759 ais->Close(); | 714 ais->Close(); |
| 760 } | 715 } |
| 761 | 716 |
| 762 // Start audio in both directions while feeding captured data into a FIFO so | 717 // Start audio in both directions while feeding captured data into a FIFO so |
| 763 // it can be read directly (in loopback) by the render side. A small extra | 718 // it can be read directly (in loopback) by the render side. A small extra |
| 764 // delay will be added by the FIFO and an estimate of this delay will be | 719 // delay will be added by the FIFO and an estimate of this delay will be |
| 765 // printed out during the test. | 720 // printed out during the test. |
| 766 // NOTE: this test requires user interaction and is not designed to run as an | 721 // NOTE: this test requires user interaction and is not designed to run as an |
| 767 // automatized test on bots. | 722 // automatized test on bots. |
| 768 TEST_P(AudioAndroidInputTest, | 723 TEST_F(AudioAndroidTest, |
| 769 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { | 724 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { |
| 770 // Get native audio parameters for the input side. | 725 // Get native audio parameters for the input side. |
| 771 AudioParameters default_input_params = GetInputStreamParameters(); | 726 AudioParameters default_input_params = GetDefaultInputStreamParameters(); |
| 772 | 727 |
| 773 // Modify the parameters so that both input and output can use the same | 728 // Modify the parameters so that both input and output can use the same |
| 774 // parameters by selecting 10ms as buffer size. This will also ensure that | 729 // parameters by selecting 10ms as buffer size. This will also ensure that |
| 775 // the output stream will be a mono stream since mono is default for input | 730 // the output stream will be a mono stream since mono is default for input |
| 776 // audio on Android. | 731 // audio on Android. |
| 777 AudioParameters io_params(default_input_params.format(), | 732 AudioParameters io_params(default_input_params.format(), |
| 778 default_input_params.channel_layout(), | 733 default_input_params.channel_layout(), |
| 779 default_input_params.sample_rate(), | 734 default_input_params.sample_rate(), |
| 780 default_input_params.bits_per_sample(), | 735 default_input_params.bits_per_sample(), |
| 781 default_input_params.sample_rate() / 100); | 736 default_input_params.sample_rate() / 100); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 804 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 759 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
| 805 fflush(stdout); | 760 fflush(stdout); |
| 806 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 807 printf("\n"); | 762 printf("\n"); |
| 808 aos->Stop(); | 763 aos->Stop(); |
| 809 ais->Stop(); | 764 ais->Stop(); |
| 810 aos->Close(); | 765 aos->Close(); |
| 811 ais->Close(); | 766 ais->Close(); |
| 812 } | 767 } |
| 813 | 768 |
| 814 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | |
| 815 testing::ValuesIn(RunAudioRecordInputPathTests())); | |
| 816 | |
| 817 } // namespace media | 769 } // namespace media |
| OLD | NEW |