Deactivate ducking when the state is perfectly changed to ducked 54/319354/1
authorsooyeon <sooyeon.kim@samsung.com>
Fri, 13 Sep 2024 10:35:35 +0000 (19:35 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Tue, 22 Oct 2024 01:53:36 +0000 (10:53 +0900)
- Issue:
Due to duration time, the ducking state is changed slowly.
When a request for deactivation is coming during the duration time, it is failed to deactivate ducking and the ducking state is maintained.

- Solution:
Deactivate ducking when the state is perfectly changed to ducked.

Change-Id: I1a932c627bc4e9d607e633666e53bec844a9f14f
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
client/vc_mgr_ducking.cpp

index 810997abcffbb5213a54373bd71f18b938f244bc..ee49f018ad7d6ea28592e57497e615fa74cbfa14 100644 (file)
 */
 
 #include <sound_manager.h>
+#include <unordered_map>
 
 #include "vc_main.h"
 
 #include "vc_mgr_ducking.h"
 
-#define SND_MGR_DUCKING_DURATION 500
+#define SND_MGR_DUCKING_DURATION       300
+#define MAX_DEACTIVATE_DUCKING_CNT     10
 
 /* for changing volume on each sound stream */
 static sound_stream_ducking_h g_media_stream_h = nullptr;
@@ -28,6 +30,8 @@ static sound_stream_ducking_h g_system_stream_h = nullptr;
 static sound_stream_ducking_h g_notification_stream_h = nullptr;
 static sound_stream_ducking_h g_alarm_stream_h = nullptr;
 static sound_stream_ducking_h g_voice_information_stream_h = nullptr;
+static std::unordered_map<sound_stream_type_e, bool> g_is_requested_activation;
+static std::unordered_map<sound_stream_type_e, bool> g_is_deactivated;
 
 static bool g_is_created = false;
 
@@ -136,14 +140,20 @@ static int activate_ducking_sound_stream(sound_stream_type_e type, sound_stream_
        ret = sound_manager_is_ducked(header, &is_ducked);
        if (is_ducked) {
                SLOG(LOG_DEBUG, TAG_VCM, "The %s is already ducked", get_ducking_stream(type));
+               g_is_deactivated[type] = false;
                return ret;
        }
 
        ret = sound_manager_activate_ducking(header, SND_MGR_DUCKING_DURATION, ratio);
-       if (SOUND_MANAGER_ERROR_NONE != ret)
+       if (SOUND_MANAGER_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to activate ducking for %s", get_ducking_stream(type));
-       else
+               g_is_requested_activation[type] = false;
+               g_is_deactivated[type] = true;
+       } else {
                SLOG(LOG_INFO, TAG_VCM, "Activate ducking for %s", get_ducking_stream(type));
+               g_is_requested_activation[type] = true;
+               g_is_deactivated[type] = false;
+       }
 
        return ret;
 }
@@ -169,42 +179,59 @@ int vc_mgr_ducking_activate(double ratio)
        return ret;
 }
 
-static int deactivate_ducking_sound_stream(sound_stream_type_e type, sound_stream_ducking_h header)
+static bool deactivate_ducking_sound_stream(sound_stream_type_e type, sound_stream_ducking_h header)
 {
+       if (true == g_is_deactivated[type])
+               return true;
+
        bool is_ducked = false;
        int ret = SOUND_MANAGER_ERROR_NONE;
        ret = sound_manager_is_ducked(header, &is_ducked);
-       if (false == is_ducked) {
+       if (false == is_ducked && false == g_is_requested_activation[type]) {
                SLOG(LOG_DEBUG, TAG_VCM, "The %s is already recovered from ducking", get_ducking_stream(type));
-               return ret;
+               g_is_deactivated[type] = true;
+               return true;
+       }
+
+       if (false == is_ducked && true == g_is_requested_activation[type]) {
+               SLOG(LOG_DEBUG, TAG_VCM, "The %s is not activated to be ducked. Please wait for duration time and try again.", get_ducking_stream(type));
+               return false;
        }
 
        ret = sound_manager_deactivate_ducking(header);
-       if (SOUND_MANAGER_ERROR_NONE != ret)
-               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to deactivate ducking for %s", get_ducking_stream(type));
-       else
-               SLOG(LOG_INFO, TAG_VCM, "Deactivate ducking for %s", get_ducking_stream(type));
+       if (SOUND_MANAGER_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to deactivate ducking for %s. Please try again.", get_ducking_stream(type));
+               return false;
+       }
 
-       return ret;
+       SLOG(LOG_INFO, TAG_VCM, "Deactivate ducking for %s", get_ducking_stream(type));
+       g_is_requested_activation[type] = false;
+       g_is_deactivated[type] = true;
+
+       return true;
 }
 
 int vc_mgr_ducking_deactivate(void)
 {
        SLOG(LOG_INFO, TAG_VCM, "vc_mgr_ducking_deactivate");
 
-       int ret = VC_ERROR_NONE;
-       ret = deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_MEDIA, g_media_stream_h);
-       if (SOUND_MANAGER_ERROR_NONE != ret)
-               return ret;
-
-       ret = deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_NOTIFICATION, g_notification_stream_h);
-       if (SOUND_MANAGER_ERROR_NONE != ret)
-               return ret;
-
-       ret = deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_ALARM, g_alarm_stream_h);
-       if (SOUND_MANAGER_ERROR_NONE != ret)
-               return ret;
-
-       ret = deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_VOICE_INFORMATION, g_voice_information_stream_h);
-       return ret;
+       bool ret = true;
+       int cnt = 1;
+       do {
+               usleep(30000);
+               ret = true;
+               ret &= deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_MEDIA, g_media_stream_h);
+               ret &= deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_NOTIFICATION, g_notification_stream_h);
+               ret &= deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_ALARM, g_alarm_stream_h);
+               ret &= deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_VOICE_INFORMATION, g_voice_information_stream_h);
+               cnt++;
+       } while (!ret || cnt <= MAX_DEACTIVATE_DUCKING_CNT);
+
+       if (true == ret) {
+               SLOG(LOG_INFO, TAG_VCM, "Succeed in deactivating ducking");
+               return VC_ERROR_NONE;
+       } else {
+               SLOG(LOG_INFO, TAG_VCM, "Fail to deactivate ducking");
+               return VC_ERROR_OPERATION_FAILED;
+       }
 }