| 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 } |
| 61 |
| 62 NOTREACHED(); |
| 63 return api::audio::DEVICE_TYPE_OTHER; |
| 64 } |
| 65 |
| 66 } // namespace |
| 67 |
| 26 class AudioServiceImpl : public AudioService, | 68 class AudioServiceImpl : public AudioService, |
| 27 public chromeos::CrasAudioHandler::AudioObserver { | 69 public chromeos::CrasAudioHandler::AudioObserver { |
| 28 public: | 70 public: |
| 29 AudioServiceImpl(); | 71 AudioServiceImpl(); |
| 30 ~AudioServiceImpl() override; | 72 ~AudioServiceImpl() override; |
| 31 | 73 |
| 32 // Called by listeners to this service to add/remove themselves as observers. | 74 // Called by listeners to this service to add/remove themselves as observers. |
| 33 void AddObserver(AudioService::Observer* observer) override; | 75 void AddObserver(AudioService::Observer* observer) override; |
| 34 void RemoveObserver(AudioService::Observer* observer) override; | 76 void RemoveObserver(AudioService::Observer* observer) override; |
| 35 | 77 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 DeviceInfoList devices_info_list; | 370 DeviceInfoList devices_info_list; |
| 329 chromeos::AudioDeviceList devices; | 371 chromeos::AudioDeviceList devices; |
| 330 cras_audio_handler_->GetAudioDevices(&devices); | 372 cras_audio_handler_->GetAudioDevices(&devices); |
| 331 for (size_t i = 0; i < devices.size(); ++i) { | 373 for (size_t i = 0; i < devices.size(); ++i) { |
| 332 AudioDeviceInfo info; | 374 AudioDeviceInfo info; |
| 333 info.id = base::Uint64ToString(devices[i].id); | 375 info.id = base::Uint64ToString(devices[i].id); |
| 334 info.stream_type = devices[i].is_input | 376 info.stream_type = devices[i].is_input |
| 335 ? extensions::api::audio::STREAM_TYPE_INPUT | 377 ? extensions::api::audio::STREAM_TYPE_INPUT |
| 336 : extensions::api::audio::STREAM_TYPE_OUTPUT; | 378 : extensions::api::audio::STREAM_TYPE_OUTPUT; |
| 337 info.is_input = devices[i].is_input; | 379 info.is_input = devices[i].is_input; |
| 338 info.device_type = chromeos::AudioDevice::GetTypeString(devices[i].type); | 380 info.device_type = GetAsAudioApiDeviceType(devices[i].type); |
| 339 info.display_name = devices[i].display_name; | 381 info.display_name = devices[i].display_name; |
| 340 info.device_name = devices[i].device_name; | 382 info.device_name = devices[i].device_name; |
| 341 info.is_active = devices[i].active; | 383 info.is_active = devices[i].active; |
| 342 info.is_muted = | 384 info.is_muted = |
| 343 devices[i].is_input | 385 devices[i].is_input |
| 344 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) | 386 ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id) |
| 345 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); | 387 : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id); |
| 346 info.level = | 388 info.level = |
| 347 devices[i].is_input | 389 devices[i].is_input |
| 348 ? cras_audio_handler_->GetOutputVolumePercentForDevice( | 390 ? cras_audio_handler_->GetOutputVolumePercentForDevice( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 360 // Notify DeviceChanged event for backward compatibility. | 402 // Notify DeviceChanged event for backward compatibility. |
| 361 // TODO(jennyz): remove this code when the old version of hotrod retires. | 403 // TODO(jennyz): remove this code when the old version of hotrod retires. |
| 362 NotifyDeviceChanged(); | 404 NotifyDeviceChanged(); |
| 363 } | 405 } |
| 364 | 406 |
| 365 AudioService* AudioService::CreateInstance() { | 407 AudioService* AudioService::CreateInstance() { |
| 366 return new AudioServiceImpl; | 408 return new AudioServiceImpl; |
| 367 } | 409 } |
| 368 | 410 |
| 369 } // namespace extensions | 411 } // namespace extensions |
| OLD | NEW |