Add code to check whether the player is initialized 95/271095/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 20 Jan 2022 06:57:51 +0000 (15:57 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 15 Feb 2022 08:54:01 +0000 (17:54 +0900)
Change-Id: Ic651a374b408dd10f0cee033e49c080d678d178f
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_player.cpp

index c792b211c905602e62e1ea30fa276ed5ba1884a1..6724965002af31d77cadbbda4c6cd168d0edd8bf 100644 (file)
@@ -1198,7 +1198,7 @@ int ttsd_player_create_instance(unsigned int uid)
 {
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* Check uid is duplicated */
@@ -1233,7 +1233,7 @@ int ttsd_player_destroy_instance(unsigned int uid)
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
                pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        player_s* current;
@@ -1289,7 +1289,7 @@ int ttsd_player_play(unsigned int uid)
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
                pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        if (NULL != g_playing_info) {
@@ -1329,6 +1329,11 @@ int ttsd_player_play(unsigned int uid)
 int ttsd_player_stop(unsigned int uid)
 {
        pthread_mutex_lock(&g_player_control_mutex);
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+               pthread_mutex_unlock(&g_player_control_mutex);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
 
        /* check whether uid is current playing or not */
        if (NULL != g_playing_info) {
@@ -1368,7 +1373,7 @@ int ttsd_player_clear(unsigned int uid)
 {
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* Check uid */
@@ -1403,7 +1408,7 @@ int ttsd_player_pause(unsigned int uid)
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
                pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* Check uid */
@@ -1455,7 +1460,7 @@ int ttsd_player_resume(unsigned int uid)
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
                pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        /* Check id */
@@ -1487,7 +1492,7 @@ int ttsd_player_all_stop()
        if (false == g_player_init) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
                pthread_mutex_unlock(&g_player_control_mutex);
-               return -1;
+               return TTSD_ERROR_OPERATION_FAILED;
        }
 
        g_playing_info = NULL;
@@ -1540,6 +1545,11 @@ int ttsd_player_all_stop()
 
 int ttsd_player_get_background_volume_ratio(double* ratio)
 {
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
        if (NULL == ratio)
                return -1;
        else
@@ -1585,6 +1595,11 @@ static void __modify_background_volume(void* data)
 
 int ttsd_player_set_background_volume_ratio(double ratio)
 {
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
        SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] ttsd_player_set_background_volume_ratio : %lf", ratio);
 
        double prev_ratio = g_bg_volume_ratio;
@@ -1605,6 +1620,11 @@ int ttsd_player_set_background_volume_ratio(double ratio)
 
 int ttsd_player_wait_to_play(unsigned int uid)
 {
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
        SLOG(LOG_INFO, tts_tag(), "[Player INFO] wait to play (%u)", uid);
 
        g_audio_state = AUDIO_STATE_WAIT_FOR_PLAYING;