*/
#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;
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;
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;
}
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;
+ }
}