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

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

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

Powered by Google App Engine
This is Rietveld 408576698