Add g_steal_pointer to avoid double-free
[platform/core/uifw/tts.git] / server / ttsd_data.h
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #ifndef __TTSD_DATA_H_
16 #define __TTSD_DATA_H_
17
18 #include "ttse.h"
19 #include "tts_ipc_method.h"
20 #include "ttsd_main.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26
27 typedef enum {
28         APP_STATE_NONE = -1,
29         APP_STATE_CREATED = 0,
30         APP_STATE_READY,
31         APP_STATE_PLAYING,
32         APP_STATE_PAUSED
33 } app_tts_state_e;
34
35 typedef enum {
36         TTS_APP_PLAY_TYPE_SYNTH = 0,
37         TTS_APP_PLAY_TYPE_PCM = 1
38 } tts_app_play_type_e;
39
40 typedef enum {
41         TTSD_SYNTHESIS_CONTROL_DOING    = 0,
42         TTSD_SYNTHESIS_CONTROL_DONE     = 1,
43         TTSD_SYNTHESIS_CONTROL_EXPIRED  = 2
44 } ttsd_synthesis_control_e;
45
46 typedef struct {
47         int speed;
48         int pitch;
49         double volume;
50         double background_volume_ratio;
51 } synthesis_parameter_s;
52
53 typedef struct {
54         int utt_id;
55         char* text;
56         voice_s voice;
57         synthesis_parameter_s synth_parameter;
58         bool is_silent;
59         unsigned int duration_in_msec;
60 } speak_data_s;
61
62 typedef struct {
63         int utt_id;
64         char* data;
65         unsigned int data_size;
66         unsigned int played_data_size;
67
68         ttse_result_event_e event;
69         ttse_audio_type_e audio_type;
70         int rate;
71         int channels;
72 } sound_data_s;
73
74
75 int ttsd_data_set_synth_control(ttsd_synthesis_control_e control);
76
77 ttsd_synthesis_control_e ttsd_data_get_synth_control();
78
79 typedef void (* ttsd_used_voice_cb)(const char* lang, int type);
80
81 int ttsd_data_new_client(int pid, unsigned int uid, ttsd_mode_e mode, ttsd_playing_mode_e playing_mode, int registered_event_mask, tts_ipc_method_e method);
82
83 int ttsd_data_delete_client(unsigned int uid);
84
85 int ttsd_data_is_client(unsigned int uid);
86
87 int ttsd_data_get_client_count();
88
89 int ttsd_data_get_pid(unsigned int uid);
90
91 tts_ipc_method_e ttsd_data_get_ipc_method(unsigned int uid);
92
93 ttsd_mode_e ttsd_data_get_mode(unsigned int uid);
94
95 ttsd_playing_mode_e ttsd_data_get_playing_mode(unsigned int uid);
96
97 int ttsd_data_set_credential(unsigned int uid, const char* credential);
98
99 char* ttsd_data_get_credential(unsigned int uid);
100
101 /* speak data */
102 speak_data_s* ttsd_data_create_speak_data(const char* text, const char* language, int voice_type, int speed, int pitch, double volume, double bg_volume, int utt_id, bool is_silent, unsigned int duration_in_msec);
103
104 void ttsd_data_destroy_speak_data(speak_data_s* speak_data);
105
106 int ttsd_data_add_speak_data(unsigned int uid, speak_data_s* data);
107
108 int ttsd_data_get_speak_data(unsigned int uid, speak_data_s** data);
109
110 int ttsd_data_get_speak_data_size(unsigned int uid);
111
112 /* sound data */
113 sound_data_s* ttsd_data_create_sound_data(int utt_id, const void* data, unsigned int data_size, ttse_result_event_e event,
114                 ttse_audio_type_e audio_type, int rate, int channels);
115
116 void ttsd_data_destroy_sound_data(sound_data_s* sound_data);
117
118 int ttsd_data_add_sound_data(unsigned int uid, sound_data_s* data);
119
120 sound_data_s* ttsd_data_get_first_sound_data(unsigned int uid);
121
122 int ttsd_data_get_sound_data_size(unsigned int uid);
123
124 int ttsd_data_set_last_sound_result_event(unsigned int uid, ttse_result_event_e event);
125
126 ttse_result_event_e ttsd_data_get_last_sound_result_event(unsigned int uid);
127
128 int ttsd_data_clear_data(unsigned int uid);
129
130
131 int ttsd_data_set_used_voice(unsigned int uid, const char* lang, int type);
132
133 int ttsd_data_reset_used_voice(unsigned int uid, ttsd_used_voice_cb callback);
134
135 app_tts_state_e ttsd_data_get_client_state(unsigned int uid);
136
137 int ttsd_data_set_client_state(unsigned int uid, app_tts_state_e state);
138
139 tts_app_play_type_e ttsd_data_get_play_type(unsigned int uid);
140
141 int ttsd_data_set_play_type(unsigned int uid, tts_app_play_type_e type);
142
143 int ttsd_data_set_paused_data(unsigned int uid, sound_data_s* sound_data);
144
145 bool ttsd_data_is_paused_data_existing(unsigned int uid);
146
147 bool ttsd_data_is_service_state_changed_cb_set(unsigned int uid);
148
149
150 unsigned int ttsd_data_get_current_playing();
151
152 typedef bool(*ttsd_data_get_client_cb)(int pid, unsigned int uid, app_tts_state_e state, void* user_data);
153
154 int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data);
155
156 unsigned int ttsd_data_get_first_client_uid();
157
158 bool ttsd_data_is_uttid_valid(unsigned int uid, int uttid);
159
160 int ttsd_data_get_same_pid_client_count(int pid);
161
162 int ttsd_data_get_activated_mode();
163
164 /* For error handing */
165 int ttsd_data_save_error_log(unsigned int uid, FILE* fp);
166
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif /* __TTSD_DATA_H_ */