Fix policy for playing pcm data 41/167941/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Wed, 22 Nov 2017 10:56:34 +0000 (19:56 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 23 Jan 2018 05:27:18 +0000 (05:27 +0000)
Change-Id: I8bdea9aa9eafbf170dffe0dc37d5a10d061f5523
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 8cce5fdd2213f3aaf885f7509726563d1c644b95)

client/tts.c
include/tts_internal.h
server/ttsd_player.c
server/ttsd_player.h
server/ttsd_server.c

index a76420b..e6385b4 100644 (file)
@@ -2359,7 +2359,7 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size,
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       if (TTS_STATE_PLAYING != client->current_state) {
+       if (TTS_STATE_CREATED == client->current_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
                return TTS_ERROR_INVALID_STATE;
        }
@@ -2483,7 +2483,7 @@ int tts_stop_pcm(tts_h tts)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       if (TTS_STATE_PLAYING != client->current_state) {
+       if (TTS_STATE_CREATED == client->current_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
                return TTS_ERROR_INVALID_STATE;
        }
index 1c02cb5..29ea810 100644 (file)
@@ -71,7 +71,7 @@ int tts_set_server_tts(tts_h tts, const char* credential);
  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
  * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
- * @pre The state should be #TTS_STATE_PLAYING.
+ * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING, or #TTS_STATE_PAUSED.
  * @see tts_play_pcm()
  * @see tts_stop_pcm()
 */
@@ -90,7 +90,7 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size,
  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
  * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
- * @pre The state should be #TTS_STATE_READY.
+ * @pre The state should be #TTS_STATE_READY or #TTS_STATE_PAUSED.
  * @see tts_add_pcm()
  * @see tts_stop_pcm()
 */
@@ -109,7 +109,7 @@ int tts_play_pcm(tts_h tts);
  * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
  * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
  * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
- * @pre The state should be #TTS_STATE_PLAYING.
+ * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING, or #TTS_STATE_PAUSED.
  * @see tts_play_pcm()
  * @see tts_add_pcm()
 */
index 44f1167..0aacbba 100644 (file)
@@ -1068,3 +1068,50 @@ int ttsd_player_all_stop()
 
        return 0;
 }
+
+int ttsd_player_play_pcm(int uid)
+{
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+               return -1;
+       }
+
+       if (NULL != g_playing_info) {
+               if (uid == g_playing_info->uid) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
+                       return 0;
+               } else {
+                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
+                       ttsd_player_stop(g_playing_info->uid);
+               }
+       }
+
+       SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
+
+       /* Check sound queue size */
+       if (0 == ttsd_data_get_sound_data_size(uid)) {
+               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
+       }
+
+       /* Check uid */
+       player_s* current;
+       current = __player_get_item(uid);
+       if (NULL == current) {
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
+               return -1;
+       }
+
+       current->state = APP_STATE_PLAYING;
+
+       g_playing_info = current;
+
+       SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
+
+//     if (0 < ttsd_data_get_sound_data_size(current->uid)) {
+               SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
+               ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
+//     }
+
+       return 0;
+}
+
index a59214b..430e2c0 100644 (file)
@@ -55,6 +55,8 @@ int ttsd_player_resume(int uid);
 
 int ttsd_player_all_stop();
 
+int ttsd_player_play_pcm(int uid);
+
 #ifdef __cplusplus
 }
 #endif
index 5f027e9..143275b 100644 (file)
@@ -1143,6 +1143,26 @@ int ttsd_server_play_pcm(int uid)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       if (APP_STATE_PAUSED == state) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
+
+               /* Resume player */
+               if (0 != ttsd_player_resume(uid)) {
+                       SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
+               }
+       } else {
+               if (0 != ttsd_player_play_pcm(uid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
+
+                       // Change ready state
+                       ttsd_server_stop(uid);
+
+                       int tmp_pid;
+                       tmp_pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+               }
+       }
+
        return TTSD_ERROR_NONE;
 }
 
@@ -1238,16 +1258,17 @@ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio
                        temp_sound_data = NULL;
                }
 
-               if (0 != ttsd_player_play(uid)) {
+/*             if (0 != ttsd_player_play(uid)) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
 
-                       /* Change ready state */
+                       // Change ready state
                        ttsd_server_stop(uid);
 
                        int tmp_pid;
                        tmp_pid = ttsd_data_get_pid(uid);
                        ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
                }
+*/
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
        }