Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace android { |
| 22 | namespace hardware { |
| 23 | namespace audio { |
| 24 | namespace V2_0 { |
| 25 | namespace implementation { |
| 26 | |
| 27 | PrimaryDevice::PrimaryDevice(audio_hw_device_t* device) |
Mikhail Naganov | 6c0f76a | 2017-05-03 12:08:22 -0700 | [diff] [blame] | 28 | : mDevice{new Device(device, AUDIO_HARDWARE_MODULE_ID_PRIMARY)} {} |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 29 | |
| 30 | PrimaryDevice::~PrimaryDevice() {} |
| 31 | |
| 32 | // Methods from ::android::hardware::audio::V2_0::IDevice follow. |
| 33 | Return<Result> PrimaryDevice::initCheck() { |
| 34 | return mDevice->initCheck(); |
| 35 | } |
| 36 | |
| 37 | Return<Result> PrimaryDevice::setMasterVolume(float volume) { |
| 38 | return mDevice->setMasterVolume(volume); |
| 39 | } |
| 40 | |
| 41 | Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) { |
| 42 | return mDevice->getMasterVolume(_hidl_cb); |
| 43 | } |
| 44 | |
| 45 | Return<Result> PrimaryDevice::setMicMute(bool mute) { |
| 46 | return mDevice->setMicMute(mute); |
| 47 | } |
| 48 | |
| 49 | Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) { |
| 50 | return mDevice->getMicMute(_hidl_cb); |
| 51 | } |
| 52 | |
| 53 | Return<Result> PrimaryDevice::setMasterMute(bool mute) { |
| 54 | return mDevice->setMasterMute(mute); |
| 55 | } |
| 56 | |
| 57 | Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) { |
| 58 | return mDevice->getMasterMute(_hidl_cb); |
| 59 | } |
| 60 | |
| 61 | Return<void> PrimaryDevice::getInputBufferSize( |
| 62 | const AudioConfig& config, getInputBufferSize_cb _hidl_cb) { |
| 63 | return mDevice->getInputBufferSize(config, _hidl_cb); |
| 64 | } |
| 65 | |
| 66 | Return<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 | |
| 75 | Return<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 Naganov | 6e81e9b | 2016-11-16 16:30:17 -0800 | [diff] [blame] | 85 | Return<bool> PrimaryDevice::supportsAudioPatches() { |
| 86 | return mDevice->supportsAudioPatches(); |
| 87 | } |
| 88 | |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 89 | Return<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 | |
| 96 | Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) { |
| 97 | return mDevice->releaseAudioPatch(patch); |
| 98 | } |
| 99 | |
| 100 | Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) { |
| 101 | return mDevice->getAudioPort(port, _hidl_cb); |
| 102 | } |
| 103 | |
| 104 | Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) { |
| 105 | return mDevice->setAudioPortConfig(config); |
| 106 | } |
| 107 | |
| 108 | Return<AudioHwSync> PrimaryDevice::getHwAvSync() { |
| 109 | return mDevice->getHwAvSync(); |
| 110 | } |
| 111 | |
| 112 | Return<Result> PrimaryDevice::setScreenState(bool turnedOn) { |
| 113 | return mDevice->setScreenState(turnedOn); |
| 114 | } |
| 115 | |
| 116 | Return<void> PrimaryDevice::getParameters( |
| 117 | const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) { |
| 118 | return mDevice->getParameters(keys, _hidl_cb); |
| 119 | } |
| 120 | |
| 121 | Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& parameters) { |
| 122 | return mDevice->setParameters(parameters); |
| 123 | } |
| 124 | |
Martijn Coenen | 70b9a15 | 2016-11-18 15:29:32 +0100 | [diff] [blame] | 125 | Return<void> PrimaryDevice::debugDump(const hidl_handle& fd) { |
Mikhail Naganov | 1054829 | 2016-10-31 10:39:47 -0700 | [diff] [blame] | 126 | return mDevice->debugDump(fd); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | // Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow. |
| 131 | Return<Result> PrimaryDevice::setVoiceVolume(float volume) { |
| 132 | return mDevice->analyzeStatus( |
| 133 | "set_voice_volume", |
| 134 | mDevice->device()->set_voice_volume(mDevice->device(), volume)); |
| 135 | } |
| 136 | |
| 137 | Return<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 | |
| 143 | Return<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 | |
| 150 | Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) { |
| 151 | return mDevice->setParam(AudioParameter::keyBtNrec, enabled); |
| 152 | } |
| 153 | |
| 154 | Return<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 | |
| 161 | Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) { |
| 162 | return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled); |
| 163 | } |
| 164 | |
| 165 | Return<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 | |
| 173 | Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) { |
| 174 | return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode)); |
| 175 | } |
| 176 | |
| 177 | Return<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 | |
| 184 | Return<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 |