Add codes in client side to set/unset callback for retrieving sythesized pcm data 33/284933/4
authorwn.jang <wn.jang@samsung.com>
Thu, 1 Dec 2022 07:48:34 +0000 (16:48 +0900)
committerwn.jang <wn.jang@samsung.com>
Thu, 1 Dec 2022 08:32:26 +0000 (17:32 +0900)
Change-Id: I938872f2546f8462eb8ffd10fc40b522909ee16c

client/tts.c
client/tts_client.c
client/tts_client.h
include/tts.h

index a662017..3df546b 100644 (file)
@@ -1390,3 +1390,36 @@ int tts_unset_service_state_changed_cb(tts_h tts)
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset service state changed cb");
        return TTS_ERROR_NONE;
 }
+
+int tts_set_synthesized_pcm_cb(tts_h tts, tts_synthesized_pcm_cb callback, void* user_data)
+{
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       tts_client_s* client = tts_client_get(tts);
+       RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
+       RETVM_IF(NULL == callback, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Set synthesized pcm cb : Input parameter is null");
+
+       tts_state_e current_state = tts_client_get_current_state(client);
+       RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
+
+       tts_client_set_synthesized_pcm_cb(client, callback, user_data);
+
+       SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set synthesized pcm cb");
+       return TTS_ERROR_NONE;
+}
+
+int tts_unset_synthesized_pcm_cb(tts_h tts)
+{
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       tts_client_s* client = tts_client_get(tts);
+       RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts);
+
+       tts_state_e current_state = tts_client_get_current_state(client);
+       RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
+
+       tts_client_set_synthesized_pcm_cb(client, NULL, NULL);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset synthesized pcm cb");
+       return TTS_ERROR_NONE;
+}
\ No newline at end of file
index 9515946..551041f 100644 (file)
@@ -147,6 +147,12 @@ static inline void __set_service_state_changed_cb(tts_client_s* client, tts_serv
        client->service_state_changed_user_data = user_data;
 }
 
