}
}
+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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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());
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");
+ }
}
}