*/
#include <sound_manager.h>
+#include <pthread.h>
#include <unordered_map>
#include "vc_main.h"
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 pthread_mutex_t g_ducking_mutex = PTHREAD_MUTEX_INITIALIZER;
static bool g_is_created = false;
static int activate_ducking_sound_stream(sound_stream_type_e type, sound_stream_ducking_h header, double ratio)
{
+ pthread_mutex_lock(&g_ducking_mutex);
+
bool is_ducked = false;
int ret = SOUND_MANAGER_ERROR_NONE;
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;
+ pthread_mutex_unlock(&g_ducking_mutex);
return ret;
}
g_is_deactivated[type] = false;
}
+ pthread_mutex_unlock(&g_ducking_mutex);
return ret;
}
static bool deactivate_ducking_sound_stream(sound_stream_type_e type, sound_stream_ducking_h header)
{
- if (true == g_is_deactivated[type])
+ pthread_mutex_lock(&g_ducking_mutex);
+
+ if (true == g_is_deactivated[type]) {
+ pthread_mutex_unlock(&g_ducking_mutex);
return true;
+ }
bool is_ducked = false;
int ret = SOUND_MANAGER_ERROR_NONE;
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));
g_is_deactivated[type] = true;
+ pthread_mutex_unlock(&g_ducking_mutex);
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));
+ pthread_mutex_unlock(&g_ducking_mutex);
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. Please try again.", get_ducking_stream(type));
+ pthread_mutex_unlock(&g_ducking_mutex);
return false;
}
g_is_requested_activation[type] = false;
g_is_deactivated[type] = true;
+ pthread_mutex_unlock(&g_ducking_mutex);
return true;
}