OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chromeos/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 const AudioNode kUSBCameraInput(true, | 185 const AudioNode kUSBCameraInput(true, |
186 kUSBCameraInputId, | 186 kUSBCameraInputId, |
187 "USB Camera", | 187 "USB Camera", |
188 "USB", | 188 "USB", |
189 "USB Camera", | 189 "USB Camera", |
190 false, | 190 false, |
191 0); | 191 0); |
192 | 192 |
193 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { | 193 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { |
194 public: | 194 public: |
195 TestObserver() : active_output_node_changed_count_(0), | 195 TestObserver() |
196 active_input_node_changed_count_(0), | 196 : active_output_node_changed_count_(0), |
197 audio_nodes_changed_count_(0), | 197 active_input_node_changed_count_(0), |
198 output_mute_changed_count_(0), | 198 audio_nodes_changed_count_(0), |
199 input_mute_changed_count_(0), | 199 output_mute_changed_count_(0), |
200 output_volume_changed_count_(0), | 200 input_mute_changed_count_(0), |
201 input_gain_changed_count_(0) { | 201 output_volume_changed_count_(0), |
202 } | 202 input_gain_changed_count_(0), |
| 203 output_mute_by_system_(false) {} |
203 | 204 |
204 int active_output_node_changed_count() const { | 205 int active_output_node_changed_count() const { |
205 return active_output_node_changed_count_; | 206 return active_output_node_changed_count_; |
206 } | 207 } |
207 | 208 |
208 void reset_active_output_node_changed_count() { | 209 void reset_active_output_node_changed_count() { |
209 active_output_node_changed_count_ = 0; | 210 active_output_node_changed_count_ = 0; |
210 } | 211 } |
211 | 212 |
212 int active_input_node_changed_count() const { | 213 int active_input_node_changed_count() const { |
213 return active_input_node_changed_count_; | 214 return active_input_node_changed_count_; |
214 } | 215 } |
215 | 216 |
216 void reset_active_input_node_changed_count() { | 217 void reset_active_input_node_changed_count() { |
217 active_input_node_changed_count_ = 0; | 218 active_input_node_changed_count_ = 0; |
218 } | 219 } |
219 | 220 |
220 int audio_nodes_changed_count() const { | 221 int audio_nodes_changed_count() const { |
221 return audio_nodes_changed_count_; | 222 return audio_nodes_changed_count_; |
222 } | 223 } |
223 | 224 |
224 int output_mute_changed_count() const { | 225 int output_mute_changed_count() const { |
225 return output_mute_changed_count_; | 226 return output_mute_changed_count_; |
226 } | 227 } |
227 | 228 |
| 229 void reset_output_mute_changed_count() { input_mute_changed_count_ = 0; } |
| 230 |
228 int input_mute_changed_count() const { | 231 int input_mute_changed_count() const { |
229 return input_mute_changed_count_; | 232 return input_mute_changed_count_; |
230 } | 233 } |
231 | 234 |
232 int output_volume_changed_count() const { | 235 int output_volume_changed_count() const { |
233 return output_volume_changed_count_; | 236 return output_volume_changed_count_; |
234 } | 237 } |
235 | 238 |
236 int input_gain_changed_count() const { | 239 int input_gain_changed_count() const { |
237 return input_gain_changed_count_; | 240 return input_gain_changed_count_; |
238 } | 241 } |
239 | 242 |
| 243 bool output_mute_by_system() const { return output_mute_by_system_; } |
| 244 |
240 ~TestObserver() override {} | 245 ~TestObserver() override {} |
241 | 246 |
242 protected: | 247 protected: |
243 // chromeos::CrasAudioHandler::AudioObserver overrides. | 248 // chromeos::CrasAudioHandler::AudioObserver overrides. |
244 void OnActiveOutputNodeChanged() override { | 249 void OnActiveOutputNodeChanged() override { |
245 ++active_output_node_changed_count_; | 250 ++active_output_node_changed_count_; |
246 } | 251 } |
247 | 252 |
248 void OnActiveInputNodeChanged() override { | 253 void OnActiveInputNodeChanged() override { |
249 ++active_input_node_changed_count_; | 254 ++active_input_node_changed_count_; |
250 } | 255 } |
251 | 256 |
252 void OnAudioNodesChanged() override { ++audio_nodes_changed_count_; } | 257 void OnAudioNodesChanged() override { ++audio_nodes_changed_count_; } |
253 | 258 |
254 void OnOutputMuteChanged(bool /* mute_on */) override { | 259 void OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) override { |
255 ++output_mute_changed_count_; | 260 ++output_mute_changed_count_; |
| 261 output_mute_by_system_ = system_adjust; |
256 } | 262 } |
257 | 263 |
258 void OnInputMuteChanged(bool /* mute_on */) override { | 264 void OnInputMuteChanged(bool /* mute_on */) override { |
259 ++input_mute_changed_count_; | 265 ++input_mute_changed_count_; |
260 } | 266 } |
261 | 267 |
262 void OnOutputNodeVolumeChanged(uint64 /* node_id */, | 268 void OnOutputNodeVolumeChanged(uint64 /* node_id */, |
263 int /* volume */) override { | 269 int /* volume */) override { |
264 ++output_volume_changed_count_; | 270 ++output_volume_changed_count_; |
265 } | 271 } |
266 | 272 |
267 void OnInputNodeGainChanged(uint64 /* node_id */, int /* gain */) override { | 273 void OnInputNodeGainChanged(uint64 /* node_id */, int /* gain */) override { |
268 ++input_gain_changed_count_; | 274 ++input_gain_changed_count_; |
269 } | 275 } |
270 | 276 |
271 private: | 277 private: |
272 int active_output_node_changed_count_; | 278 int active_output_node_changed_count_; |
273 int active_input_node_changed_count_; | 279 int active_input_node_changed_count_; |
274 int audio_nodes_changed_count_; | 280 int audio_nodes_changed_count_; |
275 int output_mute_changed_count_; | 281 int output_mute_changed_count_; |
276 int input_mute_changed_count_; | 282 int input_mute_changed_count_; |
277 int output_volume_changed_count_; | 283 int output_volume_changed_count_; |
278 int input_gain_changed_count_; | 284 int input_gain_changed_count_; |
| 285 bool output_mute_by_system_; // output mute state adjusted by system. |
279 | 286 |
280 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 287 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
281 }; | 288 }; |
282 | 289 |
283 } // namespace | 290 } // namespace |
284 | 291 |
285 class CrasAudioHandlerTest : public testing::Test { | 292 class CrasAudioHandlerTest : public testing::Test { |
286 public: | 293 public: |
287 CrasAudioHandlerTest() : cras_audio_handler_(NULL), | 294 CrasAudioHandlerTest() : cras_audio_handler_(NULL), |
288 fake_cras_audio_client_(NULL) { | 295 fake_cras_audio_client_(NULL) { |
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 // After HDMI re-discover grace period, verify HDMI output is selected as the | 2600 // After HDMI re-discover grace period, verify HDMI output is selected as the |
2594 // active device and not muted. | 2601 // active device and not muted. |
2595 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); | 2602 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); |
2596 EXPECT_TRUE( | 2603 EXPECT_TRUE( |
2597 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 2604 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
2598 EXPECT_EQ(kHDMIOutput.id, active_output.id); | 2605 EXPECT_EQ(kHDMIOutput.id, active_output.id); |
2599 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2606 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
2600 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 2607 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
2601 } | 2608 } |
2602 | 2609 |
| 2610 // This tests the case of output unmuting event is notified after the hdmi |
| 2611 // output re-discover grace period ends, see crbug.com/512601. |
| 2612 TEST_F(CrasAudioHandlerTest, HDMIOutputUnplugDuringSuspension) { |
| 2613 AudioNodeList audio_nodes; |
| 2614 audio_nodes.push_back(kInternalSpeaker); |
| 2615 audio_nodes.push_back(kHDMIOutput); |
| 2616 SetUpCrasAudioHandler(audio_nodes); |
| 2617 |
| 2618 // Verify the HDMI device has been selected as the active output, and audio |
| 2619 // output is not muted. |
| 2620 AudioDevice active_output; |
| 2621 EXPECT_TRUE( |
| 2622 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2623 EXPECT_EQ(kHDMIOutput.id, active_output.id); |
| 2624 EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2625 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 2626 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 2627 |
| 2628 // Trigger HDMI rediscovering grace period, and remove the HDMI node. |
| 2629 const int grace_period_in_ms = 200; |
| 2630 SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); |
| 2631 SetActiveHDMIRediscover(); |
| 2632 AudioNodeList audio_nodes_lost_hdmi; |
| 2633 audio_nodes_lost_hdmi.push_back(kInternalSpeaker); |
| 2634 ChangeAudioNodes(audio_nodes_lost_hdmi); |
| 2635 |
| 2636 // Verify the active output is switched to internal speaker, it is not muted |
| 2637 // by preference, but the system output is muted during the grace period. |
| 2638 EXPECT_TRUE( |
| 2639 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2640 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 2641 EXPECT_FALSE( |
| 2642 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); |
| 2643 EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); |
| 2644 |
| 2645 // After HDMI re-discover grace period, verify internal speaker is still the |
| 2646 // active output and not muted, and unmute event by system is notified. |
| 2647 test_observer_->reset_output_mute_changed_count(); |
| 2648 HDMIRediscoverWaiter waiter(this, grace_period_in_ms); |
| 2649 waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); |
| 2650 EXPECT_TRUE( |
| 2651 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2652 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 2653 EXPECT_EQ(kInternalSpeaker.id, |
| 2654 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2655 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 2656 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 2657 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
| 2658 } |
| 2659 |
2603 } // namespace chromeos | 2660 } // namespace chromeos |
OLD | NEW |