blob: af0b249f7245290e2d0194aca1b05bc4ef4c70fd [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)
Mikhail Naganov6c0f76a2017-05-03 12:08:22 -070028 : mDevice{new Device(device, AUDIO_HARDWARE_MODULE_ID_PRIMARY)} {}
Mikhail Naganov10548292016-10-31 10:39:47 -070029
30PrimaryDevice::~PrimaryDevice() {}
31
32// Methods from ::android::hardware::audio::V2_0::IDevice follow.
33Return<Result> PrimaryDevice::initCheck() {
34 return mDevice->initCheck();
35}
36
37Return<Result> PrimaryDevice::setMasterVolume(float volume) {
38 return mDevice->setMasterVolume(volume);
39}
40
41Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) {
42 return mDevice->getMasterVolume(_hidl_cb);
43}
44
45Return<Result> PrimaryDevice::setMicMute(bool mute) {
46 return mDevice->setMicMute(mute);
47}
48
49Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) {
50 return mDevice->getMicMute(_hidl_cb);
51}
52
53Return<Result> PrimaryDevice::setMasterMute(bool mute) {
54 return mDevice->setMasterMute(mute);
55}
56
57Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) {
58 return mDevice->getMasterMute(_hidl_cb);
59}
60
61Return<void> PrimaryDevice::getInputBufferSize(
62 const AudioConfig& config, getInputBufferSize_cb _hidl_cb) {
63 return mDevice->getInputBufferSize(config, _hidl_cb);
64}
65
66Return<void> PrimaryDevice::openOutputStream(
67 int32_t ioHandle,
68 const DeviceAddress& device,
69 const AudioConfig& config,
70 AudioOutputFlag flags,
71 openOutputStream_cb _hidl_cb) {
72 return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
73}
74
75Return<void> PrimaryDevice::openInputStream(
76 int32_t ioHandle,
77 const DeviceAddress& device,
78 const AudioConfig& config,
79 AudioInputFlag flags,
80 AudioSource source,
81 openInputStream_cb _hidl_cb) {
82 return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
83}
84
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080085Return<bool> PrimaryDevice::supportsAudioPatches() {
86 return mDevice->supportsAudioPatches();
87}
88
Mikhail Naganov10548292016-10-31 10:39:47 -070089Return<void> PrimaryDevice::createAudioPatch(
90 const hidl_vec<AudioPortConfig>& sources,
91 const hidl_vec<AudioPortConfig>& sinks,
92 createAudioPatch_cb _hidl_cb) {
93 return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
94}
95
96Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
97 return mDevice->releaseAudioPatch(patch);
98}
99
100Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
101 return mDevice->getAudioPort(port, _hidl_cb);
102}
103
104Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) {
105 return mDevice->setAudioPortConfig(config);
106}
107
108Return<AudioHwSync> PrimaryDevice::getHwAvSync() {
109 return mDevice->getHwAvSync();
110}
111
112Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
113 return mDevice->setScreenState(turnedOn);
114}
115
116Return<void> PrimaryDevice::getParameters(
117 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
118 return mDevice->getParameters(keys, _hidl_cb);
119}
120
121Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& parameters) {
122 return mDevice->setParameters(parameters);
123}
124
Martijn Coenen70b9a152016-11-18 15:29:32 +0100125Return<void> PrimaryDevice::debugDump(const hidl_handle& fd) {
Mikhail Naganov10548292016-10-31 10:39:47 -0700126 return mDevice->debugDump(fd);
127}
128
129
130// Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
131Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
132 return mDevice->analyzeStatus(
133 "set_voice_volume",
134 mDevice->device()->set_voice_volume(mDevice->device(), volume));
135}
136
137Return<Result> PrimaryDevice::setMode(AudioMode mode) {
138 return mDevice->analyzeStatus(
139 "set_mode",
140 mDevice->device()->set_mode(mDevice->device(), static_cast<audio_mode_t>(mode)));
141}
142
143Return<void> PrimaryDevice::getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) {
144 bool enabled;
145 Result retval = mDevice->getParam(AudioParameter::keyBtNrec, &enabled);
146 _hidl_cb(retval, enabled);
147 return Void();
148}
149
150Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
151 return mDevice->setParam(AudioParameter::keyBtNrec, enabled);
152}
153
154Return<void> PrimaryDevice::getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) {
155 bool enabled;
156 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, &enabled);
157 _hidl_cb(retval, enabled);
158 return Void();
159}
160
161Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
162 return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled);
163}
164
165Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
166 int halMode;
167 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode);
168 TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF;
169 _hidl_cb(retval, mode);
170 return Void();
171}
172
173Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
174 return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode));
175}
176
177Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
178 bool enabled;
179 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_HAC, &enabled);
180 _hidl_cb(retval, enabled);
181 return Void();
182}
183
184Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
185 return mDevice->setParam(AUDIO_PARAMETER_KEY_HAC, enabled);
186}
187
188} // namespace implementation
189} // namespace V2_0
190} // namespace audio
191} // namespace hardware
192} // namespace android