| 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 27 matching lines...) Expand all Loading... |
| 38 const uint64_t kOtherTypeInputId = 90002; | 38 const uint64_t kOtherTypeInputId = 90002; |
| 39 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; | 39 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; |
| 40 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; | 40 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; |
| 41 const uint64_t kUSBJabraSpeakerInputId1 = 90005; | 41 const uint64_t kUSBJabraSpeakerInputId1 = 90005; |
| 42 const uint64_t kUSBJabraSpeakerInputId2 = 90006; | 42 const uint64_t kUSBJabraSpeakerInputId2 = 90006; |
| 43 const uint64_t kUSBCameraInputId = 90007; | 43 const uint64_t kUSBCameraInputId = 90007; |
| 44 | 44 |
| 45 const AudioNode kInternalSpeaker( | 45 const AudioNode kInternalSpeaker( |
| 46 false, | 46 false, |
| 47 kInternalSpeakerId, | 47 kInternalSpeakerId, |
| 48 kInternalSpeakerId, |
| 48 "Fake Speaker", | 49 "Fake Speaker", |
| 49 "INTERNAL_SPEAKER", | 50 "INTERNAL_SPEAKER", |
| 50 "Speaker", | 51 "Speaker", |
| 51 false, | 52 false, |
| 52 0 | 53 0 |
| 53 ); | 54 ); |
| 54 | 55 |
| 55 const AudioNode kHeadphone( | 56 const AudioNode kHeadphone( |
| 56 false, | 57 false, |
| 57 kHeadphoneId, | 58 kHeadphoneId, |
| 59 kHeadphoneId, |
| 58 "Fake Headphone", | 60 "Fake Headphone", |
| 59 "HEADPHONE", | 61 "HEADPHONE", |
| 60 "Headphone", | 62 "Headphone", |
| 61 false, | 63 false, |
| 62 0 | 64 0 |
| 63 ); | 65 ); |
| 64 | 66 |
| 65 const AudioNode kInternalMic( | 67 const AudioNode kInternalMic( |
| 66 true, | 68 true, |
| 67 kInternalMicId, | 69 kInternalMicId, |
| 70 kInternalMicId, |
| 68 "Fake Mic", | 71 "Fake Mic", |
| 69 "INTERNAL_MIC", | 72 "INTERNAL_MIC", |
| 70 "Internal Mic", | 73 "Internal Mic", |
| 71 false, | 74 false, |
| 72 0 | 75 0 |
| 73 ); | 76 ); |
| 74 | 77 |
| 75 const AudioNode kMicJack( | 78 const AudioNode kMicJack( |
| 76 true, | 79 true, |
| 77 kMicJackId, | 80 kMicJackId, |
| 81 kMicJackId, |
| 78 "Fake Mic Jack", | 82 "Fake Mic Jack", |
| 79 "MIC", | 83 "MIC", |
| 80 "Mic Jack", | 84 "Mic Jack", |
| 81 false, | 85 false, |
| 82 0 | 86 0 |
| 83 ); | 87 ); |
| 84 | 88 |
| 85 const AudioNode kUSBMic( | 89 const AudioNode kUSBMic( |
| 86 true, | 90 true, |
| 87 kUSBMicId, | 91 kUSBMicId, |
| 92 kUSBMicId, |
| 88 "Fake USB Mic", | 93 "Fake USB Mic", |
| 89 "USB", | 94 "USB", |
| 90 "USB Microphone", | 95 "USB Microphone", |
| 91 false, | 96 false, |
| 92 0 | 97 0 |
| 93 ); | 98 ); |
| 94 | 99 |
| 95 const AudioNode kKeyboardMic( | 100 const AudioNode kKeyboardMic( |
| 96 true, | 101 true, |
| 97 kKeyboardMicId, | 102 kKeyboardMicId, |
| 103 kKeyboardMicId, |
| 98 "Fake Keyboard Mic", | 104 "Fake Keyboard Mic", |
| 99 "KEYBOARD_MIC", | 105 "KEYBOARD_MIC", |
| 100 "Keyboard Mic", | 106 "Keyboard Mic", |
| 101 false, | 107 false, |
| 102 0 | 108 0 |
| 103 ); | 109 ); |
| 104 | 110 |
| 105 const AudioNode kOtherTypeOutput( | 111 const AudioNode kOtherTypeOutput( |
| 106 false, | 112 false, |
| 107 kOtherTypeOutputId, | 113 kOtherTypeOutputId, |
| 114 kOtherTypeOutputId, |
| 108 "Output Device", | 115 "Output Device", |
| 109 "SOME_OTHER_TYPE", | 116 "SOME_OTHER_TYPE", |
| 110 "Other Type Output Device", | 117 "Other Type Output Device", |
| 111 false, | 118 false, |
| 112 0 | 119 0 |
| 113 ); | 120 ); |
| 114 | 121 |
| 115 const AudioNode kOtherTypeInput( | 122 const AudioNode kOtherTypeInput( |
| 116 true, | 123 true, |
| 117 kOtherTypeInputId, | 124 kOtherTypeInputId, |
| 125 kOtherTypeInputId, |
| 118 "Input Device", | 126 "Input Device", |
| 119 "SOME_OTHER_TYPE", | 127 "SOME_OTHER_TYPE", |
| 120 "Other Type Input Device", | 128 "Other Type Input Device", |
| 121 false, | 129 false, |
| 122 0 | 130 0 |
| 123 ); | 131 ); |
| 124 | 132 |
| 125 const AudioNode kBluetoothHeadset(false, | 133 const AudioNode kBluetoothHeadset(false, |
| 126 kBluetoothHeadsetId, | 134 kBluetoothHeadsetId, |
| 135 kBluetoothHeadsetId, |
| 127 "Bluetooth Headset", | 136 "Bluetooth Headset", |
| 128 "BLUETOOTH", | 137 "BLUETOOTH", |
| 129 "Bluetooth Headset 1", | 138 "Bluetooth Headset 1", |
| 130 false, | 139 false, |
| 131 0); | 140 0); |
| 132 | 141 |
| 133 const AudioNode kHDMIOutput(false, | 142 const AudioNode kHDMIOutput(false, |
| 134 kHDMIOutputId, | 143 kHDMIOutputId, |
| 144 kHDMIOutputId, |
| 135 "HDMI output", | 145 "HDMI output", |
| 136 "HDMI", | 146 "HDMI", |
| 137 "HDMI output", | 147 "HDMI output", |
| 138 false, | 148 false, |
| 139 0); | 149 0); |
| 140 | 150 |
| 141 const AudioNode kUSBHeadphone1(false, | 151 const AudioNode kUSBHeadphone1(false, |
| 142 kUSBHeadphoneId1, | 152 kUSBHeadphoneId1, |
| 153 kUSBHeadphoneId1, |
| 143 "USB Headphone", | 154 "USB Headphone", |
| 144 "USB", | 155 "USB", |
| 145 "USB Headphone 1", | 156 "USB Headphone 1", |
| 146 false, | 157 false, |
| 147 0); | 158 0); |
| 148 | 159 |
| 149 const AudioNode kUSBHeadphone2(false, | 160 const AudioNode kUSBHeadphone2(false, |
| 150 kUSBHeadphoneId2, | 161 kUSBHeadphoneId2, |
| 162 kUSBHeadphoneId2, |
| 151 "USB Headphone", | 163 "USB Headphone", |
| 152 "USB", | 164 "USB", |
| 153 "USB Headphone 1", | 165 "USB Headphone 1", |
| 154 false, | 166 false, |
| 155 0); | 167 0); |
| 156 | 168 |
| 157 const AudioNode kUSBJabraSpeakerOutput1(false, | 169 const AudioNode kUSBJabraSpeakerOutput1(false, |
| 158 kUSBJabraSpeakerOutputId1, | 170 kUSBJabraSpeakerOutputId1, |
| 171 kUSBJabraSpeakerOutputId1, |
| 159 "Jabra Speaker 1", | 172 "Jabra Speaker 1", |
| 160 "USB", | 173 "USB", |
| 161 "Jabra Speaker 1", | 174 "Jabra Speaker 1", |
| 162 false, | 175 false, |
| 163 0); | 176 0); |
| 164 | 177 |
| 165 const AudioNode kUSBJabraSpeakerOutput2(false, | 178 const AudioNode kUSBJabraSpeakerOutput2(false, |
| 166 kUSBJabraSpeakerOutputId2, | 179 kUSBJabraSpeakerOutputId2, |
| 180 kUSBJabraSpeakerOutputId2, |
| 167 "Jabra Speaker 2", | 181 "Jabra Speaker 2", |
| 168 "USB", | 182 "USB", |
| 169 "Jabra Speaker 2", | 183 "Jabra Speaker 2", |
| 170 false, | 184 false, |
| 171 0); | 185 0); |
| 172 | 186 |
| 173 const AudioNode kUSBJabraSpeakerInput1(true, | 187 const AudioNode kUSBJabraSpeakerInput1(true, |
| 174 kUSBJabraSpeakerInputId1, | 188 kUSBJabraSpeakerInputId1, |
| 189 kUSBJabraSpeakerInputId1, |
| 175 "Jabra Speaker 1", | 190 "Jabra Speaker 1", |
| 176 "USB", | 191 "USB", |
| 177 "Jabra Speaker", | 192 "Jabra Speaker", |
| 178 false, | 193 false, |
| 179 0); | 194 0); |
| 180 | 195 |
| 181 const AudioNode kUSBJabraSpeakerInput2(true, | 196 const AudioNode kUSBJabraSpeakerInput2(true, |
| 182 kUSBJabraSpeakerInputId2, | 197 kUSBJabraSpeakerInputId2, |
| 198 kUSBJabraSpeakerInputId2, |
| 183 "Jabra Speaker 2", | 199 "Jabra Speaker 2", |
| 184 "USB", | 200 "USB", |
| 185 "Jabra Speaker 2", | 201 "Jabra Speaker 2", |
| 186 false, | 202 false, |
| 187 0); | 203 0); |
| 188 | 204 |
| 189 const AudioNode kUSBCameraInput(true, | 205 const AudioNode kUSBCameraInput(true, |
| 190 kUSBCameraInputId, | 206 kUSBCameraInputId, |
| 207 kUSBCameraInputId, |
| 191 "USB Camera", | 208 "USB Camera", |
| 192 "USB", | 209 "USB", |
| 193 "USB Camera", | 210 "USB Camera", |
| 194 false, | 211 false, |
| 195 0); | 212 0); |
| 196 | 213 |
| 197 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { | 214 class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { |
| 198 public: | 215 public: |
| 199 TestObserver() | 216 TestObserver() |
| 200 : active_output_node_changed_count_(0), | 217 : active_output_node_changed_count_(0), |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2036 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2053 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2037 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); | 2054 EXPECT_TRUE(cras_audio_handler_->has_alternative_output()); |
| 2038 | 2055 |
| 2039 // Ensure the internal microphone has been selected as the active input, | 2056 // Ensure the internal microphone has been selected as the active input, |
| 2040 // and the input device with some random unknown type is handled gracefully. | 2057 // and the input device with some random unknown type is handled gracefully. |
| 2041 AudioDevice active_input; | 2058 AudioDevice active_input; |
| 2042 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); | 2059 EXPECT_EQ(kInternalMic.id, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 2043 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); | 2060 EXPECT_TRUE(cras_audio_handler_->has_alternative_input()); |
| 2044 } | 2061 } |
| 2045 | 2062 |
| 2063 TEST_F(CrasAudioHandlerTest, ActiveDeviceSelectionWithStableDeviceId) { |
| 2064 AudioNodeList audio_nodes; |
| 2065 AudioNode internal_speaker(kInternalSpeaker); |
| 2066 audio_nodes.push_back(internal_speaker); |
| 2067 AudioNode usb_headset(kUSBHeadphone1); |
| 2068 usb_headset.plugged_time = 80000000; |
| 2069 audio_nodes.push_back(usb_headset); |
| 2070 SetUpCrasAudioHandler(audio_nodes); |
| 2071 |
| 2072 // Verify the audio devices size. |
| 2073 AudioDeviceList audio_devices; |
| 2074 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 2075 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 2076 |
| 2077 // Initially active node is selected base on priority, so USB headphone |
| 2078 // is selected. |
| 2079 EXPECT_EQ(kUSBHeadphone1.id, |
| 2080 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2081 |
| 2082 // Change the active device to internal speaker, now USB headphone becomes |
| 2083 // inactive. |
| 2084 AudioDevice speaker(kInternalSpeaker); |
| 2085 cras_audio_handler_->SwitchToDevice(speaker, true); |
| 2086 EXPECT_NE(kUSBHeadphone1.id, |
| 2087 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2088 |
| 2089 // Unplug USB headset. |
| 2090 audio_nodes.clear(); |
| 2091 internal_speaker.active = true; |
| 2092 audio_nodes.push_back(internal_speaker); |
| 2093 ChangeAudioNodes(audio_nodes); |
| 2094 EXPECT_EQ(kInternalSpeaker.id, |
| 2095 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2096 |
| 2097 // Plug the same USB headset back, id is different, but stable_device_id |
| 2098 // remains the same. |
| 2099 usb_headset.active = false; |
| 2100 usb_headset.id = 98765; |
| 2101 audio_nodes.push_back(usb_headset); |
| 2102 ChangeAudioNodes(audio_nodes); |
| 2103 |
| 2104 // Since USB headset was inactive before it was unplugged, it won't be |
| 2105 // selected as active after it's plugged in again. |
| 2106 EXPECT_EQ(kInternalSpeaker.id, |
| 2107 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2108 |
| 2109 // Plug the second USB headset. |
| 2110 AudioNode usb_headset2(kUSBHeadphone2); |
| 2111 usb_headset2.plugged_time = 80000001; |
| 2112 audio_nodes.push_back(usb_headset2); |
| 2113 ChangeAudioNodes(audio_nodes); |
| 2114 |
| 2115 // Since the second USB device is new, it's selected as the active device |
| 2116 // by its priority. |
| 2117 EXPECT_EQ(kUSBHeadphone2.id, |
| 2118 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2119 |
| 2120 // Unplug the second USB headset. |
| 2121 audio_nodes.clear(); |
| 2122 internal_speaker.active = false; |
| 2123 audio_nodes.push_back(internal_speaker); |
| 2124 audio_nodes.push_back(usb_headset); |
| 2125 ChangeAudioNodes(audio_nodes); |
| 2126 |
| 2127 // There is no active node after USB2 unplugged, the 1st USB got selected |
| 2128 // by its priority. |
| 2129 EXPECT_EQ(usb_headset.id, |
| 2130 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2131 |
| 2132 usb_headset2.active = false; |
| 2133 usb_headset2.plugged_time = 80000002; |
| 2134 audio_nodes.push_back(usb_headset2); |
| 2135 ChangeAudioNodes(audio_nodes); |
| 2136 |
| 2137 // Plug the second USB again. Since it was the active node before it got |
| 2138 // unplugged, it is now selected as the active node. |
| 2139 EXPECT_EQ(usb_headset2.id, |
| 2140 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2141 } |
| 2142 |
| 2046 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) { | 2143 TEST_F(CrasAudioHandlerTest, ChangeActiveNodesHotrodInit) { |
| 2047 AudioNodeList audio_nodes; | 2144 AudioNodeList audio_nodes; |
| 2048 audio_nodes.push_back(kHDMIOutput); | 2145 audio_nodes.push_back(kHDMIOutput); |
| 2049 audio_nodes.push_back(kUSBJabraSpeakerOutput1); | 2146 audio_nodes.push_back(kUSBJabraSpeakerOutput1); |
| 2050 audio_nodes.push_back(kUSBJabraSpeakerOutput2); | 2147 audio_nodes.push_back(kUSBJabraSpeakerOutput2); |
| 2051 audio_nodes.push_back(kUSBJabraSpeakerInput1); | 2148 audio_nodes.push_back(kUSBJabraSpeakerInput1); |
| 2052 audio_nodes.push_back(kUSBJabraSpeakerInput2); | 2149 audio_nodes.push_back(kUSBJabraSpeakerInput2); |
| 2053 audio_nodes.push_back(kUSBCameraInput); | 2150 audio_nodes.push_back(kUSBCameraInput); |
| 2054 SetUpCrasAudioHandler(audio_nodes); | 2151 SetUpCrasAudioHandler(audio_nodes); |
| 2055 | 2152 |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 2752 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
| 2656 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 2753 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
| 2657 EXPECT_EQ(kInternalSpeaker.id, | 2754 EXPECT_EQ(kInternalSpeaker.id, |
| 2658 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2755 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
| 2659 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 2756 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
| 2660 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 2757 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
| 2661 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 2758 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
| 2662 } | 2759 } |
| 2663 | 2760 |
| 2664 } // namespace chromeos | 2761 } // namespace chromeos |
| OLD | NEW |