From cc9a2a9f28b1b16dcb4c88ed3f62f6fe601d035b Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Tue, 16 Jan 2024 22:12:35 +0900 Subject: [PATCH] Retry ducking deactivation when it is failed - Issue: Sometimes ducking deactivation can be failed and does not recovered. - Solution: This patch adds the logic for retrying ducking deactivation if the deactivation is failed. In most case, deactivation is not failed because previous logic also calcualtes the ducking duration. However, some unknown reason, deactivation can be failed. So this patch makes the framework handle this situation. Change-Id: I2fa72eafa5d095b1a44dd9aadc281cfcb16429c4 Signed-off-by: Suyeon Hwang --- server/BackgroundVolume.cpp | 53 +++++++++++++++++++++++++-------------------- server/BackgroundVolume.h | 4 ++-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/server/BackgroundVolume.cpp b/server/BackgroundVolume.cpp index fc8990c..c7b578b 100644 --- a/server/BackgroundVolume.cpp +++ b/server/BackgroundVolume.cpp @@ -136,7 +136,7 @@ void BackgroundVolume::modifyVolumeOnMainThread(void* data) } long long int diff = backgroundVolume->getDurationAfterDucking(); - if (diff >= backgroundVolume->mDuckingDuration) { + if (diff > backgroundVolume->mDuckingDuration) { double ratio = backgroundVolume->mVolumeRatio.load(); SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Modify volume ratio(%lf) directly", ratio); @@ -263,15 +263,12 @@ void BackgroundVolume::recoverVolumeOnMainThread(void* data) SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Remove modification timer. result(%p)", result); } - long long int diff = backgroundVolume->getDurationAfterDucking(); - if (diff >= backgroundVolume->mDuckingDuration) { - SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Direct deactivate ducking"); - - backgroundVolume->deactivateDuckingAll(); - } else { + if (false == backgroundVolume->deactivateDuckingAll()) { + SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Direct deactivation is failed. Try again after some moments"); + long long int diff = backgroundVolume->getDurationAfterDucking(); double delay = static_cast(backgroundVolume->mDuckingDuration - diff) / 1000.0; backgroundVolume->mPostponedRecoverTimer = ecore_timer_add(delay, postponedRecoverTimerCb, data); - SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay deactivate ducking (%p), delay(%f)", backgroundVolume->mPostponedRecoverTimer, delay); + SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay deactivation (%p), delay(%lf)", backgroundVolume->mPostponedRecoverTimer, delay); } } @@ -283,16 +280,19 @@ long long int BackgroundVolume::getDurationAfterDucking() return diff.count(); } -void BackgroundVolume::deactivateDuckingAll() +bool BackgroundVolume::deactivateDuckingAll() { if (false == isDuckingHandleValid()) { SLOG(LOG_WARN, tts_tag(), "[BackgroundVolume] There are some invalid handles. Skip ducking deactivation."); - return; + return false; } - deactivateDucking(SOUND_STREAM_TYPE_MEDIA); - deactivateDucking(SOUND_STREAM_TYPE_NOTIFICATION); - deactivateDucking(SOUND_STREAM_TYPE_ALARM); + bool result = true; + result &= deactivateDucking(SOUND_STREAM_TYPE_MEDIA); + result &= deactivateDucking(SOUND_STREAM_TYPE_NOTIFICATION); + result &= deactivateDucking(SOUND_STREAM_TYPE_ALARM); + + return result; } Eina_Bool BackgroundVolume::postponedRecoverTimerCb(void* data) @@ -303,28 +303,33 @@ Eina_Bool BackgroundVolume::postponedRecoverTimerCb(void* data) } BackgroundVolume* backgroundVolume = static_cast(data); - backgroundVolume->deactivateDuckingAll(); - backgroundVolume->mPostponedRecoverTimer = nullptr; + if (false == backgroundVolume->deactivateDuckingAll()) { + SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Try again."); + return EINA_TRUE; + } SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delayed unset policy success"); + backgroundVolume->mPostponedRecoverTimer = nullptr; return EINA_FALSE; } -void BackgroundVolume::deactivateDucking(sound_stream_type_e type) +bool BackgroundVolume::deactivateDucking(sound_stream_type_e type) { - bool isDucked = false; + bool is_ducked = false; sound_stream_ducking_h handle = getStreamDuckingHandle(type); - sound_manager_is_ducked(handle, &isDucked); - if (!isDucked) { - SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s is already recovered from ducking", get_ducking_stream(type)); - return; + sound_manager_is_ducked(handle, &is_ducked); + if (!is_ducked) { + SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s volume is already recovered", get_ducking_stream(type)); + return true; } if (SOUND_MANAGER_ERROR_NONE != sound_manager_deactivate_ducking(handle)) { - SLOG(LOG_WARN, tts_tag(), "[BackgroundVolume] Fail to deactivate ducking for %s", get_ducking_stream(type)); - } else { - SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Deactivate ducking for %s", get_ducking_stream(type)); + SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to deactivate ducking for %s", get_ducking_stream(type)); + return false; } + + SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Deactivate ducking for %s", get_ducking_stream(type)); + return true; } int BackgroundVolume::createHandles() diff --git a/server/BackgroundVolume.h b/server/BackgroundVolume.h index 0bb2e97..2367abb 100644 --- a/server/BackgroundVolume.h +++ b/server/BackgroundVolume.h @@ -48,8 +48,8 @@ private: void activateDuckingAll(unsigned int duration, double ratio); bool activateDucking(sound_stream_type_e type, unsigned int duration, double ratio); - void deactivateDuckingAll(); - void deactivateDucking(sound_stream_type_e type); + bool deactivateDuckingAll(); + bool deactivateDucking(sound_stream_type_e type); private: const long long int mDuckingDuration; -- 2.7.4