Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); | 77 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { | 81 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { |
| 82 return (base::TimeDelta::FromMicroseconds( | 82 return (base::TimeDelta::FromMicroseconds( |
| 83 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / | 83 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / |
| 84 static_cast<double>(params.sample_rate()))).InMillisecondsF(); | 84 static_cast<double>(params.sample_rate()))).InMillisecondsF(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Helper method which verifies that the device list starts with a valid | |
| 88 // default device name followed by non-default device names. | |
| 89 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | |
| 90 VLOG(2) << "Got " << device_names.size() << " audio devices."; | |
| 91 if (device_names.empty()) { | |
| 92 // Log a warning so we can see the status on the build bots. No need to | |
| 93 // break the test though since this does successfully test the code and | |
| 94 // some failure cases. | |
| 95 LOG(WARNING) << "No input devices detected"; | |
| 96 } | |
| 97 | |
| 98 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 99 | |
| 100 // The first device in the list should always be the default device. | |
| 101 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 102 it->device_name); | |
| 103 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | |
| 104 ++it; | |
| 105 | |
| 106 // Other devices should have non-empty name and id and should not contain | |
| 107 // default name or id. | |
| 108 while (it != device_names.end()) { | |
| 109 EXPECT_FALSE(it->device_name.empty()); | |
| 110 EXPECT_FALSE(it->unique_id.empty()); | |
| 111 VLOG(2) << "Device ID(" << it->unique_id | |
| 112 << "), label: " << it->device_name; | |
| 113 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 114 it->device_name); | |
| 115 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | |
| 116 it->unique_id); | |
| 117 ++it; | |
| 118 } | |
| 119 } | |
| 120 | |
| 87 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 121 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
| 88 using namespace std; | 122 using namespace std; |
| 89 os << endl << "format: " << FormatToString(params.format()) << endl | 123 os << endl << "format: " << FormatToString(params.format()) << endl |
| 90 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 124 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
| 91 << "sample rate: " << params.sample_rate() << endl | 125 << "sample rate: " << params.sample_rate() << endl |
| 92 << "bits per sample: " << params.bits_per_sample() << endl | 126 << "bits per sample: " << params.bits_per_sample() << endl |
| 93 << "frames per buffer: " << params.frames_per_buffer() << endl | 127 << "frames per buffer: " << params.frames_per_buffer() << endl |
| 94 << "channels: " << params.channels() << endl | 128 << "channels: " << params.channels() << endl |
| 95 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl | 129 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl |
| 96 << "bytes per second: " << params.GetBytesPerSecond() << endl | 130 << "bytes per second: " << params.GetBytesPerSecond() << endl |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 551 |
| 518 // Check if low-latency output is supported and log the result as output. | 552 // Check if low-latency output is supported and log the result as output. |
| 519 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { | 553 TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { |
| 520 AudioManagerAndroid* manager = | 554 AudioManagerAndroid* manager = |
| 521 static_cast<AudioManagerAndroid*>(audio_manager()); | 555 static_cast<AudioManagerAndroid*>(audio_manager()); |
| 522 bool low_latency = manager->IsAudioLowLatencySupported(); | 556 bool low_latency = manager->IsAudioLowLatencySupported(); |
| 523 low_latency ? VLOG(0) << "Low latency output is supported" | 557 low_latency ? VLOG(0) << "Low latency output is supported" |
| 524 : VLOG(0) << "Low latency output is *not* supported"; | 558 : VLOG(0) << "Low latency output is *not* supported"; |
| 525 } | 559 } |
| 526 | 560 |
| 561 // Verify input device enumeration. | |
|
tommi (sloooow) - chröme
2013/12/13 11:30:13
nit: Since these two tests are now generally usefu
henrika (OOO until Aug 14)
2013/12/13 14:15:27
My bad; I should have mentioned that I took them f
| |
| 562 TEST_F(AudioAndroidTest, GetAudioInputDeviceNames) { | |
| 563 if (!audio_manager()->HasAudioInputDevices()) | |
| 564 return; | |
| 565 AudioDeviceNames devices; | |
| 566 audio_manager()->GetAudioInputDeviceNames(&devices); | |
| 567 CheckDeviceNames(devices); | |
| 568 } | |
| 569 | |
| 570 // Verify output device enumeration. | |
| 571 TEST_F(AudioAndroidTest, GetAudioOutputDeviceNames) { | |
| 572 if (!audio_manager()->HasAudioOutputDevices()) | |
| 573 return; | |
| 574 AudioDeviceNames devices; | |
| 575 audio_manager()->GetAudioOutputDeviceNames(&devices); | |
| 576 CheckDeviceNames(devices); | |
| 577 } | |
| 578 | |
| 527 // Ensure that a default input stream can be created and closed. | 579 // Ensure that a default input stream can be created and closed. |
| 528 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { | 580 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { |
| 529 AudioParameters params = GetDefaultInputStreamParameters(); | 581 AudioParameters params = GetDefaultInputStreamParameters(); |
| 582 const char kInvalidId1[] = "_InVaLiDdEvIcEId_"; | |
| 530 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 583 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 584 params, kInvalidId1); | |
| 585 EXPECT_FALSE(ais); | |
| 586 const char kInvalidId2[] = "192837464"; | |
| 587 ais = audio_manager()->MakeAudioInputStream( | |
| 588 params, kInvalidId2); | |
| 589 EXPECT_FALSE(ais); | |
| 590 ais = audio_manager()->MakeAudioInputStream( | |
| 531 params, AudioManagerBase::kDefaultDeviceId); | 591 params, AudioManagerBase::kDefaultDeviceId); |
| 532 EXPECT_TRUE(ais); | 592 EXPECT_TRUE(ais); |
| 533 ais->Close(); | 593 ais->Close(); |
| 534 } | 594 } |
| 535 | 595 |
| 536 // Ensure that a default output stream can be created and closed. | 596 // 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 | 597 // TODO(henrika): should we also verify that this API changes the audio mode |
| 538 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 598 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 539 // it is called? | 599 // it is called? |
| 540 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { | 600 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 // something that has been added by the test. | 812 // something that has been added by the test. |
| 753 EXPECT_TRUE(ais->Open()); | 813 EXPECT_TRUE(ais->Open()); |
| 754 EXPECT_TRUE(aos->Open()); | 814 EXPECT_TRUE(aos->Open()); |
| 755 ais->Start(&full_duplex); | 815 ais->Start(&full_duplex); |
| 756 aos->Start(&full_duplex); | 816 aos->Start(&full_duplex); |
| 757 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " | 817 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " |
| 758 << "once per second during this test."; | 818 << "once per second during this test."; |
| 759 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 819 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
| 760 fflush(stdout); | 820 fflush(stdout); |
| 761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 821 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 762 printf("\n"); | 822 printf("\n"); |
|
tommi (sloooow) - chröme
2013/12/13 11:30:13
do you mind removing this? I think it's a leftover
henrika (OOO until Aug 14)
2013/12/13 14:15:27
Done.
| |
| 763 aos->Stop(); | 823 aos->Stop(); |
| 764 ais->Stop(); | 824 ais->Stop(); |
| 765 aos->Close(); | 825 aos->Close(); |
| 766 ais->Close(); | 826 ais->Close(); |
| 767 } | 827 } |
| 768 | 828 |
| 769 } // namespace media | 829 } // namespace media |
| OLD | NEW |