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

Side by Side Diff: media/audio/mac/audio_output_mac_unittest.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 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
« no previous file with comments | « media/audio/mac/audio_manager_mac.cc ('k') | media/audio/openbsd/audio_manager_openbsd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h"
6 #include "media/audio/audio_io.h" 7 #include "media/audio/audio_io.h"
7 #include "media/audio/audio_manager.h" 8 #include "media/audio/audio_manager.h"
8 #include "media/audio/simple_sources.h" 9 #include "media/audio/simple_sources.h"
9 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 using ::testing::_; 13 using ::testing::_;
13 using ::testing::AnyNumber; 14 using ::testing::AnyNumber;
14 using ::testing::DoAll; 15 using ::testing::DoAll;
15 using ::testing::Field; 16 using ::testing::Field;
(...skipping 24 matching lines...) Expand all
40 uint16 buffer[samples] = { 0xffff }; 41 uint16 buffer[samples] = { 0xffff };
41 source.OnMoreData(NULL, reinterpret_cast<uint8*>(buffer), sizeof(buffer), 42 source.OnMoreData(NULL, reinterpret_cast<uint8*>(buffer), sizeof(buffer),
42 AudioBuffersState(0, 0)); 43 AudioBuffersState(0, 0));
43 EXPECT_EQ(0, buffer[0]); 44 EXPECT_EQ(0, buffer[0]);
44 EXPECT_EQ(5126, buffer[1]); 45 EXPECT_EQ(5126, buffer[1]);
45 } 46 }
46 47
47 // =========================================================================== 48 // ===========================================================================
48 // Validation of AudioParameters::AUDIO_PCM_LINEAR 49 // Validation of AudioParameters::AUDIO_PCM_LINEAR
49 // 50 //
50 // Unlike windows, the tests can reliably detect the existense of real 51 // Unlike windows, the tests can reliably detect the existence of real
51 // audio devices on the bots thus no need for 'headless' detection. 52 // audio devices on the bots thus no need for 'headless' detection.
52 53
53 // Test that can it be created and closed. 54 // Test that can it be created and closed.
54 TEST(MacAudioTest, PCMWaveStreamGetAndClose) { 55 TEST(MacAudioTest, PCMWaveStreamGetAndClose) {
55 AudioManager* audio_man = AudioManager::GetAudioManager(); 56 scoped_refptr<AudioManager> audio_man(AudioManager::Create());
56 ASSERT_TRUE(NULL != audio_man);
57 if (!audio_man->HasAudioOutputDevices()) 57 if (!audio_man->HasAudioOutputDevices())
58 return; 58 return;
59 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 59 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
60 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 60 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
61 8000, 16, 1024)); 61 8000, 16, 1024));
62 ASSERT_TRUE(NULL != oas); 62 ASSERT_TRUE(NULL != oas);
63 oas->Close(); 63 oas->Close();
64 } 64 }
65 65
66 // Test that it can be opened and closed. 66 // Test that it can be opened and closed.
67 TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { 67 TEST(MacAudioTest, PCMWaveStreamOpenAndClose) {
68 AudioManager* audio_man = AudioManager::GetAudioManager(); 68 scoped_refptr<AudioManager> audio_man(AudioManager::Create());
69 ASSERT_TRUE(NULL != audio_man);
70 if (!audio_man->HasAudioOutputDevices()) 69 if (!audio_man->HasAudioOutputDevices())
71 return; 70 return;
72 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 71 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
73 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 72 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
74 8000, 16, 1024)); 73 8000, 16, 1024));
75 ASSERT_TRUE(NULL != oas); 74 ASSERT_TRUE(NULL != oas);
76 EXPECT_TRUE(oas->Open()); 75 EXPECT_TRUE(oas->Open());
77 oas->Close(); 76 oas->Close();
78 } 77 }
79 78
80 // This test produces actual audio for 1.5 seconds on the default wave device at 79 // This test produces actual audio for 1.5 seconds on the default wave device at
81 // 44.1K s/sec. Parameters have been chosen carefully so you should not hear 80 // 44.1K s/sec. Parameters have been chosen carefully so you should not hear
82 // pops or noises while the sound is playing. The sound must also be identical 81 // pops or noises while the sound is playing. The sound must also be identical
83 // to the sound of PCMWaveStreamPlay200HzTone22KssMono test. 82 // to the sound of PCMWaveStreamPlay200HzTone22KssMono test.
84 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { 83 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) {
85 AudioManager* audio_man = AudioManager::GetAudioManager(); 84 scoped_refptr<AudioManager> audio_man(AudioManager::Create());
86 ASSERT_TRUE(NULL != audio_man);
87 if (!audio_man->HasAudioOutputDevices()) 85 if (!audio_man->HasAudioOutputDevices())
88 return; 86 return;
89 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; 87 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10;
90 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 88 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
91 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 89 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
92 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); 90 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms));
93 ASSERT_TRUE(NULL != oas); 91 ASSERT_TRUE(NULL != oas);
94 EXPECT_TRUE(oas->Open()); 92 EXPECT_TRUE(oas->Open());
95 93
96 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, 94 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
97 200.0, AudioParameters::kAudioCDSampleRate); 95 200.0, AudioParameters::kAudioCDSampleRate);
98 oas->SetVolume(0.5); 96 oas->SetVolume(0.5);
99 oas->Start(&source); 97 oas->Start(&source);
100 usleep(500000); 98 usleep(500000);
101 99
102 // Test that the volume is within the set limits. 100 // Test that the volume is within the set limits.
103 double volume = 0.0; 101 double volume = 0.0;
104 oas->GetVolume(&volume); 102 oas->GetVolume(&volume);
105 EXPECT_LT(volume, 0.51); 103 EXPECT_LT(volume, 0.51);
106 EXPECT_GT(volume, 0.49); 104 EXPECT_GT(volume, 0.49);
107 oas->Stop(); 105 oas->Stop();
108 oas->Close(); 106 oas->Close();
109 } 107 }
110 108
111 // This test produces actual audio for 1.5 seconds on the default wave device at 109 // This test produces actual audio for 1.5 seconds on the default wave device at
112 // 22K s/sec. Parameters have been chosen carefully so you should not hear pops 110 // 22K s/sec. Parameters have been chosen carefully so you should not hear pops
113 // or noises while the sound is playing. The sound must also be identical to the 111 // or noises while the sound is playing. The sound must also be identical to the
114 // sound of PCMWaveStreamPlay200HzTone44KssMono test. 112 // sound of PCMWaveStreamPlay200HzTone44KssMono test.
115 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) { 113 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) {
116 AudioManager* audio_man = AudioManager::GetAudioManager(); 114 scoped_refptr<AudioManager> audio_man(AudioManager::Create());
117 ASSERT_TRUE(NULL != audio_man);
118 if (!audio_man->HasAudioOutputDevices()) 115 if (!audio_man->HasAudioOutputDevices())
119 return; 116 return;
120 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; 117 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10;
121 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 118 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
122 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 119 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
123 AudioParameters::kAudioCDSampleRate / 2, 16, 120 AudioParameters::kAudioCDSampleRate / 2, 16,
124 frames_100_ms)); 121 frames_100_ms));
125 ASSERT_TRUE(NULL != oas); 122 ASSERT_TRUE(NULL != oas);
126 123
127 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, 124 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
128 200.0, AudioParameters::kAudioCDSampleRate/2); 125 200.0, AudioParameters::kAudioCDSampleRate/2);
129 EXPECT_TRUE(oas->Open()); 126 EXPECT_TRUE(oas->Open());
130 oas->Start(&source); 127 oas->Start(&source);
131 usleep(1500000); 128 usleep(1500000);
132 oas->Stop(); 129 oas->Stop();
133 oas->Close(); 130 oas->Close();
134 } 131 }
135 132
136 // Custom action to clear a memory buffer. 133 // Custom action to clear a memory buffer.
137 static void ClearBuffer(AudioOutputStream* stream, uint8* dest, 134 static void ClearBuffer(AudioOutputStream* stream, uint8* dest,
138 uint32 max_size, AudioBuffersState buffers_state) { 135 uint32 max_size, AudioBuffersState buffers_state) {
139 memset(dest, 0, max_size); 136 memset(dest, 0, max_size);
140 } 137 }
141 138
142 TEST(MacAudioTest, PCMWaveStreamPendingBytes) { 139 TEST(MacAudioTest, PCMWaveStreamPendingBytes) {
143 AudioManager* audio_man = AudioManager::GetAudioManager(); 140 scoped_refptr<AudioManager> audio_man(AudioManager::Create());
144 ASSERT_TRUE(NULL != audio_man);
145 if (!audio_man->HasAudioOutputDevices()) 141 if (!audio_man->HasAudioOutputDevices())
146 return; 142 return;
147 143
148 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; 144 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10;
149 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 145 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
150 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 146 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
151 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); 147 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms));
152 ASSERT_TRUE(NULL != oas); 148 ASSERT_TRUE(NULL != oas);
153 149
154 NiceMock<MockAudioSource> source; 150 NiceMock<MockAudioSource> source;
(...skipping 19 matching lines...) Expand all
174 .WillOnce(Return(0)); 170 .WillOnce(Return(0));
175 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, _)) 171 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, _))
176 .Times(AnyNumber()) 172 .Times(AnyNumber())
177 .WillRepeatedly(Return(0)); 173 .WillRepeatedly(Return(0));
178 174
179 oas->Start(&source); 175 oas->Start(&source);
180 usleep(500000); 176 usleep(500000);
181 oas->Stop(); 177 oas->Stop();
182 oas->Close(); 178 oas->Close();
183 } 179 }
OLDNEW
« no previous file with comments | « media/audio/mac/audio_manager_mac.cc ('k') | media/audio/openbsd/audio_manager_openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698