summaryrefslogtreecommitdiff
path: root/toxav/toxav.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/toxav.h')
-rw-r--r--toxav/toxav.h300
1 files changed, 300 insertions, 0 deletions
diff --git a/toxav/toxav.h b/toxav/toxav.h
new file mode 100644
index 00000000..be7a2950
--- /dev/null
+++ b/toxav/toxav.h
@@ -0,0 +1,300 @@
1/** toxav.h
2 *
3 * Copyright (C) 2013 Tox project All Rights Reserved.
4 *
5 * This file is part of Tox.
6 *
7 * Tox is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Tox is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 * Report bugs/suggestions at #tox-dev @ freenode.net:6667
22 */
23
24
25#ifndef __TOXAV
26#define __TOXAV
27#include <inttypes.h>
28
29/* vpx_image_t */
30#include <vpx/vpx_image.h>
31
32typedef void *( *ToxAVCallback ) ( void *arg );
33typedef struct _ToxAv ToxAv;
34
35#ifndef __TOX_DEFINED__
36#define __TOX_DEFINED__
37typedef struct Tox Tox;
38#endif
39
40#define RTP_PAYLOAD_SIZE 65535
41
42/* Default video bitrate in bytes/s */
43#define VIDEO_BITRATE 10*1000*100
44
45/* Default audio bitrate in bits/s */
46#define AUDIO_BITRATE 64000
47
48/* Number of audio channels. */
49#define AUDIO_CHANNELS 1
50
51/* Audio frame duration in miliseconds */
52#define AUDIO_FRAME_DURATION 20
53
54/* Audio sample rate recommended to be 48kHz for Opus */
55#define AUDIO_SAMPLE_RATE 48000
56
57/* The amount of samples in one audio frame */
58#define AUDIO_FRAME_SIZE AUDIO_SAMPLE_RATE*AUDIO_FRAME_DURATION/1000
59
60/* Assume 60 fps*/
61#define MAX_ENCODE_TIME_US ((1000 / 60) * 1000)
62
63
64/**
65 * @brief Callbacks ids that handle the call states.
66 */
67typedef enum {
68 /* Requests */
69 OnInvite,
70 OnStart,
71 OnCancel,
72 OnReject,
73 OnEnd,
74
75 /* Responses */
76 OnRinging,
77 OnStarting,
78 OnEnding,
79
80 /* Protocol */
81 OnError,
82 OnRequestTimeout
83
84} ToxAvCallbackID;
85
86
87/**
88 * @brief Call type identifier.
89 */
90typedef enum {
91 TypeAudio = 70,
92 TypeVideo
93} ToxAvCallType;
94
95
96/**
97 * @brief Error indicators.
98 *
99 */
100typedef enum {
101 ErrorNone = 0,
102 ErrorInternal = -1, /* Internal error */
103 ErrorAlreadyInCall = -2, /* Already has an active call */
104 ErrorNoCall = -3, /* Trying to perform call action while not in a call */
105 ErrorInvalidState = -4, /* Trying to perform call action while in invalid state*/
106 ErrorNoRtpSession = -5, /* Trying to perform rtp action on invalid session */
107 ErrorAudioPacketLost = -6, /* Indicating packet loss */
108 ErrorStartingAudioRtp = -7, /* Error in toxav_prepare_transmission() */
109 ErrorStartingVideoRtp = -8 , /* Error in toxav_prepare_transmission() */
110 ErrorNoTransmission = -9, /* Returned in toxav_kill_transmission() */
111 ErrorTerminatingAudioRtp = -10, /* Returned in toxav_kill_transmission() */
112 ErrorTerminatingVideoRtp = -11, /* Returned in toxav_kill_transmission() */
113
114} ToxAvError;
115
116
117/**
118 * @brief Start new A/V session. There can only be one session at the time. If you register more
119 * it will result in undefined behaviour.
120 *
121 * @param messenger The messenger handle.
122 * @param useragent The agent handling A/V session (i.e. phone).
123 * @param ua_name Useragent name.
124 * @param video_width Width of video frame.
125 * @param video_height Height of video frame.
126 * @return ToxAv*
127 * @retval NULL On error.
128 */
129ToxAv *toxav_new(Tox *messenger, void *useragent, const char *ua_name, uint16_t video_width, uint16_t video_height);
130
131/**
132 * @brief Remove A/V session.
133 *
134 * @param av Handler.
135 * @return void
136 */
137void toxav_kill(ToxAv *av);
138
139/**
140 * @brief Register callback for call state.
141 *
142 * @param callback The callback
143 * @param id One of the ToxAvCallbackID values
144 * @return void
145 */
146void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID id);
147
148/**
149 * @brief Call user. Use its friend_id.
150 *
151 * @param av Handler.
152 * @param user The user.
153 * @param call_type Call type.
154 * @param ringing_seconds Ringing timeout.
155 * @return int
156 * @retval 0 Success.
157 * @retval ToxAvError On error.
158 */
159int toxav_call(ToxAv *av, int user, ToxAvCallType call_type, int ringing_seconds);
160
161/**
162 * @brief Hangup active call.
163 *
164 * @param av Handler.
165 * @return int
166 * @retval 0 Success.
167 * @retval ToxAvError On error.
168 */
169int toxav_hangup(ToxAv *av);
170
171/**
172 * @brief Answer incomming call.
173 *
174 * @param av Handler.
175 * @param call_type Answer with...
176 * @return int
177 * @retval 0 Success.
178 * @retval ToxAvError On error.
179 */
180int toxav_answer(ToxAv *av, ToxAvCallType call_type );
181
182/**
183 * @brief Reject incomming call.
184 *
185 * @param av Handler.
186 * @param reason Optional reason. Set NULL if none.
187 * @return int
188 * @retval 0 Success.
189 * @retval ToxAvError On error.
190 */
191int toxav_reject(ToxAv *av, const char *reason);
192
193/**
194 * @brief Cancel outgoing request.
195 *
196 * @param av Handler.
197 * @param reason Optional reason.
198 * @return int
199 * @retval 0 Success.
200 * @retval ToxAvError On error.
201 */
202int toxav_cancel(ToxAv *av, const char *reason);
203
204/**
205 * @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
206 *
207 * @param av Handler.
208 * @return int
209 * @retval 0 Success.
210 * @retval ToxAvError On error.
211 */
212int toxav_stop_call(ToxAv *av);
213
214/**
215 * @brief Must be call before any RTP transmission occurs.
216 *
217 * @param av Handler.
218 * @return int
219 * @retval 0 Success.
220 * @retval ToxAvError On error.
221 */
222int toxav_prepare_transmission(ToxAv *av);
223
224/**
225 * @brief Call this at the end of the transmission.
226 *
227 * @param av Handler.
228 * @return int
229 * @retval 0 Success.
230 * @retval ToxAvError On error.
231 */
232int toxav_kill_transmission(ToxAv *av);
233
234/**
235 * @brief Receive decoded video packet.
236 *
237 * @param av Handler.
238 * @param output Storage.
239 * @return int
240 * @retval 0 Success.
241 * @retval ToxAvError On Error.
242 */
243int toxav_recv_video ( ToxAv *av, vpx_image_t **output);
244
245/**
246 * @brief Receive decoded audio frame.
247 *
248 * @param av Handler.
249 * @param frame_size ...
250 * @param dest Destination of the packet. Make sure it has enough space for
251 * RTP_PAYLOAD_SIZE bytes.
252 * @return int
253 * @retval >=0 Size of received packet.
254 * @retval ToxAvError On error.
255 */
256int toxav_recv_audio( ToxAv *av, int frame_size, int16_t *dest );
257
258/**
259 * @brief Encode and send video packet.
260 *
261 * @param av Handler.
262 * @param input The packet.
263 * @return int
264 * @retval 0 Success.
265 * @retval ToxAvError On error.
266 */
267int toxav_send_video ( ToxAv *av, vpx_image_t *input);
268
269/**
270 * @brief Encode and send audio frame.
271 *
272 * @param av Handler.
273 * @param frame The frame.
274 * @param frame_size It's size.
275 * @return int
276 * @retval 0 Success.
277 * @retval ToxAvError On error.
278 */
279int toxav_send_audio ( ToxAv *av, const int16_t *frame, int frame_size);
280
281/**
282 * @brief Get peer transmission type. It can either be audio or video.
283 *
284 * @param av Handler.
285 * @param peer The peer
286 * @return int
287 * @retval ToxAvCallType On success.
288 * @retval ToxAvError On error.
289 */
290int toxav_get_peer_transmission_type ( ToxAv *av, int peer );
291
292/**
293 * @brief Get reference to an object that is handling av session.
294 *
295 * @param av Handler.
296 * @return void*
297 */
298void *toxav_get_agent_handler ( ToxAv *av );
299
300#endif /* __TOXAV */ \ No newline at end of file