diff options
author | Jenny Zhang <jennyz@chromium.org> | 2015-07-29 16:26:16 -0700 |
---|---|---|
committer | Jenny Zhang <jennyz@chromium.org> | 2015-07-29 23:27:58 +0000 |
commit | d7ba885a83fd3435d533516872a0aef36f527de8 (patch) | |
tree | ddf011d8dba6b09ea37192def07a0f852237b81f /chromeos | |
parent | 30c5650db8d38f6cad3218869a1a6ab71aaf96c1 (diff) | |
download | chromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.zip chromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.tar.gz chromium_src-d7ba885a83fd3435d533516872a0aef36f527de8.tar.bz2 |
Fix the UI issue for showing output muted in ash tray after the device wakes up with hdmi output removed.
BUG=512601
TBR=mnissler@chromium.org, derat@chromium.org, rkc@chromium.org
Review URL: https://codereview.chromium.org/1262723002
Cr-Commit-Position: refs/heads/master@{#340794}
Review URL: https://codereview.chromium.org/1268593002 .
Cr-Commit-Position: refs/branch-heads/2454@{#176}
Cr-Branched-From: 12bfc3360892ec53cd00fc239a47e5298beb063b-refs/heads/master@{#338390}
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/audio/cras_audio_handler.cc | 17 | ||||
-rw-r--r-- | chromeos/audio/cras_audio_handler.h | 7 | ||||
-rw-r--r-- | chromeos/audio/cras_audio_handler_unittest.cc | 75 |
3 files changed, 84 insertions, 15 deletions
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc index 1cf03d1..8ee6009 100644 --- a/chromeos/audio/cras_audio_handler.cc +++ b/chromeos/audio/cras_audio_handler.cc @@ -69,8 +69,9 @@ void CrasAudioHandler::AudioObserver::OnInputNodeGainChanged( int /* gain */) { } -void CrasAudioHandler::AudioObserver::OnOutputMuteChanged(bool /* mute_on */) { -} +void CrasAudioHandler::AudioObserver::OnOutputMuteChanged( + bool /* mute_on */, + bool /* system_adjust */) {} void CrasAudioHandler::AudioObserver::OnInputMuteChanged(bool /* mute_on */) { } @@ -370,8 +371,9 @@ void CrasAudioHandler::SetOutputMute(bool mute_on) { } } - FOR_EACH_OBSERVER(AudioObserver, observers_, - OnOutputMuteChanged(output_mute_on_)); + FOR_EACH_OBSERVER( + AudioObserver, observers_, + OnOutputMuteChanged(output_mute_on_, false /* system_adjust */)); } void CrasAudioHandler::AdjustOutputVolumeToAudibleLevel() { @@ -1014,8 +1016,13 @@ void CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod() { hdmi_rediscovering_ = false; if (!IsOutputMutedForDevice(active_output_node_id_)) { // Unmute the audio output after the HDMI transition period. - VLOG(1) << "Unmute output after HDMI rediscovring grace period."; + VLOG(1) << "Unmute output after HDMI rediscovering grace period."; SetOutputMuteInternal(false); + + // Notify UI about the mute state change. + FOR_EACH_OBSERVER( + AudioObserver, observers_, + OnOutputMuteChanged(output_mute_on_, true /* system adjustment */)); } } diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h index 10c77a4..60a3131 100644 --- a/chromeos/audio/cras_audio_handler.h +++ b/chromeos/audio/cras_audio_handler.h @@ -41,7 +41,12 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume); // Called when output mute state changed. - virtual void OnOutputMuteChanged(bool mute_on); + // |mute_on|: True if output is muted. + // |system_adjust|: True if the mute state is adjusted by the system + // automatically(i.e. not by user). UI should reflect the system's mute + // state, but it should not be too loud, e.g., the volume pop up window + // should not be triggered. + virtual void OnOutputMuteChanged(bool mute_on, bool system_adjust); // Called when active input node's gain changed. virtual void OnInputNodeGainChanged(uint64_t node_id, int gain); diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc index 1a01d2e..4633d87 100644 --- a/chromeos/audio/cras_audio_handler_unittest.cc +++ b/chromeos/audio/cras_audio_handler_unittest.cc @@ -192,14 +192,15 @@ const AudioNode kUSBCameraInput(true, class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { public: - TestObserver() : active_output_node_changed_count_(0), - active_input_node_changed_count_(0), - audio_nodes_changed_count_(0), - output_mute_changed_count_(0), - input_mute_changed_count_(0), - output_volume_changed_count_(0), - input_gain_changed_count_(0) { - } + TestObserver() + : active_output_node_changed_count_(0), + active_input_node_changed_count_(0), + audio_nodes_changed_count_(0), + output_mute_changed_count_(0), + input_mute_changed_count_(0), + output_volume_changed_count_(0), + input_gain_changed_count_(0), + output_mute_by_system_(false) {} int active_output_node_changed_count() const { return active_output_node_changed_count_; @@ -225,6 +226,8 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { return output_mute_changed_count_; } + void reset_output_mute_changed_count() { input_mute_changed_count_ = 0; } + int input_mute_changed_count() const { return input_mute_changed_count_; } @@ -237,6 +240,8 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { return input_gain_changed_count_; } + bool output_mute_by_system() const { return output_mute_by_system_; } + ~TestObserver() override {} protected: @@ -251,8 +256,9 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { void OnAudioNodesChanged() override { ++audio_nodes_changed_count_; } - void OnOutputMuteChanged(bool /* mute_on */) override { + void OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) override { ++output_mute_changed_count_; + output_mute_by_system_ = system_adjust; } void OnInputMuteChanged(bool /* mute_on */) override { @@ -276,6 +282,7 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { int input_mute_changed_count_; int output_volume_changed_count_; int input_gain_changed_count_; + bool output_mute_by_system_; // output mute state adjusted by system. DISALLOW_COPY_AND_ASSIGN(TestObserver); }; @@ -2600,4 +2607,54 @@ TEST_F(CrasAudioHandlerTest, HDMIOutputRediscover) { EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); } +// This tests the case of output unmuting event is notified after the hdmi +// output re-discover grace period ends, see crbug.com/512601. +TEST_F(CrasAudioHandlerTest, HDMIOutputUnplugDuringSuspension) { + AudioNodeList audio_nodes; + audio_nodes.push_back(kInternalSpeaker); + audio_nodes.push_back(kHDMIOutput); + SetUpCrasAudioHandler(audio_nodes); + + // Verify the HDMI device has been selected as the active output, and audio + // output is not muted. + AudioDevice active_output; + EXPECT_TRUE( + cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); + EXPECT_EQ(kHDMIOutput.id, active_output.id); + EXPECT_EQ(kHDMIOutput.id, cras_audio_handler_->GetPrimaryActiveOutputNode()); + EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); + EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); + + // Trigger HDMI rediscovering grace period, and remove the HDMI node. + const int grace_period_in_ms = 200; + SetHDMIRediscoverGracePeriodDuration(grace_period_in_ms); + SetActiveHDMIRediscover(); + AudioNodeList audio_nodes_lost_hdmi; + audio_nodes_lost_hdmi.push_back(kInternalSpeaker); + ChangeAudioNodes(audio_nodes_lost_hdmi); + + // Verify the active output is switched to internal speaker, it is not muted + // by preference, but the system output is muted during the grace period. + EXPECT_TRUE( + cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); + EXPECT_EQ(kInternalSpeaker.id, active_output.id); + EXPECT_FALSE( + cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); + EXPECT_TRUE(cras_audio_handler_->IsOutputMuted()); + + // After HDMI re-discover grace period, verify internal speaker is still the + // active output and not muted, and unmute event by system is notified. + test_observer_->reset_output_mute_changed_count(); + HDMIRediscoverWaiter waiter(this, grace_period_in_ms); + waiter.WaitUntilHDMIRediscoverGracePeriodEnd(); + EXPECT_TRUE( + cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); + EXPECT_EQ(kInternalSpeaker.id, active_output.id); + EXPECT_EQ(kInternalSpeaker.id, + cras_audio_handler_->GetPrimaryActiveOutputNode()); + EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); + EXPECT_EQ(1, test_observer_->output_mute_changed_count()); + EXPECT_TRUE(test_observer_->output_mute_by_system()); +} + } // namespace chromeos |