Chromium Code Reviews| 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" | 5 #include "base/android/build_info.h" |
| 6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "media/audio/android/audio_manager_android.h" | 18 #include "media/audio/android/audio_manager_android.h" |
| 18 #include "media/audio/audio_io.h" | 19 #include "media/audio/audio_io.h" |
| 19 #include "media/audio/audio_manager_base.h" | 20 #include "media/audio/audio_manager_base.h" |
| 20 #include "media/audio/mock_audio_source_callback.h" | 21 #include "media/audio/mock_audio_source_callback.h" |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 scoped_ptr<media::SeekableBuffer> fifo_; | 404 scoped_ptr<media::SeekableBuffer> fifo_; |
| 404 scoped_ptr<uint8[]> buffer_; | 405 scoped_ptr<uint8[]> buffer_; |
| 405 bool started_; | 406 bool started_; |
| 406 | 407 |
| 407 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); | 408 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); |
| 408 }; | 409 }; |
| 409 | 410 |
| 410 // Test fixture class for tests which only exercise the output path. | 411 // Test fixture class for tests which only exercise the output path. |
| 411 class AudioAndroidOutputTest : public testing::Test { | 412 class AudioAndroidOutputTest : public testing::Test { |
| 412 public: | 413 public: |
| 413 AudioAndroidOutputTest() {} | 414 AudioAndroidOutputTest() |
| 415 : loop_(new base::MessageLoopForUI()), | |
| 416 audio_manager_(AudioManager::CreateForTesting()), | |
| 417 audio_output_stream_(NULL) { | |
| 418 } | |
| 419 | |
| 420 virtual ~AudioAndroidOutputTest() { | |
| 421 } | |
| 414 | 422 |
| 415 protected: | 423 protected: |
| 416 virtual void SetUp() { | 424 AudioManager* audio_manager() { return audio_manager_.get(); } |
| 417 audio_manager_.reset(AudioManager::CreateForTesting()); | 425 base::MessageLoopForUI* loop() { return loop_.get(); } |
| 418 loop_.reset(new base::MessageLoopForUI()); | 426 AudioParameters audio_output_parameters() const { |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
nit: return const&?
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 427 return audio_output_parameters_; | |
| 428 } | |
| 429 AudioOutputStream* audio_output_stream() const { | |
| 430 return audio_output_stream_; | |
| 419 } | 431 } |
| 420 | 432 |
| 421 virtual void TearDown() {} | 433 // Synchronously runs the provided callback/closure on the audio thread. |
| 434 void RunOnAudioThread(const base::Closure& closure) { | |
| 435 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { | |
| 436 base::WaitableEvent event(false, false); | |
| 437 audio_manager()->GetTaskRunner()->PostTask( | |
| 438 FROM_HERE, | |
| 439 base::Bind(&AudioAndroidOutputTest::RunOnAudioThreadImpl, | |
| 440 base::Unretained(this), | |
| 441 closure, | |
| 442 &event)); | |
| 443 event.Wait(); | |
| 444 } else { | |
| 445 closure.Run(); | |
| 446 } | |
| 447 } | |
| 422 | 448 |
| 423 AudioManager* audio_manager() { return audio_manager_.get(); } | 449 void RunOnAudioThreadImpl(const base::Closure& closure, |
| 424 base::MessageLoopForUI* loop() { return loop_.get(); } | 450 base::WaitableEvent* event) { |
| 451 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 452 closure.Run(); | |
| 453 event->Signal(); | |
| 454 } | |
| 425 | 455 |
| 426 AudioParameters GetDefaultOutputStreamParameters() { | 456 void GetDefaultOutputStreamParametersOnAudioThread() { |
| 427 return audio_manager()->GetDefaultOutputStreamParameters(); | 457 RunOnAudioThread( |
| 458 base::Bind(&AudioAndroidOutputTest::GetDefaultOutputStreamParameters, | |
| 459 base::Unretained(this))); | |
| 460 } | |
| 461 | |
| 462 void MakeAOSOnAudioThread(const AudioParameters& params) { | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
MakeOutputStreamOnAudioThread
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 463 RunOnAudioThread( | |
| 464 base::Bind(&AudioAndroidOutputTest::MakeOutputStream, | |
| 465 base::Unretained(this), | |
| 466 params)); | |
| 467 } | |
| 468 | |
| 469 void OpenAndCloseAOSOnAudioThread() { | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
OpenAndCloseOutputStreamOnAudioThread
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 470 RunOnAudioThread( | |
| 471 base::Bind(&AudioAndroidOutputTest::OpenAndClose, | |
| 472 base::Unretained(this))); | |
| 473 } | |
| 474 | |
| 475 void OpenAndStartAOSOnAudioThread( | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
AOS -> OutputStream
same below
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 476 AudioOutputStream::AudioSourceCallback* source) { | |
| 477 RunOnAudioThread( | |
| 478 base::Bind(&AudioAndroidOutputTest::OpenAndStart, | |
| 479 base::Unretained(this), | |
| 480 source)); | |
| 481 } | |
| 482 | |
| 483 void StopAndCloseAOSOnAudioThread() { | |
| 484 RunOnAudioThread( | |
| 485 base::Bind(&AudioAndroidOutputTest::StopAndClose, | |
| 486 base::Unretained(this))); | |
| 428 } | 487 } |
| 429 | 488 |
| 430 double AverageTimeBetweenCallbacks(int num_callbacks) const { | 489 double AverageTimeBetweenCallbacks(int num_callbacks) const { |
| 431 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) | 490 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) |
| 432 .InMillisecondsF(); | 491 .InMillisecondsF(); |
| 433 } | 492 } |
| 434 | 493 |
| 435 void StartOutputStreamCallbacks(const AudioParameters& params) { | 494 void StartOutputStreamCallbacks(const AudioParameters& params) { |
| 436 double expected_time_between_callbacks_ms = | 495 double expected_time_between_callbacks_ms = |
| 437 ExpectedTimeBetweenCallbacks(params); | 496 ExpectedTimeBetweenCallbacks(params); |
| 438 const int num_callbacks = | 497 const int num_callbacks = |
| 439 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 498 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
| 440 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( | 499 MakeAOSOnAudioThread(params); |
| 441 params, std::string()); | |
| 442 EXPECT_TRUE(stream); | |
| 443 | 500 |
| 444 int count = 0; | 501 int count = 0; |
| 445 MockAudioSourceCallback source; | 502 MockAudioSourceCallback source; |
| 446 | 503 |
| 447 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 504 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
| 448 .Times(AtLeast(num_callbacks)) | 505 .Times(AtLeast(num_callbacks)) |
| 449 .WillRepeatedly( | 506 .WillRepeatedly( |
| 450 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 507 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
| 451 Invoke(RealOnMoreData))); | 508 Invoke(RealOnMoreData))); |
| 452 EXPECT_CALL(source, OnError(stream)).Times(0); | 509 EXPECT_CALL(source, OnError(audio_output_stream())).Times(0); |
| 453 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | 510 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); |
| 454 | 511 |
| 455 EXPECT_TRUE(stream->Open()); | 512 OpenAndStartAOSOnAudioThread(&source); |
| 456 stream->Start(&source); | 513 |
| 457 start_time_ = base::TimeTicks::Now(); | 514 start_time_ = base::TimeTicks::Now(); |
| 458 loop()->Run(); | 515 loop()->Run(); |
| 459 end_time_ = base::TimeTicks::Now(); | 516 end_time_ = base::TimeTicks::Now(); |
| 460 stream->Stop(); | 517 |
| 461 stream->Close(); | 518 StopAndCloseAOSOnAudioThread(); |
| 462 | 519 |
| 463 double average_time_between_callbacks_ms = | 520 double average_time_between_callbacks_ms = |
| 464 AverageTimeBetweenCallbacks(num_callbacks); | 521 AverageTimeBetweenCallbacks(num_callbacks); |
| 465 VLOG(0) << "expected time between callbacks: " | 522 VLOG(0) << "expected time between callbacks: " |
| 466 << expected_time_between_callbacks_ms << " ms"; | 523 << expected_time_between_callbacks_ms << " ms"; |
| 467 VLOG(0) << "average time between callbacks: " | 524 VLOG(0) << "average time between callbacks: " |
| 468 << average_time_between_callbacks_ms << " ms"; | 525 << average_time_between_callbacks_ms << " ms"; |
| 469 EXPECT_GE(average_time_between_callbacks_ms, | 526 EXPECT_GE(average_time_between_callbacks_ms, |
| 470 0.70 * expected_time_between_callbacks_ms); | 527 0.70 * expected_time_between_callbacks_ms); |
| 471 EXPECT_LE(average_time_between_callbacks_ms, | 528 EXPECT_LE(average_time_between_callbacks_ms, |
| 472 1.30 * expected_time_between_callbacks_ms); | 529 1.30 * expected_time_between_callbacks_ms); |
| 473 } | 530 } |
| 474 | 531 |
| 532 void GetDefaultOutputStreamParameters() { | |
| 533 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 534 audio_output_parameters_ = | |
| 535 audio_manager()->GetDefaultOutputStreamParameters(); | |
| 536 EXPECT_TRUE(audio_output_parameters_.IsValid()); | |
| 537 } | |
| 538 | |
| 539 void MakeOutputStream(const AudioParameters& params) { | |
| 540 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 541 audio_output_stream_ = audio_manager()->MakeAudioOutputStream( | |
| 542 params, std::string()); | |
| 543 EXPECT_TRUE(audio_output_stream_); | |
| 544 } | |
| 545 | |
| 546 void OpenAndClose() { | |
| 547 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 548 EXPECT_TRUE(audio_output_stream()->Open()); | |
| 549 audio_output_stream()->Close(); | |
| 550 } | |
| 551 | |
| 552 void OpenAndStart(AudioOutputStream::AudioSourceCallback* source) { | |
| 553 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 554 EXPECT_TRUE(audio_output_stream()->Open()); | |
| 555 audio_output_stream()->Start(source); | |
| 556 } | |
| 557 | |
| 558 void StopAndClose() { | |
| 559 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 560 audio_output_stream()->Stop(); | |
| 561 audio_output_stream()->Close(); | |
| 562 } | |
| 563 | |
| 475 scoped_ptr<base::MessageLoopForUI> loop_; | 564 scoped_ptr<base::MessageLoopForUI> loop_; |
| 476 scoped_ptr<AudioManager> audio_manager_; | 565 scoped_ptr<AudioManager> audio_manager_; |
| 566 AudioParameters audio_output_parameters_; | |
| 567 AudioOutputStream* audio_output_stream_; | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
This variable is deleted when Close() is called, r
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done. Please check again. Perhaps you meant someth
| |
| 477 base::TimeTicks start_time_; | 568 base::TimeTicks start_time_; |
| 478 base::TimeTicks end_time_; | 569 base::TimeTicks end_time_; |
| 479 | 570 |
| 480 private: | 571 private: |
| 481 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); | 572 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); |
| 482 }; | 573 }; |
| 483 | 574 |
| 484 // AudioRecordInputStream should only be created on Jelly Bean and higher. This | 575 // AudioRecordInputStream should only be created on Jelly Bean and higher. This |
| 485 // ensures we only test against the AudioRecord path when that is satisfied. | 576 // ensures we only test against the AudioRecord path when that is satisfied. |
| 486 std::vector<bool> RunAudioRecordInputPathTests() { | 577 std::vector<bool> RunAudioRecordInputPathTests() { |
| 487 std::vector<bool> tests; | 578 std::vector<bool> tests; |
| 488 tests.push_back(false); | 579 tests.push_back(false); |
| 489 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) | 580 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) |
| 490 tests.push_back(true); | 581 tests.push_back(true); |
| 491 return tests; | 582 return tests; |
| 492 } | 583 } |
| 493 | 584 |
| 494 // Test fixture class for tests which exercise the input path, or both input and | 585 // Test fixture class for tests which exercise the input path, or both input and |
| 495 // output paths. It is value-parameterized to test against both the Java | 586 // output paths. It is value-parameterized to test against both the Java |
| 496 // AudioRecord (when true) and native OpenSLES (when false) input paths. | 587 // AudioRecord (when true) and native OpenSLES (when false) input paths. |
| 497 class AudioAndroidInputTest : public AudioAndroidOutputTest, | 588 class AudioAndroidInputTest : public AudioAndroidOutputTest, |
| 498 public testing::WithParamInterface<bool> { | 589 public testing::WithParamInterface<bool> { |
| 499 public: | 590 public: |
| 500 AudioAndroidInputTest() {} | 591 AudioAndroidInputTest() : audio_input_stream_(NULL) {} |
| 501 | 592 |
| 502 protected: | 593 protected: |
| 594 AudioInputStream* audio_input_stream() { return audio_input_stream_; } | |
| 595 AudioParameters audio_input_parameters() { return audio_input_parameters_; } | |
| 596 | |
| 503 AudioParameters GetInputStreamParameters() { | 597 AudioParameters GetInputStreamParameters() { |
| 504 AudioParameters input_params = audio_manager()->GetInputStreamParameters( | 598 GetDefaultInputStreamParametersOnAudioThread(); |
| 505 AudioManagerBase::kDefaultDeviceId); | 599 |
| 506 // Override the platform effects setting to use the AudioRecord or OpenSLES | 600 // Override the platform effects setting to use the AudioRecord or OpenSLES |
| 507 // path as requested. | 601 // path as requested. |
| 508 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : | 602 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : |
| 509 AudioParameters::NO_EFFECTS; | 603 AudioParameters::NO_EFFECTS; |
| 510 AudioParameters params(input_params.format(), | 604 AudioParameters params(audio_input_parameters().format(), |
| 511 input_params.channel_layout(), | 605 audio_input_parameters().channel_layout(), |
| 512 input_params.input_channels(), | 606 audio_input_parameters().input_channels(), |
| 513 input_params.sample_rate(), | 607 audio_input_parameters().sample_rate(), |
| 514 input_params.bits_per_sample(), | 608 audio_input_parameters().bits_per_sample(), |
| 515 input_params.frames_per_buffer(), | 609 audio_input_parameters().frames_per_buffer(), |
| 516 effects); | 610 effects); |
| 517 return params; | 611 return params; |
| 518 } | 612 } |
| 519 | 613 |
| 614 void GetDefaultInputStreamParametersOnAudioThread() { | |
| 615 RunOnAudioThread( | |
| 616 base::Bind(&AudioAndroidInputTest::GetDefaultInputStreamParameters, | |
| 617 base::Unretained(this))); | |
| 618 } | |
| 619 | |
| 620 void MakeAISOnAudioThread(const AudioParameters& params) { | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
AIS -> InputStream
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 621 RunOnAudioThread( | |
| 622 base::Bind(&AudioAndroidInputTest::MakeInputStream, | |
| 623 base::Unretained(this), | |
| 624 params)); | |
| 625 } | |
| 626 | |
| 627 void OpenAndCloseAISOnAudioThread() { | |
| 628 RunOnAudioThread( | |
| 629 base::Bind(&AudioAndroidInputTest::OpenAndClose, | |
| 630 base::Unretained(this))); | |
| 631 } | |
| 632 | |
| 633 void OpenAndStartAISOnAudioThread( | |
| 634 AudioInputStream::AudioInputCallback* sink) { | |
| 635 RunOnAudioThread( | |
| 636 base::Bind(&AudioAndroidInputTest::OpenAndStart, | |
| 637 base::Unretained(this), | |
| 638 sink)); | |
| 639 } | |
| 640 | |
| 641 void StopAndCloseAISOnAudioThread() { | |
| 642 RunOnAudioThread( | |
| 643 base::Bind(&AudioAndroidInputTest::StopAndClose, | |
| 644 base::Unretained(this))); | |
| 645 } | |
| 646 | |
| 520 void StartInputStreamCallbacks(const AudioParameters& params) { | 647 void StartInputStreamCallbacks(const AudioParameters& params) { |
| 521 double expected_time_between_callbacks_ms = | 648 double expected_time_between_callbacks_ms = |
| 522 ExpectedTimeBetweenCallbacks(params); | 649 ExpectedTimeBetweenCallbacks(params); |
| 523 const int num_callbacks = | 650 const int num_callbacks = |
| 524 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 651 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
| 525 AudioInputStream* stream = audio_manager()->MakeAudioInputStream( | 652 |
| 526 params, AudioManagerBase::kDefaultDeviceId); | 653 MakeAISOnAudioThread(params); |
| 527 EXPECT_TRUE(stream); | |
| 528 | 654 |
| 529 int count = 0; | 655 int count = 0; |
| 530 MockAudioInputCallback sink; | 656 MockAudioInputCallback sink; |
| 531 | 657 |
| 532 EXPECT_CALL(sink, | 658 EXPECT_CALL(sink, |
| 533 OnData(stream, NotNull(), params.GetBytesPerBuffer(), _, _)) | 659 OnData(audio_input_stream(), |
| 660 NotNull(), | |
| 661 params. | |
| 662 GetBytesPerBuffer(), _, _)) | |
| 534 .Times(AtLeast(num_callbacks)) | 663 .Times(AtLeast(num_callbacks)) |
| 535 .WillRepeatedly( | 664 .WillRepeatedly( |
| 536 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); | 665 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); |
| 537 EXPECT_CALL(sink, OnError(stream)).Times(0); | 666 EXPECT_CALL(sink, OnError(audio_input_stream())).Times(0); |
| 538 | 667 |
| 539 EXPECT_TRUE(stream->Open()); | 668 OpenAndStartAISOnAudioThread(&sink); |
| 540 stream->Start(&sink); | 669 |
| 541 start_time_ = base::TimeTicks::Now(); | 670 start_time_ = base::TimeTicks::Now(); |
| 542 loop()->Run(); | 671 loop()->Run(); |
| 543 end_time_ = base::TimeTicks::Now(); | 672 end_time_ = base::TimeTicks::Now(); |
| 544 stream->Stop(); | 673 |
| 545 stream->Close(); | 674 StopAndCloseAISOnAudioThread(); |
| 546 | 675 |
| 547 double average_time_between_callbacks_ms = | 676 double average_time_between_callbacks_ms = |
| 548 AverageTimeBetweenCallbacks(num_callbacks); | 677 AverageTimeBetweenCallbacks(num_callbacks); |
| 549 VLOG(0) << "expected time between callbacks: " | 678 VLOG(0) << "expected time between callbacks: " |
| 550 << expected_time_between_callbacks_ms << " ms"; | 679 << expected_time_between_callbacks_ms << " ms"; |
| 551 VLOG(0) << "average time between callbacks: " | 680 VLOG(0) << "average time between callbacks: " |
| 552 << average_time_between_callbacks_ms << " ms"; | 681 << average_time_between_callbacks_ms << " ms"; |
| 553 EXPECT_GE(average_time_between_callbacks_ms, | 682 EXPECT_GE(average_time_between_callbacks_ms, |
| 554 0.70 * expected_time_between_callbacks_ms); | 683 0.70 * expected_time_between_callbacks_ms); |
| 555 EXPECT_LE(average_time_between_callbacks_ms, | 684 EXPECT_LE(average_time_between_callbacks_ms, |
| 556 1.30 * expected_time_between_callbacks_ms); | 685 1.30 * expected_time_between_callbacks_ms); |
| 557 } | 686 } |
| 558 | 687 |
| 688 void GetDefaultInputStreamParameters() { | |
| 689 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 690 audio_input_parameters_ = audio_manager()->GetInputStreamParameters( | |
| 691 AudioManagerBase::kDefaultDeviceId); | |
| 692 } | |
| 693 | |
| 694 void MakeInputStream(const AudioParameters& params) { | |
| 695 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 696 audio_input_stream_ = audio_manager()->MakeAudioInputStream( | |
| 697 params, AudioManagerBase::kDefaultDeviceId); | |
| 698 EXPECT_TRUE(audio_input_stream_); | |
| 699 } | |
| 700 | |
| 701 void OpenAndClose() { | |
| 702 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 703 EXPECT_TRUE(audio_input_stream()->Open()); | |
| 704 audio_input_stream()->Close(); | |
| 705 } | |
| 706 | |
| 707 void OpenAndStart(AudioInputStream::AudioInputCallback* sink) { | |
| 708 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 709 EXPECT_TRUE(audio_input_stream()->Open()); | |
| 710 audio_input_stream()->Start(sink); | |
| 711 } | |
| 712 | |
| 713 void StopAndClose() { | |
| 714 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); | |
| 715 audio_input_stream()->Stop(); | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
out of curiosity, is there a reason you call the m
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Actually no good reason at all. Do you want me to
| |
| 716 audio_input_stream()->Close(); | |
| 717 } | |
| 559 | 718 |
| 560 private: | 719 private: |
| 720 AudioInputStream* audio_input_stream_; | |
|
tommi (sloooow) - chröme
2014/02/17 13:24:55
same thing here re dangling pointer
henrika (OOO until Aug 14)
2014/02/17 15:14:41
Done.
| |
| 721 AudioParameters audio_input_parameters_; | |
| 561 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | 722 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); |
| 562 }; | 723 }; |
| 563 | 724 |
| 564 // Get the default audio input parameters and log the result. | 725 // Get the default audio input parameters and log the result. |
| 565 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { | 726 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { |
| 566 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here | 727 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here |
| 567 // so that we can log the real (non-overridden) values of the effects. | 728 // so that we can log the real (non-overridden) values of the effects. |
| 568 AudioParameters params = audio_manager()->GetInputStreamParameters( | 729 GetDefaultInputStreamParametersOnAudioThread(); |
| 569 AudioManagerBase::kDefaultDeviceId); | 730 EXPECT_TRUE(audio_input_parameters().IsValid()); |
| 570 EXPECT_TRUE(params.IsValid()); | 731 VLOG(1) << audio_input_parameters(); |
| 571 VLOG(1) << params; | |
| 572 } | 732 } |
| 573 | 733 |
| 574 // Get the default audio output parameters and log the result. | 734 // Get the default audio output parameters and log the result. |
| 575 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { | 735 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { |
| 576 AudioParameters params = GetDefaultOutputStreamParameters(); | 736 GetDefaultOutputStreamParametersOnAudioThread(); |
| 577 EXPECT_TRUE(params.IsValid()); | 737 VLOG(1) << audio_output_parameters(); |
| 578 VLOG(1) << params; | |
| 579 } | |
| 580 | |
| 581 // Check if low-latency output is supported and log the result as output. | |
| 582 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { | |
| 583 AudioManagerAndroid* manager = | |
| 584 static_cast<AudioManagerAndroid*>(audio_manager()); | |
| 585 bool low_latency = manager->IsAudioLowLatencySupported(); | |
| 586 low_latency ? VLOG(0) << "Low latency output is supported" | |
| 587 : VLOG(0) << "Low latency output is *not* supported"; | |
| 588 } | 738 } |
| 589 | 739 |
| 590 // Verify input device enumeration. | 740 // Verify input device enumeration. |
| 591 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { | 741 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { |
| 592 if (!audio_manager()->HasAudioInputDevices()) | 742 if (!audio_manager()->HasAudioInputDevices()) |
| 593 return; | 743 return; |
| 594 AudioDeviceNames devices; | 744 AudioDeviceNames devices; |
| 595 audio_manager()->GetAudioInputDeviceNames(&devices); | 745 RunOnAudioThread( |
| 746 base::Bind(&AudioManager::GetAudioInputDeviceNames, | |
| 747 base::Unretained(audio_manager()), | |
| 748 &devices)); | |
| 596 CheckDeviceNames(devices); | 749 CheckDeviceNames(devices); |
| 597 } | 750 } |
| 598 | 751 |
| 599 // Verify output device enumeration. | 752 // Verify output device enumeration. |
| 600 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { | 753 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { |
| 601 if (!audio_manager()->HasAudioOutputDevices()) | 754 if (!audio_manager()->HasAudioOutputDevices()) |
| 602 return; | 755 return; |
| 603 AudioDeviceNames devices; | 756 AudioDeviceNames devices; |
| 604 audio_manager()->GetAudioOutputDeviceNames(&devices); | 757 RunOnAudioThread( |
| 758 base::Bind(&AudioManager::GetAudioOutputDeviceNames, | |
| 759 base::Unretained(audio_manager()), | |
| 760 &devices)); | |
| 605 CheckDeviceNames(devices); | 761 CheckDeviceNames(devices); |
| 606 } | 762 } |
| 607 | 763 |
| 608 // Ensure that a default input stream can be created and closed. | 764 // Ensure that a default input stream can be created and closed. |
| 609 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { | 765 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
| 610 AudioParameters params = GetInputStreamParameters(); | 766 AudioParameters params = GetInputStreamParameters(); |
| 611 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 767 MakeAISOnAudioThread(params); |
| 612 params, AudioManagerBase::kDefaultDeviceId); | 768 RunOnAudioThread( |
| 613 EXPECT_TRUE(ais); | 769 base::Bind(&AudioInputStream::Close, |
| 614 ais->Close(); | 770 base::Unretained(audio_input_stream()))); |
| 615 } | 771 } |
| 616 | 772 |
| 617 // Ensure that a default output stream can be created and closed. | 773 // Ensure that a default output stream can be created and closed. |
| 618 // TODO(henrika): should we also verify that this API changes the audio mode | 774 // TODO(henrika): should we also verify that this API changes the audio mode |
| 619 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 775 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 620 // it is called? | 776 // it is called? |
| 621 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 777 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
| 622 AudioParameters params = GetDefaultOutputStreamParameters(); | 778 GetDefaultOutputStreamParametersOnAudioThread(); |
| 623 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 779 MakeAOSOnAudioThread(audio_output_parameters()); |
| 624 params, std::string()); | 780 RunOnAudioThread( |
| 625 EXPECT_TRUE(aos); | 781 base::Bind(&AudioOutputStream::Close, |
| 626 aos->Close(); | 782 base::Unretained(audio_output_stream()))); |
| 627 } | 783 } |
| 628 | 784 |
| 629 // Ensure that a default input stream can be opened and closed. | 785 // Ensure that a default input stream can be opened and closed. |
| 630 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { | 786 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { |
| 631 AudioParameters params = GetInputStreamParameters(); | 787 AudioParameters params = GetInputStreamParameters(); |
| 632 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 788 MakeAISOnAudioThread(params); |
| 633 params, AudioManagerBase::kDefaultDeviceId); | 789 OpenAndCloseAISOnAudioThread(); |
| 634 EXPECT_TRUE(ais); | |
| 635 EXPECT_TRUE(ais->Open()); | |
| 636 ais->Close(); | |
| 637 } | 790 } |
| 638 | 791 |
| 639 // Ensure that a default output stream can be opened and closed. | 792 // Ensure that a default output stream can be opened and closed. |
| 640 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { | 793 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { |
| 641 AudioParameters params = GetDefaultOutputStreamParameters(); | 794 GetDefaultOutputStreamParametersOnAudioThread(); |
| 642 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 795 MakeAOSOnAudioThread(audio_output_parameters()); |
| 643 params, std::string()); | 796 OpenAndCloseAOSOnAudioThread(); |
| 644 EXPECT_TRUE(aos); | |
| 645 EXPECT_TRUE(aos->Open()); | |
| 646 aos->Close(); | |
| 647 } | 797 } |
| 648 | 798 |
| 649 // Start input streaming using default input parameters and ensure that the | 799 // Start input streaming using default input parameters and ensure that the |
| 650 // callback sequence is sane. | 800 // callback sequence is sane. |
| 651 // Disabled per crbug/337867 | |
| 652 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { | 801 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { |
| 653 AudioParameters params = GetInputStreamParameters(); | 802 AudioParameters native_params = GetInputStreamParameters(); |
| 654 StartInputStreamCallbacks(params); | 803 StartInputStreamCallbacks(native_params); |
| 655 } | 804 } |
| 656 | 805 |
| 657 // Start input streaming using non default input parameters and ensure that the | 806 // Start input streaming using non default input parameters and ensure that the |
| 658 // callback sequence is sane. The only change we make in this test is to select | 807 // callback sequence is sane. The only change we make in this test is to select |
| 659 // a 10ms buffer size instead of the default size. | 808 // a 10ms buffer size instead of the default size. |
| 660 // TODO(henrika): possibly add support for more variations. | 809 TEST_P(AudioAndroidInputTest, |
| 661 // Disabled per crbug/337867 | 810 DISABLED_StartInputStreamCallbacksNonDefaultParameters) { |
| 662 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacksNonDefaultParame ters) { | |
| 663 AudioParameters native_params = GetInputStreamParameters(); | 811 AudioParameters native_params = GetInputStreamParameters(); |
| 664 AudioParameters params(native_params.format(), | 812 AudioParameters params(native_params.format(), |
| 665 native_params.channel_layout(), | 813 native_params.channel_layout(), |
| 666 native_params.input_channels(), | 814 native_params.input_channels(), |
| 667 native_params.sample_rate(), | 815 native_params.sample_rate(), |
| 668 native_params.bits_per_sample(), | 816 native_params.bits_per_sample(), |
| 669 native_params.sample_rate() / 100, | 817 native_params.sample_rate() / 100, |
| 670 native_params.effects()); | 818 native_params.effects()); |
| 671 StartInputStreamCallbacks(params); | 819 StartInputStreamCallbacks(params); |
| 672 } | 820 } |
| 673 | 821 |
| 674 // Start output streaming using default output parameters and ensure that the | 822 // Start output streaming using default output parameters and ensure that the |
| 675 // callback sequence is sane. | 823 // callback sequence is sane. |
| 676 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) { | 824 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) { |
| 677 AudioParameters params = GetDefaultOutputStreamParameters(); | 825 GetDefaultOutputStreamParametersOnAudioThread(); |
| 678 StartOutputStreamCallbacks(params); | 826 StartOutputStreamCallbacks(audio_output_parameters()); |
| 679 } | 827 } |
| 680 | 828 |
| 681 // Start output streaming using non default output parameters and ensure that | 829 // Start output streaming using non default output parameters and ensure that |
| 682 // the callback sequence is sane. The only change we make in this test is to | 830 // the callback sequence is sane. The only change we make in this test is to |
| 683 // select a 10ms buffer size instead of the default size and to open up the | 831 // select a 10ms buffer size instead of the default size and to open up the |
| 684 // device in mono. | 832 // device in mono. |
| 685 // TODO(henrika): possibly add support for more variations. | 833 // TODO(henrika): possibly add support for more variations. |
| 686 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacksNonDefaultParameters) { | 834 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacksNonDefaultParameters) { |
| 687 AudioParameters native_params = GetDefaultOutputStreamParameters(); | 835 GetDefaultOutputStreamParametersOnAudioThread(); |
| 688 AudioParameters params(native_params.format(), | 836 AudioParameters params(audio_output_parameters().format(), |
| 689 CHANNEL_LAYOUT_MONO, | 837 CHANNEL_LAYOUT_MONO, |
| 690 native_params.sample_rate(), | 838 audio_output_parameters().sample_rate(), |
| 691 native_params.bits_per_sample(), | 839 audio_output_parameters().bits_per_sample(), |
| 692 native_params.sample_rate() / 100); | 840 audio_output_parameters().sample_rate() / 100); |
| 693 StartOutputStreamCallbacks(params); | 841 StartOutputStreamCallbacks(params); |
| 694 } | 842 } |
| 695 | 843 |
| 696 // Play out a PCM file segment in real time and allow the user to verify that | 844 // Play out a PCM file segment in real time and allow the user to verify that |
| 697 // the rendered audio sounds OK. | 845 // the rendered audio sounds OK. |
| 698 // NOTE: this test requires user interaction and is not designed to run as an | 846 // NOTE: this test requires user interaction and is not designed to run as an |
| 699 // automatized test on bots. | 847 // automatized test on bots. |
| 700 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { | 848 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { |
| 701 AudioParameters params = GetDefaultOutputStreamParameters(); | 849 GetDefaultOutputStreamParametersOnAudioThread(); |
| 702 VLOG(1) << params; | 850 VLOG(1) << audio_output_parameters(); |
| 703 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 851 MakeAOSOnAudioThread(audio_output_parameters()); |
| 704 params, std::string()); | |
| 705 EXPECT_TRUE(aos); | |
| 706 | 852 |
| 707 std::string file_name; | 853 std::string file_name; |
| 854 const AudioParameters params = audio_output_parameters(); | |
| 708 if (params.sample_rate() == 48000 && params.channels() == 2) { | 855 if (params.sample_rate() == 48000 && params.channels() == 2) { |
| 709 file_name = kSpeechFile_16b_s_48k; | 856 file_name = kSpeechFile_16b_s_48k; |
| 710 } else if (params.sample_rate() == 48000 && params.channels() == 1) { | 857 } else if (params.sample_rate() == 48000 && params.channels() == 1) { |
| 711 file_name = kSpeechFile_16b_m_48k; | 858 file_name = kSpeechFile_16b_m_48k; |
| 712 } else if (params.sample_rate() == 44100 && params.channels() == 2) { | 859 } else if (params.sample_rate() == 44100 && params.channels() == 2) { |
| 713 file_name = kSpeechFile_16b_s_44k; | 860 file_name = kSpeechFile_16b_s_44k; |
| 714 } else if (params.sample_rate() == 44100 && params.channels() == 1) { | 861 } else if (params.sample_rate() == 44100 && params.channels() == 1) { |
| 715 file_name = kSpeechFile_16b_m_44k; | 862 file_name = kSpeechFile_16b_m_44k; |
| 716 } else { | 863 } else { |
| 717 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only."; | 864 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only."; |
| 718 return; | 865 return; |
| 719 } | 866 } |
| 720 | 867 |
| 721 base::WaitableEvent event(false, false); | 868 base::WaitableEvent event(false, false); |
| 722 FileAudioSource source(&event, file_name); | 869 FileAudioSource source(&event, file_name); |
| 723 | 870 |
| 724 EXPECT_TRUE(aos->Open()); | 871 OpenAndStartAOSOnAudioThread(&source); |
| 725 aos->SetVolume(1.0); | |
| 726 aos->Start(&source); | |
| 727 VLOG(0) << ">> Verify that the file is played out correctly..."; | 872 VLOG(0) << ">> Verify that the file is played out correctly..."; |
| 728 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 873 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 729 aos->Stop(); | 874 StopAndCloseAOSOnAudioThread(); |
| 730 aos->Close(); | |
| 731 } | 875 } |
| 732 | 876 |
| 733 // Start input streaming and run it for ten seconds while recording to a | 877 // Start input streaming and run it for ten seconds while recording to a |
| 734 // local audio file. | 878 // local audio file. |
| 735 // NOTE: this test requires user interaction and is not designed to run as an | 879 // NOTE: this test requires user interaction and is not designed to run as an |
| 736 // automatized test on bots. | 880 // automatized test on bots. |
| 737 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { | 881 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { |
| 738 AudioParameters params = GetInputStreamParameters(); | 882 AudioParameters params = GetInputStreamParameters(); |
| 739 VLOG(1) << params; | 883 VLOG(1) << params; |
| 740 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 884 MakeAISOnAudioThread(params); |
| 741 params, AudioManagerBase::kDefaultDeviceId); | |
| 742 EXPECT_TRUE(ais); | |
| 743 | 885 |
| 744 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", | 886 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", |
| 745 params.sample_rate(), | 887 params.sample_rate(), |
| 746 params.frames_per_buffer(), | 888 params.frames_per_buffer(), |
| 747 params.channels()); | 889 params.channels()); |
| 748 | 890 |
| 749 base::WaitableEvent event(false, false); | 891 base::WaitableEvent event(false, false); |
| 750 FileAudioSink sink(&event, params, file_name); | 892 FileAudioSink sink(&event, params, file_name); |
| 751 | 893 |
| 752 EXPECT_TRUE(ais->Open()); | 894 OpenAndStartAISOnAudioThread(&sink); |
| 753 ais->Start(&sink); | |
| 754 VLOG(0) << ">> Speak into the microphone to record audio..."; | 895 VLOG(0) << ">> Speak into the microphone to record audio..."; |
| 755 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 896 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 756 ais->Stop(); | 897 StopAndCloseAISOnAudioThread(); |
| 757 ais->Close(); | |
| 758 } | 898 } |
| 759 | 899 |
| 760 // Same test as RunSimplexInputStreamWithFileAsSink but this time output | 900 // Same test as RunSimplexInputStreamWithFileAsSink but this time output |
| 761 // streaming is active as well (reads zeros only). | 901 // streaming is active as well (reads zeros only). |
| 762 // NOTE: this test requires user interaction and is not designed to run as an | 902 // NOTE: this test requires user interaction and is not designed to run as an |
| 763 // automatized test on bots. | 903 // automatized test on bots. |
| 764 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { | 904 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { |
| 765 AudioParameters in_params = GetInputStreamParameters(); | 905 AudioParameters in_params = GetInputStreamParameters(); |
| 766 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 906 VLOG(1) << in_params; |
| 767 in_params, AudioManagerBase::kDefaultDeviceId); | 907 MakeAISOnAudioThread(in_params); |
| 768 EXPECT_TRUE(ais); | |
| 769 | 908 |
| 770 AudioParameters out_params = | 909 GetDefaultOutputStreamParametersOnAudioThread(); |
| 771 audio_manager()->GetDefaultOutputStreamParameters(); | 910 VLOG(1) << audio_output_parameters(); |
| 772 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 911 MakeAOSOnAudioThread(audio_output_parameters()); |
| 773 out_params, std::string()); | |
| 774 EXPECT_TRUE(aos); | |
| 775 | 912 |
| 776 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", | 913 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", |
| 777 in_params.sample_rate(), | 914 in_params.sample_rate(), |
| 778 in_params.frames_per_buffer(), | 915 in_params.frames_per_buffer(), |
| 779 in_params.channels()); | 916 in_params.channels()); |
| 780 | 917 |
| 781 base::WaitableEvent event(false, false); | 918 base::WaitableEvent event(false, false); |
| 782 FileAudioSink sink(&event, in_params, file_name); | 919 FileAudioSink sink(&event, in_params, file_name); |
| 783 MockAudioSourceCallback source; | 920 MockAudioSourceCallback source; |
| 784 | 921 |
| 785 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 922 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
| 786 .WillRepeatedly(Invoke(RealOnMoreData)); | 923 .WillRepeatedly(Invoke(RealOnMoreData)); |
| 787 EXPECT_CALL(source, OnError(aos)).Times(0); | 924 EXPECT_CALL(source, OnError(audio_output_stream())).Times(0); |
| 788 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | 925 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); |
| 789 | 926 |
| 790 EXPECT_TRUE(ais->Open()); | 927 OpenAndStartAISOnAudioThread(&sink); |
| 791 EXPECT_TRUE(aos->Open()); | 928 OpenAndStartAOSOnAudioThread(&source); |
| 792 ais->Start(&sink); | |
| 793 aos->Start(&source); | |
| 794 VLOG(0) << ">> Speak into the microphone to record audio"; | 929 VLOG(0) << ">> Speak into the microphone to record audio"; |
| 795 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 930 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 796 aos->Stop(); | 931 StopAndCloseAOSOnAudioThread(); |
| 797 ais->Stop(); | 932 StopAndCloseAISOnAudioThread(); |
| 798 aos->Close(); | |
| 799 ais->Close(); | |
| 800 } | 933 } |
| 801 | 934 |
| 802 // Start audio in both directions while feeding captured data into a FIFO so | 935 // Start audio in both directions while feeding captured data into a FIFO so |
| 803 // it can be read directly (in loopback) by the render side. A small extra | 936 // it can be read directly (in loopback) by the render side. A small extra |
| 804 // delay will be added by the FIFO and an estimate of this delay will be | 937 // delay will be added by the FIFO and an estimate of this delay will be |
| 805 // printed out during the test. | 938 // printed out during the test. |
| 806 // NOTE: this test requires user interaction and is not designed to run as an | 939 // NOTE: this test requires user interaction and is not designed to run as an |
| 807 // automatized test on bots. | 940 // automatized test on bots. |
| 808 TEST_P(AudioAndroidInputTest, | 941 TEST_P(AudioAndroidInputTest, |
| 809 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { | 942 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { |
| 810 // Get native audio parameters for the input side. | 943 // Get native audio parameters for the input side. |
| 811 AudioParameters default_input_params = GetInputStreamParameters(); | 944 AudioParameters default_input_params = GetInputStreamParameters(); |
| 812 | 945 |
| 813 // Modify the parameters so that both input and output can use the same | 946 // Modify the parameters so that both input and output can use the same |
| 814 // parameters by selecting 10ms as buffer size. This will also ensure that | 947 // parameters by selecting 10ms as buffer size. This will also ensure that |
| 815 // the output stream will be a mono stream since mono is default for input | 948 // the output stream will be a mono stream since mono is default for input |
| 816 // audio on Android. | 949 // audio on Android. |
| 817 AudioParameters io_params(default_input_params.format(), | 950 AudioParameters io_params(default_input_params.format(), |
| 818 default_input_params.channel_layout(), | 951 default_input_params.channel_layout(), |
| 819 ChannelLayoutToChannelCount( | 952 ChannelLayoutToChannelCount( |
| 820 default_input_params.channel_layout()), | 953 default_input_params.channel_layout()), |
| 821 default_input_params.sample_rate(), | 954 default_input_params.sample_rate(), |
| 822 default_input_params.bits_per_sample(), | 955 default_input_params.bits_per_sample(), |
| 823 default_input_params.sample_rate() / 100, | 956 default_input_params.sample_rate() / 100, |
| 824 default_input_params.effects()); | 957 default_input_params.effects()); |
| 825 VLOG(1) << io_params; | 958 VLOG(1) << io_params; |
| 826 | 959 |
| 827 // Create input and output streams using the common audio parameters. | 960 // Create input and output streams using the common audio parameters. |
| 828 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 961 MakeAISOnAudioThread(io_params); |
| 829 io_params, AudioManagerBase::kDefaultDeviceId); | 962 MakeAOSOnAudioThread(io_params); |
| 830 EXPECT_TRUE(ais); | |
| 831 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | |
| 832 io_params, std::string()); | |
| 833 EXPECT_TRUE(aos); | |
| 834 | 963 |
| 835 FullDuplexAudioSinkSource full_duplex(io_params); | 964 FullDuplexAudioSinkSource full_duplex(io_params); |
| 836 | 965 |
| 837 // Start a full duplex audio session and print out estimates of the extra | 966 // Start a full duplex audio session and print out estimates of the extra |
| 838 // delay we should expect from the FIFO. If real-time delay measurements are | 967 // delay we should expect from the FIFO. If real-time delay measurements are |
| 839 // performed, the result should be reduced by this extra delay since it is | 968 // performed, the result should be reduced by this extra delay since it is |
| 840 // something that has been added by the test. | 969 // something that has been added by the test. |
| 841 EXPECT_TRUE(ais->Open()); | 970 OpenAndStartAISOnAudioThread(&full_duplex); |
| 842 EXPECT_TRUE(aos->Open()); | 971 OpenAndStartAOSOnAudioThread(&full_duplex); |
| 843 ais->Start(&full_duplex); | |
| 844 aos->Start(&full_duplex); | |
| 845 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " | 972 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " |
| 846 << "once per second during this test."; | 973 << "once per second during this test."; |
| 847 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 974 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
| 848 fflush(stdout); | 975 fflush(stdout); |
| 849 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 976 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 850 printf("\n"); | 977 printf("\n"); |
| 851 aos->Stop(); | 978 StopAndCloseAOSOnAudioThread(); |
| 852 ais->Stop(); | 979 StopAndCloseAISOnAudioThread(); |
| 853 aos->Close(); | |
| 854 ais->Close(); | |
| 855 } | 980 } |
| 856 | 981 |
| 857 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 982 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 858 testing::ValuesIn(RunAudioRecordInputPathTests())); | 983 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 859 | 984 |
| 860 } // namespace media | 985 } // namespace media |
| OLD | NEW |