Added set/unset background volume ratio fucntion. 38/215838/4 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.020148 accepted/tizen/5.5/unified/mobile/hotfix/20201027.080119 accepted/tizen/unified/20191018.222501 submit/tizen/20191017.122545 submit/tizen_5.5/20191031.000005 submit/tizen_5.5_mobile_hotfix/20201026.185105 tizen_5.5.m2_release
authorsungrae jo <seongrae.jo@samsung.com>
Wed, 16 Oct 2019 10:49:02 +0000 (19:49 +0900)
committerwn.jang <wn.jang@samsung.com>
Thu, 17 Oct 2019 11:43:21 +0000 (20:43 +0900)
Change-Id: I8babe58e22ff854920bed1d15e86576bb2499f73
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
13 files changed:
client/tts.c
client/tts_setting.c
common/tts_config_mgr.c
common/tts_config_mgr.h
common/tts_config_parser.c
common/tts_config_parser.h
include/tts_setting.h
server/ttsd_config.c
server/ttsd_config.h
server/ttsd_player.c
server/ttsd_player.h
server/ttsd_server.c
tts-config.xml

index a58dd6f..67db4b9 100644 (file)
@@ -287,7 +287,7 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
+       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
index fa1b90a..50d0cdc 100644 (file)
@@ -46,6 +46,8 @@ static void* g_speed_changed_user_data;
 static tts_setting_pitch_changed_cb g_pitch_changed_cb;
 static void* g_pitch_changed_user_data;
 
+static tts_setting_background_volume_ratio_changed_cb g_bg_volume_ratio_changed_cb;
+static void* g_bg_volume_ratio_changed_user_data;
 
 
 const char* tts_tag()
@@ -104,6 +106,14 @@ void __setting_config_pitch_changed_cb(int value, void* user_data)
                g_pitch_changed_cb(value, g_pitch_changed_user_data);
 }
 
+void __setting_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "Rratio : %lf", value);
+
+       if (NULL != g_bg_volume_ratio_changed_cb)
+               g_bg_volume_ratio_changed_cb(value, g_bg_volume_ratio_changed_user_data);
+}
+
 int tts_setting_initialize()
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Initialize TTS Setting");
@@ -120,8 +130,8 @@ int tts_setting_initialize()
                return __setting_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb, 
-               __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, NULL);
+       ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb,
+                                                                         __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, __setting_config_bg_volume_ratio_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                return __setting_convert_config_error_code(ret);
@@ -527,6 +537,63 @@ int tts_setting_set_pitch(int pitch)
        return __setting_convert_config_error_code(ret);
 }
 
+int tts_setting_get_background_volume_ratio(double *ratio)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get background ratio");
+
+       if (TTS_SETTING_STATE_NONE == g_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+               return TTS_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == ratio) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Param is NULL");
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       double temp;
+       temp = 0;
+
+       int ret = tts_config_mgr_get_bg_volume_ratio(&temp);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+       } else {
+               /* Copy value */
+               *ratio = temp;
+               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get bg volume duration : %lf", *ratio);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return __setting_convert_config_error_code(ret);
+}
+
+int tts_setting_set_background_volume_ratio(double ratio)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set bg volume duration");
+
+       if (TTS_SETTING_STATE_NONE == g_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+               return TTS_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (0.0 > ratio || ratio > 1.0) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid bg volume ratio(%lf)", ratio);
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = tts_config_mgr_set_bg_volume_ratio(ratio);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+       } else {
+               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set bg volume ratio : %lf", ratio);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return __setting_convert_config_error_code(ret);
+}
+
 int tts_setting_get_pitch(int* pitch)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default pitch");
@@ -640,3 +707,25 @@ int tts_setting_unset_pitch_changed_cb()
 
        return TTS_SETTING_ERROR_NONE;
 }
+
+
+int tts_setting_set_background_volume_ratio_changed_cb(tts_setting_background_volume_ratio_changed_cb callback, void* user_data)
+{
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input param is NULL");
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       g_bg_volume_ratio_changed_cb = callback;
+       g_bg_volume_ratio_changed_user_data = user_data;
+
+       return TTS_SETTING_ERROR_NONE;
+}
+
+int tts_setting_unset_background_volume_ratio_changed_cb()
+{
+       g_bg_volume_ratio_changed_cb = NULL;
+       g_bg_volume_ratio_changed_user_data = NULL;
+
+       return TTS_SETTING_ERROR_NONE;
+}
index a5d4e7b..375bc70 100644 (file)
@@ -33,6 +33,7 @@ typedef struct {
        tts_config_speech_rate_changed_cb       speech_cb;
        tts_config_screen_reader_changed_cb     screen_cb;
        tts_config_pitch_changed_cb             pitch_cb;
+       tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb;
        void*   user_data;
 } tts_config_client_s;
 
