Clean up code to enhance readability 84/271884/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 28 May 2021 09:40:07 +0000 (18:40 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 14 Mar 2022 05:25:31 +0000 (14:25 +0900)
This patch includes these to enhance readability.
- Remove unused headers and invaluable comments
- Change log level to help logging.
- Remove invaluable keywords.
- Fix NULL to nullptr.

Change-Id: Iadb75d1fb42cebf5740b9e0d2df0581785427acb
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_data.h
server/ttsd_dbus.c
server/ttsd_player.cpp
server/ttsd_server.c
server/ttsd_tidl.c

index 2362059..ce7de2e 100644 (file)
@@ -16,7 +16,6 @@
 #define __TTSD_DATA_H_
 
 #include "ttse.h"
-#include "ttsd_stub.h"
 #include "tts_ipc_method.h"
 #include "ttsd_main.h"
 
index 3de1de8..cac61c4 100644 (file)
 #include <dlfcn.h>
 #include <Ecore.h>
 
-#include "tts_config_mgr.h"
 #include "ttsd_main.h"
 #include "ttsd_dbus_server.h"
 #include "ttsd_dbus.h"
-#include "ttsd_server.h"
 
 static DBusConnection* g_conn_sender = NULL;
 static DBusConnection* g_conn_listener = NULL;
index ef07eb3..8d5e09f 100644 (file)
 */
 
 #include "ttsd_main.h"
-#include "ttsd_player.h"
+#include "ttsd_server.h"
 #include "ttsd_data.h"
-#include "ttsd_dbus.h"
 #include "ttsd_ipc.h"
+#include "ttsd_player.h"
 
 #include "BackgroundVolume.h"
 #include "AudioStream.h"
 #include "PlayerThread.h"
 
-#include "tts_internal.h"
-#include "ttsd_server.h"
-
 
 #define SOUND_BUFFER_LENGTH    2048
 
+/* CAUTION!
+If you change this constant value. Please check the function '__set_timer_for_delay_recover()'.
+If you choose too big value, it may cause integer overflow issue.
+*/
+static const int SND_MGR_DUCKING_DURATION = 500;
 static const intptr_t CHECK_TIMER_DELETE = 1;
 static const int EXTRA_INFO_LENGTH = 20;
 
@@ -45,14 +47,7 @@ static pthread_mutex_t g_buf_save_mutex = PTHREAD_MUTEX_INITIALIZER;
 /** player init info */
 static bool g_player_init = false;
 
-static bool g_is_set_policy;
-
-/* CAUTION!
-If you change this constant value. Please check the function '__set_timer_for_delay_recover()'.
-If you choose too big value, it may cause integer overflow issue.
-*/
-#define SND_MGR_DUCKING_DURATION 500
-
+static volatile bool g_is_set_policy = false;
 
 static BackgroundVolume* g_background_volume = nullptr;
 static AudioStream* g_audio_stream = nullptr;
@@ -186,7 +181,7 @@ static void __focus_release_callback()
 
 static void __set_policy_for_playing(void)
 {
-       const char* extra_info = NULL;
+       const char* extra_info = nullptr;
        if (TTSD_MODE_INTERRUPT == ttsd_get_mode()) {
                extra_info = "TTSD_MODE_INTERRUPT";
        }
@@ -196,8 +191,6 @@ static void __set_policy_for_playing(void)
        g_is_set_policy = true;
        SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", g_is_set_policy);
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
-
-       return;
 }
 
 static void __unset_policy_for_playing()
@@ -207,8 +200,6 @@ static void __unset_policy_for_playing()
        g_is_set_policy = false;
        SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", g_is_set_policy);
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
-
-       return;
 }
 
 static bool __does_interrupt_have_focus(sound_stream_focus_change_reason_e reason, int sound_behavior, char *extra_info)
@@ -218,7 +209,7 @@ static bool __does_interrupt_have_focus(sound_stream_focus_change_reason_e reaso
                return false;
        }
 
-       if (NULL == extra_info || 0 >= strlen(extra_info) || 0 != strncmp(extra_info, "TTSD_MODE_INTERRUPT", EXTRA_INFO_LENGTH)) {
+       if (nullptr == extra_info || 0 >= strlen(extra_info) || 0 != strncmp(extra_info, "TTSD_MODE_INTERRUPT", EXTRA_INFO_LENGTH)) {
                return false;
        }
 
@@ -229,7 +220,7 @@ bool ttsd_player_does_interrupt_have_playback_focus()
 {
        sound_stream_focus_change_reason_e reason;
        int sound_behavior = 0;
-       char *extra_info = NULL;
+       char *extra_info = nullptr;
        if (SOUND_MANAGER_ERROR_NONE != sound_manager_get_current_playback_focus(&reason, &sound_behavior, &extra_info)) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to get focus information");
                return false;
@@ -382,7 +373,7 @@ static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
 
                        SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
                                sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
-               } else { // NO player->is_paused_data
+               } else {
                        if (nullptr == sound_data) {
                                SLOG(LOG_ERROR, tts_tag(), "[Player] No sound data. Waiting mode");
 
@@ -394,7 +385,7 @@ static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
 
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
                                continue;
-                       } // NULL == sound_data
+                       }
 
                        /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
                         * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
@@ -407,7 +398,7 @@ static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
                                if (TTSD_ERROR_INVALID_PARAMETER == ret) {
                                        break;
                                }
-                       } // (TTSE_RESULT_EVENT_START == sound_data->event || (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event))
+                       }
 
                        /* Save last event to check utterance start */
                        ttsd_data_set_last_sound_result_event(uid, sound_data->event);
@@ -430,8 +421,8 @@ static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
                                }
 
                                continue;
-                       } // (NULL == sound_data->data || 0 >= sound_data->data_size)
-               } // NO player->is_paused_data
+                       }
+               }
 
                int ret = __play_sound_data(player, uid, sound_data);
                if (TTSD_ERROR_INVALID_STATE == ret) {
@@ -456,14 +447,14 @@ static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
                        if (TTSD_ERROR_NONE != __notify_utterance_completed_event(uid, utt_id)) {
                                break;
                        }
-               } // (TTSE_RESULT_EVENT_FINISH == event)
+               }
 
                app_tts_state_e state = ttsd_data_get_client_state(uid);
                if (APP_STATE_READY == state) {
                        /* player_stop */
                        SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
                        break;
-               } // (NULL == g_playing_info && APP_STATE_READY == player->state)
+               }
        }
 
        g_audio_stream->unprepareAudioOut();
@@ -599,7 +590,7 @@ int ttsd_player_pause(unsigned int uid)
 #endif
 
        __set_playing_status(false);
-       SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%u)", uid);
+       SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Pause player : uid(%u)", uid);
        return 0;
 }
 
@@ -659,7 +650,7 @@ int ttsd_player_get_background_volume_ratio(double* ratio)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (NULL == ratio) {
+       if (nullptr == ratio) {
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
index 68517dd..1766754 100644 (file)
@@ -18,8 +18,6 @@
 
 #include "ttsd_config.h"
 #include "ttsd_data.h"
-#include "ttsd_dbus.h"
-#include "ttsd_dbus_server.h"
 #include "ttsd_ipc.h"
 #include "ttsd_engine_agent.h"
 #include "ttsd_main.h"
index a430967..285f90e 100644 (file)
@@ -16,9 +16,8 @@
 #include <pthread.h>
 
 #include "ttsd_main.h"
-#include "ttsd_ipc.h"
-#include "ttsd_data.h"
 #include "ttsd_server.h"
+#include "ttsd_stub.h"
 
 #include "ttsd_tidl.h"