platform_hardware_interfaces/audio/2.0/default/PrimaryDevice.cpp
Mikhail Naganov 6e81e9bb3c Audio HAL: fixes for issues discovered after client conversion
Several issues addressed:

  -- added IDevice.supportsAudioPatches to query whether
     create/removeAudioPatch is actually supported by HAL;

  -- IStreamOutCallback proxy needs to be owned by IStreamOut
     implementation. In order for the client to reset the reference,
     added method IStreamOut.clearCallback;

  -- IDevice.open{Input|Output}Stream need to return a "suggested" audio
     config from HAL;

  -- code for converting between system/audio.h and HIDL
     data structures has been moved to
     android.hardware.audio.common@2.0-util library for reuse;

  -- added a workaround for the issue with QC effects HAL trying to write
     into the input parameters buffer, which is r/o by Binder design.

Bug: 30222631
Change-Id: I64af24d79c12d6ac3b0f87d085a821913e29237b
Test: tried using with WIP HIDL client on N5X
2016-12-01 13:48:58 -08:00

193 lines
5.9 KiB
C++

/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "PrimaryDeviceHAL"
#include "PrimaryDevice.h"
namespace android {
namespace hardware {
namespace audio {
namespace V2_0 {
namespace implementation {
PrimaryDevice::PrimaryDevice(audio_hw_device_t* device)
: mDevice(new Device(device)) {
}
PrimaryDevice::~PrimaryDevice() {}
// Methods from ::android::hardware::audio::V2_0::IDevice follow.
Return<Result> PrimaryDevice::initCheck() {
return mDevice->initCheck();
}
Return<Result> PrimaryDevice::setMasterVolume(float volume) {
return mDevice->setMasterVolume(volume);
}
Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) {
return mDevice->getMasterVolume(_hidl_cb);
}
Return<Result> PrimaryDevice::setMicMute(bool mute) {
return mDevice->setMicMute(mute);
}
Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) {
return mDevice->getMicMute(_hidl_cb);
}
Return<Result> PrimaryDevice::setMasterMute(bool mute) {
return mDevice->setMasterMute(mute);
}
Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) {
return mDevice->getMasterMute(_hidl_cb);
}
Return<void> PrimaryDevice::getInputBufferSize(
const AudioConfig& config, getInputBufferSize_cb _hidl_cb) {
return mDevice->getInputBufferSize(config, _hidl_cb);
}
Return<void> PrimaryDevice::openOutputStream(
int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
AudioOutputFlag flags,
openOutputStream_cb _hidl_cb) {
return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
}
Return<void> PrimaryDevice::openInputStream(
int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
AudioInputFlag flags,
AudioSource source,
openInputStream_cb _hidl_cb) {
return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
}
Return<bool> PrimaryDevice::supportsAudioPatches() {
return mDevice->supportsAudioPatches();
}
Return<void> PrimaryDevice::createAudioPatch(
const hidl_vec<AudioPortConfig>& sources,
const hidl_vec<AudioPortConfig>& sinks,
createAudioPatch_cb _hidl_cb) {
return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
}
Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
return mDevice->releaseAudioPatch(patch);
}
Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
return mDevice->getAudioPort(port, _hidl_cb);
}
Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) {
return mDevice->setAudioPortConfig(config);
}
Return<AudioHwSync> PrimaryDevice::getHwAvSync() {
return mDevice->getHwAvSync();
}
Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
return mDevice->setScreenState(turnedOn);
}
Return<void> PrimaryDevice::getParameters(
const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
return mDevice->getParameters(keys, _hidl_cb);
}
Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& parameters) {
return mDevice->setParameters(parameters);
}
Return<void> PrimaryDevice::debugDump(const hidl_handle& fd) {
return mDevice->debugDump(fd);
}
// Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
return mDevice->analyzeStatus(
"set_voice_volume",
mDevice->device()->set_voice_volume(mDevice->device(), volume));
}
Return<Result> PrimaryDevice::setMode(AudioMode mode) {
return mDevice->analyzeStatus(
"set_mode",
mDevice->device()->set_mode(mDevice->device(), static_cast<audio_mode_t>(mode)));
}
Return<void> PrimaryDevice::getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) {
bool enabled;
Result retval = mDevice->getParam(AudioParameter::keyBtNrec, &enabled);
_hidl_cb(retval, enabled);
return Void();
}
Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
return mDevice->setParam(AudioParameter::keyBtNrec, enabled);
}
Return<void> PrimaryDevice::getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) {
bool enabled;
Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, &enabled);
_hidl_cb(retval, enabled);
return Void();
}
Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled);
}
Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
int halMode;
Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode);
TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF;
_hidl_cb(retval, mode);
return Void();
}
Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE, static_cast<int>(mode));
}
Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
bool enabled;
Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_HAC, &enabled);
_hidl_cb(retval, enabled);
return Void();
}
Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
return mDevice->setParam(AUDIO_PARAMETER_KEY_HAC, enabled);
}
} // namespace implementation
} // namespace V2_0
} // namespace audio
} // namespace hardware
} // namespace android