@@ -349,11 +350,12 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
                int voice_type = -1;
                int speech_rate = -1;
                int pitch = -1;
+               double bg_volume_ratio = -1;
 
                GSList *iter = NULL;
                tts_config_client_s* temp_client = NULL;
 
-               if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch))
+               if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch, &bg_volume_ratio))
                        return ECORE_CALLBACK_PASS_ON;
 
                /* engine changed */
@@ -480,6 +482,28 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
                        }
                }
 
+               if (-1 != bg_volume_ratio) {
+                       g_config_info->bg_volume_ratio = bg_volume_ratio;
+
+                       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio change(%lf)", g_config_info->bg_volume_ratio);
+
+                       /* Call all callbacks of client*/
+                       iter = g_slist_nth(g_config_client_list, 0);
+
+                       while (NULL != iter) {
+                               temp_client = iter->data;
+
+                               if (NULL != temp_client) {
+                                       if (NULL != temp_client->bg_volume_ratio_cb) {
+                                               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio changed callback : uid(%d)", temp_client->uid);
+                                               temp_client->bg_volume_ratio_cb(g_config_info->bg_volume_ratio, temp_client->user_data);
+                                       }
+                               }
+
+                               iter = g_slist_next(iter);
+                       }
+               }
+
                if (NULL != engine) {
                        free(engine);
                        engine = NULL;
@@ -1053,6 +1077,7 @@ int tts_config_mgr_initialize(int uid)
                temp_client->speech_cb = NULL;
                temp_client->pitch_cb = NULL;
                temp_client->screen_cb = NULL;
+               temp_client->bg_volume_ratio_cb = NULL;
                temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
@@ -1071,6 +1096,7 @@ int tts_config_mgr_initialize(int uid)
                temp_client->speech_cb = NULL;
                temp_client->pitch_cb = NULL;
                temp_client->screen_cb = NULL;
+               temp_client->bg_volume_ratio_cb = NULL;
                temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
@@ -1190,6 +1216,7 @@ int tts_config_mgr_initialize(int uid)
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voice type : %d", g_config_info->type);
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " speech rate : %d", g_config_info->speech_rate);
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " pitch : %d", g_config_info->pitch);
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " bg volume ratio : %lf", g_config_info->bg_volume_ratio);
        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@@@");
 
        if (0 != __tts_config_mgr_register_config_event()) {
@@ -1246,6 +1273,7 @@ int tts_config_mgr_set_callback(int uid,
                                tts_config_voice_changed_cb voice_cb, 
                                tts_config_speech_rate_changed_cb speech_cb, 
                                tts_config_pitch_changed_cb pitch_cb,
+                               tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb,
                                void* user_data)
 {
        GSList *iter = NULL;
@@ -1263,6 +1291,7 @@ int tts_config_mgr_set_callback(int uid,
                                temp_client->voice_cb = voice_cb;
                                temp_client->speech_cb = speech_cb;
                                temp_client->pitch_cb = pitch_cb;
+                               temp_client->bg_volume_ratio_cb = bg_volume_ratio_cb;
                                temp_client->user_data = user_data;
                        }
                }
@@ -1289,6 +1318,7 @@ int tts_config_mgr_unset_callback(int uid)
                                temp_client->voice_cb = NULL;
                                temp_client->speech_cb = NULL;
                                temp_client->pitch_cb = NULL;
+                               temp_client->bg_volume_ratio_cb = NULL;
                                temp_client->user_data = NULL;
                        }
                }
@@ -1896,6 +1926,40 @@ int tts_config_mgr_set_pitch(int value)
        return 0;
 }
 
