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

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

Issue 105893005: Revert 240883 "Refactor audio manager for Android to avoid heavy..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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
123 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { 88 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) {
124 using namespace std; 89 using namespace std;
125 os << endl << "format: " << FormatToString(params.format()) << endl 90 os << endl << "format: " << FormatToString(params.format()) << endl
126 << "channel layout: " << LayoutToString(params.channel_layout()) << endl 91 << "channel layout: " << LayoutToString(params.channel_layout()) << endl
127 << "sample rate: " << params.sample_rate() << endl 92 << "sample rate: " << params.sample_rate() << endl
128 << "bits per sample: " << params.bits_per_sample() << endl 93 << "bits per sample: " << params.bits_per_sample() << endl
129 << "frames per buffer: " << params.frames_per_buffer() << endl 94 << "frames per buffer: " << params.frames_per_buffer() << endl
130 << "channels: " << params.channels() << endl 95 << "channels: " << params.channels() << endl
131 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl 96 << "bytes per buffer: " << params.GetBytesPerBuffer() << endl
132 << "bytes per second: " << params.GetBytesPerSecond() << endl 97 << "bytes per second: " << params.GetBytesPerSecond() << endl
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 560
596 // 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.
597 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { 562 TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) {
598 AudioManagerAndroid* manager = 563 AudioManagerAndroid* manager =
599 static_cast<AudioManagerAndroid*>(audio_manager()); 564 static_cast<AudioManagerAndroid*>(audio_manager());
600 bool low_latency = manager->IsAudioLowLatencySupported(); 565 bool low_latency = manager->IsAudioLowLatencySupported();
601 low_latency ? VLOG(0) << "Low latency output is supported" 566 low_latency ? VLOG(0) << "Low latency output is supported"
602 : VLOG(0) << "Low latency output is *not* supported"; 567 : VLOG(0) << "Low latency output is *not* supported";
603 } 568 }
604 569
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
623 // Ensure that a default input stream can be created and closed. 570 // Ensure that a default input stream can be created and closed.
624 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { 571 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) {
625 AudioParameters params = GetInputStreamParameters(); 572 AudioParameters params = GetInputStreamParameters();
626 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( 573 AudioInputStream* ais = audio_manager()->MakeAudioInputStream(
627 params, AudioManagerBase::kDefaultDeviceId); 574 params, AudioManagerBase::kDefaultDeviceId);
628 EXPECT_TRUE(ais); 575 EXPECT_TRUE(ais);
629 ais->Close(); 576 ais->Close();
630 } 577 }
631 578
632 // Ensure that a default output stream can be created and closed. 579 // Ensure that a default output stream can be created and closed.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 aos->Stop(); 808 aos->Stop();
862 ais->Stop(); 809 ais->Stop();
863 aos->Close(); 810 aos->Close();
864 ais->Close(); 811 ais->Close();
865 } 812 }
866 813
867 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, 814 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest,
868 testing::ValuesIn(RunAudioRecordInputPathTests())); 815 testing::ValuesIn(RunAudioRecordInputPathTests()));
869 816
870 } // namespace media 817 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/build/android/findbugs_filter/findbugs_known_bugs.txt ('k') | trunk/src/media/audio/android/audio_manager_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698