Chromium Code Reviews| 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 "chrome/browser/extensions/api/audio/audio_service.h" | 5 #include "chrome/browser/extensions/api/audio/audio_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chromeos/audio/audio_device.h" | 10 #include "chromeos/audio/audio_device.h" |
| 11 #include "chromeos/audio/cras_audio_handler.h" | 11 #include "chromeos/audio/cras_audio_handler.h" |
| 12 #include "chromeos/dbus/cras_audio_client.h" | |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 | 15 |
| 14 using content::BrowserThread; | 16 using content::BrowserThread; |
| 15 | 17 |
| 16 namespace extensions { | 18 namespace extensions { |
| 17 | 19 |
| 18 using api::audio::OutputDeviceInfo; | 20 using api::audio::OutputDeviceInfo; |
| 19 using api::audio::InputDeviceInfo; | 21 using api::audio::InputDeviceInfo; |
| 20 | 22 |
| 21 class AudioServiceImpl : public AudioService, | 23 class AudioServiceImpl : public AudioService, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } | 133 } |
| 132 | 134 |
| 133 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) { | 135 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) { |
| 134 DCHECK(cras_audio_handler_); | 136 DCHECK(cras_audio_handler_); |
| 135 if (!cras_audio_handler_) | 137 if (!cras_audio_handler_) |
| 136 return; | 138 return; |
| 137 | 139 |
| 138 bool input_device_set = false; | 140 bool input_device_set = false; |
| 139 bool output_device_set = false; | 141 bool output_device_set = false; |
| 140 | 142 |
| 143 std::string active_input_node_ids, active_output_node_ids; | |
| 141 for (size_t i = 0; i < device_list.size(); ++i) { | 144 for (size_t i = 0; i < device_list.size(); ++i) { |
| 142 chromeos::AudioDevice device; | 145 chromeos::AudioDevice device; |
| 143 bool found = FindDevice(GetIdFromStr(device_list[i]), &device); | 146 bool found = FindDevice(GetIdFromStr(device_list[i]), &device); |
| 144 if (found) { | 147 if (found) { |
| 145 if (device.is_input && !input_device_set) { | 148 if (device.is_input && !input_device_set) { |
| 146 cras_audio_handler_->SwitchToDevice(device); | 149 cras_audio_handler_->SwitchToDevice(device); |
| 147 input_device_set = true; | 150 input_device_set = true; |
| 151 active_input_node_ids.push_back(device.id); | |
|
jennyz
2014/08/12 18:37:54
Yes, hychao's comment later is right, this line sh
| |
| 148 } else if (!device.is_input && !output_device_set) { | 152 } else if (!device.is_input && !output_device_set) { |
| 149 cras_audio_handler_->SwitchToDevice(device); | 153 cras_audio_handler_->SwitchToDevice(device); |
| 150 output_device_set = true; | 154 output_device_set = true; |
| 155 active_output_node_ids.push_back(device.id); | |
|
hychao
2014/08/12 10:47:40
The push_back calls should be pulled out from if/e
| |
| 151 } | 156 } |
| 152 } | 157 } |
| 153 } | 158 } |
| 159 | |
| 160 // Once we have set our devices to active and all the inactive ones have been | |
| 161 // set correctly to inactive, go through our active devices again and set | |
|
hychao
2014/08/12 10:47:40
I don't see where we deactivate the old active inp
| |
| 162 // them to active using the AddActiveNode API. This is an ugly hack till | |
| 163 // http://crbug.com/402072 is fixed. | |
| 164 for (size_t i = 0; i < active_input_node_ids.size(); ++i) { | |
| 165 chromeos::DBusThreadManager::Get() | |
| 166 ->GetCrasAudioClient() | |
| 167 ->AddActiveInputNode(active_input_node_ids[i]); | |
| 168 } | |
| 169 for (size_t i = 0; i < active_output_node_ids.size(); ++i) { | |
| 170 chromeos::DBusThreadManager::Get() | |
| 171 ->GetCrasAudioClient() | |
| 172 ->AddActiveOutputNode(active_output_node_ids[i]); | |
| 173 } | |
| 154 } | 174 } |
| 155 | 175 |
| 156 bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, | 176 bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, |
| 157 bool muted, | 177 bool muted, |
| 158 int volume, | 178 int volume, |
| 159 int gain) { | 179 int gain) { |
| 160 DCHECK(cras_audio_handler_); | 180 DCHECK(cras_audio_handler_); |
| 161 if (!cras_audio_handler_) | 181 if (!cras_audio_handler_) |
| 162 return false; | 182 return false; |
| 163 | 183 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 250 |
| 231 void AudioServiceImpl::NotifyDeviceChanged() { | 251 void AudioServiceImpl::NotifyDeviceChanged() { |
| 232 FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, OnDeviceChanged()); | 252 FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, OnDeviceChanged()); |
| 233 } | 253 } |
| 234 | 254 |
| 235 AudioService* AudioService::CreateInstance() { | 255 AudioService* AudioService::CreateInstance() { |
| 236 return new AudioServiceImpl; | 256 return new AudioServiceImpl; |
| 237 } | 257 } |
| 238 | 258 |
| 239 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |