Fix focus and release issue in ttsd_player 25/109825/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 2 Jan 2017 07:42:41 +0000 (16:42 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Thu, 12 Jan 2017 02:07:29 +0000 (18:07 -0800)
Change-Id: I3d5b9538796ae7ab54e7925f43a0e771ee3a3991
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit d36b3a396be3e2cf3c0d63ba10df9c38e61b8071)

server/ttsd_dbus.c
server/ttsd_player.c
server/ttsd_server.c

index e993ad5..5342bd3 100644 (file)
@@ -299,6 +299,20 @@ void __ttsd_dbus_service_free()
        }
 }
 
+void __ttsd_dbus_connection_free()
+{
+       if (NULL != g_conn_listener) {
+               dbus_connection_close(g_conn_listener);
+               dbus_connection_unref(g_conn_listener);
+               g_conn_listener = NULL;
+       }
+       if (NULL != g_conn_sender) {
+               dbus_connection_close(g_conn_sender);
+               dbus_connection_unref(g_conn_sender);
+               g_conn_sender = NULL;
+       }
+}
+
 int ttsd_dbus_open_connection()
 {
        DBusError err;
@@ -323,17 +337,13 @@ int ttsd_dbus_open_connection()
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
                dbus_error_free(&err);
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
        if (NULL == g_conn_listener) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection");
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
@@ -368,12 +378,7 @@ int ttsd_dbus_open_connection()
        if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
                __ttsd_dbus_service_free();
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
@@ -381,24 +386,14 @@ int ttsd_dbus_open_connection()
        ret = dbus_bus_request_name(g_conn_listener, g_service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
        if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to be primary owner");
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to request dbus name : %s", err.message);
                dbus_error_free(&err);
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
@@ -412,12 +407,7 @@ int ttsd_dbus_open_connection()
 
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
@@ -427,12 +417,7 @@ int ttsd_dbus_open_connection()
        g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
        if (NULL == g_dbus_fd_handler) {
                SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get fd handler");
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
+               __ttsd_dbus_connection_free();
                return -1;
        }
 
@@ -455,18 +440,9 @@ int ttsd_dbus_close_connection()
                        SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
                        dbus_error_free(&err);
                }
-
-               dbus_connection_close(g_conn_listener);
-               dbus_connection_unref(g_conn_listener);
-               g_conn_listener = NULL;
-       }
-
-       if (NULL != g_conn_sender) {
-               dbus_connection_close(g_conn_sender);
-               dbus_connection_unref(g_conn_sender);
-               g_conn_sender = NULL;
        }
 
+       __ttsd_dbus_connection_free();
        __ttsd_dbus_service_free();
 
        return 0;
index 06c2ca5..110da50 100644 (file)
@@ -108,21 +108,25 @@ void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus
        if (AUDIO_STATE_PLAY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
                if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
                        g_audio_state = AUDIO_STATE_READY;
-       
+
                        if (NULL == g_playing_info) {
-               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
                                return;
                        }
 
                        if (APP_STATE_PLAYING == g_playing_info->state) {
-                               g_playing_info->state = APP_STATE_PAUSED;
-       
-                               ttsd_data_set_client_state(g_playing_info->uid, APP_STATE_PAUSED);
+                               int uid = g_playing_info->uid;
 
-                               int pid = ttsd_data_get_pid(g_playing_info->uid);
+                               if (0 != ttsd_player_pause(uid)) {
+                                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
+                                       return;
+                               }
 
+                               g_playing_info->state = APP_STATE_PAUSED;
+                               ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
+                               int pid = ttsd_data_get_pid(uid);
                                /* send message to client about changing state */
-                               ttsdc_send_set_state_message(pid, g_playing_info->uid, APP_STATE_PAUSED);
+                               ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
                        }
                } else {
                        SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
@@ -217,9 +221,17 @@ static void __unset_policy_for_playing()
        int ret;
        /* Unset stream info */
        if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
-               ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
+               sound_stream_focus_state_e state_for_playing = SOUND_STREAM_FOCUS_STATE_ACQUIRED;
+               ret = sound_manager_get_focus_state(g_stream_info_h, &state_for_playing, NULL);
                if (SOUND_MANAGER_ERROR_NONE != ret) {
-                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
+                       SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to get focus state: %d", ret);
+               }
+
+               if (SOUND_STREAM_FOCUS_STATE_ACQUIRED == state_for_playing) {
+                       ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
+                       if (SOUND_MANAGER_ERROR_NONE != ret) {
+                               SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
+                       }
                }
        }
 
index 3698b11..5a657a5 100755 (executable)
@@ -520,7 +520,7 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
 
 static Eina_Bool __quit_ecore_loop(void *data)
 {
-//     ttsd_dbus_close_connection();
+       ttsd_dbus_close_connection();
 
        ttsd_network_finalize();