OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/audio_output_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 30 matching lines...) Expand all Loading... |
41 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 41 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
42 static const int kSamplesPerPacket = kSampleRate / 100; | 42 static const int kSamplesPerPacket = kSampleRate / 100; |
43 static const double kTestVolume = 0.25; | 43 static const double kTestVolume = 0.25; |
44 static const float kBufferNonZeroData = 1.0f; | 44 static const float kBufferNonZeroData = 1.0f; |
45 | 45 |
46 class MockAudioOutputControllerEventHandler | 46 class MockAudioOutputControllerEventHandler |
47 : public AudioOutputController::EventHandler { | 47 : public AudioOutputController::EventHandler { |
48 public: | 48 public: |
49 MockAudioOutputControllerEventHandler() {} | 49 MockAudioOutputControllerEventHandler() {} |
50 | 50 |
51 MOCK_METHOD0(OnCreated, void()); | 51 MOCK_METHOD0(OnControllerCreated, void()); |
52 MOCK_METHOD0(OnPlaying, void()); | 52 MOCK_METHOD0(OnControllerPlaying, void()); |
53 MOCK_METHOD0(OnPaused, void()); | 53 MOCK_METHOD0(OnControllerPaused, void()); |
54 MOCK_METHOD0(OnError, void()); | 54 MOCK_METHOD0(OnControllerError, void()); |
55 | 55 |
56 private: | 56 private: |
57 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); | 57 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); |
58 }; | 58 }; |
59 | 59 |
60 class MockAudioOutputControllerSyncReader | 60 class MockAudioOutputControllerSyncReader |
61 : public AudioOutputController::SyncReader { | 61 : public AudioOutputController::SyncReader { |
62 public: | 62 public: |
63 MockAudioOutputControllerSyncReader() {} | 63 MockAudioOutputControllerSyncReader() {} |
64 | 64 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 ~AudioOutputControllerTest() override {} | 119 ~AudioOutputControllerTest() override {} |
120 | 120 |
121 protected: | 121 protected: |
122 void Create(int samples_per_packet) { | 122 void Create(int samples_per_packet) { |
123 params_ = AudioParameters( | 123 params_ = AudioParameters( |
124 AudioParameters::AUDIO_FAKE, kChannelLayout, | 124 AudioParameters::AUDIO_FAKE, kChannelLayout, |
125 kSampleRate, kBitsPerSample, samples_per_packet); | 125 kSampleRate, kBitsPerSample, samples_per_packet); |
126 | 126 |
127 if (params_.IsValid()) { | 127 if (params_.IsValid()) { |
128 EXPECT_CALL(mock_event_handler_, OnCreated()); | 128 EXPECT_CALL(mock_event_handler_, OnControllerCreated()); |
129 } | 129 } |
130 | 130 |
131 controller_ = AudioOutputController::Create( | 131 controller_ = AudioOutputController::Create( |
132 audio_manager_.get(), &mock_event_handler_, params_, std::string(), | 132 audio_manager_.get(), &mock_event_handler_, params_, std::string(), |
133 &mock_sync_reader_); | 133 &mock_sync_reader_); |
134 if (controller_.get()) | 134 if (controller_.get()) |
135 controller_->SetVolume(kTestVolume); | 135 controller_->SetVolume(kTestVolume); |
136 | 136 |
137 EXPECT_EQ(params_.IsValid(), controller_.get() != NULL); | 137 EXPECT_EQ(params_.IsValid(), controller_.get() != NULL); |
138 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
139 } | 139 } |
140 | 140 |
141 void Play() { | 141 void Play() { |
142 // Expect the event handler to receive one OnPlaying() call. | 142 // Expect the event handler to receive one OnControllerPlaying() call. |
143 EXPECT_CALL(mock_event_handler_, OnPlaying()); | 143 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); |
144 | 144 |
145 // During playback, the mock pretends to provide audio data rendered and | 145 // During playback, the mock pretends to provide audio data rendered and |
146 // sent from the render process. | 146 // sent from the render process. |
147 EXPECT_CALL(mock_sync_reader_, RequestMoreData(_, _, _)).Times(AtLeast(1)); | 147 EXPECT_CALL(mock_sync_reader_, RequestMoreData(_, _, _)).Times(AtLeast(1)); |
148 EXPECT_CALL(mock_sync_reader_, Read(_)).WillRepeatedly(PopulateBuffer()); | 148 EXPECT_CALL(mock_sync_reader_, Read(_)).WillRepeatedly(PopulateBuffer()); |
149 controller_->Play(); | 149 controller_->Play(); |
150 base::RunLoop().RunUntilIdle(); | 150 base::RunLoop().RunUntilIdle(); |
151 } | 151 } |
152 | 152 |
153 void Pause() { | 153 void Pause() { |
154 // Expect the event handler to receive one OnPaused() call. | 154 // Expect the event handler to receive one OnControllerPaused() call. |
155 EXPECT_CALL(mock_event_handler_, OnPaused()); | 155 EXPECT_CALL(mock_event_handler_, OnControllerPaused()); |
156 | 156 |
157 controller_->Pause(); | 157 controller_->Pause(); |
158 base::RunLoop().RunUntilIdle(); | 158 base::RunLoop().RunUntilIdle(); |
159 } | 159 } |
160 | 160 |
161 void ChangeDevice() { | 161 void ChangeDevice() { |
162 // Expect the event handler to receive one OnPaying() call and no OnPaused() | 162 // Expect the event handler to receive one OnControllerPaying() call and no |
163 // call. | 163 // OnControllerPaused() call. |
164 EXPECT_CALL(mock_event_handler_, OnPlaying()); | 164 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); |
165 EXPECT_CALL(mock_event_handler_, OnPaused()) | 165 EXPECT_CALL(mock_event_handler_, OnControllerPaused()).Times(0); |
166 .Times(0); | |
167 | 166 |
168 // Simulate a device change event to AudioOutputController from the | 167 // Simulate a device change event to AudioOutputController from the |
169 // AudioManager. | 168 // AudioManager. |
170 audio_manager_->GetTaskRunner()->PostTask( | 169 audio_manager_->GetTaskRunner()->PostTask( |
171 FROM_HERE, | 170 FROM_HERE, |
172 base::Bind(&AudioOutputController::OnDeviceChange, controller_)); | 171 base::Bind(&AudioOutputController::OnDeviceChange, controller_)); |
173 } | 172 } |
174 | 173 |
175 void Divert(bool was_playing, int num_times_to_be_started) { | 174 void Divert(bool was_playing, int num_times_to_be_started) { |
176 if (was_playing) { | 175 if (was_playing) { |
177 // Expect the handler to receive one OnPlaying() call as a result of the | 176 // Expect the handler to receive one OnControllerPlaying() call as a |
178 // stream switching. | 177 // result of the stream switching. |
179 EXPECT_CALL(mock_event_handler_, OnPlaying()); | 178 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); |
180 } | 179 } |
181 | 180 |
182 EXPECT_CALL(mock_stream_, Open()) | 181 EXPECT_CALL(mock_stream_, Open()) |
183 .WillOnce(Return(true)); | 182 .WillOnce(Return(true)); |
184 EXPECT_CALL(mock_stream_, SetVolume(kTestVolume)); | 183 EXPECT_CALL(mock_stream_, SetVolume(kTestVolume)); |
185 if (num_times_to_be_started > 0) { | 184 if (num_times_to_be_started > 0) { |
186 EXPECT_CALL(mock_stream_, Start(NotNull())) | 185 EXPECT_CALL(mock_stream_, Start(NotNull())) |
187 .Times(num_times_to_be_started) | 186 .Times(num_times_to_be_started) |
188 .WillRepeatedly( | 187 .WillRepeatedly( |
189 Invoke(&mock_stream_, &MockAudioOutputStream::SetCallback)); | 188 Invoke(&mock_stream_, &MockAudioOutputStream::SetCallback)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::TimeDelta(), base::TimeTicks::Now(), 0, dest.get()); | 220 base::TimeDelta(), base::TimeTicks::Now(), 0, dest.get()); |
222 | 221 |
223 EXPECT_LT(0, frames_read); | 222 EXPECT_LT(0, frames_read); |
224 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); | 223 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); |
225 | 224 |
226 base::RunLoop().RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
227 } | 226 } |
228 | 227 |
229 void Revert(bool was_playing) { | 228 void Revert(bool was_playing) { |
230 if (was_playing) { | 229 if (was_playing) { |
231 // Expect the handler to receive one OnPlaying() call as a result of the | 230 // Expect the handler to receive one OnControllerPlaying() call as a |
232 // stream switching back. | 231 // result of the stream switching back. |
233 EXPECT_CALL(mock_event_handler_, OnPlaying()); | 232 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); |
234 } | 233 } |
235 | 234 |
236 EXPECT_CALL(mock_stream_, Close()); | 235 EXPECT_CALL(mock_stream_, Close()); |
237 | 236 |
238 controller_->StopDiverting(); | 237 controller_->StopDiverting(); |
239 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
240 } | 239 } |
241 | 240 |
242 void StopDuplicating(MockAudioPushSink* sink) { | 241 void StopDuplicating(MockAudioPushSink* sink) { |
243 EXPECT_CALL(*sink, Close()); | 242 EXPECT_CALL(*sink, Close()); |
244 controller_->StopDuplicating(sink); | 243 controller_->StopDuplicating(sink); |
245 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
246 } | 245 } |
247 | 246 |
248 void SwitchDevice(bool diverting) { | 247 void SwitchDevice(bool diverting) { |
249 if (!diverting) { | 248 if (!diverting) { |
250 // Expect the current stream to close and a new stream to start | 249 // Expect the current stream to close and a new stream to start |
251 // playing if not diverting. When diverting, nothing happens | 250 // playing if not diverting. When diverting, nothing happens |
252 // until diverting is stopped. | 251 // until diverting is stopped. |
253 EXPECT_CALL(mock_event_handler_, OnPlaying()); | 252 EXPECT_CALL(mock_event_handler_, OnControllerPlaying()); |
254 } | 253 } |
255 | 254 |
256 controller_->SwitchOutputDevice( | 255 controller_->SwitchOutputDevice( |
257 AudioDeviceDescription::GetDefaultDeviceName(), | 256 AudioDeviceDescription::GetDefaultDeviceName(), |
258 base::Bind(&base::DoNothing)); | 257 base::Bind(&base::DoNothing)); |
259 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
260 } | 259 } |
261 | 260 |
262 void Close() { | 261 void Close() { |
263 EXPECT_CALL(mock_sync_reader_, Close()); | 262 EXPECT_CALL(mock_sync_reader_, Close()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 // Switching device would trigger a read, and in turn it would trigger a push | 430 // Switching device would trigger a read, and in turn it would trigger a push |
432 // to sink. | 431 // to sink. |
433 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); | 432 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); |
434 SwitchDevice(false); | 433 SwitchDevice(false); |
435 | 434 |
436 StopDuplicating(&mock_sink); | 435 StopDuplicating(&mock_sink); |
437 Close(); | 436 Close(); |
438 } | 437 } |
439 | 438 |
440 } // namespace media | 439 } // namespace media |
OLD | NEW |