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 "extensions/browser/api/audio/audio_service.h" | 5 #include "extensions/browser/api/audio/audio_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 AudioServiceImpl(); | 41 AudioServiceImpl(); |
| 42 ~AudioServiceImpl() override; | 42 ~AudioServiceImpl() override; |
| 43 | 43 |
| 44 // Called by listeners to this service to add/remove themselves as observers. | 44 // Called by listeners to this service to add/remove themselves as observers. |
| 45 void AddObserver(AudioService::Observer* observer) override; | 45 void AddObserver(AudioService::Observer* observer) override; |
| 46 void RemoveObserver(AudioService::Observer* observer) override; | 46 void RemoveObserver(AudioService::Observer* observer) override; |
| 47 | 47 |
| 48 // Start to query audio device information. | 48 // Start to query audio device information. |
| 49 bool GetInfo(OutputInfo* output_info_out, InputInfo* input_info_out) override; | 49 bool GetInfo(OutputInfo* output_info_out, InputInfo* input_info_out) override; |
| 50 void SetActiveDevices(const DeviceIdList& device_list) override; | 50 void SetActiveDevices(const DeviceIdList& device_list) override; |
| 51 bool SetDeviceProperties(const std::string& device_id, | 51 bool SetDeviceSoundLevel(const std::string& device_id, |
| 52 bool muted, | |
| 53 int volume, | 52 int volume, |
| 54 int gain) override; | 53 int gain) override; |
| 54 bool SetMuteForDevice(const std::string& device_id, bool value) override; | |
| 55 bool SetMute(bool is_input, bool value) override; | |
| 56 bool GetMute(bool is_input, bool* value) override; | |
| 55 | 57 |
| 56 protected: | 58 protected: |
| 57 // chromeos::CrasAudioHandler::AudioObserver overrides. | 59 // chromeos::CrasAudioHandler::AudioObserver overrides. |
| 58 void OnOutputNodeVolumeChanged(uint64_t id, int volume) override; | 60 void OnOutputNodeVolumeChanged(uint64_t id, int volume) override; |
| 59 void OnInputNodeGainChanged(uint64_t id, int gain) override; | 61 void OnInputNodeGainChanged(uint64_t id, int gain) override; |
| 60 void OnOutputMuteChanged(bool mute_on, bool system_adjust) override; | 62 void OnOutputMuteChanged(bool mute_on, bool system_adjust) override; |
| 61 void OnInputMuteChanged(bool mute_on) override; | 63 void OnInputMuteChanged(bool mute_on) override; |
| 62 void OnAudioNodesChanged() override; | 64 void OnAudioNodesChanged() override; |
| 63 void OnActiveOutputNodeChanged() override; | 65 void OnActiveOutputNodeChanged() override; |
| 64 void OnActiveInputNodeChanged() override; | 66 void OnActiveInputNodeChanged() override; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 153 |
| 152 chromeos::CrasAudioHandler::NodeIdList id_list; | 154 chromeos::CrasAudioHandler::NodeIdList id_list; |
| 153 for (size_t i = 0; i < device_list.size(); ++i) { | 155 for (size_t i = 0; i < device_list.size(); ++i) { |
| 154 chromeos::AudioDevice device; | 156 chromeos::AudioDevice device; |
| 155 if (FindDevice(GetIdFromStr(device_list[i]), &device)) | 157 if (FindDevice(GetIdFromStr(device_list[i]), &device)) |
| 156 id_list.push_back(device.id); | 158 id_list.push_back(device.id); |
| 157 } | 159 } |
| 158 cras_audio_handler_->ChangeActiveNodes(id_list); | 160 cras_audio_handler_->ChangeActiveNodes(id_list); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, | 163 bool AudioServiceImpl::SetDeviceSoundLevel(const std::string& device_id, |
| 162 bool muted, | |
| 163 int volume, | 164 int volume, |
| 164 int gain) { | 165 int gain) { |
| 165 DCHECK(cras_audio_handler_); | 166 DCHECK(cras_audio_handler_); |
| 166 if (!cras_audio_handler_) | 167 if (!cras_audio_handler_) |
| 167 return false; | 168 return false; |
| 168 | 169 |
| 169 chromeos::AudioDevice device; | 170 chromeos::AudioDevice device; |
| 170 bool found = FindDevice(GetIdFromStr(device_id), &device); | 171 bool found = FindDevice(GetIdFromStr(device_id), &device); |
| 171 if (!found) | 172 if (!found) |
| 172 return false; | 173 return false; |
| 173 | 174 |
| 174 cras_audio_handler_->SetMuteForDevice(device.id, muted); | |
| 175 | |
| 176 if (!device.is_input && volume != -1) { | 175 if (!device.is_input && volume != -1) { |
| 177 cras_audio_handler_->SetVolumeGainPercentForDevice(device.id, volume); | 176 cras_audio_handler_->SetVolumeGainPercentForDevice(device.id, volume); |
| 178 return true; | 177 return true; |
| 179 } else if (device.is_input && gain != -1) { | 178 } else if (device.is_input && gain != -1) { |
| 180 cras_audio_handler_->SetVolumeGainPercentForDevice(device.id, gain); | 179 cras_audio_handler_->SetVolumeGainPercentForDevice(device.id, gain); |
| 181 return true; | 180 return true; |
| 182 } | 181 } |
| 183 | 182 |
| 184 return false; | 183 return false; |
| 185 } | 184 } |
| 186 | 185 |
| 186 bool AudioServiceImpl::SetMuteForDevice(const std::string& device_id, | |
| 187 bool value) { | |
| 188 DCHECK(cras_audio_handler_); | |
| 189 if (!cras_audio_handler_) | |
| 190 return false; | |
| 191 | |
| 192 chromeos::AudioDevice device; | |
| 193 bool found = FindDevice(GetIdFromStr(device_id), &device); | |
| 194 if (!found) | |
| 195 return false; | |
|
jennyz
2017/01/10 00:47:53
Combined into one line, no need to use bool found.
tbarzic
2017/01/11 00:47:03
Done.
| |
| 196 | |
| 197 cras_audio_handler_->SetMuteForDevice(device.id, value); | |
| 198 return true; | |
| 199 } | |
| 200 | |
| 201 bool AudioServiceImpl::SetMute(bool is_input, bool value) { | |
| 202 DCHECK(cras_audio_handler_); | |
| 203 if (!cras_audio_handler_) | |
| 204 return false; | |
| 205 | |
| 206 if (is_input) { | |
|
jennyz
2017/01/10 00:47:53
Don't need "{" for one line if or else block.
tbarzic
2017/01/11 00:47:03
Done.
| |
| 207 cras_audio_handler_->SetInputMute(value); | |
| 208 } else { | |
| 209 cras_audio_handler_->SetOutputMute(value); | |
| 210 } | |
| 211 return true; | |
| 212 } | |
| 213 | |
| 214 bool AudioServiceImpl::GetMute(bool is_input, bool* value) { | |
| 215 DCHECK(cras_audio_handler_); | |
| 216 if (!cras_audio_handler_) | |
| 217 return false; | |
| 218 | |
| 219 if (is_input) { | |
|
jennyz
2017/01/10 00:47:53
ditto
tbarzic
2017/01/11 00:47:03
Done.
| |
| 220 *value = cras_audio_handler_->IsInputMuted(); | |
| 221 } else { | |
| 222 *value = cras_audio_handler_->IsOutputMuted(); | |
| 223 } | |
| 224 return true; | |
| 225 } | |
| 226 | |
| 187 bool AudioServiceImpl::FindDevice(uint64_t id, chromeos::AudioDevice* device) { | 227 bool AudioServiceImpl::FindDevice(uint64_t id, chromeos::AudioDevice* device) { |
| 188 chromeos::AudioDeviceList devices; | 228 chromeos::AudioDeviceList devices; |
| 189 cras_audio_handler_->GetAudioDevices(&devices); | 229 cras_audio_handler_->GetAudioDevices(&devices); |
| 190 | 230 |
| 191 for (size_t i = 0; i < devices.size(); ++i) { | 231 for (size_t i = 0; i < devices.size(); ++i) { |
| 192 if (devices[i].id == id) { | 232 if (devices[i].id == id) { |
| 193 *device = devices[i]; | 233 *device = devices[i]; |
| 194 return true; | 234 return true; |
| 195 } | 235 } |
| 196 } | 236 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 void AudioServiceImpl::NotifyDevicesChanged() { | 299 void AudioServiceImpl::NotifyDevicesChanged() { |
| 260 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 300 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 261 DCHECK(cras_audio_handler_); | 301 DCHECK(cras_audio_handler_); |
| 262 | 302 |
| 263 DeviceInfoList devices_info_list; | 303 DeviceInfoList devices_info_list; |
| 264 chromeos::AudioDeviceList devices; | 304 chromeos::AudioDeviceList devices; |
| 265 cras_audio_handler_->GetAudioDevices(&devices); | 305 cras_audio_handler_->GetAudioDevices(&devices); |
| 266 for (size_t i = 0; i < devices.size(); ++i) { | 306 for (size_t i = 0; i < devices.size(); ++i) { |
| 267 AudioDeviceInfo info; | 307 AudioDeviceInfo info; |
| 268 info.id = base::Uint64ToString(devices[i].id); | 308 info.id = base::Uint64ToString(devices[i].id); |
| 309 info.stream_type = devices[i].is_input | |
| 310 ? extensions::api::audio::STREAM_TYPE_INPUT | |
| 311 : extensions::api::audio::STREAM_TYPE_OUTPUT; | |
| 269 info.is_input = devices[i].is_input; | 312 info.is_input = devices[i].is_input; |
| 270 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type); | 313 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type); |
| 271 info.display_name = devices[i].display_name; | 314 info.display_name = devices[i].display_name; |
| 272 info.device_name = devices[i].device_name; | 315 info.device_name = devices[i].device_name; |
| 273 info.is_active = devices[i].active; | 316 info.is_active = devices[i].active; |
| 274 info.is_muted = | 317 info.is_muted = |
| 275 devices[i].is_input | 318 devices[i].is_input |
| 276 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 319 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 277 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 320 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 278 info.level = | 321 info.level = |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 292 // Notify DeviceChanged event for backward compatibility. | 335 // Notify DeviceChanged event for backward compatibility. |
| 293 // TODO(jennyz): remove this code when the old version of hotrod retires. | 336 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 294 NotifyDeviceChanged(); | 337 NotifyDeviceChanged(); |
| 295 } | 338 } |
| 296 | 339 |
| 297 AudioService* AudioService::CreateInstance() { | 340 AudioService* AudioService::CreateInstance() { |
| 298 return new AudioServiceImpl; | 341 return new AudioServiceImpl; |
| 299 } | 342 } |
| 300 | 343 |
| 301 } // namespace extensions | 344 } // namespace extensions |
| OLD | NEW |