blob: 905203b53987fcb84dea5fa76300898151429ad5 [file] [log] [blame]
Mikhail Naganov10548292016-10-31 10:39:47 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "PrimaryDeviceHAL"
18
19#include "PrimaryDevice.h"
20
21namespace android {
22namespace hardware {
23namespace audio {
24namespace V2_0 {
25namespace implementation {
26
27PrimaryDevice::PrimaryDevice(audio_hw_device_t* device)
28 : mDevice(new Device(device)) {
29}
30
31PrimaryDevice::~PrimaryDevice() {}
32
33// Methods from ::android::hardware::audio::V2_0::IDevice follow.
34Return<Result> PrimaryDevice::initCheck() {
35 return mDevice->initCheck();
36}
37
38Return<Result> PrimaryDevice::setMasterVolume(float volume) {
39 return mDevice->setMasterVolume(volume);
40}
41
42Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) {
43 return mDevice->getMasterVolume(_hidl_cb);
44}
45
46Return<Result> PrimaryDevice::setMicMute(bool mute) {
47 return mDevice->setMicMute(mute);
48}
49
50Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) {
51 return mDevice->getMicMute(_hidl_cb);
52}
53
54Return<Result> PrimaryDevice::setMasterMute(bool mute) {
55 return mDevice->setMasterMute(mute);
56}
57
58Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) {
59 return mDevice->getMasterMute(_hidl_cb);
60}
61
62Return<void> PrimaryDevice::getInputBufferSize(
63 const AudioConfig& config, getInputBufferSize_cb _hidl_cb) {
64 return mDevice->getInputBufferSize(config, _hidl_cb);
65}
66
67Return<void> PrimaryDevice::openOutputStream(
68 int32_t ioHandle,
69 const DeviceAddress& device,
70 const AudioConfig& config,
71 AudioOutputFlag flags,
72 openOutputStream_cb _hidl_cb) {
73 return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
74}
75
76Return<void> PrimaryDevice::openInputStream(
77 int32_t ioHandle,
78 const DeviceAddress& device,
79 const AudioConfig& config,
80 AudioInputFlag flags,
81 AudioSource source,
82 openInputStream_cb _hidl_cb) {
83 return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
84}
85
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080086Return<bool> PrimaryDevice::supportsAudioPatches() {
87 return mDevice->supportsAudioPatches();
88}
89
Mikhail Naganov10548292016-10-31 10:39:47 -070090Return<void> PrimaryDevice::createAudioPatch(
91 const hidl_vec<AudioPortConfig>& sources,
92 const hidl_vec<AudioPortConfig>& sinks,
93 createAudioPatch_cb _hidl_cb) {
94 return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
95}
96
97Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
98 return mDevice->releaseAudioPatch(patch);
99}
100
101Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
102 return mDevice->getAudioPort(port, _hidl_cb);
103}
104
105Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) {
106 return mDevice->setAudioPortConfig(config);
107}
108
109Return<AudioHwSync> PrimaryDevice::getHwAvSync() {
110 return mDevice->getHwAvSync();
111}
112
113Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
114 return mDevice->setScreenState(turnedOn);
115}
116
117Return<void> PrimaryDevice::getParameters(
118 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
119 return mDevice->getParameters(keys, _hidl_cb);
120}
121
122Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& parameters) {
123 return mDevice->setParameters(parameters);
124}
125
Martijn Coenen70b9a152016-11-18 15:29:32 +0100126Return<void> PrimaryDevice::debugDump(const hidl_handle& fd) {
Mikhail Naganov10548292016-10-31 10:39:47 -0700127 return mDevice->debugDump(fd);
128}
129
130
131// Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
132Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
133 return mDevice->analyzeStatus(
134 "set_voice_volume",
135 mDevice->device()->set_voice_volume(mDevice->device(), volume));
136}
137
138Return<Result> PrimaryDevice::setMode(AudioMode mode) {
139 return mDevice->analyzeStatus(
140 "set_mode",
141 mDevice->device()->set_mode(mDevice->device(), static_cast<audio_mode_t>(mode)));
142}
143
144Return<void> PrimaryDevice::getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) {
145 bool enabled;
146 Result retval = mDevice->getParam(AudioParameter::keyBtNrec, &enabled);
147 _hidl_cb(retval, enabled);
148 return Void();
149}
150
151Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
152 return mDevice->setParam(AudioParameter::keyBtNrec, enabled);
153}
154
155Return<void> PrimaryDevice::getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) {
156 bool enabled;
157 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, &enabled);
158 _hidl_cb(retval, enabled);
159 return Void();
160}
161
162Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
163 return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled);
164}
165
166Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
167 int halMode;
168 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode);
169 TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF;
170 _hidl_cb(retval, mode);
171 return Void();
172}
173
174Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
175 return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode));
176}
177
178Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
179 bool enabled;
180 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_HAC, &enabled);
181 _hidl_cb(retval, enabled);
182 return Void();
183}
184
185Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
186 return mDevice->setParam(AUDIO_PARAMETER_KEY_HAC, enabled);
187}
188
189} // namespace implementation
190} // namespace V2_0
191} // namespace audio
192} // namespace hardware
193} // namespace android