+int tts_config_mgr_get_bg_volume_ratio(double *value)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == value)
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       else
+               *value = g_config_info->bg_volume_ratio;
+
+       return 0;
+}
+
+int tts_config_mgr_set_bg_volume_ratio(double value)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
+       if (0 != tts_parser_set_bg_volume_ratio(value))
+       {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       g_config_info->bg_volume_ratio = value;
+
+       return 0;
+}
+
 bool tts_config_check_default_engine_is_valid(const char* engine)
 {
        if (0 >= g_slist_length(g_config_client_list)) {
index dd6e2da..8aee904 100644 (file)
@@ -61,6 +61,8 @@ typedef void (*tts_config_speech_rate_changed_cb)(int value, void* user_data);
 
 typedef void (*tts_config_pitch_changed_cb)(int value, void* user_data);
 
+typedef void (*tts_config_bg_volume_ratio_changed_cb)(double value, void* user_data);
+
 typedef void (*tts_config_screen_reader_changed_cb)(bool value);
 
 
@@ -74,6 +76,7 @@ int tts_config_mgr_set_callback(int uid,
                                tts_config_voice_changed_cb voice_cb, 
                                tts_config_speech_rate_changed_cb speech_cb, 
                                tts_config_pitch_changed_cb pitch_cb,
+                               tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb,
                                void* user_data);
 
 int tts_config_mgr_unset_callback(int uid);
@@ -108,6 +111,9 @@ int tts_config_mgr_get_pitch(int* value);
 
 int tts_config_mgr_set_pitch(int value);
 
+int tts_config_mgr_get_bg_volume_ratio(double *value);
+int tts_config_mgr_set_bg_volume_ratio(double value);
+
 bool tts_config_check_default_engine_is_valid(const char* engine);
 
 bool tts_config_check_default_voice_is_valid(const char* language, int type);
index 1cbdec8..51ff971 100644 (file)
@@ -39,6 +39,7 @@
 #define TTS_TAG_CONFIG_LANGUAGE                "language"
 #define TTS_TAG_CONFIG_SPEECH_RATE     "speech-rate"
 #define TTS_TAG_CONFIG_PITCH           "pitch"
+#define TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO         "background-volume-ratio"
 #define TTS_TAG_VOICE_TYPE_FEMALE      "female"
 #define TTS_TAG_VOICE_TYPE_MALE                "male"
 #define TTS_TAG_VOICE_TYPE_CHILD       "child"
@@ -516,6 +517,15 @@ int tts_parser_load_config(tts_config_s** config_info)
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               temp->bg_volume_ratio = atof((char*)key);
+                               xmlFree(key);
+                               key = NULL;
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Background volume ratio is NULL");
+                       }
                } else {
 
                }
@@ -951,8 +961,65 @@ int tts_parser_set_pitch(int value)
        return 0;
 }
 
+int tts_parser_set_bg_volume_ratio(double value)
+{
+       xmlNodePtr cur = NULL;
+       cur = xmlDocGetRootElement(g_config_doc);
+       if (cur == NULL) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+               return -1;
+       }
+
+       if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
+               return -1;
+       }
+
+       cur = cur->xmlChildrenNode;
+       if (cur == NULL) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+               return -1;
+       }
+
+       while (cur != NULL) {
+               if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       char temp[10];
+                       memset(temp, '\0', 10);
+                       snprintf(temp, 10, "%lf", value);
+                       xmlNodeSetContent(cur, (const xmlChar *)temp);
+                       break;
+               }
+
+               cur = cur->next;
+       }
+
+       if (0 == access(TTS_CONFIG, F_OK)) {
+               int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
+               if (0 > ret) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
+               } else {
+                       static FILE* pFile;
+                       pFile = fopen(TTS_CONFIG, "r");
+                       int fd = -1;
+                       if (NULL == pFile) {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
+                       } else {
+                               fd = fileno(pFile);
+                               fsync(fd);
+                               fclose(pFile);
+                               SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
+                       }
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
+       }
+
+       return 0;
+}
+
 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type, 
-                                  int* speech_rate, int* pitch)
+                                  int* speech_rate, int* pitch, double* bg_volume_ratio)
 {
        if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
@@ -1175,6 +1242,26 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
                        }
+               } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                               key_old = xmlNodeGetContent(cur_old);
+                               if (NULL != key_old) {
+                                       key_new = xmlNodeGetContent(cur_new);
+                                       if (NULL != key_new) {
+                                               if (0 != xmlStrcmp(key_old, key_new)) {
+                                                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)", 
+                                                               (char*)key_old, (char*)key_new);
+                                                       *bg_volume_ratio = atof((char*)key_new);
+                                               }
+                                               xmlFree(key_new);
+                                               key_new = NULL;
+                                       }
+                                       xmlFree(key_old);
+                                       key_old = NULL;
+                               }
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
+                       }
                } else {
 
                }
