| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/arc/audio/arc_audio_bridge.h" | 5 #include "components/arc/audio/arc_audio_bridge.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/system_tray_notifier.h" | 7 #include "ash/common/system/tray/system_tray_notifier.h" |
| 8 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chromeos/audio/audio_device.h" | 10 #include "chromeos/audio/audio_device.h" |
| 11 | 11 |
| 12 namespace arc { | 12 namespace arc { |
| 13 | 13 |
| 14 ArcAudioBridge::ArcAudioBridge(ArcBridgeService* bridge_service) | 14 ArcAudioBridge::ArcAudioBridge(ArcBridgeService* bridge_service) |
| 15 : ArcService(bridge_service), binding_(this) { | 15 : ArcService(bridge_service), binding_(this) { |
| 16 arc_bridge_service()->AddObserver(this); | 16 arc_bridge_service()->audio()->AddObserver(this); |
| 17 if (chromeos::CrasAudioHandler::IsInitialized()) { | 17 if (chromeos::CrasAudioHandler::IsInitialized()) { |
| 18 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); | 18 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); |
| 19 cras_audio_handler_->AddAudioObserver(this); | 19 cras_audio_handler_->AddAudioObserver(this); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 ArcAudioBridge::~ArcAudioBridge() { | 23 ArcAudioBridge::~ArcAudioBridge() { |
| 24 arc_bridge_service()->RemoveObserver(this); | |
| 25 if (cras_audio_handler_ && chromeos::CrasAudioHandler::IsInitialized()) { | 24 if (cras_audio_handler_ && chromeos::CrasAudioHandler::IsInitialized()) { |
| 26 cras_audio_handler_->RemoveAudioObserver(this); | 25 cras_audio_handler_->RemoveAudioObserver(this); |
| 27 } | 26 } |
| 27 arc_bridge_service()->audio()->RemoveObserver(this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void ArcAudioBridge::OnAudioInstanceReady() { | 30 void ArcAudioBridge::OnInstanceReady() { |
| 31 mojom::AudioInstance* audio_instance = | 31 mojom::AudioInstance* audio_instance = |
| 32 arc_bridge_service()->audio_instance(); | 32 arc_bridge_service()->audio()->instance(); |
| 33 if (!audio_instance) { | 33 if (!audio_instance) { |
| 34 LOG(ERROR) << "OnAudioInstanceReady called, " | 34 LOG(ERROR) << "OnAudioInstanceReady called, " |
| 35 << "but no audio instance found"; | 35 << "but no audio instance found"; |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 if (arc_bridge_service()->audio_version() < 1) { | 38 if (arc_bridge_service()->audio()->version() < 1) { |
| 39 LOG(WARNING) << "Audio instance is too old and does not support Init()"; | 39 LOG(WARNING) << "Audio instance is too old and does not support Init()"; |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 audio_instance->Init(binding_.CreateInterfacePtrAndBind()); | 42 audio_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ArcAudioBridge::ShowVolumeControls() { | 45 void ArcAudioBridge::ShowVolumeControls() { |
| 46 VLOG(2) << "ArcAudioBridge::ShowVolumeControls"; | 46 VLOG(2) << "ArcAudioBridge::ShowVolumeControls"; |
| 47 ash::WmShell::Get()->system_tray_notifier()-> | 47 ash::WmShell::Get()->system_tray_notifier()->NotifyAudioOutputVolumeChanged( |
| 48 NotifyAudioOutputVolumeChanged(0, 0); | 48 0, 0); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ArcAudioBridge::OnAudioNodesChanged() { | 51 void ArcAudioBridge::OnAudioNodesChanged() { |
| 52 uint64_t output_id = cras_audio_handler_->GetPrimaryActiveOutputNode(); | 52 uint64_t output_id = cras_audio_handler_->GetPrimaryActiveOutputNode(); |
| 53 const chromeos::AudioDevice* output_device = | 53 const chromeos::AudioDevice* output_device = |
| 54 cras_audio_handler_->GetDeviceFromId(output_id); | 54 cras_audio_handler_->GetDeviceFromId(output_id); |
| 55 bool headphone_inserted = | 55 bool headphone_inserted = |
| 56 (output_device && | 56 (output_device && |
| 57 output_device->type == chromeos::AudioDeviceType::AUDIO_TYPE_HEADPHONE); | 57 output_device->type == chromeos::AudioDeviceType::AUDIO_TYPE_HEADPHONE); |
| 58 | 58 |
| 59 uint64_t input_id = cras_audio_handler_->GetPrimaryActiveInputNode(); | 59 uint64_t input_id = cras_audio_handler_->GetPrimaryActiveInputNode(); |
| 60 const chromeos::AudioDevice* input_device = | 60 const chromeos::AudioDevice* input_device = |
| 61 cras_audio_handler_->GetDeviceFromId(input_id); | 61 cras_audio_handler_->GetDeviceFromId(input_id); |
| 62 bool microphone_inserted = | 62 bool microphone_inserted = |
| 63 (input_device && | 63 (input_device && |
| 64 input_device->type == chromeos::AudioDeviceType::AUDIO_TYPE_MIC); | 64 input_device->type == chromeos::AudioDeviceType::AUDIO_TYPE_MIC); |
| 65 | 65 |
| 66 VLOG(1) << "HEADPHONE " << headphone_inserted | 66 VLOG(1) << "HEADPHONE " << headphone_inserted << " MICROPHONE " |
| 67 << " MICROPHONE " << microphone_inserted; | 67 << microphone_inserted; |
| 68 SendSwitchState(headphone_inserted, microphone_inserted); | 68 SendSwitchState(headphone_inserted, microphone_inserted); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ArcAudioBridge::SendSwitchState(bool headphone_inserted, | 71 void ArcAudioBridge::SendSwitchState(bool headphone_inserted, |
| 72 bool microphone_inserted) { | 72 bool microphone_inserted) { |
| 73 uint32_t switch_state = 0; | 73 uint32_t switch_state = 0; |
| 74 if (headphone_inserted) { | 74 if (headphone_inserted) { |
| 75 switch_state |= | 75 switch_state |= |
| 76 (1 << static_cast<uint32_t>(mojom::AudioSwitch::SW_HEADPHONE_INSERT)); | 76 (1 << static_cast<uint32_t>(mojom::AudioSwitch::SW_HEADPHONE_INSERT)); |
| 77 } | 77 } |
| 78 if (microphone_inserted) { | 78 if (microphone_inserted) { |
| 79 switch_state |= | 79 switch_state |= |
| 80 (1 << static_cast<uint32_t>(mojom::AudioSwitch::SW_MICROPHONE_INSERT)); | 80 (1 << static_cast<uint32_t>(mojom::AudioSwitch::SW_MICROPHONE_INSERT)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 VLOG(1) << "Send switch state " << switch_state; | 83 VLOG(1) << "Send switch state " << switch_state; |
| 84 mojom::AudioInstance* audio_instance = arc_bridge_service()->audio_instance(); | 84 mojom::AudioInstance* audio_instance = |
| 85 arc_bridge_service()->audio()->instance(); |
| 85 if (audio_instance) | 86 if (audio_instance) |
| 86 audio_instance->NotifySwitchState(switch_state); | 87 audio_instance->NotifySwitchState(switch_state); |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace arc | 90 } // namespace arc |
| OLD | NEW |