| 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) { | 26 uint64_t GetV1StableDeviceId(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) | 27 if (device.stable_device_id_version == 1) |
| 31 return device.stable_device_id; | 28 return device.stable_device_id; |
| 32 if (device.stable_device_id_version == 2) | 29 if (device.stable_device_id_version == 2) |
| 33 return device.deprecated_stable_device_id; | 30 return device.deprecated_stable_device_id; |
| 34 NOTREACHED() << "Unsupported stable audio devide id version."; | 31 NOTREACHED() << "Unsupported stable audio devide id version."; |
| 35 return 0; | 32 return 0; |
| 36 } | 33 } |
| 37 | 34 |
| 38 class AudioServiceImpl : public AudioService, | 35 class AudioServiceImpl : public AudioService, |
| 39 public chromeos::CrasAudioHandler::AudioObserver { | 36 public chromeos::CrasAudioHandler::AudioObserver { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 info.is_active = devices[i].active; | 270 info.is_active = devices[i].active; |
| 274 info.is_muted = | 271 info.is_muted = |
| 275 devices[i].is_input | 272 devices[i].is_input |
| 276 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 273 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 277 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 274 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 278 info.level = | 275 info.level = |
| 279 devices[i].is_input | 276 devices[i].is_input |
| 280 ? cras_audio_handler_->GetOutputVolumePercentForDevice( | 277 ? cras_audio_handler_->GetOutputVolumePercentForDevice( |
| 281 devices[i].id) | 278 devices[i].id) |
| 282 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); | 279 : cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id); |
| 280 info.stable_id = devices[i].stable_device_id_version == 2 |
| 281 ? base::Uint64ToString(devices[i].stable_device_id) |
| 282 : ""; |
| 283 info.stable_device_id.reset( | 283 info.stable_device_id.reset( |
| 284 new std::string(base::Uint64ToString(GetStableDeviceId(devices[i])))); | 284 new std::string(base::Uint64ToString(GetV1StableDeviceId(devices[i])))); |
| 285 | 285 |
| 286 devices_info_list.push_back(std::move(info)); | 286 devices_info_list.push_back(std::move(info)); |
| 287 } | 287 } |
| 288 | 288 |
| 289 for (auto& observer : observer_list_) | 289 for (auto& observer : observer_list_) |
| 290 observer.OnDevicesChanged(devices_info_list); | 290 observer.OnDevicesChanged(devices_info_list); |
| 291 | 291 |
| 292 // Notify DeviceChanged event for backward compatibility. | 292 // Notify DeviceChanged event for backward compatibility. |
| 293 // TODO(jennyz): remove this code when the old version of hotrod retires. | 293 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 294 NotifyDeviceChanged(); | 294 NotifyDeviceChanged(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 AudioService* AudioService::CreateInstance() { | 297 AudioService* AudioService::CreateInstance() { |
| 298 return new AudioServiceImpl; | 298 return new AudioServiceImpl; |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace extensions | 301 } // namespace extensions |
| OLD | NEW |