index ad736b8..cbe0952 100644 (file)
@@ -54,6 +54,7 @@ typedef struct {
        int     speech_rate;
        int     pitch;
        bool    credential;
+       double bg_volume_ratio;
 } tts_config_s;
 
 
@@ -77,8 +78,10 @@ int tts_parser_set_speech_rate(int value);
 
 int tts_parser_set_pitch(int value);
 
+int tts_parser_set_bg_volume_ratio(double value);
+
 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type, 
-                                  int* speech_rate, int* pitch);
+                                  int* speech_rate, int* pitch, double* bg_volume_ratio);
 
 int tts_parser_copy_xml(const char* original, const char* destination);
 
index cada3e7..75351e0 100644 (file)
@@ -148,6 +148,18 @@ typedef void (*tts_setting_speed_changed_cb)(int speed, void *user_data);
 */
 typedef void (*tts_setting_pitch_changed_cb)(int pitch, void *user_data);
 
+/**
+* @brief Called when the current background volume ratio is changed.
+*
+* @param[in] ratio Current background volume ratio
+* @param[in] user_data The user data passed from the callback registration function
+*
+* @pre An application registers this callback using registration function.
+*
+* @see tts_setting_set_background_volume_ratio_changed_cb()
+* @see tts_setting_unset_background_volume_ratio_changed_cb()
+*/
+typedef void (*tts_setting_background_volume_ratio_changed_cb)(double ratio, void *user_data);
 
 /**
 * @brief Initialize TTS setting.
@@ -426,6 +438,40 @@ int tts_setting_get_pitch(int* pitch);
 int tts_setting_set_pitch(int pitch);
 
 /**
+* @brief Gets a current background volume ratio.
+*
+* @param[out] ratio Current background volume ratio
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #TTS_SETTING_ERROR_NONE Success.
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #TTS_SETTING_ERROR_INVALID_STATE Not initialized.
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Operation failure.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED_FEATURE Not supported feature.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_set_background_volume_ratio()
+*/
+int tts_setting_get_background_volume_ratio(double *ratio);
+
+/**
+* @brief Sets a current background volume ratio.
+*
+* @param[in] ratio Current background volume ratio (Range 0.0 ~ 1.0)
+*
+* @return 0 on success, otherwise a negative error value.
+* @retval #TTS_SETTING_ERROR_NONE Success.
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter.
+* @retval #TTS_SETTING_ERROR_INVALID_STATE Not initialized.
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Operation failure.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED_FEATURE Not supported feature.
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_get_background_volume_ratio()
+*/
+int tts_setting_set_background_volume_ratio(double ratio);
+
+/**
 * @brief Registers a callback function to be called when engine information is changed
 *
 * @param[in] callback The callback function to register
@@ -542,6 +588,35 @@ int tts_setting_set_pitch_changed_cb(tts_setting_pitch_changed_cb callback, void
 int tts_setting_unset_pitch_changed_cb();
 
 
+/**
+* @brief Sets a callback function to be called when current background volume is changed
+*
+* @param[in] callback The callback function to register
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #TTS_SETTING_ERROR_NONE Successful
+* @retval #TTS_SETTING_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Invalid state
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_background_volume_ratio_changed_cb()
+* @see tts_setting_unset_background_volume_ratio_changed_cb()
+*/
+int tts_setting_set_background_volume_ratio_changed_cb(tts_setting_background_volume_ratio_changed_cb callback, void* user_data);
+
+/**
+* @brief Unsets the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #TTS_SETTING_ERROR_NONE Successful
+* @retval #TTS_SETTING_ERROR_OPERATION_FAILED Invalid state
+* @retval #TTS_SETTING_ERROR_NOT_SUPPORTED TTS NOT supported
+*
+* @see tts_setting_set_background_volume_ratio_changed_cb()
+*/
+int tts_setting_unset_background_volume_ratio_changed_cb();
+
 #ifdef __cplusplus
 }
 #endif
index 58dc2fa..341ae96 100644 (file)
@@ -34,9 +34,9 @@ void __ttsd_config_engine_changed_cb(const char* engine_id, const char* setting,
 
        if (NULL != g_callback) {
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the engine reload callback : engine id(%s)", engine_id);
-               g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0);
+               g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0, 0);
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the voice changed callback : lang(%s), type(%d)", language, voice_type);
-               g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type);
+               g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type, 0);
        } else {
                SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
        }
