Loading services/audioflinger/sounddose/Android.bp +97 −0 Original line number Diff line number Diff line Loading @@ -7,12 +7,109 @@ package { default_applicable_licenses: ["frameworks_av_services_audioflinger_license"], } audioflinger_sounddose_tidy_errors = [ // https://clang.llvm.org/extra/clang-tidy/checks/list.html // For many categories, the checks are too many to specify individually. // Feel free to disable as needed - as warnings are generally ignored, // we treat warnings as errors. "android-*", "bugprone-*", "cert-*", "clang-analyzer-security*", "google-*", "misc-*", //"modernize-*", // explicitly list the modernize as they can be subjective. "modernize-avoid-bind", "modernize-avoid-c-arrays", // std::array<> can be verbose "modernize-concat-nested-namespaces", "modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent. "modernize-deprecated-ios-base-aliases", "modernize-loop-convert", "modernize-make-shared", "modernize-make-unique", "modernize-pass-by-value", "modernize-raw-string-literal", "modernize-redundant-void-arg", "modernize-replace-auto-ptr", "modernize-replace-random-shuffle", "modernize-return-braced-init-list", "modernize-shrink-to-fit", "modernize-unary-static-assert", "modernize-use-auto", // debatable - auto can obscure type "modernize-use-bool-literals", "modernize-use-default-member-init", "modernize-use-emplace", "modernize-use-equals-default", "modernize-use-equals-delete", "modernize-use-nodiscard", "modernize-use-noexcept", "modernize-use-nullptr", "modernize-use-override", // "modernize-use-trailing-return-type", // not necessarily more readable "modernize-use-transparent-functors", "modernize-use-uncaught-exceptions", "modernize-use-using", "performance-*", // Remove some pedantic stylistic requirements. "-google-readability-casting", // C++ casts not always necessary and may be verbose "-google-readability-todo", // do not require TODO(info) "-bugprone-unhandled-self-assignment", "-bugprone-suspicious-string-compare", "-cert-oop54-cpp", // found in TransactionLog.h "-bugprone-narrowing-conversions", // b/182410845 "-misc-non-private-member-variables-in-classes", ] // Eventually use common tidy defaults cc_defaults { name: "audioflinger_sounddose_flags_defaults", // https://clang.llvm.org/docs/UsersManual.html#command-line-options // https://clang.llvm.org/docs/DiagnosticsReference.html cflags: [ "-Wall", "-Wdeprecated", "-Werror", "-Werror=implicit-fallthrough", "-Werror=sometimes-uninitialized", "-Werror=conditional-uninitialized", "-Wextra", // suppress some warning chatter. "-Wno-deprecated-copy-with-dtor", "-Wno-deprecated-copy-with-user-provided-dtor", "-Wredundant-decls", "-Wshadow", "-Wstrict-aliasing", "-fstrict-aliasing", "-Wthread-safety", //"-Wthread-safety-negative", // experimental - looks broken in R. "-Wunreachable-code", "-Wunreachable-code-break", "-Wunreachable-code-return", "-Wunused", "-Wused-but-marked-unused", "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS", ], // https://clang.llvm.org/extra/clang-tidy/ tidy: true, tidy_checks: audioflinger_sounddose_tidy_errors, tidy_checks_as_errors: audioflinger_sounddose_tidy_errors, tidy_flags: [ "-format-style=file", ], } cc_library { name: "libsounddose", double_loadable: true, defaults: [ "audioflinger_sounddose_flags_defaults", "latest_android_media_audio_common_types_ndk_shared", "latest_android_hardware_audio_core_sounddose_ndk_shared", "latest_android_hardware_audio_sounddose_ndk_shared", Loading services/audioflinger/sounddose/SoundDoseManager.cpp +36 −34 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ namespace android { using aidl::android::media::audio::common::AudioDevice; using aidl::android::media::audio::common::AudioDeviceAddress; namespace { Loading @@ -48,7 +47,7 @@ int64_t getMonotonicSecond() { sp<audio_utils::MelProcessor> SoundDoseManager::getOrCreateProcessorForDevice( audio_port_handle_t deviceId, audio_io_handle_t streamHandle, uint32_t sampleRate, size_t channelCount, audio_format_t format) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mHalSoundDose != nullptr && mEnabledCsd) { ALOGD("%s: using HAL MEL computation, no MelProcessor needed.", __func__); Loading Loading @@ -86,8 +85,9 @@ sp<audio_utils::MelProcessor> SoundDoseManager::getOrCreateProcessorForDevice( bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose>& halSoundDose) { ALOGV("%s", __func__); std::shared_ptr<HalSoundDoseCallback> halSoundDoseCallback; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mHalSoundDose = halSoundDose; if (halSoundDose == nullptr) { Loading @@ -106,9 +106,11 @@ bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose mHalSoundDoseCallback = ndk::SharedRefBase::make<HalSoundDoseCallback>(this); } halSoundDoseCallback = mHalSoundDoseCallback; } auto status = halSoundDose->registerSoundDoseCallback(mHalSoundDoseCallback); auto status = halSoundDose->registerSoundDoseCallback(halSoundDoseCallback); if (!status.isOk()) { // Not a warning since this can happen if the callback was registered before ALOGI("%s: Cannot register HAL sound dose callback with status message: %s", Loading @@ -121,7 +123,7 @@ bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { ALOGV("%s", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mHalSoundDose != nullptr) { // using the HAL sound dose interface Loading @@ -134,9 +136,9 @@ void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { } for (auto& streamProcessor : mActiveProcessors) { sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote(); const sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote(); if (processor != nullptr) { status_t result = processor->setOutputRs2UpperBound(rs2Value); const status_t result = processor->setOutputRs2UpperBound(rs2Value); if (result != NO_ERROR) { ALOGW("%s: could not set RS2 upper bound %f for stream %d", __func__, rs2Value, streamProcessor.first); Loading @@ -148,7 +150,7 @@ void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { } void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); auto callbackToRemove = mActiveProcessors.find(streamHandle); if (callbackToRemove != mActiveProcessors.end()) { mActiveProcessors.erase(callbackToRemove); Loading @@ -156,7 +158,7 @@ void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) { } audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& audioDevice) const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); audio_devices_t type; std::string address; Loading @@ -178,14 +180,14 @@ audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& aud void SoundDoseManager::mapAddressToDeviceId(const AudioDeviceTypeAddr& adt, const audio_port_handle_t deviceId) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); ALOGI("%s: map address: %d to device id: %d", __func__, adt.mType, deviceId); mActiveDevices[adt] = deviceId; mActiveDeviceTypes[deviceId] = adt.mType; } void SoundDoseManager::clearMapDeviceIdEntries(audio_port_handle_t deviceId) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); for (auto activeDevice = mActiveDevices.begin(); activeDevice != mActiveDevices.end();) { if (activeDevice->second == deviceId) { ALOGI("%s: clear mapping type: %d to deviceId: %d", Loading Loading @@ -303,7 +305,7 @@ binder::Status SoundDoseManager::SoundDose::getOutputRs2UpperBound(float* value) ALOGV("%s", __func__); auto soundDoseManager = mSoundDoseManager.promote(); if (soundDoseManager != nullptr) { std::lock_guard _l(soundDoseManager->mLock); const std::lock_guard _l(soundDoseManager->mLock); *value = soundDoseManager->mRs2UpperBound; } return binder::Status::ok(); Loading Loading @@ -348,7 +350,7 @@ binder::Status SoundDoseManager::SoundDose::isSoundDoseHalSupported(bool* value) } void SoundDoseManager::updateAttenuation(float attenuationDB, audio_devices_t deviceType) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); ALOGV("%s: updating MEL processor attenuation for device type %d to %f", __func__, deviceType, attenuationDB); mMelAttenuationDB[deviceType] = attenuationDB; Loading @@ -368,7 +370,7 @@ void SoundDoseManager::updateAttenuation(float attenuationDB, audio_devices_t de void SoundDoseManager::setCsdEnabled(bool enabled) { ALOGV("%s", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mEnabledCsd = enabled; for (auto& activeEntry : mActiveProcessors) { Loading @@ -384,7 +386,7 @@ void SoundDoseManager::setCsdEnabled(bool enabled) { } bool SoundDoseManager::isCsdEnabled() { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mEnabledCsd; } Loading @@ -392,52 +394,51 @@ void SoundDoseManager::setUseFrameworkMel(bool useFrameworkMel) { // invalidate any HAL sound dose interface used setHalSoundDoseInterface(nullptr); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mUseFrameworkMel = useFrameworkMel; } bool SoundDoseManager::forceUseFrameworkMel() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mUseFrameworkMel; } void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mComputeCsdOnAllDevices = computeCsdOnAllDevices; } bool SoundDoseManager::forceComputeCsdOnAllDevices() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mComputeCsdOnAllDevices; } bool SoundDoseManager::isSoundDoseHalSupported() const { if (!mEnabledCsd) { return false; { const std::lock_guard _l(mLock); if (!mEnabledCsd) return false; } std::shared_ptr<ISoundDose> halSoundDose; getHalSoundDose(&halSoundDose); if (mHalSoundDose == nullptr) { return false; } return true; return halSoundDose != nullptr; } void SoundDoseManager::getHalSoundDose(std::shared_ptr<ISoundDose>* halSoundDose) const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); *halSoundDose = mHalSoundDose; } void SoundDoseManager::resetSoundDose() { std::lock_guard lock(mLock); const std::lock_guard lock(mLock); mSoundDose = nullptr; } void SoundDoseManager::resetCsd(float currentCsd, const std::vector<media::SoundDoseRecord>& records) { std::lock_guard lock(mLock); const std::lock_guard lock(mLock); std::vector<audio_utils::CsdRecord> resetRecords; resetRecords.reserve(records.size()); for (const auto& record : records) { resetRecords.emplace_back(record.timestamp, record.duration, record.value, record.averageMel); Loading @@ -455,13 +456,13 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off std::vector<audio_utils::CsdRecord> records; float currentCsd; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { return; } int64_t timestampSec = getMonotonicSecond(); const int64_t timestampSec = getMonotonicSecond(); // only for internal callbacks records = mMelAggregator->aggregateAndAddNewMelRecord(audio_utils::MelRecord( Loading @@ -475,6 +476,7 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off if (records.size() > 0 && soundDoseCallback != nullptr) { std::vector<media::SoundDoseRecord> newRecordsToReport; newRecordsToReport.resize(records.size()); for (const auto& record : records) { newRecordsToReport.emplace_back(csdRecordToSoundDoseRecord(record)); } Loading @@ -484,7 +486,7 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off } sp<media::ISoundDoseCallback> SoundDoseManager::getSoundDoseCallback() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mSoundDose == nullptr) { return nullptr; } Loading @@ -496,7 +498,7 @@ void SoundDoseManager::onMomentaryExposure(float currentMel, audio_port_handle_t ALOGV("%s: Momentary exposure for device %d triggered: %f MEL", __func__, deviceId, currentMel); { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { return; } Loading @@ -512,7 +514,7 @@ sp<media::ISoundDose> SoundDoseManager::getSoundDoseInterface( const sp<media::ISoundDoseCallback>& callback) { ALOGV("%s: Register ISoundDoseCallback", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mSoundDose == nullptr) { mSoundDose = sp<SoundDose>::make(this, callback); } Loading @@ -522,7 +524,7 @@ sp<media::ISoundDose> SoundDoseManager::getSoundDoseInterface( std::string SoundDoseManager::dump() const { std::string output; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { base::StringAppendF(&output, "CSD is disabled"); return output; Loading services/audioflinger/sounddose/SoundDoseManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ private: mSoundDoseCallback(callback) {} /** IBinder::DeathRecipient. Listen to the death of ISoundDoseCallback. */ virtual void binderDied(const wp<IBinder>& who); void binderDied(const wp<IBinder>& who) override; /** BnSoundDose override */ binder::Status setOutputRs2UpperBound(float value) override; Loading Loading
services/audioflinger/sounddose/Android.bp +97 −0 Original line number Diff line number Diff line Loading @@ -7,12 +7,109 @@ package { default_applicable_licenses: ["frameworks_av_services_audioflinger_license"], } audioflinger_sounddose_tidy_errors = [ // https://clang.llvm.org/extra/clang-tidy/checks/list.html // For many categories, the checks are too many to specify individually. // Feel free to disable as needed - as warnings are generally ignored, // we treat warnings as errors. "android-*", "bugprone-*", "cert-*", "clang-analyzer-security*", "google-*", "misc-*", //"modernize-*", // explicitly list the modernize as they can be subjective. "modernize-avoid-bind", "modernize-avoid-c-arrays", // std::array<> can be verbose "modernize-concat-nested-namespaces", "modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent. "modernize-deprecated-ios-base-aliases", "modernize-loop-convert", "modernize-make-shared", "modernize-make-unique", "modernize-pass-by-value", "modernize-raw-string-literal", "modernize-redundant-void-arg", "modernize-replace-auto-ptr", "modernize-replace-random-shuffle", "modernize-return-braced-init-list", "modernize-shrink-to-fit", "modernize-unary-static-assert", "modernize-use-auto", // debatable - auto can obscure type "modernize-use-bool-literals", "modernize-use-default-member-init", "modernize-use-emplace", "modernize-use-equals-default", "modernize-use-equals-delete", "modernize-use-nodiscard", "modernize-use-noexcept", "modernize-use-nullptr", "modernize-use-override", // "modernize-use-trailing-return-type", // not necessarily more readable "modernize-use-transparent-functors", "modernize-use-uncaught-exceptions", "modernize-use-using", "performance-*", // Remove some pedantic stylistic requirements. "-google-readability-casting", // C++ casts not always necessary and may be verbose "-google-readability-todo", // do not require TODO(info) "-bugprone-unhandled-self-assignment", "-bugprone-suspicious-string-compare", "-cert-oop54-cpp", // found in TransactionLog.h "-bugprone-narrowing-conversions", // b/182410845 "-misc-non-private-member-variables-in-classes", ] // Eventually use common tidy defaults cc_defaults { name: "audioflinger_sounddose_flags_defaults", // https://clang.llvm.org/docs/UsersManual.html#command-line-options // https://clang.llvm.org/docs/DiagnosticsReference.html cflags: [ "-Wall", "-Wdeprecated", "-Werror", "-Werror=implicit-fallthrough", "-Werror=sometimes-uninitialized", "-Werror=conditional-uninitialized", "-Wextra", // suppress some warning chatter. "-Wno-deprecated-copy-with-dtor", "-Wno-deprecated-copy-with-user-provided-dtor", "-Wredundant-decls", "-Wshadow", "-Wstrict-aliasing", "-fstrict-aliasing", "-Wthread-safety", //"-Wthread-safety-negative", // experimental - looks broken in R. "-Wunreachable-code", "-Wunreachable-code-break", "-Wunreachable-code-return", "-Wunused", "-Wused-but-marked-unused", "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS", ], // https://clang.llvm.org/extra/clang-tidy/ tidy: true, tidy_checks: audioflinger_sounddose_tidy_errors, tidy_checks_as_errors: audioflinger_sounddose_tidy_errors, tidy_flags: [ "-format-style=file", ], } cc_library { name: "libsounddose", double_loadable: true, defaults: [ "audioflinger_sounddose_flags_defaults", "latest_android_media_audio_common_types_ndk_shared", "latest_android_hardware_audio_core_sounddose_ndk_shared", "latest_android_hardware_audio_sounddose_ndk_shared", Loading
services/audioflinger/sounddose/SoundDoseManager.cpp +36 −34 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ namespace android { using aidl::android::media::audio::common::AudioDevice; using aidl::android::media::audio::common::AudioDeviceAddress; namespace { Loading @@ -48,7 +47,7 @@ int64_t getMonotonicSecond() { sp<audio_utils::MelProcessor> SoundDoseManager::getOrCreateProcessorForDevice( audio_port_handle_t deviceId, audio_io_handle_t streamHandle, uint32_t sampleRate, size_t channelCount, audio_format_t format) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mHalSoundDose != nullptr && mEnabledCsd) { ALOGD("%s: using HAL MEL computation, no MelProcessor needed.", __func__); Loading Loading @@ -86,8 +85,9 @@ sp<audio_utils::MelProcessor> SoundDoseManager::getOrCreateProcessorForDevice( bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose>& halSoundDose) { ALOGV("%s", __func__); std::shared_ptr<HalSoundDoseCallback> halSoundDoseCallback; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mHalSoundDose = halSoundDose; if (halSoundDose == nullptr) { Loading @@ -106,9 +106,11 @@ bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose mHalSoundDoseCallback = ndk::SharedRefBase::make<HalSoundDoseCallback>(this); } halSoundDoseCallback = mHalSoundDoseCallback; } auto status = halSoundDose->registerSoundDoseCallback(mHalSoundDoseCallback); auto status = halSoundDose->registerSoundDoseCallback(halSoundDoseCallback); if (!status.isOk()) { // Not a warning since this can happen if the callback was registered before ALOGI("%s: Cannot register HAL sound dose callback with status message: %s", Loading @@ -121,7 +123,7 @@ bool SoundDoseManager::setHalSoundDoseInterface(const std::shared_ptr<ISoundDose void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { ALOGV("%s", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mHalSoundDose != nullptr) { // using the HAL sound dose interface Loading @@ -134,9 +136,9 @@ void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { } for (auto& streamProcessor : mActiveProcessors) { sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote(); const sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote(); if (processor != nullptr) { status_t result = processor->setOutputRs2UpperBound(rs2Value); const status_t result = processor->setOutputRs2UpperBound(rs2Value); if (result != NO_ERROR) { ALOGW("%s: could not set RS2 upper bound %f for stream %d", __func__, rs2Value, streamProcessor.first); Loading @@ -148,7 +150,7 @@ void SoundDoseManager::setOutputRs2UpperBound(float rs2Value) { } void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); auto callbackToRemove = mActiveProcessors.find(streamHandle); if (callbackToRemove != mActiveProcessors.end()) { mActiveProcessors.erase(callbackToRemove); Loading @@ -156,7 +158,7 @@ void SoundDoseManager::removeStreamProcessor(audio_io_handle_t streamHandle) { } audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& audioDevice) const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); audio_devices_t type; std::string address; Loading @@ -178,14 +180,14 @@ audio_port_handle_t SoundDoseManager::getIdForAudioDevice(const AudioDevice& aud void SoundDoseManager::mapAddressToDeviceId(const AudioDeviceTypeAddr& adt, const audio_port_handle_t deviceId) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); ALOGI("%s: map address: %d to device id: %d", __func__, adt.mType, deviceId); mActiveDevices[adt] = deviceId; mActiveDeviceTypes[deviceId] = adt.mType; } void SoundDoseManager::clearMapDeviceIdEntries(audio_port_handle_t deviceId) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); for (auto activeDevice = mActiveDevices.begin(); activeDevice != mActiveDevices.end();) { if (activeDevice->second == deviceId) { ALOGI("%s: clear mapping type: %d to deviceId: %d", Loading Loading @@ -303,7 +305,7 @@ binder::Status SoundDoseManager::SoundDose::getOutputRs2UpperBound(float* value) ALOGV("%s", __func__); auto soundDoseManager = mSoundDoseManager.promote(); if (soundDoseManager != nullptr) { std::lock_guard _l(soundDoseManager->mLock); const std::lock_guard _l(soundDoseManager->mLock); *value = soundDoseManager->mRs2UpperBound; } return binder::Status::ok(); Loading Loading @@ -348,7 +350,7 @@ binder::Status SoundDoseManager::SoundDose::isSoundDoseHalSupported(bool* value) } void SoundDoseManager::updateAttenuation(float attenuationDB, audio_devices_t deviceType) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); ALOGV("%s: updating MEL processor attenuation for device type %d to %f", __func__, deviceType, attenuationDB); mMelAttenuationDB[deviceType] = attenuationDB; Loading @@ -368,7 +370,7 @@ void SoundDoseManager::updateAttenuation(float attenuationDB, audio_devices_t de void SoundDoseManager::setCsdEnabled(bool enabled) { ALOGV("%s", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mEnabledCsd = enabled; for (auto& activeEntry : mActiveProcessors) { Loading @@ -384,7 +386,7 @@ void SoundDoseManager::setCsdEnabled(bool enabled) { } bool SoundDoseManager::isCsdEnabled() { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mEnabledCsd; } Loading @@ -392,52 +394,51 @@ void SoundDoseManager::setUseFrameworkMel(bool useFrameworkMel) { // invalidate any HAL sound dose interface used setHalSoundDoseInterface(nullptr); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mUseFrameworkMel = useFrameworkMel; } bool SoundDoseManager::forceUseFrameworkMel() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mUseFrameworkMel; } void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); mComputeCsdOnAllDevices = computeCsdOnAllDevices; } bool SoundDoseManager::forceComputeCsdOnAllDevices() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); return mComputeCsdOnAllDevices; } bool SoundDoseManager::isSoundDoseHalSupported() const { if (!mEnabledCsd) { return false; { const std::lock_guard _l(mLock); if (!mEnabledCsd) return false; } std::shared_ptr<ISoundDose> halSoundDose; getHalSoundDose(&halSoundDose); if (mHalSoundDose == nullptr) { return false; } return true; return halSoundDose != nullptr; } void SoundDoseManager::getHalSoundDose(std::shared_ptr<ISoundDose>* halSoundDose) const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); *halSoundDose = mHalSoundDose; } void SoundDoseManager::resetSoundDose() { std::lock_guard lock(mLock); const std::lock_guard lock(mLock); mSoundDose = nullptr; } void SoundDoseManager::resetCsd(float currentCsd, const std::vector<media::SoundDoseRecord>& records) { std::lock_guard lock(mLock); const std::lock_guard lock(mLock); std::vector<audio_utils::CsdRecord> resetRecords; resetRecords.reserve(records.size()); for (const auto& record : records) { resetRecords.emplace_back(record.timestamp, record.duration, record.value, record.averageMel); Loading @@ -455,13 +456,13 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off std::vector<audio_utils::CsdRecord> records; float currentCsd; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { return; } int64_t timestampSec = getMonotonicSecond(); const int64_t timestampSec = getMonotonicSecond(); // only for internal callbacks records = mMelAggregator->aggregateAndAddNewMelRecord(audio_utils::MelRecord( Loading @@ -475,6 +476,7 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off if (records.size() > 0 && soundDoseCallback != nullptr) { std::vector<media::SoundDoseRecord> newRecordsToReport; newRecordsToReport.resize(records.size()); for (const auto& record : records) { newRecordsToReport.emplace_back(csdRecordToSoundDoseRecord(record)); } Loading @@ -484,7 +486,7 @@ void SoundDoseManager::onNewMelValues(const std::vector<float>& mels, size_t off } sp<media::ISoundDoseCallback> SoundDoseManager::getSoundDoseCallback() const { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mSoundDose == nullptr) { return nullptr; } Loading @@ -496,7 +498,7 @@ void SoundDoseManager::onMomentaryExposure(float currentMel, audio_port_handle_t ALOGV("%s: Momentary exposure for device %d triggered: %f MEL", __func__, deviceId, currentMel); { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { return; } Loading @@ -512,7 +514,7 @@ sp<media::ISoundDose> SoundDoseManager::getSoundDoseInterface( const sp<media::ISoundDoseCallback>& callback) { ALOGV("%s: Register ISoundDoseCallback", __func__); std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (mSoundDose == nullptr) { mSoundDose = sp<SoundDose>::make(this, callback); } Loading @@ -522,7 +524,7 @@ sp<media::ISoundDose> SoundDoseManager::getSoundDoseInterface( std::string SoundDoseManager::dump() const { std::string output; { std::lock_guard _l(mLock); const std::lock_guard _l(mLock); if (!mEnabledCsd) { base::StringAppendF(&output, "CSD is disabled"); return output; Loading
services/audioflinger/sounddose/SoundDoseManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ private: mSoundDoseCallback(callback) {} /** IBinder::DeathRecipient. Listen to the death of ISoundDoseCallback. */ virtual void binderDied(const wp<IBinder>& who); void binderDied(const wp<IBinder>& who) override; /** BnSoundDose override */ binder::Status setOutputRs2UpperBound(float value) override; Loading