| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { | 199 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { |
| 200 public: | 200 public: |
| 201 TestObserver() | 201 TestObserver() |
| 202 : active_output_node_changed_count_(0), | 202 : active_output_node_changed_count_(0), |
| 203 active_input_node_changed_count_(0), | 203 active_input_node_changed_count_(0), |
| 204 audio_nodes_changed_count_(0), | 204 audio_nodes_changed_count_(0), |
| 205 output_mute_changed_count_(0), | 205 output_mute_changed_count_(0), |
| 206 input_mute_changed_count_(0), | 206 input_mute_changed_count_(0), |
| 207 output_volume_changed_count_(0), | 207 output_volume_changed_count_(0), |
| 208 input_gain_changed_count_(0), | 208 input_gain_changed_count_(0), |
| 209 output_mute_by_system_(false) {} | 209 output_mute_by_system_(false), |
| 210 output_channel_remixing_changed_count_(0) {} |
| 210 | 211 |
| 211 int active_output_node_changed_count() const { | 212 int active_output_node_changed_count() const { |
| 212 return active_output_node_changed_count_; | 213 return active_output_node_changed_count_; |
| 213 } | 214 } |
| 214 | 215 |
| 215 void reset_active_output_node_changed_count() { | 216 void reset_active_output_node_changed_count() { |
| 216 active_output_node_changed_count_ = 0; | 217 active_output_node_changed_count_ = 0; |
| 217 } | 218 } |
| 218 | 219 |
| 219 int active_input_node_changed_count() const { | 220 int active_input_node_changed_count() const { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 241 int output_volume_changed_count() const { | 242 int output_volume_changed_count() const { |
| 242 return output_volume_changed_count_; | 243 return output_volume_changed_count_; |
| 243 } | 244 } |
| 244 | 245 |
| 245 int input_gain_changed_count() const { | 246 int input_gain_changed_count() const { |
| 246 return input_gain_changed_count_; | 247 return input_gain_changed_count_; |
| 247 } | 248 } |
| 248 | 249 |
| 249 bool output_mute_by_system() const { return output_mute_by_system_; } | 250 bool output_mute_by_system() const { return output_mute_by_system_; } |
| 250 | 251 |
| 252 int output_channel_remixing_changed_count() const { |
| 253 return output_channel_remixing_changed_count_; |
| 254 } |
| 255 |
| 251 ~TestObserver() override {} | 256 ~TestObserver() override {} |
| 252 | 257 |
| 253 protected: | 258 protected: |
| 254 // chromeos::CrasAudioHandler::AudioObserver overrides. | 259 // chromeos::CrasAudioHandler::AudioObserver overrides. |
| 255 void OnActiveOutputNodeChanged() override { | 260 void OnActiveOutputNodeChanged() override { |
| 256 ++active_output_node_changed_count_; | 261 ++active_output_node_changed_count_; |
| 257 } | 262 } |
| 258 | 263 |
| 259 void OnActiveInputNodeChanged() override { | 264 void OnActiveInputNodeChanged() override { |
| 260 ++active_input_node_changed_count_; | 265 ++active_input_node_changed_count_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 273 | 278 |
| 274 void OnOutputNodeVolumeChanged(uint64_t /* node_id */, | 279 void OnOutputNodeVolumeChanged(uint64_t /* node_id */, |
| 275 int /* volume */) override { | 280 int /* volume */) override { |
| 276 ++output_volume_changed_count_; | 281 ++output_volume_changed_count_; |
| 277 } | 282 } |
| 278 | 283 |
| 279 void OnInputNodeGainChanged(uint64_t /* node_id */, int /* gain */) override { | 284 void OnInputNodeGainChanged(uint64_t /* node_id */, int /* gain */) override { |
| 280 ++input_gain_changed_count_; | 285 ++input_gain_changed_count_; |
| 281 } | 286 } |
| 282 | 287 |
| 288 void OnOuputChannelRemixingChanged(bool /* mono_on */) override { |
| 289 ++output_channel_remixing_changed_count_; |
| 290 } |
| 291 |
| 283 private: | 292 private: |
| 284 int active_output_node_changed_count_; | 293 int active_output_node_changed_count_; |
| 285 int active_input_node_changed_count_; | 294 int active_input_node_changed_count_; |
| 286 int audio_nodes_changed_count_; | 295 int audio_nodes_changed_count_; |
| 287 int output_mute_changed_count_; | 296 int output_mute_changed_count_; |
| 288 int input_mute_changed_count_; | 297 int input_mute_changed_count_; |
| 289 int output_volume_changed_count_; | 298 int output_volume_changed_count_; |
| 290 int input_gain_changed_count_; | 299 int input_gain_changed_count_; |
| 291 bool output_mute_by_system_; // output mute state adjusted by system. | 300 bool output_mute_by_system_; // output mute state adjusted by system. |
| 301 int output_channel_remixing_changed_count_; |
| 292 | 302 |
| 293 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 303 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 294 }; | 304 }; |
| 295 | 305 |
| 296 } // namespace | 306 } // namespace |
| 297 | 307 |
| 298 class CrasAudioHandlerTest : public testing::Test { | 308 class CrasAudioHandlerTest : public testing::Test { |
| 299 public: | 309 public: |
| 300 CrasAudioHandlerTest() : cras_audio_handler_(NULL), | 310 CrasAudioHandlerTest() : cras_audio_handler_(NULL), |
| 301 fake_cras_audio_client_(NULL) { | 311 fake_cras_audio_client_(NULL) { |
| (...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 1889 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 1880 EXPECT_EQ(internal_speaker.id, active_output.id); | 1890 EXPECT_EQ(internal_speaker.id, active_output.id); |
| 1881 EXPECT_TRUE(active_output.active); | 1891 EXPECT_TRUE(active_output.active); |
| 1882 | 1892 |
| 1883 // Verify the active input device id is set to internal mic. | 1893 // Verify the active input device id is set to internal mic. |
| 1884 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 1894 EXPECT_EQ(internal_mic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 1885 const AudioDevice* changed_active_input = GetDeviceFromId(internal_mic.id); | 1895 const AudioDevice* changed_active_input = GetDeviceFromId(internal_mic.id); |
| 1886 EXPECT_TRUE(changed_active_input->active); | 1896 EXPECT_TRUE(changed_active_input->active); |
| 1887 } | 1897 } |
| 1888 | 1898 |
| 1899 TEST_F(CrasAudioHandlerTest, SetOutputMono) { |
| 1900 AudioNodeList audio_nodes; |
| 1901 audio_nodes.push_back(kHeadphone); |
| 1902 SetUpCrasAudioHandler(audio_nodes); |
| 1903 EXPECT_EQ(0, test_observer_->output_channel_remixing_changed_count()); |
| 1904 |
| 1905 // Set output mono |
| 1906 cras_audio_handler_->SetOutputMono(true); |
| 1907 |
| 1908 // Verify the output is in mono mode, OnOuputChannelRemixingChanged event |
| 1909 // is fired. |
| 1910 EXPECT_TRUE(cras_audio_handler_->IsOutputMonoEnabled()); |
| 1911 EXPECT_EQ(1, test_observer_->output_channel_remixing_changed_count()); |
| 1912 |
| 1913 // Set output stereo |
| 1914 cras_audio_handler_->SetOutputMono(false); |
| 1915 EXPECT_FALSE(cras_audio_handler_->IsOutputMonoEnabled()); |
| 1916 EXPECT_EQ(2, test_observer_->output_channel_remixing_changed_count()); |
| 1917 } |
| 1918 |
| 1889 TEST_F(CrasAudioHandlerTest, SetOutputMute) { | 1919 TEST_F(CrasAudioHandlerTest, SetOutputMute) { |
| 1890 AudioNodeList audio_nodes; | 1920 AudioNodeList audio_nodes; |
| 1891 audio_nodes.push_back(kInternalSpeaker); | 1921 audio_nodes.push_back(kInternalSpeaker); |
| 1892 SetUpCrasAudioHandler(audio_nodes); | 1922 SetUpCrasAudioHandler(audio_nodes); |
| 1893 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); | 1923 EXPECT_EQ(0, test_observer_->output_mute_changed_count()); |
| 1894 | 1924 |
| 1895 // Mute the device. | 1925 // Mute the device. |
| 1896 cras_audio_handler_->SetOutputMute(true); | 1926 cras_audio_handler_->SetOutputMute(true); |
| 1897 | 1927 |
| 1898 // Verify the output is muted, OnOutputMuteChanged event is fired, | 1928 // Verify the output is muted, OnOutputMuteChanged event is fired, |
| (...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3066 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3096 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 3067 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 3097 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 3068 EXPECT_EQ(kInternalSpeaker.id, | 3098 EXPECT_EQ(kInternalSpeaker.id, |
| 3069 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3099 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 3070 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3100 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 3071 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 3101 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 3072 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 3102 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
| 3073 } | 3103 } |
| 3074 | 3104 |
| 3075 } // namespace chromeos | 3105 } // namespace chromeos |
| OLD | NEW |