diff options
Diffstat (limited to 'toxav/toxav_new_1.h')
-rw-r--r-- | toxav/toxav_new_1.h | 329 |
1 files changed, 0 insertions, 329 deletions
diff --git a/toxav/toxav_new_1.h b/toxav/toxav_new_1.h deleted file mode 100644 index 3696f961..00000000 --- a/toxav/toxav_new_1.h +++ /dev/null | |||
@@ -1,329 +0,0 @@ | |||
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 | |||
22 | |||
23 | #ifndef __TOXAV | ||
24 | #define __TOXAV | ||
25 | #include <inttypes.h> | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | typedef struct _ToxAv ToxAv; | ||
32 | |||
33 | /* vpx_image_t */ | ||
34 | #include <vpx/vpx_image.h> | ||
35 | |||
36 | typedef void ( *ToxAVCallback ) ( void *agent, int32_t call_idx, void *arg ); | ||
37 | typedef void ( *ToxAvAudioCallback ) (void *agent, int32_t call_idx, const int16_t *PCM, uint16_t size, void *data); | ||
38 | typedef void ( *ToxAvVideoCallback ) (void *agent, int32_t call_idx, const vpx_image_t *img, void *data); | ||
39 | |||
40 | #ifndef __TOX_DEFINED__ | ||
41 | #define __TOX_DEFINED__ | ||
42 | typedef struct Tox Tox; | ||
43 | #endif | ||
44 | |||
45 | #define RTP_PAYLOAD_SIZE 65535 | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Callbacks ids that handle the call states. | ||
50 | */ | ||
51 | typedef enum { | ||
52 | av_OnInvite, /* Incoming call */ | ||
53 | av_OnRinging, /* When peer is ready to accept/reject the call */ | ||
54 | av_OnStart, /* Call (RTP transmission) started */ | ||
55 | av_OnCancel, /* The side that initiated call canceled invite */ | ||
56 | av_OnReject, /* The side that was invited rejected the call */ | ||
57 | av_OnEnd, /* Call that was active ended */ | ||
58 | av_OnRequestTimeout, /* When the requested action didn't get response in specified time */ | ||
59 | av_OnPeerTimeout, /* Peer timed out; stop the call */ | ||
60 | av_OnPeerCSChange, /* Peer changing Csettings. Prepare for changed AV */ | ||
61 | av_OnSelfCSChange /* Csettings change confirmation. Once triggered peer is ready to recv changed AV */ | ||
62 | } ToxAvCallbackID; | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Call type identifier. | ||
67 | */ | ||
68 | typedef enum { | ||
69 | av_TypeAudio = 192, | ||
70 | av_TypeVideo | ||
71 | } ToxAvCallType; | ||
72 | |||
73 | |||
74 | typedef enum { | ||
75 | av_CallNonExistent = -1, | ||
76 | av_CallInviting, /* when sending call invite */ | ||
77 | av_CallStarting, /* when getting call invite */ | ||
78 | av_CallActive, | ||
79 | av_CallHold, | ||
80 | av_CallHungUp | ||
81 | } ToxAvCallState; | ||
82 | |||
83 | /** | ||
84 | * Error indicators. Values under -20 are reserved for toxcore. | ||
85 | */ | ||
86 | typedef enum { | ||
87 | av_ErrorNone = 0, | ||
88 | av_ErrorUnknown = -1, /* Unknown error */ | ||
89 | av_ErrorNoCall = -20, /* Trying to perform call action while not in a call */ | ||
90 | av_ErrorInvalidState = -21, /* Trying to perform call action while in invalid state*/ | ||
91 | av_ErrorAlreadyInCallWithPeer = -22, /* Trying to call peer when already in a call with peer */ | ||
92 | av_ErrorReachedCallLimit = -23, /* Cannot handle more calls */ | ||
93 | av_ErrorInitializingCodecs = -30, /* Failed creating CSSession */ | ||
94 | av_ErrorSettingVideoResolution = -31, /* Error setting resolution */ | ||
95 | av_ErrorSettingVideoBitrate = -32, /* Error setting bitrate */ | ||
96 | av_ErrorSplittingVideoPayload = -33, /* Error splitting video payload */ | ||
97 | av_ErrorEncodingVideo = -34, /* vpx_codec_encode failed */ | ||
98 | av_ErrorEncodingAudio = -35, /* opus_encode failed */ | ||
99 | av_ErrorSendingPayload = -40, /* Sending lossy packet failed */ | ||
100 | av_ErrorCreatingRtpSessions = -41, /* One of the rtp sessions failed to initialize */ | ||
101 | av_ErrorNoRtpSession = -50, /* Trying to perform rtp action on invalid session */ | ||
102 | av_ErrorInvalidCodecState = -51, /* Codec state not initialized */ | ||
103 | av_ErrorPacketTooLarge = -52, /* Split packet exceeds it's limit */ | ||
104 | } ToxAvError; | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Locally supported capabilities. | ||
109 | */ | ||
110 | typedef enum { | ||
111 | av_AudioEncoding = 1 << 0, | ||
112 | av_AudioDecoding = 1 << 1, | ||
113 | av_VideoEncoding = 1 << 2, | ||
114 | av_VideoDecoding = 1 << 3 | ||
115 | } ToxAvCapabilities; | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Encoding settings. | ||
120 | */ | ||
121 | typedef struct _ToxAvCSettings { | ||
122 | ToxAvCallType call_type; | ||
123 | |||
124 | uint32_t video_bitrate; /* In kbits/s */ | ||
125 | uint16_t max_video_width; /* In px */ | ||
126 | uint16_t max_video_height; /* In px */ | ||
127 | |||
128 | uint32_t audio_bitrate; /* In bits/s */ | ||
129 | uint16_t audio_frame_duration; /* In ms */ | ||
130 | uint32_t audio_sample_rate; /* In Hz */ | ||
131 | uint32_t audio_channels; | ||
132 | } ToxAvCSettings; | ||
133 | |||
134 | extern const ToxAvCSettings av_DefaultSettings; | ||
135 | |||
136 | /** | ||
137 | * Start new A/V session. There can only be one session at the time. | ||
138 | */ | ||
139 | ToxAv *toxav_new(Tox *messenger, int32_t max_calls); | ||
140 | |||
141 | /** | ||
142 | * Remove A/V session. | ||
143 | */ | ||
144 | void toxav_kill(ToxAv *av); | ||
145 | |||
146 | /** | ||
147 | * Returns the interval in milliseconds when the next toxav_do() should be called. | ||
148 | * If no call is active at the moment returns 200. | ||
149 | */ | ||
150 | uint32_t toxav_do_interval(ToxAv *av); | ||
151 | |||
152 | /** | ||
153 | * Main loop for the session. Best called right after tox_do(); | ||
154 | */ | ||
155 | void toxav_do(ToxAv *av); | ||
156 | |||
157 | /** | ||
158 | * Register callback for call state. | ||
159 | */ | ||
160 | void toxav_register_callstate_callback (ToxAv *av, ToxAVCallback cb, ToxAvCallbackID id, void *userdata); | ||
161 | |||
162 | /** | ||
163 | * Register callback for audio data. | ||
164 | */ | ||
165 | void toxav_register_audio_callback (ToxAv *av, ToxAvAudioCallback cb, void *userdata); | ||
166 | |||
167 | /** | ||
168 | * Register callback for video data. | ||
169 | */ | ||
170 | void toxav_register_video_callback (ToxAv *av, ToxAvVideoCallback cb, void *userdata); | ||
171 | |||
172 | /** | ||
173 | * Call user. Use its friend_id. | ||
174 | */ | ||
175 | int toxav_call(ToxAv *av, | ||
176 | int32_t *call_index, | ||
177 | int friend_id, | ||
178 | const ToxAvCSettings *csettings, | ||
179 | int ringing_seconds); | ||
180 | |||
181 | /** | ||
182 | * Hangup active call. | ||
183 | */ | ||
184 | int toxav_hangup(ToxAv *av, int32_t call_index); | ||
185 | |||
186 | /** | ||
187 | * Answer incoming call. Pass the csettings that you will use. | ||
188 | */ | ||
189 | int toxav_answer(ToxAv *av, int32_t call_index, const ToxAvCSettings *csettings ); | ||
190 | |||
191 | /** | ||
192 | * Reject incoming call. | ||
193 | */ | ||
194 | int toxav_reject(ToxAv *av, int32_t call_index, const char *reason); | ||
195 | |||
196 | /** | ||
197 | * Cancel outgoing request. | ||
198 | */ | ||
199 | int toxav_cancel(ToxAv *av, int32_t call_index, int peer_id, const char *reason); | ||
200 | |||
201 | /** | ||
202 | * Notify peer that we are changing codec settings. | ||
203 | */ | ||
204 | int toxav_change_settings(ToxAv *av, int32_t call_index, const ToxAvCSettings *csettings); | ||
205 | |||
206 | /** | ||
207 | * Terminate transmission. Note that transmission will be | ||
208 | * terminated without informing remote peer. Usually called when we can't inform peer. | ||
209 | */ | ||
210 | int toxav_stop_call(ToxAv *av, int32_t call_index); | ||
211 | |||
212 | /** | ||
213 | * Allocates transmission data. Must be call before calling toxav_prepare_* and toxav_send_*. | ||
214 | * Also, it must be called when call is started | ||
215 | */ | ||
216 | int toxav_prepare_transmission(ToxAv *av, int32_t call_index, int support_video); | ||
217 | |||
218 | /** | ||
219 | * Clears transmission data. Call this at the end of the transmission. | ||
220 | */ | ||
221 | int toxav_kill_transmission(ToxAv *av, int32_t call_index); | ||
222 | |||
223 | /** | ||
224 | * Encode video frame. | ||
225 | */ | ||
226 | int toxav_prepare_video_frame ( ToxAv *av, | ||
227 | int32_t call_index, | ||
228 | uint8_t *dest, | ||
229 | int dest_max, | ||
230 | vpx_image_t *input); | ||
231 | |||
232 | /** | ||
233 | * Send encoded video packet. | ||
234 | */ | ||
235 | int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, uint32_t frame_size); | ||
236 | |||
237 | /** | ||
238 | * Encode audio frame. | ||
239 | */ | ||
240 | int toxav_prepare_audio_frame ( ToxAv *av, | ||
241 | int32_t call_index, | ||
242 | uint8_t *dest, | ||
243 | int dest_max, | ||
244 | const int16_t *frame, | ||
245 | int frame_size); | ||
246 | |||
247 | /** | ||
248 | * Send encoded audio frame. | ||
249 | */ | ||
250 | int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, unsigned int size); | ||
251 | |||
252 | /** | ||
253 | * Get codec settings from the peer. These were exchanged during call initialization | ||
254 | * or when peer send us new csettings. | ||
255 | */ | ||
256 | int toxav_get_peer_csettings ( ToxAv *av, int32_t call_index, int peer, ToxAvCSettings *dest ); | ||
257 | |||
258 | /** | ||
259 | * Get friend id of peer participating in conversation. | ||
260 | */ | ||
261 | int toxav_get_peer_id ( ToxAv *av, int32_t call_index, int peer ); | ||
262 | |||
263 | /** | ||
264 | * Get current call state. | ||
265 | */ | ||
266 | ToxAvCallState toxav_get_call_state ( ToxAv *av, int32_t call_index ); | ||
267 | |||
268 | /** | ||
269 | * Is certain capability supported. Used to determine if encoding/decoding is ready. | ||
270 | */ | ||
271 | int toxav_capability_supported ( ToxAv *av, int32_t call_index, ToxAvCapabilities capability ); | ||
272 | |||
273 | /** | ||
274 | * Returns tox reference. | ||
275 | */ | ||
276 | Tox *toxav_get_tox (ToxAv *av); | ||
277 | |||
278 | /** | ||
279 | * Returns number of active calls or -1 on error. | ||
280 | */ | ||
281 | int toxav_get_active_count (ToxAv *av); | ||
282 | |||
283 | /* Create a new toxav group. | ||
284 | * | ||
285 | * return group number on success. | ||
286 | * return -1 on failure. | ||
287 | * | ||
288 | * Audio data callback format: | ||
289 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | ||
290 | * | ||
291 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
292 | */ | ||
293 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(Tox *, int, int, const int16_t *, unsigned int, uint8_t, | ||
294 | unsigned int, void *), void *userdata); | ||
295 | |||
296 | /* Join a AV group (you need to have been invited first.) | ||
297 | * | ||
298 | * returns group number on success | ||
299 | * returns -1 on failure. | ||
300 | * | ||
301 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | ||
302 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | ||
303 | * | ||
304 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
305 | */ | ||
306 | int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, | ||
307 | void (*audio_callback)(Tox *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata); | ||
308 | |||
309 | /* Send audio to the group chat. | ||
310 | * | ||
311 | * return 0 on success. | ||
312 | * return -1 on failure. | ||
313 | * | ||
314 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
315 | * | ||
316 | * Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000) | ||
317 | * Valid number of channels are 1 or 2. | ||
318 | * Valid sample rates are 8000, 12000, 16000, 24000, or 48000. | ||
319 | * | ||
320 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 | ||
321 | */ | ||
322 | int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | ||
323 | unsigned int sample_rate); | ||
324 | |||
325 | #ifdef __cplusplus | ||
326 | } | ||
327 | #endif | ||
328 | |||
329 | #endif /* __TOXAV */ | ||