@@ -51,7 +51,7 @@ void __ttsd_config_voice_changed_cb(const char* before_language, int before_type
        }
 
        if (NULL != g_callback) {
-               g_callback(TTS_CONFIG_TYPE_VOICE, language, type);
+               g_callback(TTS_CONFIG_TYPE_VOICE, language, type, 0);
        } else {
                SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
        }
@@ -60,7 +60,7 @@ void __ttsd_config_voice_changed_cb(const char* before_language, int before_type
 void __ttsd_config_speech_rate_changed_cb(int value, void* user_data)
 {
        if (NULL != g_callback) {
-               g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value);
+               g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value, 0);
        } else {
                SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
        }
@@ -69,7 +69,7 @@ void __ttsd_config_speech_rate_changed_cb(int value, void* user_data)
 void __ttsd_config_pitch_changed_cb(int value, void* user_data)
 {
        if (NULL != g_callback) {
-               g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value);
+               g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value, 0);
        } else {
                SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
        }
@@ -82,6 +82,14 @@ void __ttsd_config_screen_reader_changed_cb(bool value)
        }
 }
 
+void __ttsd_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+       if (NULL != g_callback)
+               g_callback(TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO, NULL, 0, value);
+       else
+               SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
+}
+
 int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
 {
        if (NULL == config_cb) {
@@ -100,7 +108,7 @@ int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
        }
 
        ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb, 
-               __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, NULL);
+               __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, __ttsd_config_bg_volume_ratio_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set config changed : %d", ret);
                return -1;
@@ -201,6 +209,19 @@ int ttsd_config_get_default_pitch(int* pitch)
        return 0;
 }
 
+int ttsd_config_get_bg_volume_ratio(double* ratio)
+{
+       if (NULL == ratio)
+               return -1;
+
+       if (0 != tts_config_mgr_get_bg_volume_ratio(ratio)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default bg volume ratio");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       return 0;
+}
+
 int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text, 
                           const char* func, int line, const char* message)
 {
index 26ad74f..dc2fb84 100644 (file)
@@ -25,10 +25,11 @@ typedef enum {
        TTS_CONFIG_TYPE_ENGINE,
        TTS_CONFIG_TYPE_VOICE,
        TTS_CONFIG_TYPE_SPEED,
-       TTS_CONFIG_TYPE_PITCH
+       TTS_CONFIG_TYPE_PITCH,
+       TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO
 } tts_config_type_e;
 
-typedef void (*ttsd_config_changed_cb)(tts_config_type_e type, const char* str_param, int int_param);
+typedef void (*ttsd_config_changed_cb)(tts_config_type_e type, const char* str_param, int int_param, double double_param);
 
 typedef void (*ttsd_config_screen_reader_changed_cb)(bool value);
 
@@ -48,6 +49,8 @@ int ttsd_config_get_default_speed(int* speed);
 
 int ttsd_config_get_default_pitch(int* pitch);
 
+int ttsd_config_get_bg_volume_ratio(double* ratio);
+
 int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text, 
                           const char* func, int line, const char* message);
 
index 3ca665b..688bd6a 100644 (file)
@@ -81,8 +81,15 @@ static audio_out_h g_audio_h;
 
 static sound_stream_info_h g_stream_info_h;
 
+static sound_stream_ducking_h g_stream_ducking;
+
+static bool ducking_flag;
+
+#define SND_MGR_DUCKING_DURATION 500
+
 static int g_focus_watch_id;
 
