summaryrefslogtreecommitdiff
path: root/toxav/msi.h
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-11-18 00:46:46 +0100
committermannol <eniz_vukovic@hotmail.com>2014-11-18 00:46:46 +0100
commit386c9748d48d3bb4513e8e5c32e2b30a4d6a00d4 (patch)
tree55d0fb2e9fb6e1149317b9de355c28dd86c57014 /toxav/msi.h
parent4e6f993e7d22865ee2ac90bd7dd3ff25b078c55c (diff)
av refactor
Diffstat (limited to 'toxav/msi.h')
-rw-r--r--toxav/msi.h158
1 files changed, 47 insertions, 111 deletions
diff --git a/toxav/msi.h b/toxav/msi.h
index 64fa0881..1ece8817 100644
--- a/toxav/msi.h
+++ b/toxav/msi.h
@@ -31,9 +31,8 @@ typedef uint8_t MSICallIDType[12];
31typedef uint8_t MSIReasonStrType[255]; 31typedef uint8_t MSIReasonStrType[255];
32typedef void ( *MSICallbackType ) ( void *agent, int32_t call_idx, void *arg ); 32typedef void ( *MSICallbackType ) ( void *agent, int32_t call_idx, void *arg );
33 33
34
35/** 34/**
36 * @brief Call type identifier. Also used as rtp callback prefix. 35 * Call type identifier. Also used as rtp callback prefix.
37 */ 36 */
38typedef enum { 37typedef enum {
39 type_audio = 192, 38 type_audio = 192,
@@ -42,7 +41,7 @@ typedef enum {
42 41
43 42
44/** 43/**
45 * @brief Call state identifiers. 44 * Call state identifiers.
46 */ 45 */
47typedef enum { 46typedef enum {
48 call_inviting, /* when sending call invite */ 47 call_inviting, /* when sending call invite */
@@ -55,7 +54,7 @@ typedef enum {
55 54
56 55
57/** 56/**
58 * @brief Encoding settings. 57 * Encoding settings.
59 */ 58 */
60typedef struct _MSICodecSettings { 59typedef struct _MSICodecSettings {
61 MSICallType call_type; 60 MSICallType call_type;
@@ -72,29 +71,24 @@ typedef struct _MSICodecSettings {
72 71
73 72
74/** 73/**
75 * @brief Callbacks ids that handle the states 74 * Callbacks ids that handle the states
76 */ 75 */
77typedef enum { 76typedef enum {
78 /* Requests */ 77 MSI_OnInvite, /* Incoming call */
79 MSI_OnInvite, 78 MSI_OnRinging, /* When peer is ready to accept/reject the call */
80 MSI_OnStart, 79 MSI_OnStart, /* Call (RTP transmission) started */
81 MSI_OnCancel, 80 MSI_OnCancel, /* The side that initiated call canceled invite */
82 MSI_OnReject, 81 MSI_OnReject, /* The side that was invited rejected the call */
83 MSI_OnEnd, 82 MSI_OnEnd, /* Call that was active ended */
84 83 MSI_OnRequestTimeout, /* When the requested action didn't get response in specified time */
85 /* Responses */ 84 MSI_OnPeerTimeout, /* Peer timed out; stop the call */
86 MSI_OnRinging, 85 MSI_OnPeerCSChange, /* Peer requested Csettings change */
87 MSI_OnStarting, 86 MSI_OnSelfCSChange /* Csettings change confirmation */
88 MSI_OnEnding,
89
90 /* Protocol */
91 MSI_OnRequestTimeout,
92 MSI_OnPeerTimeout,
93 MSI_OnMediaChange
94} MSICallbackID; 87} MSICallbackID;
95 88
89
96/** 90/**
97 * @brief Callbacks container 91 * Callbacks container
98 */ 92 */
99typedef struct _MSICallbackCont { 93typedef struct _MSICallbackCont {
100 MSICallbackType function; 94 MSICallbackType function;
@@ -102,16 +96,15 @@ typedef struct _MSICallbackCont {
102} MSICallbackCont; 96} MSICallbackCont;
103 97
104/** 98/**
105 * @brief The call struct. 99 * The call struct.
106 *
107 */ 100 */
108typedef struct _MSICall { /* Call info structure */ 101typedef struct _MSICall { /* Call info structure */
109 struct _MSISession *session; /* Session pointer */ 102 struct _MSISession *session; /* Session pointer */
110 103
111 MSICallState state; 104 MSICallState state;
112 105
113 MSICSettings csettings_local; /* Local call settings */ 106 MSICSettings csettings_local; /* Local call settings */
114 MSICSettings *csettings_peer; /* Peers call settings */ 107 MSICSettings *csettings_peer; /* Peers call settings */
115 108
116 MSICallIDType id; /* Random value identifying the call */ 109 MSICallIDType id; /* Random value identifying the call */
117 110
@@ -120,8 +113,6 @@ typedef struct _MSICall { /* Call info structure */
120 int request_timer_id; /* Timer id for outgoing request/action */ 113 int request_timer_id; /* Timer id for outgoing request/action */
121 int ringing_timer_id; /* Timer id for ringing timeout */ 114 int ringing_timer_id; /* Timer id for ringing timeout */
122 115
123
124 pthread_mutex_t mutex; /* */
125 uint32_t *peers; 116 uint32_t *peers;
126 uint16_t peer_count; 117 uint16_t peer_count;
127 118
@@ -130,8 +121,7 @@ typedef struct _MSICall { /* Call info structure */
130 121
131 122
132/** 123/**
133 * @brief Control session struct 124 * Control session struct
134 *
135 */ 125 */
136typedef struct _MSISession { 126typedef struct _MSISession {
137 127
@@ -143,125 +133,71 @@ typedef struct _MSISession {
143 Messenger *messenger_handle; 133 Messenger *messenger_handle;
144 134
145 uint32_t frequ; 135 uint32_t frequ;
146 uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */ 136 uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */
147 137
148 pthread_mutex_t mutex; 138 pthread_mutex_t mutex;
149 139
150 void *timer_handler; 140 void *timer_handler;
151 MSICallbackCont callbacks[11]; /* Callbacks used by this session */ 141 MSICallbackCont callbacks[10]; /* Callbacks used by this session */
152} MSISession; 142} MSISession;
153 143
154/** 144/**
155 * @brief Callback setter. 145 * Start the control session.
156 *
157 * @param session The container.
158 * @param callback The callback.
159 * @param id The id.
160 * @return void
161 */ 146 */
162void msi_register_callback(MSISession *session, MSICallbackType callback, MSICallbackID id, void *userdata); 147MSISession *msi_new ( Messenger *messenger, int32_t max_calls );
163
164 148
165/** 149/**
166 * @brief Start the control session. 150 * Terminate control session.
167 *
168 * @param messenger Tox* object.
169 * @param max_calls Amount of calls possible
170 * @return MSISession* The created session.
171 * @retval NULL Error occurred.
172 */ 151 */
173MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls ); 152int msi_kill ( MSISession *session );
174
175 153
176/** 154/**
177 * @brief Terminate control session. 155 * Callback setter.
178 *
179 * @param session The session
180 * @return int
181 */ 156 */
182int msi_terminate_session ( MSISession *session ); 157void msi_register_callback(MSISession *session, MSICallbackType callback, MSICallbackID id, void *userdata);
183
184 158
185/** 159/**
186 * @brief Send invite request to friend_id. 160 * Send invite request to friend_id.
187 *
188 * @param session Control session.
189 * @param call_index Set to new call index.
190 * @param call_type Type of the call. Audio or Video(both audio and video)
191 * @param rngsec Ringing timeout.
192 * @param friend_id The friend.
193 * @return int
194 */ 161 */
195int msi_invite ( MSISession *session, int32_t *call_index, MSICSettings csettings, uint32_t rngsec, 162int msi_invite ( MSISession *session,
163 int32_t *call_index,
164 const MSICSettings* csettings,
165 uint32_t rngsec,
196 uint32_t friend_id ); 166 uint32_t friend_id );
197 167
198
199/** 168/**
200 * @brief Hangup active call. 169 * Hangup active call.
201 *
202 * @param session Control session.
203 * @param call_index To which call is this action handled.
204 * @return int
205 * @retval -1 Error occurred.
206 * @retval 0 Success.
207 */ 170 */
208int msi_hangup ( MSISession *session, int32_t call_index ); 171int msi_hangup ( MSISession *session, int32_t call_index );
209 172
210
211/** 173/**
212 * @brief Answer active call request. 174 * Answer active call request.
213 *
214 * @param session Control session.
215 * @param call_index To which call is this action handled.
216 * @param call_type Answer with Audio or Video(both).
217 * @return int
218 */ 175 */
219int msi_answer ( MSISession *session, int32_t call_index, MSICSettings csettings ); 176int msi_answer ( MSISession *session, int32_t call_index, const MSICSettings* csettings );
220
221 177
222/** 178/**
223 * @brief Cancel request. 179 * Cancel request.
224 *
225 * @param session Control session.
226 * @param call_index To which call is this action handled.
227 * @param peer To which peer.
228 * @param reason Set optional reason header. Pass NULL if none.
229 * @return int
230 */ 180 */
231int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason ); 181int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason );
232 182
233
234/** 183/**
235 * @brief Reject request. 184 * Reject incoming call.
236 *
237 * @param session Control session.
238 * @param call_index To which call is this action handled.
239 * @param reason Set optional reason header. Pass NULL if none.
240 * @return int
241 */ 185 */
242int msi_reject ( MSISession *session, int32_t call_index, const char *reason ); 186int msi_reject ( MSISession *session, int32_t call_index, const char *reason );
243 187
188/**
189 * Terminate the call.
190 */
191int msi_stopcall ( MSISession *session, int32_t call_index );
244 192
245/** 193/**
246 * @brief Send invite request to friend_id. 194 * Change codec settings of the current call.
247 *
248 * @param session Control session.
249 * @param call_index Call index.
250 * @param call_type Type of the call. Audio or Video(both audio and video)
251 * @param rngsec Ringing timeout.
252 * @param friend_id The friend.
253 * @return int
254 */ 195 */
255int msi_change_csettings ( MSISession *session, int32_t call_index, MSICSettings csettings ); 196int msi_change_csettings ( MSISession* session, int32_t call_index, const MSICSettings* csettings );
256
257 197
258/** 198/**
259 * @brief Terminate the current call. 199 * Main msi loop
260 *
261 * @param session Control session.
262 * @param call_index To which call is this action handled.
263 * @return int
264 */ 200 */
265int msi_stopcall ( MSISession *session, int32_t call_index ); 201void msi_do( MSISession* session );
266 202
267#endif /* __TOXMSI */ 203#endif /* __TOXMSI */