Loading audio/aidl/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ aidl_interface { "android/hardware/audio/common/SinkMetadata.aidl", "android/hardware/audio/common/SourceMetadata.aidl", ], frozen: true, imports: [ "android.media.audio.common.types-V2", ], Loading audio/aidl/TEST_MAPPING +12 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,18 @@ "presubmit": [ { "name": "VtsHalAudioCoreTargetTest" }, { "name": "VtsHalAudioEffectFactoryTargetTest" }, { "name": "VtsHalAudioEffectTargetTest" }, { "name": "VtsHalEqualizerTargetTest" }, { "name": "VtsHalLoudnessEnhancerTargetTest" } ] } audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ package android.hardware.audio.effect; union BassBoost { android.hardware.audio.effect.VendorExtension vendor; int strengthPm; const int MIN_PER_MILLE_STRENGTH = 0; const int MAX_PER_MILLE_STRENGTH = 1000; @VintfStability union Id { int vendorExtensionTag; Loading audio/aidl/android/hardware/audio/effect/BassBoost.aidl +10 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,16 @@ union BassBoost { boolean strengthSupported; } /** * Minimal possible per mille strength. */ const int MIN_PER_MILLE_STRENGTH = 0; /** * Maximum possible per mille strength. */ const int MAX_PER_MILLE_STRENGTH = 1000; /** * The per mille strength of the bass boost effect. * Loading audio/aidl/default/EffectImpl.cpp +45 −58 Original line number Diff line number Diff line Loading @@ -25,41 +25,33 @@ ndk::ScopedAStatus EffectImpl::open(const Parameter::Common& common, const std::optional<Parameter::Specific>& specific, OpenEffectReturn* ret) { LOG(DEBUG) << __func__; { std::lock_guard lg(mMutex); RETURN_OK_IF(mState != State::INIT); mContext = createContext(common); RETURN_IF(!mContext, EX_ILLEGAL_ARGUMENT, "createContextFailed"); setContext(mContext); } auto context = createContext(common); RETURN_IF(!context, EX_NULL_POINTER, "createContextFailed"); RETURN_IF_ASTATUS_NOT_OK(setParameterCommon(common), "setCommParamErr"); if (specific.has_value()) { RETURN_IF_ASTATUS_NOT_OK(setParameterSpecific(specific.value()), "setSpecParamErr"); } RETURN_IF(createThread(LOG_TAG) != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); { std::lock_guard lg(mMutex); mContext->dupeFmq(ret); mState = State::IDLE; } context->dupeFmq(ret); RETURN_IF(createThread(context, getEffectName()) != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::close() { std::lock_guard lg(mMutex); RETURN_OK_IF(mState == State::INIT); RETURN_IF(mState == State::PROCESSING, EX_ILLEGAL_STATE, "closeAtProcessing"); // stop the worker thread, ignore the return code RETURN_IF(destroyThread() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToDestroyWorker"); mState = State::INIT; RETURN_IF(releaseContext() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); mState = State::INIT; LOG(DEBUG) << __func__; return ndk::ScopedAStatus::ok(); } Loading Loading @@ -113,29 +105,30 @@ ndk::ScopedAStatus EffectImpl::getParameter(const Parameter::Id& id, Parameter* } ndk::ScopedAStatus EffectImpl::setParameterCommon(const Parameter& param) { std::lock_guard lg(mMutex); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); auto tag = param.getTag(); switch (tag) { case Parameter::common: RETURN_IF(mContext->setCommon(param.get<Parameter::common>()) != RetCode::SUCCESS, RETURN_IF(context->setCommon(param.get<Parameter::common>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setCommFailed"); break; case Parameter::deviceDescription: RETURN_IF(mContext->setOutputDevice(param.get<Parameter::deviceDescription>()) != RETURN_IF(context->setOutputDevice(param.get<Parameter::deviceDescription>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setDeviceFailed"); break; case Parameter::mode: RETURN_IF(mContext->setAudioMode(param.get<Parameter::mode>()) != RetCode::SUCCESS, RETURN_IF(context->setAudioMode(param.get<Parameter::mode>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setModeFailed"); break; case Parameter::source: RETURN_IF(mContext->setAudioSource(param.get<Parameter::source>()) != RetCode::SUCCESS, RETURN_IF(context->setAudioSource(param.get<Parameter::source>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setSourceFailed"); break; case Parameter::volumeStereo: RETURN_IF(mContext->setVolumeStereo(param.get<Parameter::volumeStereo>()) != RETURN_IF(context->setVolumeStereo(param.get<Parameter::volumeStereo>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setVolumeStereoFailed"); break; Loading @@ -149,27 +142,28 @@ ndk::ScopedAStatus EffectImpl::setParameterCommon(const Parameter& param) { } ndk::ScopedAStatus EffectImpl::getParameterCommon(const Parameter::Tag& tag, Parameter* param) { std::lock_guard lg(mMutex); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); switch (tag) { case Parameter::common: { param->set<Parameter::common>(mContext->getCommon()); param->set<Parameter::common>(context->getCommon()); break; } case Parameter::deviceDescription: { param->set<Parameter::deviceDescription>(mContext->getOutputDevice()); param->set<Parameter::deviceDescription>(context->getOutputDevice()); break; } case Parameter::mode: { param->set<Parameter::mode>(mContext->getAudioMode()); param->set<Parameter::mode>(context->getAudioMode()); break; } case Parameter::source: { param->set<Parameter::source>(mContext->getAudioSource()); param->set<Parameter::source>(context->getAudioSource()); break; } case Parameter::volumeStereo: { param->set<Parameter::volumeStereo>(mContext->getVolumeStereo()); param->set<Parameter::volumeStereo>(context->getVolumeStereo()); break; } default: { Loading @@ -182,39 +176,30 @@ ndk::ScopedAStatus EffectImpl::getParameterCommon(const Parameter::Tag& tag, Par } ndk::ScopedAStatus EffectImpl::getState(State* state) { std::lock_guard lg(mMutex); *state = mState; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::command(CommandId command) { std::lock_guard lg(mMutex); RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "CommandStateError"); LOG(DEBUG) << __func__ << ": receive command: " << toString(command) << " at state " << toString(mState); RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "CommandStateError"); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); switch (command) { case CommandId::START: RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "instanceNotOpen"); RETURN_OK_IF(mState == State::PROCESSING); RETURN_IF_ASTATUS_NOT_OK(commandStart(), "commandStartFailed"); mState = State::PROCESSING; RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed"); startThread(); return ndk::ScopedAStatus::ok(); mState = State::PROCESSING; break; case CommandId::STOP: RETURN_OK_IF(mState == State::IDLE); mState = State::IDLE; RETURN_IF_ASTATUS_NOT_OK(commandStop(), "commandStopFailed"); stopThread(); return ndk::ScopedAStatus::ok(); case CommandId::RESET: RETURN_OK_IF(mState == State::IDLE); mState = State::IDLE; RETURN_IF_ASTATUS_NOT_OK(commandStop(), "commandStopFailed"); stopThread(); mContext->resetBuffer(); return ndk::ScopedAStatus::ok(); RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed"); mState = State::IDLE; break; default: LOG(ERROR) << __func__ << " instance still processing"; return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, Loading @@ -224,6 +209,15 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) { return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::commandImpl(CommandId command) { auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); if (command == CommandId::RESET) { context->resetBuffer(); } return ndk::ScopedAStatus::ok(); } void EffectImpl::cleanUp() { command(CommandId::STOP); close(); Loading @@ -238,19 +232,12 @@ IEffect::Status EffectImpl::status(binder_status_t status, size_t consumed, size } // A placeholder processing implementation to copy samples from input to output IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int processSamples) { // lock before access context/parameters std::lock_guard lg(mMutex); IEffect::Status status = {EX_NULL_POINTER, 0, 0}; RETURN_VALUE_IF(!mContext, status, "nullContext"); auto frameSize = mContext->getInputFrameSize(); RETURN_VALUE_IF(0 == frameSize, status, "frameSizeIs0"); LOG(DEBUG) << __func__ << " in " << in << " out " << out << " samples " << processSamples << " frames " << processSamples * sizeof(float) / frameSize; for (int i = 0; i < processSamples; i++) { IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int samples) { for (int i = 0; i < samples; i++) { *out++ = *in++; } LOG(DEBUG) << __func__ << " done processing " << processSamples << " samples"; return {STATUS_OK, processSamples, processSamples}; LOG(DEBUG) << __func__ << " done processing " << samples << " samples"; return {STATUS_OK, samples, samples}; } } // namespace aidl::android::hardware::audio::effect Loading
audio/aidl/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ aidl_interface { "android/hardware/audio/common/SinkMetadata.aidl", "android/hardware/audio/common/SourceMetadata.aidl", ], frozen: true, imports: [ "android.media.audio.common.types-V2", ], Loading
audio/aidl/TEST_MAPPING +12 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,18 @@ "presubmit": [ { "name": "VtsHalAudioCoreTargetTest" }, { "name": "VtsHalAudioEffectFactoryTargetTest" }, { "name": "VtsHalAudioEffectTargetTest" }, { "name": "VtsHalEqualizerTargetTest" }, { "name": "VtsHalLoudnessEnhancerTargetTest" } ] }
audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/BassBoost.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ package android.hardware.audio.effect; union BassBoost { android.hardware.audio.effect.VendorExtension vendor; int strengthPm; const int MIN_PER_MILLE_STRENGTH = 0; const int MAX_PER_MILLE_STRENGTH = 1000; @VintfStability union Id { int vendorExtensionTag; Loading
audio/aidl/android/hardware/audio/effect/BassBoost.aidl +10 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,16 @@ union BassBoost { boolean strengthSupported; } /** * Minimal possible per mille strength. */ const int MIN_PER_MILLE_STRENGTH = 0; /** * Maximum possible per mille strength. */ const int MAX_PER_MILLE_STRENGTH = 1000; /** * The per mille strength of the bass boost effect. * Loading
audio/aidl/default/EffectImpl.cpp +45 −58 Original line number Diff line number Diff line Loading @@ -25,41 +25,33 @@ ndk::ScopedAStatus EffectImpl::open(const Parameter::Common& common, const std::optional<Parameter::Specific>& specific, OpenEffectReturn* ret) { LOG(DEBUG) << __func__; { std::lock_guard lg(mMutex); RETURN_OK_IF(mState != State::INIT); mContext = createContext(common); RETURN_IF(!mContext, EX_ILLEGAL_ARGUMENT, "createContextFailed"); setContext(mContext); } auto context = createContext(common); RETURN_IF(!context, EX_NULL_POINTER, "createContextFailed"); RETURN_IF_ASTATUS_NOT_OK(setParameterCommon(common), "setCommParamErr"); if (specific.has_value()) { RETURN_IF_ASTATUS_NOT_OK(setParameterSpecific(specific.value()), "setSpecParamErr"); } RETURN_IF(createThread(LOG_TAG) != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); { std::lock_guard lg(mMutex); mContext->dupeFmq(ret); mState = State::IDLE; } context->dupeFmq(ret); RETURN_IF(createThread(context, getEffectName()) != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::close() { std::lock_guard lg(mMutex); RETURN_OK_IF(mState == State::INIT); RETURN_IF(mState == State::PROCESSING, EX_ILLEGAL_STATE, "closeAtProcessing"); // stop the worker thread, ignore the return code RETURN_IF(destroyThread() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToDestroyWorker"); mState = State::INIT; RETURN_IF(releaseContext() != RetCode::SUCCESS, EX_UNSUPPORTED_OPERATION, "FailedToCreateWorker"); mState = State::INIT; LOG(DEBUG) << __func__; return ndk::ScopedAStatus::ok(); } Loading Loading @@ -113,29 +105,30 @@ ndk::ScopedAStatus EffectImpl::getParameter(const Parameter::Id& id, Parameter* } ndk::ScopedAStatus EffectImpl::setParameterCommon(const Parameter& param) { std::lock_guard lg(mMutex); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); auto tag = param.getTag(); switch (tag) { case Parameter::common: RETURN_IF(mContext->setCommon(param.get<Parameter::common>()) != RetCode::SUCCESS, RETURN_IF(context->setCommon(param.get<Parameter::common>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setCommFailed"); break; case Parameter::deviceDescription: RETURN_IF(mContext->setOutputDevice(param.get<Parameter::deviceDescription>()) != RETURN_IF(context->setOutputDevice(param.get<Parameter::deviceDescription>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setDeviceFailed"); break; case Parameter::mode: RETURN_IF(mContext->setAudioMode(param.get<Parameter::mode>()) != RetCode::SUCCESS, RETURN_IF(context->setAudioMode(param.get<Parameter::mode>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setModeFailed"); break; case Parameter::source: RETURN_IF(mContext->setAudioSource(param.get<Parameter::source>()) != RetCode::SUCCESS, RETURN_IF(context->setAudioSource(param.get<Parameter::source>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setSourceFailed"); break; case Parameter::volumeStereo: RETURN_IF(mContext->setVolumeStereo(param.get<Parameter::volumeStereo>()) != RETURN_IF(context->setVolumeStereo(param.get<Parameter::volumeStereo>()) != RetCode::SUCCESS, EX_ILLEGAL_ARGUMENT, "setVolumeStereoFailed"); break; Loading @@ -149,27 +142,28 @@ ndk::ScopedAStatus EffectImpl::setParameterCommon(const Parameter& param) { } ndk::ScopedAStatus EffectImpl::getParameterCommon(const Parameter::Tag& tag, Parameter* param) { std::lock_guard lg(mMutex); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); switch (tag) { case Parameter::common: { param->set<Parameter::common>(mContext->getCommon()); param->set<Parameter::common>(context->getCommon()); break; } case Parameter::deviceDescription: { param->set<Parameter::deviceDescription>(mContext->getOutputDevice()); param->set<Parameter::deviceDescription>(context->getOutputDevice()); break; } case Parameter::mode: { param->set<Parameter::mode>(mContext->getAudioMode()); param->set<Parameter::mode>(context->getAudioMode()); break; } case Parameter::source: { param->set<Parameter::source>(mContext->getAudioSource()); param->set<Parameter::source>(context->getAudioSource()); break; } case Parameter::volumeStereo: { param->set<Parameter::volumeStereo>(mContext->getVolumeStereo()); param->set<Parameter::volumeStereo>(context->getVolumeStereo()); break; } default: { Loading @@ -182,39 +176,30 @@ ndk::ScopedAStatus EffectImpl::getParameterCommon(const Parameter::Tag& tag, Par } ndk::ScopedAStatus EffectImpl::getState(State* state) { std::lock_guard lg(mMutex); *state = mState; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::command(CommandId command) { std::lock_guard lg(mMutex); RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "CommandStateError"); LOG(DEBUG) << __func__ << ": receive command: " << toString(command) << " at state " << toString(mState); RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "CommandStateError"); RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext"); switch (command) { case CommandId::START: RETURN_IF(mState == State::INIT, EX_ILLEGAL_STATE, "instanceNotOpen"); RETURN_OK_IF(mState == State::PROCESSING); RETURN_IF_ASTATUS_NOT_OK(commandStart(), "commandStartFailed"); mState = State::PROCESSING; RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed"); startThread(); return ndk::ScopedAStatus::ok(); mState = State::PROCESSING; break; case CommandId::STOP: RETURN_OK_IF(mState == State::IDLE); mState = State::IDLE; RETURN_IF_ASTATUS_NOT_OK(commandStop(), "commandStopFailed"); stopThread(); return ndk::ScopedAStatus::ok(); case CommandId::RESET: RETURN_OK_IF(mState == State::IDLE); mState = State::IDLE; RETURN_IF_ASTATUS_NOT_OK(commandStop(), "commandStopFailed"); stopThread(); mContext->resetBuffer(); return ndk::ScopedAStatus::ok(); RETURN_IF_ASTATUS_NOT_OK(commandImpl(command), "commandImplFailed"); mState = State::IDLE; break; default: LOG(ERROR) << __func__ << " instance still processing"; return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, Loading @@ -224,6 +209,15 @@ ndk::ScopedAStatus EffectImpl::command(CommandId command) { return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus EffectImpl::commandImpl(CommandId command) { auto context = getContext(); RETURN_IF(!context, EX_NULL_POINTER, "nullContext"); if (command == CommandId::RESET) { context->resetBuffer(); } return ndk::ScopedAStatus::ok(); } void EffectImpl::cleanUp() { command(CommandId::STOP); close(); Loading @@ -238,19 +232,12 @@ IEffect::Status EffectImpl::status(binder_status_t status, size_t consumed, size } // A placeholder processing implementation to copy samples from input to output IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int processSamples) { // lock before access context/parameters std::lock_guard lg(mMutex); IEffect::Status status = {EX_NULL_POINTER, 0, 0}; RETURN_VALUE_IF(!mContext, status, "nullContext"); auto frameSize = mContext->getInputFrameSize(); RETURN_VALUE_IF(0 == frameSize, status, "frameSizeIs0"); LOG(DEBUG) << __func__ << " in " << in << " out " << out << " samples " << processSamples << " frames " << processSamples * sizeof(float) / frameSize; for (int i = 0; i < processSamples; i++) { IEffect::Status EffectImpl::effectProcessImpl(float* in, float* out, int samples) { for (int i = 0; i < samples; i++) { *out++ = *in++; } LOG(DEBUG) << __func__ << " done processing " << processSamples << " samples"; return {STATUS_OK, processSamples, processSamples}; LOG(DEBUG) << __func__ << " done processing " << samples << " samples"; return {STATUS_OK, samples, samples}; } } // namespace aidl::android::hardware::audio::effect