+static double g_bg_volume_ratio;
 
 /*
 * Internal Interfaces
@@ -233,6 +240,58 @@ void __player_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask,
        return;
 }
 
+void __sound_stream_ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data)
+{
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ ducking state changed cb");
+
+       SLOG(LOG_DEBUG, tts_tag(), "[Player] is ducked : %d", is_ducked);
+
+       ducking_flag = true;
+       return;
+}
+
+static void __change_background_volume()
+{
+       int ret = SOUND_MANAGER_ERROR_NONE;
+       bool is_ducked = false;
+       ret = sound_manager_is_ducked(g_stream_ducking, &is_ducked);
+       if (is_ducked) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] The background volume is already ducked");
+               return;
+       }
+
+       ducking_flag = false;
+       ret = sound_manager_activate_ducking(g_stream_ducking, SND_MGR_DUCKING_DURATION, g_bg_volume_ratio);
+       if (SOUND_MANAGER_ERROR_NONE != ret) {
+               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to activate ducking");
+               return;
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] Activate ducking");
+       }
+
+       while (ducking_flag == false) {
+               usleep(10000);
+               SLOG(LOG_DEBUG, tts_tag(), "ducking waiting");
+       }
+}
+
+static void __recover_background_volume()
+{
+       int ret = SOUND_MANAGER_ERROR_NONE;
+       bool is_ducked = false;
+       ret = sound_manager_is_ducked(g_stream_ducking, &is_ducked);
+       if (!is_ducked) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] The background volume is already recovered");
+               return;
+       }
+
+       ret = sound_manager_deactivate_ducking(g_stream_ducking);
+       if (SOUND_MANAGER_ERROR_NONE != ret)
+               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to deactivate ducking");
+       else
+               SLOG(LOG_WARN, tts_tag(), "[Player] Deactivate ducking");
+}
+
 static int __create_audio_out(ttse_audio_type_e type, int rate)
 {
        int ret = -1;
@@ -322,6 +381,8 @@ static void __set_policy_for_playing(int volume)
                SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
        }
 
+       __change_background_volume();
+
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
 
        return;
@@ -351,6 +412,8 @@ static void __unset_policy_for_playing()
                }
        }
 
+       __recover_background_volume();
+
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
 
        return;
@@ -795,6 +858,12 @@ int ttsd_player_init()
                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Add sound focus watch callback");
        }
 
+       ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_MEDIA, __sound_stream_ducking_state_changed_cb, NULL, &g_stream_ducking);
+       if (SOUND_MANAGER_ERROR_NONE != ret)
+               SLOG(LOG_ERROR, tts_tag(), "[Player WARNING] Fail to create stream ducking");
+       else
+               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream ducking");
+
        ecore_thread_max_set(1);
 
        ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
@@ -858,6 +927,12 @@ int ttsd_player_release(void)
                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Remove the focus state watch cb");
        }
 
+       ret = sound_manager_destroy_stream_ducking(g_stream_ducking);
+       if (SOUND_MANAGER_ERROR_NONE != ret)
+               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream ducking");
+       else
+               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream ducking");
+
        /* clear g_player_list */
        g_playing_info = NULL;
        g_player_init = false;
@@ -1304,3 +1379,20 @@ int ttsd_player_play_pcm(int uid)
        return 0;
 }
 
+int ttsd_player_get_background_volume_ratio(double* ratio)
+{
+       if (NULL == ratio)
+               return -1;
+       else
+               *ratio = g_bg_volume_ratio;
+
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_player_set_background_volume_ratio(double ratio)
+{
+       SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] ttsd_player_set_background_volume_ratio : %lf", ratio);
+
+       g_bg_volume_ratio = ratio;
+       return TTSD_ERROR_NONE;
+}
index ffa0c37..1221d93 100644 (file)
@@ -59,6 +59,8 @@ int ttsd_player_play_pcm(int uid);
 
 int ttsd_player_check_current_playback_focus(bool *is_current_interrupt);
 
+int ttsd_player_set_background_volume_ratio(double ratio);
+
 #ifdef __cplusplus
 }
 #endif
index c1b5ab8..6a4e6e2 100644 (file)
@@ -294,7 +294,7 @@ bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
        return true;
 }
 
-void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param)
+void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
 {
        switch (type) {
        case TTS_CONFIG_TYPE_ENGINE:
@@ -383,6 +383,19 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
                }
                break;
        }
+
+       case TTS_CONFIG_TYPE_BACKGROUND_VOLUME_RATIO:
+       {
+               if (0.0 <= double_param && double_param <= 1.0) {
+                       /* set default bg volume ratio */
+                       int ret = 0;
+                       ret = ttsd_player_set_background_volume_ratio(double_param);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set default bg volume ratio : result(%d)", ret);
+                       }
+               }
+               break;
+       }
        }
 
        return;
@@ -423,6 +436,17 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
        }
 
+       double ratio;
+       if (0 == ttsd_config_get_bg_volume_ratio(&ratio))
+       {
+               SLOG(LOG_ERROR, tts_tag(), "[Server] get bg volume ratio is %lf", ratio);
+               int ret = ttsd_player_set_background_volume_ratio(ratio);
+               if (0 != ret)
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set bg volume ratio : result(%d)", ret);
+       }
+       else
+               SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to get bg volume ratio");
+
        /* player init */
        if (ttsd_player_init()) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
index 61b9161..1b96796 100644 (file)
@@ -7,4 +7,5 @@
         <voice-type>female</voice-type>
         <speech-rate>8</speech-rate>
         <pitch>8</pitch>
+        <background-volume-ratio>1.0</background-volume-ratio>
 </tts-config>