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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "chromeos/audio/audio_device.h" | 14 #include "chromeos/audio/audio_device.h" |
| 15 #include "chromeos/audio/cras_audio_handler.h" | 15 #include "chromeos/audio/cras_audio_handler.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 using api::audio::OutputDeviceInfo; | 22 using api::audio::OutputDeviceInfo; |
| 23 using api::audio::InputDeviceInfo; | 23 using api::audio::InputDeviceInfo; |
| 24 using api::audio::AudioDeviceInfo; | 24 using api::audio::AudioDeviceInfo; |
| 25 | 25 |
| 26 uint64_t GetStableDeviceId(const chromeos::AudioDevice& device) { | |
| 27 // TODO(tbarzic): Update audio API to expose new stable device ID version. | |
|
jennyz
2016/12/09 23:52:19
Can you file a separate bug for this work item and
tbarzic
2016/12/10 02:35:08
Done.
| |
| 28 // For now, for the sake of backward compatibility, use deprecated version. | |
| 29 if (device.stable_device_id_version == 1) | |
| 30 return device.stable_device_id; | |
| 31 if (device.stable_device_id_version == 2) | |
| 32 return device.deprecated_stable_device_id; | |
| 33 NOTREACHED() << "Unsupported stable audio devide id version."; | |
| 34 return 0; | |
| 35 } | |
| 36 | |
| 26 class AudioServiceImpl : public AudioService, | 37 class AudioServiceImpl : public AudioService, |
| 27 public chromeos::CrasAudioHandler::AudioObserver { | 38 public chromeos::CrasAudioHandler::AudioObserver { |
| 28 public: | 39 public: |
| 29 AudioServiceImpl(); | 40 AudioServiceImpl(); |
| 30 ~AudioServiceImpl() override; | 41 ~AudioServiceImpl() override; |
| 31 | 42 |
| 32 // Called by listeners to this service to add/remove themselves as observers. | 43 // Called by listeners to this service to add/remove themselves as observers. |
| 33 void AddObserver(AudioService::Observer* observer) override; | 44 void AddObserver(AudioService::Observer* observer) override; |
| 34 void RemoveObserver(AudioService::Observer* observer) override; | 45 void RemoveObserver(AudioService::Observer* observer) override; |
| 35 | 46 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 info.is_muted = | 273 info.is_muted = |
| 263 devices[i].is_input | 274 devices[i].is_input |
| 264 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 275 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 265 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 276 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 266 info.level = | 277 info.level = |
| 267 devices[i].is_input | 278 devices[i].is_input |
| 268 ? cras_audio_handler_->GetOutputVolumePercentForDevice( | 279 ? cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 269 devices[i].id) | 280 devices[i].id) |
| 270 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); | 281 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); |
| 271 info.stable_device_id.reset( | 282 info.stable_device_id.reset( |
| 272 new std::string(base::Uint64ToString(devices[i].stable_device_id))); | 283 new std::string(base::Uint64ToString(GetStableDeviceId(devices[i])))); |
| 273 | 284 |
| 274 devices_info_list.push_back(std::move(info)); | 285 devices_info_list.push_back(std::move(info)); |
| 275 } | 286 } |
| 276 | 287 |
| 277 for (auto& observer : observer_list_) | 288 for (auto& observer : observer_list_) |
| 278 observer.OnDevicesChanged(devices_info_list); | 289 observer.OnDevicesChanged(devices_info_list); |
| 279 | 290 |
| 280 // Notify DeviceChanged event for backward compatibility. | 291 // Notify DeviceChanged event for backward compatibility. |
| 281 // TODO(jennyz): remove this code when the old version of hotrod retires. | 292 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 282 NotifyDeviceChanged(); | 293 NotifyDeviceChanged(); |
| 283 } | 294 } |
| 284 | 295 |
| 285 AudioService* AudioService::CreateInstance() { | 296 AudioService* AudioService::CreateInstance() { |
| 286 return new AudioServiceImpl; | 297 return new AudioServiceImpl; |
| 287 } | 298 } |
| 288 | 299 |
| 289 } // namespace extensions | 300 } // namespace extensions |
| OLD | NEW |