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 namespace { | |
| 27 | |
| 28 api::audio::DeviceType GetAsAudioApiDeviceType(chromeos::AudioDeviceType type) { | |
| 29 switch (type) { | |
| 30 case chromeos::AUDIO_TYPE_HEADPHONE: | |
| 31 return api::audio::DEVICE_TYPE_HEADPHONE; | |
| 32 case chromeos::AUDIO_TYPE_MIC: | |
| 33 return api::audio::DEVICE_TYPE_MIC; | |
| 34 case chromeos::AUDIO_TYPE_USB: | |
| 35 return api::audio::DEVICE_TYPE_USB; | |
| 36 case chromeos::AUDIO_TYPE_BLUETOOTH: | |
| 37 return api::audio::DEVICE_TYPE_BLUETOOTH; | |
| 38 case chromeos::AUDIO_TYPE_HDMI: | |
| 39 return api::audio::DEVICE_TYPE_HDMI; | |
| 40 case chromeos::AUDIO_TYPE_INTERNAL_SPEAKER: | |
| 41 return api::audio::DEVICE_TYPE_INTERNAL_SPEAKER; | |
| 42 case chromeos::AUDIO_TYPE_INTERNAL_MIC: | |
| 43 return api::audio::DEVICE_TYPE_INTERNAL_MIC; | |
| 44 case chromeos::AUDIO_TYPE_FRONT_MIC: | |
| 45 return api::audio::DEVICE_TYPE_FRONT_MIC; | |
| 46 case chromeos::AUDIO_TYPE_REAR_MIC: | |
| 47 return api::audio::DEVICE_TYPE_REAR_MIC; | |
| 48 case chromeos::AUDIO_TYPE_KEYBOARD_MIC: | |
| 49 return api::audio::DEVICE_TYPE_KEYBOARD_MIC; | |
| 50 case chromeos::AUDIO_TYPE_HOTWORD: | |
| 51 return api::audio::DEVICE_TYPE_HOTWORD; | |
| 52 case chromeos::AUDIO_TYPE_LINEOUT: | |
| 53 return api::audio::DEVICE_TYPE_LINEOUT; | |
| 54 case chromeos::AUDIO_TYPE_POST_MIX_LOOPBACK: | |
| 55 return api::audio::DEVICE_TYPE_POST_MIX_LOOPBACK; | |
| 56 case chromeos::AUDIO_TYPE_POST_DSP_LOOPBACK: | |
| 57 return api::audio::DEVICE_TYPE_POST_DSP_LOOPBACK; | |
| 58 case chromeos::AUDIO_TYPE_OTHER: | |
| 59 return api::audio::DEVICE_TYPE_OTHER; | |
| 60 } | |
|
Devlin
2017/01/30 21:32:38
nit: should there be a NOTREACHED() here?
tbarzic
2017/01/30 21:46:28
yep, there probably should.
| |
| 61 return api::audio::DEVICE_TYPE_OTHER; | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 26 class AudioServiceImpl : public AudioService, | 66 class AudioServiceImpl : public AudioService, |
| 27 public chromeos::CrasAudioHandler::AudioObserver { | 67 public chromeos::CrasAudioHandler::AudioObserver { |
| 28 public: | 68 public: |
| 29 AudioServiceImpl(); | 69 AudioServiceImpl(); |
| 30 ~AudioServiceImpl() override; | 70 ~AudioServiceImpl() override; |
| 31 | 71 |
| 32 // Called by listeners to this service to add/remove themselves as observers. | 72 // Called by listeners to this service to add/remove themselves as observers. |
| 33 void AddObserver(AudioService::Observer* observer) override; | 73 void AddObserver(AudioService::Observer* observer) override; |
| 34 void RemoveObserver(AudioService::Observer* observer) override; | 74 void RemoveObserver(AudioService::Observer* observer) override; |
| 35 | 75 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 DeviceInfoList devices_info_list; | 368 DeviceInfoList devices_info_list; |
| 329 chromeos::AudioDeviceList devices; | 369 chromeos::AudioDeviceList devices; |
| 330 cras_audio_handler_->GetAudioDevices(&devices); | 370 cras_audio_handler_->GetAudioDevices(&devices); |
| 331 for (size_t i = 0; i < devices.size(); ++i) { | 371 for (size_t i = 0; i < devices.size(); ++i) { |
| 332 AudioDeviceInfo info; | 372 AudioDeviceInfo info; |
| 333 info.id = base::Uint64ToString(devices[i].id); | 373 info.id = base::Uint64ToString(devices[i].id); |
| 334 info.stream_type = devices[i].is_input | 374 info.stream_type = devices[i].is_input |
| 335 ? extensions::api::audio::STREAM_TYPE_INPUT | 375 ? extensions::api::audio::STREAM_TYPE_INPUT |
| 336 : extensions::api::audio::STREAM_TYPE_OUTPUT; | 376 : extensions::api::audio::STREAM_TYPE_OUTPUT; |
| 337 info.is_input = devices[i].is_input; | 377 info.is_input = devices[i].is_input; |
| 338 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type); | 378 info.device_type = GetAsAudioApiDeviceType(devices[i].type); |
| 339 info.display_name = devices[i].display_name; | 379 info.display_name = devices[i].display_name; |
| 340 info.device_name = devices[i].device_name; | 380 info.device_name = devices[i].device_name; |
| 341 info.is_active = devices[i].active; | 381 info.is_active = devices[i].active; |
| 342 info.is_muted = | 382 info.is_muted = |
| 343 devices[i].is_input | 383 devices[i].is_input |
| 344 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 384 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 345 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 385 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 346 info.level = | 386 info.level = |
| 347 devices[i].is_input | 387 devices[i].is_input |
| 348 ? cras_audio_handler_->GetOutputVolumePercentForDevice( | 388 ? cras_audio_handler_->GetOutputVolumePercentForDevice( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 360 // Notify DeviceChanged event for backward compatibility. | 400 // Notify DeviceChanged event for backward compatibility. |
| 361 // TODO(jennyz): remove this code when the old version of hotrod retires. | 401 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 362 NotifyDeviceChanged(); | 402 NotifyDeviceChanged(); |
| 363 } | 403 } |
| 364 | 404 |
| 365 AudioService* AudioService::CreateInstance() { | 405 AudioService* AudioService::CreateInstance() { |
| 366 return new AudioServiceImpl; | 406 return new AudioServiceImpl; |
| 367 } | 407 } |
| 368 | 408 |
| 369 } // namespace extensions | 409 } // namespace extensions |
| OLD | NEW |