Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: components/arc/audio/arc_audio_bridge.cc

Issue 1817093003: Host-side implementation of ARC audio bridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated commit message Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/arc/audio/arc_audio_bridge.h"
6
7 #include "base/logging.h"
8 #include "chromeos/audio/audio_device.h"
9
10 namespace arc {
11
12 ArcAudioBridge::ArcAudioBridge(ArcBridgeService* bridge_service)
13 : ArcService(bridge_service), binding_(this) {
14 arc_bridge_service()->AddObserver(this);
15 if (chromeos::CrasAudioHandler::IsInitialized()) {
16 cras_audio_handler_ = chromeos::CrasAudioHandler::Get();
17 cras_audio_handler_->AddAudioObserver(this);
18 }
19 }
20
21 ArcAudioBridge::~ArcAudioBridge() {
22 arc_bridge_service()->RemoveObserver(this);
23 if (cras_audio_handler_ && chromeos::CrasAudioHandler::IsInitialized()) {
24 cras_audio_handler_->RemoveAudioObserver(this);
25 }
26 }
27
28 void ArcAudioBridge::OnAudioInstanceReady() {
29 AudioInstance* audio_instance = arc_bridge_service()->audio_instance();
30 if (!audio_instance) {
31 LOG(ERROR) << "OnAudioInstanceReady called, but no audio instance found";
32 return;
33 }
34
35 audio_instance->Init(binding_.CreateInterfacePtrAndBind());
36 }
37
38 void ArcAudioBridge::OnAudioNodesChanged() {
39 chromeos::AudioDeviceList devices;
40 cras_audio_handler_->GetAudioDevices(&devices);
41 uint64_t output_id = cras_audio_handler_->GetPrimaryActiveOutputNode();
42 uint64_t input_id = cras_audio_handler_->GetPrimaryActiveInputNode();
43
44 bool headphone_inserted = false, microphone_inserted = false;
45 for (size_t i = 0; i < devices.size(); ++i) {
46 if (devices[i].id == output_id) {
47 headphone_inserted =
48 (devices[i].type == chromeos::AudioDeviceType::AUDIO_TYPE_HEADPHONE);
49 }
50 if (devices[i].id == input_id) {
51 microphone_inserted =
52 (devices[i].type == chromeos::AudioDeviceType::AUDIO_TYPE_MIC);
53 }
54 }
jennyz 2016/03/23 23:50:42 GetDeviceFromId from CrasAudioHandler is more conv
chinyue 2016/03/25 09:50:31 Done.
55
56 VLOG(1) << "HEADPHONE " << headphone_inserted
57 << " MICROPHONE " << microphone_inserted;
58 SendSwitchState(headphone_inserted, microphone_inserted);
59 }
60
61 void ArcAudioBridge::SendSwitchState(bool headphone_inserted,
62 bool microphone_inserted) {
63 int switch_state = 0;
64 if (headphone_inserted)
65 switch_state |= (1 << (int)AudioSwitch::SW_HEADPHONE_INSERT);
66 if (microphone_inserted)
67 switch_state |= (1 << (int)AudioSwitch::SW_MICROPHONE_INSERT);
68
69 VLOG(1) << "Send switch state " << switch_state;
70 AudioInstance* audio_instance = arc_bridge_service()->audio_instance();
71 if (audio_instance)
72 audio_instance->NotifySwitchState(switch_state);
73 }
74
75 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698