+static inline void __set_synthesized_pcm_cb(tts_client_s* client, tts_synthesized_pcm_cb callback, void* user_data)
+{
+       client->synthesized_pcm_cb = callback;
+       client->synthesized_pcm_user_data = user_data;
+}
+
 int tts_client_new(tts_h* tts)
 {
        tts_client_s* client = (tts_client_s*)calloc(1, sizeof(tts_client_s));
@@ -656,6 +662,14 @@ void tts_client_set_service_state_changed_cb(tts_client_s* client, tts_service_s
        __set_service_state_changed_cb(client, callback, user_data);
 }
 
+void tts_client_set_synthesized_pcm_cb(tts_client_s* client, tts_synthesized_pcm_cb callback, void* user_data)
+{
+       if (false == tts_client_is_valid_client(client)) {
+               return;
+       }
+       __set_synthesized_pcm_cb(client, callback, user_data);
+}
+
 tts_state_changed_cb tts_client_get_state_changed_cb(tts_client_s* client)
 {
        if (false == tts_client_is_valid_client(client)) {
@@ -802,6 +816,22 @@ void* tts_client_get_service_state_changed_user_data(tts_client_s* client)
        return client->service_state_changed_user_data;
 }
 
+tts_synthesized_pcm_cb tts_client_get_synthesized_pcm_cb(tts_client_s* client)
+{
+       if (false == tts_client_is_valid_client(client)) {
+               return NULL;
+       }
+       return client->synthesized_pcm_cb;
+}
+
+void* tts_client_get_synthesized_pcm_user_data(tts_client_s* client)
+{
+       if (false == tts_client_is_valid_client(client)) {
+               return NULL;
+       }
+       return client->synthesized_pcm_user_data;
+}
+
 int tts_client_get_registered_event_mask(tts_client_s* client)
 {
        if (false == tts_client_is_valid_client(client)) {
@@ -834,4 +864,5 @@ void tts_client_unset_all_cb(tts_client_s* client)
        __set_engine_changed_cb(client, NULL, NULL);
        __set_supported_voice_cb(client, NULL, NULL);
        __set_service_state_changed_cb(client, NULL, NULL);
+       __set_synthesized_pcm_cb(client, NULL, NULL);
 }
\ No newline at end of file
index da298c5..4faebc0 100644 (file)
@@ -54,6 +54,9 @@ typedef struct {
        void*                           supported_voice_user_data;
        tts_service_state_changed_cb            service_state_changed_cb;
        void*                           service_state_changed_user_data;
+       tts_synthesized_pcm_cb          synthesized_pcm_cb;
+       void*                           synthesized_pcm_user_data;
+
        int registered_event_mask;
 
        /* mode / state */
@@ -142,6 +145,7 @@ void tts_client_set_engine_changed_cb(tts_client_s* client, tts_engine_changed_c
 void tts_client_set_screen_reader_changed_cb(tts_client_s* client, tts_screen_reader_changed_cb callback, void* user_data);
 void tts_client_set_supported_voice_cb(tts_client_s* client, tts_supported_voice_cb callback, void* user_data);
 void tts_client_set_service_state_changed_cb(tts_client_s* client, tts_service_state_changed_cb callback, void* user_data);
+void tts_client_set_synthesized_pcm_cb(tts_client_s* client, tts_synthesized_pcm_cb callback, void* user_data);
 
 tts_state_changed_cb tts_client_get_state_changed_cb(tts_client_s* client);
 void* tts_client_get_state_changed_user_data(tts_client_s* client);
@@ -170,6 +174,9 @@ void* tts_client_get_supported_voice_user_data(tts_client_s* client);
 tts_service_state_changed_cb tts_client_get_service_state_changed_cb(tts_client_s* client);
 void* tts_client_get_service_state_changed_user_data(tts_client_s* client);
 
+tts_synthesized_pcm_cb tts_client_get_synthesized_pcm_cb(tts_client_s* client);
+void* tts_client_get_synthesized_pcm_user_data(tts_client_s* client);
+
 int tts_client_get_registered_event_mask(tts_client_s* client);
 
 void tts_client_unset_all_cb(tts_client_s* client);
index 142acd8..985d638 100644 (file)
@@ -97,6 +97,18 @@ typedef enum {
 
 
 /**
+ * @brief Enumeration for synthesized pcm event.
+ * @since_tizen 7.5
+*/
+typedef enum {
+       TTS_SYNTHESIZED_PCM_EVENT_FAIL = -1, /**< 'Error' event */
+       TTS_SYNTHESIZED_PCM_EVENT_START, /**< 'Started' event */
+       TTS_SYNTHESIZED_PCM_EVENT_CONTINUE, /**< 'Finished' event */
+       TTS_SYNTHESIZED_PCM_EVENT_FINISH, /**< 'Finished' event */
+} tts_synthesized_pcm_event_e;
+
+
+/**
  * @brief Definition for automatic speaking speed.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
 */
@@ -268,6 +280,23 @@ typedef void (*tts_screen_reader_changed_cb)(tts_h tts, bool is_on, void* user_d
 */
 typedef void (*tts_service_state_changed_cb)(tts_h tts, tts_service_state_e previous, tts_service_state_e current, void* user_data);
 
+
+/**
+ * @brief Called when the synthesized pcm data is come from the engine.
+ * @since_tizen 7.5
+ * @remarks The @a tts handle should not be destroyed in the callback.
+ * @param[in] tts The TTS handle, the same handle for which the callback was set.
+ * @param[in] event The event type
+ * @param[in] buffer The synthesized pcm data
+ * @param[in] buffer_size The size of the buffer
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre An application registers this callback using tts_set_synthesized_pcm_cb() to get pcm data.
+ * @see tts_set_synthesized_pcm_cb()
+ * @see tts_unset_synthesized_pcm_cb()
+ */
+typedef void (*tts_synthesized_pcm_cb)(tts_h tts, tts_synthesized_pcm_event_e event, char* buffer, int buffer_size, void *user_data);
+
+
 /**
  * @brief Creates a handle for TTS.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
@@ -1013,6 +1042,41 @@ int tts_set_service_state_changed_cb(tts_h tts, tts_service_state_changed_cb cal
 */
 int tts_unset_service_state_changed_cb(tts_h tts);
 
+
+/**
+ * @brief Sets the default to be called when the synthesized pcm data is recieved.
+ * @since_tizen 7.5
+ * @param[in] tts The TTS handle
+ * @param callback The callback function to register
+ * @param user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *                otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @pre The TTS state should be #TTS_STATE_CREATED.
+ * @see tts_synthesized_pcm_cb()
+ * @see tts_unset_synthesized_pcm_cb()
+ */
+int tts_set_synthesized_pcm_cb(tts_h tts, tts_synthesized_pcm_cb callback, void* user_data);
+
+
+/**
+ * @brief Unsets the callback function.
+ * @since_tizen 7.5
+ * @param tts The TTS handle
+ * @return @c 0 on success,
+ *                otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @pre The TTS state should be #TTS_STATE_CREATED.
+ * @see tts_set_synthesized_pcm_cb()
+  */
+int tts_unset_synthesized_pcm_cb(tts_h tts);
+
 #ifdef __cplusplus
 }
 #endif