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/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 Loading... | |
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 Loading... | |
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) | |
ajm
2013/12/10 06:37:16
Although this works in my testing, I suspect it mi
| |
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 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 params.SetPlatformEffects(effects); | |
489 return params; | |
490 } | |
491 | |
492 void StartInputStreamCallbacks(const AudioParameters& params) { | |
457 double expected_time_between_callbacks_ms = | 493 double expected_time_between_callbacks_ms = |
458 ExpectedTimeBetweenCallbacks(params); | 494 ExpectedTimeBetweenCallbacks(params); |
459 const int num_callbacks = | 495 const int num_callbacks = |
460 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 496 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
461 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( | 497 AudioInputStream* stream = audio_manager()->MakeAudioInputStream( |
462 params, std::string(), std::string()); | 498 params, AudioManagerBase::kDefaultDeviceId); |
463 EXPECT_TRUE(stream); | 499 EXPECT_TRUE(stream); |
464 | 500 |
465 int count = 0; | 501 int count = 0; |
466 MockAudioOutputCallback source; | 502 MockAudioInputCallback sink; |
467 | 503 |
468 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 504 EXPECT_CALL(sink, |
505 OnData(stream, NotNull(), params.GetBytesPerBuffer(), _, _)) | |
469 .Times(AtLeast(num_callbacks)) | 506 .Times(AtLeast(num_callbacks)) |
470 .WillRepeatedly( | 507 .WillRepeatedly( |
471 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 508 CheckCountAndPostQuitTask(&count, num_callbacks, loop())); |
472 Invoke(&source, &MockAudioOutputCallback::RealOnMoreData))); | 509 EXPECT_CALL(sink, OnError(stream)).Times(0); |
473 EXPECT_CALL(source, OnError(stream)).Times(0); | 510 EXPECT_CALL(sink, OnClose(stream)).Times(1); |
474 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | |
475 | 511 |
476 EXPECT_TRUE(stream->Open()); | 512 EXPECT_TRUE(stream->Open()); |
477 stream->Start(&source); | 513 stream->Start(&sink); |
478 start_time_ = base::TimeTicks::Now(); | 514 start_time_ = base::TimeTicks::Now(); |
479 loop()->Run(); | 515 loop()->Run(); |
480 end_time_ = base::TimeTicks::Now(); | 516 end_time_ = base::TimeTicks::Now(); |
481 stream->Stop(); | 517 stream->Stop(); |
482 stream->Close(); | 518 stream->Close(); |
483 | 519 |
484 double average_time_between_callbacks_ms = | 520 double average_time_between_callbacks_ms = |
485 AverageTimeBetweenCallbacks(num_callbacks); | 521 AverageTimeBetweenCallbacks(num_callbacks); |
486 VLOG(0) << "expected time between callbacks: " | 522 VLOG(0) << "expected time between callbacks: " |
487 << expected_time_between_callbacks_ms << " ms"; | 523 << expected_time_between_callbacks_ms << " ms"; |
488 VLOG(0) << "average time between callbacks: " | 524 VLOG(0) << "average time between callbacks: " |
489 << average_time_between_callbacks_ms << " ms"; | 525 << average_time_between_callbacks_ms << " ms"; |
490 EXPECT_GE(average_time_between_callbacks_ms, | 526 EXPECT_GE(average_time_between_callbacks_ms, |
491 0.70 * expected_time_between_callbacks_ms); | 527 0.70 * expected_time_between_callbacks_ms); |
492 EXPECT_LE(average_time_between_callbacks_ms, | 528 EXPECT_LE(average_time_between_callbacks_ms, |
493 1.30 * expected_time_between_callbacks_ms); | 529 1.30 * expected_time_between_callbacks_ms); |
494 } | 530 } |
495 | 531 |
496 scoped_ptr<base::MessageLoopForUI> loop_; | |
497 scoped_ptr<AudioManager> audio_manager_; | |
498 base::TimeTicks start_time_; | |
499 base::TimeTicks end_time_; | |
500 | 532 |
501 DISALLOW_COPY_AND_ASSIGN(AudioAndroidTest); | 533 private: |
534 DISALLOW_COPY_AND_ASSIGN(AudioAndroidInputTest); | |
502 }; | 535 }; |
503 | 536 |
504 // Get the default audio input parameters and log the result. | 537 // Get the default audio input parameters and log the result. |
505 TEST_F(AudioAndroidTest, GetInputStreamParameters) { | 538 TEST_P(AudioAndroidInputTest, GetDefaultInputStreamParameters) { |
506 AudioParameters params = GetDefaultInputStreamParameters(); | 539 // We don't go through AudioAndroidInputTest::GetInputStreamParameters() here |
540 // so that we can log the real (non-overridden) values of the effects. | |
541 AudioParameters params = audio_manager()->GetInputStreamParameters( | |
542 AudioManagerBase::kDefaultDeviceId); | |
507 EXPECT_TRUE(params.IsValid()); | 543 EXPECT_TRUE(params.IsValid()); |
508 VLOG(1) << params; | 544 VLOG(1) << params; |
509 } | 545 } |
510 | 546 |
511 // Get the default audio output parameters and log the result. | 547 // Get the default audio output parameters and log the result. |
512 TEST_F(AudioAndroidTest, GetDefaultOutputStreamParameters) { | 548 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { |
513 AudioParameters params = GetDefaultOutputStreamParameters(); | 549 AudioParameters params = GetDefaultOutputStreamParameters(); |
514 EXPECT_TRUE(params.IsValid()); | 550 EXPECT_TRUE(params.IsValid()); |
515 VLOG(1) << params; | 551 VLOG(1) << params; |
516 } | 552 } |
517 | 553 |
518 // Check if low-latency output is supported and log the result as output. | 554 // Check if low-latency output is supported and log the result as output. |
519 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { | 555 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { |
520 AudioManagerAndroid* manager = | 556 AudioManagerAndroid* manager = |
521 static_cast<AudioManagerAndroid*>(audio_manager()); | 557 static_cast<AudioManagerAndroid*>(audio_manager()); |
522 bool low_latency = manager->IsAudioLowLatencySupported(); | 558 bool low_latency = manager->IsAudioLowLatencySupported(); |
523 low_latency ? VLOG(0) << "Low latency output is supported" | 559 low_latency ? VLOG(0) << "Low latency output is supported" |
524 : VLOG(0) << "Low latency output is *not* supported"; | 560 : VLOG(0) << "Low latency output is *not* supported"; |
525 } | 561 } |
526 | 562 |
527 // Ensure that a default input stream can be created and closed. | 563 // Ensure that a default input stream can be created and closed. |
528 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { | 564 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { |
529 AudioParameters params = GetDefaultInputStreamParameters(); | 565 AudioParameters params = GetInputStreamParameters(); |
530 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 566 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
531 params, AudioManagerBase::kDefaultDeviceId); | 567 params, AudioManagerBase::kDefaultDeviceId); |
532 EXPECT_TRUE(ais); | 568 EXPECT_TRUE(ais); |
533 ais->Close(); | 569 ais->Close(); |
534 } | 570 } |
535 | 571 |
536 // Ensure that a default output stream can be created and closed. | 572 // 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 | 573 // TODO(henrika): should we also verify that this API changes the audio mode |
538 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 574 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
539 // it is called? | 575 // it is called? |
540 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { | 576 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
541 AudioParameters params = GetDefaultOutputStreamParameters(); | 577 AudioParameters params = GetDefaultOutputStreamParameters(); |
542 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 578 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
543 params, std::string(), std::string()); | 579 params, std::string(), std::string()); |
544 EXPECT_TRUE(aos); | 580 EXPECT_TRUE(aos); |
545 aos->Close(); | 581 aos->Close(); |
546 } | 582 } |
547 | 583 |
548 // Ensure that a default input stream can be opened and closed. | 584 // Ensure that a default input stream can be opened and closed. |
549 TEST_F(AudioAndroidTest, OpenAndCloseInputStream) { | 585 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { |
550 AudioParameters params = GetDefaultInputStreamParameters(); | 586 AudioParameters params = GetInputStreamParameters(); |
551 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 587 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
552 params, AudioManagerBase::kDefaultDeviceId); | 588 params, AudioManagerBase::kDefaultDeviceId); |
553 EXPECT_TRUE(ais); | 589 EXPECT_TRUE(ais); |
554 EXPECT_TRUE(ais->Open()); | 590 EXPECT_TRUE(ais->Open()); |
555 ais->Close(); | 591 ais->Close(); |
556 } | 592 } |
557 | 593 |
558 // Ensure that a default output stream can be opened and closed. | 594 // Ensure that a default output stream can be opened and closed. |
559 TEST_F(AudioAndroidTest, OpenAndCloseOutputStream) { | 595 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { |
560 AudioParameters params = GetDefaultOutputStreamParameters(); | 596 AudioParameters params = GetDefaultOutputStreamParameters(); |
561 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 597 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
562 params, std::string(), std::string()); | 598 params, std::string(), std::string()); |
563 EXPECT_TRUE(aos); | 599 EXPECT_TRUE(aos); |
564 EXPECT_TRUE(aos->Open()); | 600 EXPECT_TRUE(aos->Open()); |
565 aos->Close(); | 601 aos->Close(); |
566 } | 602 } |
567 | 603 |
568 // Start input streaming using default input parameters and ensure that the | 604 // Start input streaming using default input parameters and ensure that the |
569 // callback sequence is sane. | 605 // callback sequence is sane. |
570 TEST_F(AudioAndroidTest, StartInputStreamCallbacks) { | 606 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacks) { |
571 AudioParameters params = GetDefaultInputStreamParameters(); | 607 AudioParameters params = GetInputStreamParameters(); |
572 StartInputStreamCallbacks(params); | 608 StartInputStreamCallbacks(params); |
573 } | 609 } |
574 | 610 |
575 // Start input streaming using non default input parameters and ensure that the | 611 // 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 | 612 // 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. | 613 // a 10ms buffer size instead of the default size. |
578 // TODO(henrika): possibly add support for more variations. | 614 // TODO(henrika): possibly add support for more variations. |
579 TEST_F(AudioAndroidTest, StartInputStreamCallbacksNonDefaultParameters) { | 615 TEST_P(AudioAndroidInputTest, StartInputStreamCallbacksNonDefaultParameters) { |
580 AudioParameters native_params = GetDefaultInputStreamParameters(); | 616 AudioParameters native_params = GetInputStreamParameters(); |
581 AudioParameters params(native_params.format(), | 617 AudioParameters params(native_params.format(), |
582 native_params.channel_layout(), | 618 native_params.channel_layout(), |
583 native_params.sample_rate(), | 619 native_params.sample_rate(), |
584 native_params.bits_per_sample(), | 620 native_params.bits_per_sample(), |
585 native_params.sample_rate() / 100); | 621 native_params.sample_rate() / 100); |
622 params.SetPlatformEffects(native_params.effects()); | |
586 StartInputStreamCallbacks(params); | 623 StartInputStreamCallbacks(params); |
587 } | 624 } |
588 | 625 |
589 // Start output streaming using default output parameters and ensure that the | 626 // Start output streaming using default output parameters and ensure that the |
590 // callback sequence is sane. | 627 // callback sequence is sane. |
591 TEST_F(AudioAndroidTest, StartOutputStreamCallbacks) { | 628 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) { |
592 AudioParameters params = GetDefaultOutputStreamParameters(); | 629 AudioParameters params = GetDefaultOutputStreamParameters(); |
593 StartOutputStreamCallbacks(params); | 630 StartOutputStreamCallbacks(params); |
594 } | 631 } |
595 | 632 |
596 // Start output streaming using non default output parameters and ensure that | 633 // 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 | 634 // 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 | 635 // select a 10ms buffer size instead of the default size and to open up the |
599 // device in mono. | 636 // device in mono. |
600 // TODO(henrika): possibly add support for more variations. | 637 // TODO(henrika): possibly add support for more variations. |
601 TEST_F(AudioAndroidTest, StartOutputStreamCallbacksNonDefaultParameters) { | 638 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacksNonDefaultParameters) { |
602 AudioParameters native_params = GetDefaultOutputStreamParameters(); | 639 AudioParameters native_params = GetDefaultOutputStreamParameters(); |
603 AudioParameters params(native_params.format(), | 640 AudioParameters params(native_params.format(), |
604 CHANNEL_LAYOUT_MONO, | 641 CHANNEL_LAYOUT_MONO, |
605 native_params.sample_rate(), | 642 native_params.sample_rate(), |
606 native_params.bits_per_sample(), | 643 native_params.bits_per_sample(), |
607 native_params.sample_rate() / 100); | 644 native_params.sample_rate() / 100); |
608 StartOutputStreamCallbacks(params); | 645 StartOutputStreamCallbacks(params); |
609 } | 646 } |
610 | 647 |
611 // Play out a PCM file segment in real time and allow the user to verify that | 648 // Play out a PCM file segment in real time and allow the user to verify that |
612 // the rendered audio sounds OK. | 649 // the rendered audio sounds OK. |
613 // NOTE: this test requires user interaction and is not designed to run as an | 650 // NOTE: this test requires user interaction and is not designed to run as an |
614 // automatized test on bots. | 651 // automatized test on bots. |
615 TEST_F(AudioAndroidTest, DISABLED_RunOutputStreamWithFileAsSource) { | 652 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { |
616 AudioParameters params = GetDefaultOutputStreamParameters(); | 653 AudioParameters params = GetDefaultOutputStreamParameters(); |
617 VLOG(1) << params; | 654 VLOG(1) << params; |
618 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 655 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
619 params, std::string(), std::string()); | 656 params, std::string(), std::string()); |
620 EXPECT_TRUE(aos); | 657 EXPECT_TRUE(aos); |
621 | 658 |
622 std::string file_name; | 659 std::string file_name; |
623 if (params.sample_rate() == 48000 && params.channels() == 2) { | 660 if (params.sample_rate() == 48000 && params.channels() == 2) { |
624 file_name = kSpeechFile_16b_s_48k; | 661 file_name = kSpeechFile_16b_s_48k; |
625 } else if (params.sample_rate() == 48000 && params.channels() == 1) { | 662 } else if (params.sample_rate() == 48000 && params.channels() == 1) { |
(...skipping 16 matching lines...) Expand all Loading... | |
642 VLOG(0) << ">> Verify that the file is played out correctly..."; | 679 VLOG(0) << ">> Verify that the file is played out correctly..."; |
643 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 680 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
644 aos->Stop(); | 681 aos->Stop(); |
645 aos->Close(); | 682 aos->Close(); |
646 } | 683 } |
647 | 684 |
648 // Start input streaming and run it for ten seconds while recording to a | 685 // Start input streaming and run it for ten seconds while recording to a |
649 // local audio file. | 686 // local audio file. |
650 // NOTE: this test requires user interaction and is not designed to run as an | 687 // NOTE: this test requires user interaction and is not designed to run as an |
651 // automatized test on bots. | 688 // automatized test on bots. |
652 TEST_F(AudioAndroidTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { | 689 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { |
653 AudioParameters params = GetDefaultInputStreamParameters(); | 690 AudioParameters params = GetInputStreamParameters(); |
654 VLOG(1) << params; | 691 VLOG(1) << params; |
655 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 692 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
656 params, AudioManagerBase::kDefaultDeviceId); | 693 params, AudioManagerBase::kDefaultDeviceId); |
657 EXPECT_TRUE(ais); | 694 EXPECT_TRUE(ais); |
658 | 695 |
659 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", | 696 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", |
660 params.sample_rate(), | 697 params.sample_rate(), |
661 params.frames_per_buffer(), | 698 params.frames_per_buffer(), |
662 params.channels()); | 699 params.channels()); |
663 | 700 |
664 base::WaitableEvent event(false, false); | 701 base::WaitableEvent event(false, false); |
665 FileAudioSink sink(&event, params, file_name); | 702 FileAudioSink sink(&event, params, file_name); |
666 | 703 |
667 EXPECT_TRUE(ais->Open()); | 704 EXPECT_TRUE(ais->Open()); |
668 ais->Start(&sink); | 705 ais->Start(&sink); |
669 VLOG(0) << ">> Speak into the microphone to record audio..."; | 706 VLOG(0) << ">> Speak into the microphone to record audio..."; |
670 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 707 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
671 ais->Stop(); | 708 ais->Stop(); |
672 ais->Close(); | 709 ais->Close(); |
673 } | 710 } |
674 | 711 |
675 // Same test as RunSimplexInputStreamWithFileAsSink but this time output | 712 // Same test as RunSimplexInputStreamWithFileAsSink but this time output |
676 // streaming is active as well (reads zeros only). | 713 // streaming is active as well (reads zeros only). |
677 // NOTE: this test requires user interaction and is not designed to run as an | 714 // NOTE: this test requires user interaction and is not designed to run as an |
678 // automatized test on bots. | 715 // automatized test on bots. |
679 TEST_F(AudioAndroidTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { | 716 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { |
680 AudioParameters in_params = GetDefaultInputStreamParameters(); | 717 AudioParameters in_params = GetInputStreamParameters(); |
681 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 718 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
682 in_params, AudioManagerBase::kDefaultDeviceId); | 719 in_params, AudioManagerBase::kDefaultDeviceId); |
683 EXPECT_TRUE(ais); | 720 EXPECT_TRUE(ais); |
684 | 721 |
685 AudioParameters out_params = | 722 AudioParameters out_params = |
686 audio_manager()->GetDefaultOutputStreamParameters(); | 723 audio_manager()->GetDefaultOutputStreamParameters(); |
687 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 724 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
688 out_params, std::string(), std::string()); | 725 out_params, std::string(), std::string()); |
689 EXPECT_TRUE(aos); | 726 EXPECT_TRUE(aos); |
690 | 727 |
(...skipping 22 matching lines...) Expand all Loading... | |
713 aos->Close(); | 750 aos->Close(); |
714 ais->Close(); | 751 ais->Close(); |
715 } | 752 } |
716 | 753 |
717 // Start audio in both directions while feeding captured data into a FIFO so | 754 // 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 | 755 // 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 | 756 // delay will be added by the FIFO and an estimate of this delay will be |
720 // printed out during the test. | 757 // printed out during the test. |
721 // NOTE: this test requires user interaction and is not designed to run as an | 758 // NOTE: this test requires user interaction and is not designed to run as an |
722 // automatized test on bots. | 759 // automatized test on bots. |
723 TEST_F(AudioAndroidTest, | 760 TEST_P(AudioAndroidInputTest, |
724 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { | 761 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { |
725 // Get native audio parameters for the input side. | 762 // Get native audio parameters for the input side. |
726 AudioParameters default_input_params = GetDefaultInputStreamParameters(); | 763 AudioParameters default_input_params = GetInputStreamParameters(); |
727 | 764 |
728 // Modify the parameters so that both input and output can use the same | 765 // 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 | 766 // 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 | 767 // the output stream will be a mono stream since mono is default for input |
731 // audio on Android. | 768 // audio on Android. |
732 AudioParameters io_params(default_input_params.format(), | 769 AudioParameters io_params(default_input_params.format(), |
733 default_input_params.channel_layout(), | 770 default_input_params.channel_layout(), |
734 default_input_params.sample_rate(), | 771 default_input_params.sample_rate(), |
735 default_input_params.bits_per_sample(), | 772 default_input_params.bits_per_sample(), |
736 default_input_params.sample_rate() / 100); | 773 default_input_params.sample_rate() / 100); |
(...skipping 22 matching lines...) Expand all Loading... | |
759 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 796 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
760 fflush(stdout); | 797 fflush(stdout); |
761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 798 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
762 printf("\n"); | 799 printf("\n"); |
763 aos->Stop(); | 800 aos->Stop(); |
764 ais->Stop(); | 801 ais->Stop(); |
765 aos->Close(); | 802 aos->Close(); |
766 ais->Close(); | 803 ais->Close(); |
767 } | 804 } |
768 | 805 |
806 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | |
807 testing::ValuesIn(RunAudioRecordInputPathTests())); | |
808 | |
769 } // namespace media | 809 } // namespace media |
OLD | NEW |