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

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

Issue 117073002: Reland "Refactor audio manager for Android to avoid heavy tasks at startup" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | Annotate | Revision Log
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/android/build_info.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return std::string("CHANNEL_LAYOUT_UNSUPPORTED"); 78 return std::string("CHANNEL_LAYOUT_UNSUPPORTED");
79 } 79 }
80 } 80 }
81 81
82 static double ExpectedTimeBetweenCallbacks(AudioParameters params) { 82 static double ExpectedTimeBetweenCallbacks(AudioParameters params) {
83 return (base::TimeDelta::FromMicroseconds( 83 return (base::TimeDelta::FromMicroseconds(
84 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / 84 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
85 static_cast<double>(params.sample_rate()))).InMillisecondsF(); 85 static_cast<double>(params.sample_rate()))).InMillisecondsF();
86 } 86 }
87 87
88 // Helper method which verifies that the device list starts with a valid
89 // default device name followed by non-default device names.
90 static void CheckDeviceNames(const AudioDeviceNames& device_names) {
91 VLOG(2) << "Got " << device_names.size() << " audio devices.";
92 if (device_names.empty()) {
93 // Log a warning so we can see the status on the build bots. No need to
94 // break the test though since this does successfully test the code and
95 // some failure cases.
96 LOG(WARNING) << "No input devices detected";
97 return;
98 }
99
100 AudioDeviceNames::const_iterator it = device_names.begin();
101
102 // The first device in the list should always be the default device.
103 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName),
104 it->device_name);
105 EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id);
106 ++it;
107
108 // Other devices should have non-empty name and id and should not contain
109 // default name or id.
110 while (it != device_names.end()) {
111 EXPECT_FALSE(it->device_name.empty());
112 EXPECT_FALSE(it->unique_id.empty());
113 VLOG(2) << "Device ID(" << it->unique_id
114 << "), label: " << it->device_name;
115 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName),
116 it->device_name);
117 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId),
118 it->unique_id);
119 ++it;
120 }
121 }
122
88 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { 123 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) {
89 using namespace std; 124 using namespace std;
90 os << endl << "format: " << FormatToString(params.format()) << endl 125 os << endl << "format: " << FormatToString(params.format()) << endl
91 << "channel layout: " << LayoutToString(params.channel_layout()) << endl 126 << "channel layout: " << LayoutToString(params.channel_layout()) << endl
92 << "sample rate: " << params.sample_rate() << endl 127 << "sample rate: " << params.sample_rate() << endl
93 << "bits per sample: " << params.bits_per_sample() << endl 128 << "bits per sample: " << params.bits_per_sample() << endl
94 << "frames per buffer: " << params.frames_per_buffer() << endl 129 << "frames per buffer: " << params.frames_per_buffer() << endl
95 << "channels: " << params.channels() << endl 130 << "channels: " << params.channels() << endl
96 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl 131 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl
97 << "bytes per second: " << params.GetBytesPerSecond() << endl 132 << "bytes per second: " << params.GetBytesPerSecond() << endl
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 595
561 // Check if low-latency output is supported and log the result as output. 596 // Check if low-latency output is supported and log the result as output.
562 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { 597 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) {
563 AudioManagerAndroid* manager = 598 AudioManagerAndroid* manager =
564 static_cast<AudioManagerAndroid*>(audio_manager()); 599 static_cast<AudioManagerAndroid*>(audio_manager());
565 bool low_latency = manager->IsAudioLowLatencySupported(); 600 bool low_latency = manager->IsAudioLowLatencySupported();
566 low_latency ? VLOG(0) << "Low latency output is supported" 601 low_latency ? VLOG(0) << "Low latency output is supported"
567 : VLOG(0) << "Low latency output is *not* supported"; 602 : VLOG(0) << "Low latency output is *not* supported";
568 } 603 }
569 604
605 // Verify input device enumeration.
606 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) {
607 if (!audio_manager()->HasAudioInputDevices())
608 return;
609 AudioDeviceNames devices;
610 audio_manager()->GetAudioInputDeviceNames(&devices);
611 CheckDeviceNames(devices);
612 }
613
614 // Verify output device enumeration.
615 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) {
616 if (!audio_manager()->HasAudioOutputDevices())
617 return;
618 AudioDeviceNames devices;
619 audio_manager()->GetAudioOutputDeviceNames(&devices);
620 CheckDeviceNames(devices);
621 }
622
570 // Ensure that a default input stream can be created and closed. 623 // Ensure that a default input stream can be created and closed.
571 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { 624 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) {
572 AudioParameters params = GetInputStreamParameters(); 625 AudioParameters params = GetInputStreamParameters();
573 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( 626 AudioInputStream* ais = audio_manager()->MakeAudioInputStream(
574 params, AudioManagerBase::kDefaultDeviceId); 627 params, AudioManagerBase::kDefaultDeviceId);
575 EXPECT_TRUE(ais); 628 EXPECT_TRUE(ais);
576 ais->Close(); 629 ais->Close();
577 } 630 }
578 631
579 // Ensure that a default output stream can be created and closed. 632 // Ensure that a default output stream can be created and closed.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 aos->Stop(); 861 aos->Stop();
809 ais->Stop(); 862 ais->Stop();
810 aos->Close(); 863 aos->Close();
811 ais->Close(); 864 ais->Close();
812 } 865 }
813 866
814 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, 867 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest,
815 testing::ValuesIn(RunAudioRecordInputPathTests())); 868 testing::ValuesIn(RunAudioRecordInputPathTests()));
816 869
817 } // namespace media 870 } // namespace media
OLDNEW
« no previous file with comments | « build/android/findbugs_filter/findbugs_known_bugs.txt ('k') | media/audio/android/audio_manager_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698