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

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

Issue 110173003: Refactor audio manager for Android to avoid heavy tasks at startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed mActive state 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/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
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
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 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
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");
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
OLDNEW
« no previous file with comments | « no previous file | media/audio/android/audio_manager_android.h » ('j') | media/audio/android/audio_manager_android.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698