Merge "Add backward compatibility in effect hal default implementation" into main
This commit is contained in:
commit
3ed9b6bbce
3 changed files with 42 additions and 20 deletions
|
@ -22,6 +22,7 @@
|
||||||
using aidl::android::hardware::audio::common::getChannelCount;
|
using aidl::android::hardware::audio::common::getChannelCount;
|
||||||
using aidl::android::hardware::audio::common::getFrameSizeInBytes;
|
using aidl::android::hardware::audio::common::getFrameSizeInBytes;
|
||||||
using aidl::android::hardware::audio::effect::IEffect;
|
using aidl::android::hardware::audio::effect::IEffect;
|
||||||
|
using aidl::android::hardware::audio::effect::kReopenSupportedVersion;
|
||||||
using aidl::android::media::audio::common::PcmType;
|
using aidl::android::media::audio::common::PcmType;
|
||||||
using ::android::hardware::EventFlag;
|
using ::android::hardware::EventFlag;
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ EffectContext::EffectContext(size_t statusDepth, const Parameter::Common& common
|
||||||
mOutputMQ = std::make_shared<DataMQ>(outBufferSizeInFloat);
|
mOutputMQ = std::make_shared<DataMQ>(outBufferSizeInFloat);
|
||||||
|
|
||||||
if (!mStatusMQ->isValid() || !mInputMQ->isValid() || !mOutputMQ->isValid()) {
|
if (!mStatusMQ->isValid() || !mInputMQ->isValid() || !mOutputMQ->isValid()) {
|
||||||
LOG(ERROR) << __func__ << " created invalid FMQ";
|
LOG(ERROR) << __func__ << " created invalid FMQ, statusMQ: " << mStatusMQ->isValid()
|
||||||
|
<< " inputMQ: " << mInputMQ->isValid() << " outputMQ: " << mOutputMQ->isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t status =
|
::android::status_t status =
|
||||||
|
@ -52,7 +54,9 @@ EffectContext::EffectContext(size_t statusDepth, const Parameter::Common& common
|
||||||
// reset buffer status by abandon input data in FMQ
|
// reset buffer status by abandon input data in FMQ
|
||||||
void EffectContext::resetBuffer() {
|
void EffectContext::resetBuffer() {
|
||||||
auto buffer = static_cast<float*>(mWorkBuffer.data());
|
auto buffer = static_cast<float*>(mWorkBuffer.data());
|
||||||
std::vector<IEffect::Status> status(mStatusMQ->availableToRead());
|
if (mStatusMQ) {
|
||||||
|
std::vector<IEffect::Status> status(mStatusMQ->availableToRead());
|
||||||
|
}
|
||||||
if (mInputMQ) {
|
if (mInputMQ) {
|
||||||
mInputMQ->read(buffer, mInputMQ->availableToRead());
|
mInputMQ->read(buffer, mInputMQ->availableToRead());
|
||||||
}
|
}
|
||||||
|
@ -71,7 +75,7 @@ void EffectContext::dupeFmqWithReopen(IEffect::OpenEffectReturn* effectRet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectContext::dupeFmq(IEffect::OpenEffectReturn* effectRet) {
|
void EffectContext::dupeFmq(IEffect::OpenEffectReturn* effectRet) {
|
||||||
if (effectRet) {
|
if (effectRet && mStatusMQ && mInputMQ && mOutputMQ) {
|
||||||
effectRet->statusMQ = mStatusMQ->dupeDesc();
|
effectRet->statusMQ = mStatusMQ->dupeDesc();
|
||||||
effectRet->inputDataMQ = mInputMQ->dupeDesc();
|
effectRet->inputDataMQ = mInputMQ->dupeDesc();
|
||||||
effectRet->outputDataMQ = mOutputMQ->dupeDesc();
|
effectRet->outputDataMQ = mOutputMQ->dupeDesc();
|
||||||
|
@ -191,24 +195,34 @@ EventFlag* EffectContext::getStatusEventFlag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
RetCode EffectContext::updateIOFrameSize(const Parameter::Common& common) {
|
RetCode EffectContext::updateIOFrameSize(const Parameter::Common& common) {
|
||||||
const auto iFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes(
|
const auto prevInputFrameSize = mInputFrameSize;
|
||||||
|
const auto prevOutputFrameSize = mOutputFrameSize;
|
||||||
|
mInputFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes(
|
||||||
common.input.base.format, common.input.base.channelMask);
|
common.input.base.format, common.input.base.channelMask);
|
||||||
const auto oFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes(
|
mOutputFrameSize = ::aidl::android::hardware::audio::common::getFrameSizeInBytes(
|
||||||
common.output.base.format, common.output.base.channelMask);
|
common.output.base.format, common.output.base.channelMask);
|
||||||
|
|
||||||
|
// workBuffer and data MQ not allocated yet, no need to update
|
||||||
|
if (mWorkBuffer.size() == 0 || !mInputMQ || !mOutputMQ) {
|
||||||
|
return RetCode::SUCCESS;
|
||||||
|
}
|
||||||
|
// IEffect::reopen introduced in android.hardware.audio.effect-V2
|
||||||
|
if (mVersion < kReopenSupportedVersion) {
|
||||||
|
LOG(WARNING) << __func__ << " skipped for HAL version " << mVersion;
|
||||||
|
return RetCode::SUCCESS;
|
||||||
|
}
|
||||||
bool needUpdateMq = false;
|
bool needUpdateMq = false;
|
||||||
if (mInputMQ &&
|
if (mInputFrameSize != prevInputFrameSize ||
|
||||||
(mInputFrameSize != iFrameSize || mCommon.input.frameCount != common.input.frameCount)) {
|
mCommon.input.frameCount != common.input.frameCount) {
|
||||||
mInputMQ.reset();
|
mInputMQ.reset();
|
||||||
needUpdateMq = true;
|
needUpdateMq = true;
|
||||||
}
|
}
|
||||||
if (mOutputMQ &&
|
if (mOutputFrameSize != prevOutputFrameSize ||
|
||||||
(mOutputFrameSize != oFrameSize || mCommon.output.frameCount != common.output.frameCount)) {
|
mCommon.output.frameCount != common.output.frameCount) {
|
||||||
mOutputMQ.reset();
|
mOutputMQ.reset();
|
||||||
needUpdateMq = true;
|
needUpdateMq = true;
|
||||||
}
|
}
|
||||||
mInputFrameSize = iFrameSize;
|
|
||||||
mOutputFrameSize = oFrameSize;
|
|
||||||
if (needUpdateMq) {
|
if (needUpdateMq) {
|
||||||
mWorkBuffer.resize(std::max(common.input.frameCount * mInputFrameSize / sizeof(float),
|
mWorkBuffer.resize(std::max(common.input.frameCount * mInputFrameSize / sizeof(float),
|
||||||
common.output.frameCount * mOutputFrameSize / sizeof(float)));
|
common.output.frameCount * mOutputFrameSize / sizeof(float)));
|
||||||
|
|
|
@ -49,10 +49,16 @@ ndk::ScopedAStatus EffectImpl::open(const Parameter::Common& common,
|
||||||
RETURN_IF(common.input.base.format.pcm != common.output.base.format.pcm ||
|
RETURN_IF(common.input.base.format.pcm != common.output.base.format.pcm ||
|
||||||
common.input.base.format.pcm != PcmType::FLOAT_32_BIT,
|
common.input.base.format.pcm != PcmType::FLOAT_32_BIT,
|
||||||
EX_ILLEGAL_ARGUMENT, "dataMustBe32BitsFloat");
|
EX_ILLEGAL_ARGUMENT, "dataMustBe32BitsFloat");
|
||||||
|
|
||||||
std::lock_guard lg(mImplMutex);
|
std::lock_guard lg(mImplMutex);
|
||||||
RETURN_OK_IF(mState != State::INIT);
|
RETURN_OK_IF(mState != State::INIT);
|
||||||
mImplContext = createContext(common);
|
mImplContext = createContext(common);
|
||||||
RETURN_IF(!mImplContext, EX_NULL_POINTER, "nullContext");
|
RETURN_IF(!mImplContext, EX_NULL_POINTER, "nullContext");
|
||||||
|
|
||||||
|
int version = 0;
|
||||||
|
RETURN_IF(!getInterfaceVersion(&version).isOk(), EX_UNSUPPORTED_OPERATION,
|
||||||
|
"FailedToGetInterfaceVersion");
|
||||||
|
mImplContext->setVersion(version);
|
||||||
mEventFlag = mImplContext->getStatusEventFlag();
|
mEventFlag = mImplContext->getStatusEventFlag();
|
||||||
|
|
||||||
if (specific.has_value()) {
|
if (specific.has_value()) {
|
||||||
|
|
|
@ -44,6 +44,7 @@ class EffectContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setVersion(int version) { mVersion = version; }
|
||||||
std::shared_ptr<StatusMQ> getStatusFmq() const;
|
std::shared_ptr<StatusMQ> getStatusFmq() const;
|
||||||
std::shared_ptr<DataMQ> getInputDataFmq() const;
|
std::shared_ptr<DataMQ> getInputDataFmq() const;
|
||||||
std::shared_ptr<DataMQ> getOutputDataFmq() const;
|
std::shared_ptr<DataMQ> getOutputDataFmq() const;
|
||||||
|
@ -82,10 +83,11 @@ class EffectContext {
|
||||||
virtual ::android::hardware::EventFlag* getStatusEventFlag();
|
virtual ::android::hardware::EventFlag* getStatusEventFlag();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t mInputFrameSize;
|
int mVersion = 0;
|
||||||
size_t mOutputFrameSize;
|
size_t mInputFrameSize = 0;
|
||||||
size_t mInputChannelCount;
|
size_t mOutputFrameSize = 0;
|
||||||
size_t mOutputChannelCount;
|
size_t mInputChannelCount = 0;
|
||||||
|
size_t mOutputChannelCount = 0;
|
||||||
Parameter::Common mCommon = {};
|
Parameter::Common mCommon = {};
|
||||||
std::vector<aidl::android::media::audio::common::AudioDeviceDescription> mOutputDevice = {};
|
std::vector<aidl::android::media::audio::common::AudioDeviceDescription> mOutputDevice = {};
|
||||||
aidl::android::media::audio::common::AudioMode mMode =
|
aidl::android::media::audio::common::AudioMode mMode =
|
||||||
|
@ -98,13 +100,13 @@ class EffectContext {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// fmq and buffers
|
// fmq and buffers
|
||||||
std::shared_ptr<StatusMQ> mStatusMQ;
|
std::shared_ptr<StatusMQ> mStatusMQ = nullptr;
|
||||||
std::shared_ptr<DataMQ> mInputMQ;
|
std::shared_ptr<DataMQ> mInputMQ = nullptr;
|
||||||
std::shared_ptr<DataMQ> mOutputMQ;
|
std::shared_ptr<DataMQ> mOutputMQ = nullptr;
|
||||||
// std::shared_ptr<IEffect::OpenEffectReturn> mRet;
|
// std::shared_ptr<IEffect::OpenEffectReturn> mRet;
|
||||||
// work buffer set by effect instances, the access and update are in same thread
|
// work buffer set by effect instances, the access and update are in same thread
|
||||||
std::vector<float> mWorkBuffer;
|
std::vector<float> mWorkBuffer = {};
|
||||||
|
|
||||||
::android::hardware::EventFlag* mEfGroup;
|
::android::hardware::EventFlag* mEfGroup = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace aidl::android::hardware::audio::effect
|
} // namespace aidl::android::hardware::audio::effect
|
||||||
|
|
Loading…
Reference in a new issue