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 record followed by non-default device names. | |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
nit; took me a couple of reads to understand that
henrika (OOO until Aug 14)
2013/12/11 13:16:38
fixed. I was thinking in Pascal ;-)
| |
| 89 static void CheckDeviceNames(const AudioDeviceNames& device_names) { | |
| 90 VLOG(2) << "Got " << device_names.size() << " audio devices."; | |
| 91 if (!device_names.empty()) { | |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
nit: to reduce scopes:
if (device_names.empty())
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Done.
| |
| 92 AudioDeviceNames::const_iterator it = device_names.begin(); | |
| 93 | |
| 94 // The first device in the list should always be the default device. | |
| 95 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 96 it->device_name); | |
| 97 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | |
| 98 ++it; | |
| 99 | |
| 100 // Other devices should have non-empty name and id and should not contain | |
| 101 // default name or id. | |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
good thing to test
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Thx.
| |
| 102 while (it != device_names.end()) { | |
| 103 EXPECT_FALSE(it->device_name.empty()); | |
| 104 EXPECT_FALSE(it->unique_id.empty()); | |
| 105 VLOG(2) << "Device ID(" << it->unique_id | |
| 106 << "), label: " << it->device_name; | |
| 107 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), | |
| 108 it->device_name); | |
| 109 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), | |
| 110 it->unique_id); | |
| 111 ++it; | |
| 112 } | |
| 113 } else { | |
| 114 // Log a warning so we can see the status on the build bots. No need to | |
| 115 // break the test though since this does successfully test the code and | |
| 116 // some failure cases. | |
| 117 LOG(WARNING) << "No input devices detected"; | |
| 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. | |
| 562 TEST_F(AudioAndroidTest, GetAudioInputDeviceNames) { | |
| 563 AudioManagerAndroid* manager = | |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
Do you need AudioManagerAndroid* or is AudioManage
henrika (OOO until Aug 14)
2013/12/11 13:16:38
My bad. Fixed.
| |
| 564 static_cast<AudioManagerAndroid*>(audio_manager()); | |
| 565 if (!manager->HasAudioInputDevices()) | |
| 566 return; | |
| 567 AudioDeviceNames devices; | |
| 568 manager->GetAudioInputDeviceNames(&devices); | |
| 569 CheckDeviceNames(devices); | |
| 570 } | |
| 571 | |
| 572 // Verify output device enumeration. | |
| 573 TEST_F(AudioAndroidTest, GetAudioOutputDeviceNames) { | |
| 574 AudioManagerAndroid* manager = | |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
AudioManager* enough? These tests seem like valid
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Done.
| |
| 575 static_cast<AudioManagerAndroid*>(audio_manager()); | |
| 576 if (!manager->HasAudioOutputDevices()) | |
| 577 return; | |
| 578 AudioDeviceNames devices; | |
| 579 manager->GetAudioOutputDeviceNames(&devices); | |
| 580 CheckDeviceNames(devices); | |
| 581 } | |
| 582 | |
| 527 // Ensure that a default input stream can be created and closed. | 583 // Ensure that a default input stream can be created and closed. |
| 528 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { | 584 TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { |
| 529 AudioParameters params = GetDefaultInputStreamParameters(); | 585 AudioParameters params = GetDefaultInputStreamParameters(); |
| 586 const char kInvalidId1[] = "_InVaLiDdEvIcEId_"; | |
| 530 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 587 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| 588 params, kInvalidId1); | |
| 589 EXPECT_FALSE(ais); | |
| 590 const char kInvalidId2[] = "192837464"; | |
| 591 ais = audio_manager()->MakeAudioInputStream( | |
| 592 params, kInvalidId2); | |
| 593 EXPECT_FALSE(ais); | |
| 594 ais = audio_manager()->MakeAudioInputStream( | |
| 531 params, AudioManagerBase::kDefaultDeviceId); | 595 params, AudioManagerBase::kDefaultDeviceId); |
| 532 EXPECT_TRUE(ais); | 596 EXPECT_TRUE(ais); |
| 533 ais->Close(); | 597 ais->Close(); |
| 534 } | 598 } |
| 535 | 599 |
| 536 // Ensure that a default output stream can be created and closed. | 600 // 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 | 601 // TODO(henrika): should we also verify that this API changes the audio mode |
| 538 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 602 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
| 539 // it is called? | 603 // it is called? |
| 540 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { | 604 TEST_F(AudioAndroidTest, CreateAndCloseOutputStream) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 fflush(stdout); | 824 fflush(stdout); |
| 761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 825 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 762 printf("\n"); | 826 printf("\n"); |
| 763 aos->Stop(); | 827 aos->Stop(); |
| 764 ais->Stop(); | 828 ais->Stop(); |
| 765 aos->Close(); | 829 aos->Close(); |
| 766 ais->Close(); | 830 ais->Close(); |
| 767 } | 831 } |
| 768 | 832 |
| 769 } // namespace media | 833 } // namespace media |
| OLD | NEW |