Retry ducking deactivation when it is failed 83/304383/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 16 Jan 2024 13:12:35 +0000 (22:12 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 16 Jan 2024 13:12:35 +0000 (22:12 +0900)
- 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 <stom.hwang@samsung.com>
server/BackgroundVolume.cpp
server/BackgroundVolume.h

index fc8990c..c7b578b 100644 (file)
@@ -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<double>(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<BackgroundVolume*>(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()
index 0bb2e97..2367abb 100644 (file)
@@ -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;