| 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. | |
| 28 // For now, for the sake of backward compatibility, use deprecated version. | |
| 29 // http://crbug.com/673392 | |
| 30 if (device.stable_device_id_version == 1) | |
| 31 return device.stable_device_id; | |
| 32 if (device.stable_device_id_version == 2) | |
| 33 return device.deprecated_stable_device_id; | |
| 34 NOTREACHED() << "Unsupported stable audio devide id version."; | |
| 35 return 0; | |
| 36 } | |
| 37 | |
| 38 class AudioServiceImpl : public AudioService, | 26 class AudioServiceImpl : public AudioService, |
| 39 public chromeos::CrasAudioHandler::AudioObserver { | 27 public chromeos::CrasAudioHandler::AudioObserver { |
| 40 public: | 28 public: |
| 41 AudioServiceImpl(); | 29 AudioServiceImpl(); |
| 42 ~AudioServiceImpl() override; | 30 ~AudioServiceImpl() override; |
| 43 | 31 |
| 44 // Called by listeners to this service to add/remove themselves as observers. | 32 // Called by listeners to this service to add/remove themselves as observers. |
| 45 void AddObserver(AudioService::Observer* observer) override; | 33 void AddObserver(AudioService::Observer* observer) override; |
| 46 void RemoveObserver(AudioService::Observer* observer) override; | 34 void RemoveObserver(AudioService::Observer* observer) override; |
| 47 | 35 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 info.is_muted = | 301 info.is_muted = |
| 314 devices[i].is_input | 302 devices[i].is_input |
| 315 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 303 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 316 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 304 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 317 info.level = | 305 info.level = |
| 318 devices[i].is_input | 306 devices[i].is_input |
| 319 ? cras_audio_handler_->GetOutputVolumePercentForDevice( | 307 ? cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 320 devices[i].id) | 308 devices[i].id) |
| 321 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); | 309 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); |
| 322 info.stable_device_id.reset( | 310 info.stable_device_id.reset( |
| 323 new std::string(base::Uint64ToString(GetStableDeviceId(devices[i])))); | 311 new std::string(base::Uint64ToString(devices[i].stable_device_id))); |
| 324 | 312 |
| 325 devices_info_list.push_back(std::move(info)); | 313 devices_info_list.push_back(std::move(info)); |
| 326 } | 314 } |
| 327 | 315 |
| 328 for (auto& observer : observer_list_) | 316 for (auto& observer : observer_list_) |
| 329 observer.OnDevicesChanged(devices_info_list); | 317 observer.OnDevicesChanged(devices_info_list); |
| 330 | 318 |
| 331 // Notify DeviceChanged event for backward compatibility. | 319 // Notify DeviceChanged event for backward compatibility. |
| 332 // TODO(jennyz): remove this code when the old version of hotrod retires. | 320 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 333 NotifyDeviceChanged(); | 321 NotifyDeviceChanged(); |
| 334 } | 322 } |
| 335 | 323 |
| 336 AudioService* AudioService::CreateInstance() { | 324 AudioService* AudioService::CreateInstance() { |
| 337 return new AudioServiceImpl; | 325 return new AudioServiceImpl; |
| 338 } | 326 } |
| 339 | 327 |
| 340 } // namespace extensions | 328 } // namespace extensions |
| OLD | NEW |