blob: 9f5180cebbe95dcccb424d4e24b0333deeb80823 [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
86Return<void> PrimaryDevice::createAudioPatch(
87 const hidl_vec<AudioPortConfig>& sources,
88 const hidl_vec<AudioPortConfig>& sinks,
89 createAudioPatch_cb _hidl_cb) {
90 return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
91}
92
93Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
94 return mDevice->releaseAudioPatch(patch);
95}
96
97Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
98 return mDevice->getAudioPort(port, _hidl_cb);
99}
100
101Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) {
102 return mDevice->setAudioPortConfig(config);
103}
104
105Return<AudioHwSync> PrimaryDevice::getHwAvSync() {
106 return mDevice->getHwAvSync();
107}
108
109Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
110 return mDevice->setScreenState(turnedOn);
111}
112
113Return<void> PrimaryDevice::getParameters(
114 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
115 return mDevice->getParameters(keys, _hidl_cb);
116}
117
118Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& parameters) {
119 return mDevice->setParameters(parameters);
120}
121
122Return<void> PrimaryDevice::debugDump(const native_handle_t* fd) {
123 return mDevice->debugDump(fd);
124}
125
126
127// Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
128Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
129 return mDevice->analyzeStatus(
130 "set_voice_volume",
131 mDevice->device()->set_voice_volume(mDevice->device(), volume));
132}
133
134Return<Result> PrimaryDevice::setMode(AudioMode mode) {
135 return mDevice->analyzeStatus(
136 "set_mode",
137 mDevice->device()->set_mode(mDevice->device(), static_cast<audio_mode_t>(mode)));
138}
139
140Return<void> PrimaryDevice::getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) {
141 bool enabled;
142 Result retval = mDevice->getParam(AudioParameter::keyBtNrec, &enabled);
143 _hidl_cb(retval, enabled);
144 return Void();
145}
146
147Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
148 return mDevice->setParam(AudioParameter::keyBtNrec, enabled);
149}
150
151Return<void> PrimaryDevice::getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) {
152 bool enabled;
153 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, &enabled);
154 _hidl_cb(retval, enabled);
155 return Void();
156}
157
158Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
159 return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled);
160}
161
162Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
163 int halMode;
164 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode);
165 TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF;
166 _hidl_cb(retval, mode);
167 return Void();
168}
169
170Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
171 return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode));
172}
173
174Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
175 bool enabled;
176 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_HAC, &enabled);
177 _hidl_cb(retval, enabled);
178 return Void();
179}
180
181Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
182 return mDevice->setParam(AUDIO_PARAMETER_KEY_HAC, enabled);
183}
184
185} // namespace implementation
186} // namespace V2_0
187} // namespace audio
188} // namespace hardware
189} // namespace android