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

Side by Side Diff: media/audio/android/audio_android_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698