summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--other/apidsl/toxav.in.h625
1 files changed, 625 insertions, 0 deletions
diff --git a/other/apidsl/toxav.in.h b/other/apidsl/toxav.in.h
new file mode 100644
index 00000000..9de1e184
--- /dev/null
+++ b/other/apidsl/toxav.in.h
@@ -0,0 +1,625 @@
1%{
2/* toxav.h
3 *
4 * Copyright (C) 2013-2015 Tox project All Rights Reserved.
5 *
6 * This file is part of Tox.
7 *
8 * Tox is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Tox is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef TOXAV_H
24#define TOXAV_H
25
26#include <stdbool.h>
27#include <stddef.h>
28#include <stdint.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33%}
34
35/** \page av Public audio/video API for Tox clients.
36 *
37 * This API can handle multiple calls. Each call has its state, in very rare
38 * occasions the library can change the state of the call without apps knowledge.
39 *
40 */
41
42/** \subsection events Events and callbacks
43 *
44 * As in Core API, events are handled by callbacks. One callback can be
45 * registered per event. All events have a callback function type named
46 * `toxav_{event}_cb` and a function to register it named `tox_callback_{event}`.
47 * Passing a NULL callback will result in no callback being registered for that
48 * event. Only one callback per event can be registered, so if a client needs
49 * multiple event listeners, it needs to implement the dispatch functionality
50 * itself. Unlike Core API, lack of some event handlers will cause the the
51 * library to drop calls before they are started. Hanging up call from a
52 * callback causes undefined behaviour.
53 *
54 */
55
56/** \subsection threading Threading implications
57 *
58 * Unlike the Core API, this API is fully thread-safe. The library will ensure
59 * the proper synchronisation of parallel calls.
60 *
61 * A common way to run ToxAV (multiple or single instance) is to have a thread,
62 * separate from tox instance thread, running a simple ${toxAV.iterate} loop,
63 * sleeping for ${toxAV.iteration_interval} * milliseconds on each iteration.
64 *
65 */
66
67/**
68 * External Tox type.
69 */
70class tox {
71 struct this;
72}
73
74/**
75 * ToxAV.
76 */
77class toxAV {
78
79/**
80 * The ToxAV instance type. Each ToxAV instance can be bound to only one Tox
81 * instance, and Tox instance can have only one ToxAV instance. One must make
82 * sure to close ToxAV instance prior closing Tox instance otherwise undefined
83 * behaviour occurs. Upon closing of ToxAV instance, all active calls will be
84 * forcibly terminated without notifying peers.
85 *
86 */
87struct this;
88/*******************************************************************************
89 *
90 * :: API version
91 *
92 ******************************************************************************/
93/**
94 * The major version number. Incremented when the API or ABI changes in an
95 * incompatible way.
96 */
97#define TOXAV_VERSION_MAJOR 0u
98/**
99 * The minor version number. Incremented when functionality is added without
100 * breaking the API or ABI. Set to 0 when the major version number is
101 * incremented.
102 */
103#define TOXAV_VERSION_MINOR 0u
104/**
105 * The patch or revision number. Incremented when bugfixes are applied without
106 * changing any functionality or API or ABI.
107 */
108#define TOXAV_VERSION_PATCH 0u
109
110/**
111 * A macro to check at preprocessing time whether the client code is compatible
112 * with the installed version of ToxAV.
113 */
114#define TOXAV_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
115 (TOXAV_VERSION_MAJOR == MAJOR && \
116 (TOXAV_VERSION_MINOR > MINOR || \
117 (TOXAV_VERSION_MINOR == MINOR && \
118 TOXAV_VERSION_PATCH >= PATCH)))
119
120/**
121 * A macro to make compilation fail if the client code is not compatible with
122 * the installed version of ToxAV.
123 */
124#define TOXAV_VERSION_REQUIRE(MAJOR, MINOR, PATCH) \
125 typedef char toxav_required_version[TOXAV_IS_COMPATIBLE(MAJOR, MINOR, PATCH) ? 1 : -1]
126
127/**
128 * A convenience macro to call ${version.is_compatible} with the currently
129 * compiling API version.
130 */
131#define TOXAV_VERSION_IS_ABI_COMPATIBLE() \
132 toxav_version_is_compatible(TOXAV_VERSION_MAJOR, TOXAV_VERSION_MINOR, TOXAV_VERSION_PATCH)
133
134
135static namespace version {
136
137 /**
138 * Return the major version number of the library. Can be used to display the
139 * ToxAV library version or to check whether the client is compatible with the
140 * dynamically linked version of ToxAV.
141 */
142 uint32_t major();
143
144 /**
145 * Return the minor version number of the library.
146 */
147 uint32_t minor();
148
149 /**
150 * Return the patch number of the library.
151 */
152 uint32_t patch();
153
154 /**
155 * Return whether the compiled library version is compatible with the passed
156 * version numbers.
157 */
158 bool is_compatible(uint32_t major, uint32_t minor, uint32_t patch);
159
160}
161/*******************************************************************************
162 *
163 * :: Creation and destruction
164 *
165 ******************************************************************************/
166/**
167 * Start new A/V session. There can only be only one session per Tox instance.
168 */
169static this new (tox::this *tox) {
170 NULL,
171 /**
172 * Memory allocation failure while trying to allocate structures required for
173 * the A/V session.
174 */
175 MALLOC,
176 /**
177 * Attempted to create a second session for the same Tox instance.
178 */
179 MULTIPLE,
180}
181/**
182 * Releases all resources associated with the A/V session.
183 *
184 * If any calls were ongoing, these will be forcibly terminated without
185 * notifying peers. After calling this function, no other functions may be
186 * called and the av pointer becomes invalid.
187 */
188void kill();
189/**
190 * Returns the Tox instance the A/V object was created for.
191 */
192tox::this *tox { get(); }
193/*******************************************************************************
194 *
195 * :: A/V event loop
196 *
197 ******************************************************************************/
198/**
199 * Returns the interval in milliseconds when the next toxav_iterate call should
200 * be. If no call is active at the moment, this function returns 200.
201 */
202const uint32_t iteration_interval();
203/**
204 * Main loop for the session. This function needs to be called in intervals of
205 * toxav_iteration_interval() milliseconds. It is best called in the separate
206 * thread from tox_iterate.
207 */
208void iterate();
209/*******************************************************************************
210 *
211 * :: Call setup
212 *
213 ******************************************************************************/
214/**
215 * Call a friend. This will start ringing the friend.
216 *
217 * It is the client's responsibility to stop ringing after a certain timeout,
218 * if such behaviour is desired. If the client does not stop ringing, the
219 * library will not stop until the friend is disconnected.
220 *
221 * @param friend_number The friend number of the friend that should be called.
222 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
223 * audio sending.
224 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
225 * video sending.
226 */
227bool call(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) {
228 /**
229 * A resource allocation error occurred while trying to create the structures
230 * required for the call.
231 */
232 MALLOC,
233 /**
234 * The friend number did not designate a valid friend.
235 */
236 FRIEND_NOT_FOUND,
237 /**
238 * The friend was valid, but not currently connected.
239 */
240 FRIEND_NOT_CONNECTED,
241 /**
242 * Attempted to call a friend while already in an audio or video call with
243 * them.
244 */
245 FRIEND_ALREADY_IN_CALL,
246 /**
247 * Audio or video bit rate is invalid.
248 */
249 INVALID_BIT_RATE,
250}
251event call {
252 /**
253 * The function type for the ${event call} callback.
254 *
255 * @param friend_number The friend number from which the call is incoming.
256 * @param audio_enabled True if friend is sending audio.
257 * @param video_enabled True if friend is sending video.
258 */
259 typedef void(uint32_t friend_number, bool audio_enabled, bool video_enabled);
260}
261/**
262 * Accept an incoming call.
263 *
264 * If answering fails for any reason, the call will still be pending and it is
265 * possible to try and answer it later.
266 *
267 * @param friend_number The friend number of the friend that is calling.
268 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
269 * audio sending.
270 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
271 * video sending.
272 */
273bool answer(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) {
274 /**
275 * Failed to initialize codecs for call session. Note that codec initiation
276 * will fail if there is no receive callback registered for either audio or
277 * video.
278 */
279 CODEC_INITIALIZATION,
280 /**
281 * The friend number did not designate a valid friend.
282 */
283 FRIEND_NOT_FOUND,
284 /**
285 * The friend was valid, but they are not currently trying to initiate a call.
286 * This is also returned if this client is already in a call with the friend.
287 */
288 FRIEND_NOT_CALLING,
289 /**
290 * Audio or video bit rate is invalid.
291 */
292 INVALID_BIT_RATE,
293}
294/*******************************************************************************
295 *
296 * :: Call state graph
297 *
298 ******************************************************************************/
299bitmask CALL_STATE {
300 /**
301 * Set by the AV core if an error occurred on the remote end or if friend
302 * timed out. This is the final state after which no more state
303 * transitions can occur for the call. This call state will never be triggered
304 * in combination with other call states.
305 */
306 ERROR,
307 /**
308 * The call has finished. This is the final state after which no more state
309 * transitions can occur for the call. This call state will never be
310 * triggered in combination with other call states.
311 */
312 FINISHED,
313 /**
314 * The flag that marks that friend is sending audio.
315 */
316 SENDING_A,
317 /**
318 * The flag that marks that friend is sending video.
319 */
320 SENDING_V,
321 /**
322 * The flag that marks that friend is receiving audio.
323 */
324 RECEIVING_A,
325 /**
326 * The flag that marks that friend is receiving video.
327 */
328 RECEIVING_V,
329}
330event call_state {
331 /**
332 * The function type for the ${event call_state} callback.
333 *
334 * @param friend_number The friend number for which the call state changed.
335 * @param state The new call state which is guaranteed to be different than
336 * the previous state. The state is set to 0 when the call is paused.
337 */
338 typedef void(uint32_t friend_number, uint32_t state);
339}
340/*******************************************************************************
341 *
342 * :: Call control
343 *
344 ******************************************************************************/
345enum class CALL_CONTROL {
346 /**
347 * Resume a previously paused call. Only valid if the pause was caused by this
348 * client, if not, this control is ignored. Not valid before the call is accepted.
349 */
350 RESUME,
351 /**
352 * Put a call on hold. Not valid before the call is accepted.
353 */
354 PAUSE,
355 /**
356 * Reject a call if it was not answered, yet. Cancel a call after it was
357 * answered.
358 */
359 CANCEL,
360 /**
361 * Request that the friend stops sending audio. Regardless of the friend's
362 * compliance, this will cause the ${event audio.receive_frame} event to stop being
363 * triggered on receiving an audio frame from the friend.
364 */
365 MUTE_AUDIO,
366 /**
367 * Calling this control will notify client to start sending audio again.
368 */
369 UNMUTE_AUDIO,
370 /**
371 * Request that the friend stops sending video. Regardless of the friend's
372 * compliance, this will cause the ${event video.receive_frame} event to stop being
373 * triggered on receiving an video frame from the friend.
374 */
375 HIDE_VIDEO,
376 /**
377 * Calling this control will notify client to start sending video again.
378 */
379 SHOW_VIDEO,
380}
381/**
382 * Sends a call control command to a friend.
383 *
384 * @param friend_number The friend number of the friend this client is in a call
385 * with.
386 * @param control The control command to send.
387 *
388 * @return true on success.
389 */
390bool call_control (uint32_t friend_number, CALL_CONTROL control) {
391 /**
392 * The friend_number passed did not designate a valid friend.
393 */
394 FRIEND_NOT_FOUND,
395 /**
396 * This client is currently not in a call with the friend. Before the call is
397 * answered, only CANCEL is a valid control.
398 */
399 FRIEND_NOT_IN_CALL,
400 /**
401 * Happens if user tried to pause an already paused call or if trying to
402 * resume a call that is not paused.
403 */
404 INVALID_TRANSITION,
405}
406/*******************************************************************************
407 *
408 * :: Controlling bit rates
409 *
410 ******************************************************************************/
411error for set_bit_rate {
412 /**
413 * The bit rate passed was not one of the supported values.
414 */
415 INVALID,
416 /**
417 * The friend_number passed did not designate a valid friend.
418 */
419 FRIEND_NOT_FOUND,
420 /**
421 * This client is currently not in a call with the friend.
422 */
423 FRIEND_NOT_IN_CALL,
424}
425namespace audio {
426 namespace bit_rate {
427 event status {
428 /**
429 * The function type for the ${event status} callback.
430 *
431 * @param friend_number The friend number of the friend for which to set the
432 * audio bit rate.
433 * @param stable Is the stream stable enough to keep the bit rate.
434 * Upon successful, non forceful, bit rate change, this is set to
435 * true and 'bit_rate' is set to new bit rate.
436 * The stable is set to false with bit_rate set to the unstable
437 * bit rate when either current stream is unstable with said bit rate
438 * or the non forceful change failed.
439 * @param bit_rate The bit rate in Kb/sec.
440 */
441 typedef void(uint32_t friend_number, bool stable, uint32_t bit_rate);
442 }
443 /**
444 * Set the audio bit rate to be used in subsequent audio frames. If the passed
445 * bit rate is the same as the current bit rate this function will return true
446 * without calling a callback. If there is an active non forceful setup with the
447 * passed audio bit rate and the new set request is forceful, the bit rate is
448 * forcefully set and the previous non forceful request is cancelled. The active
449 * non forceful setup will be canceled in favour of new non forceful setup.
450 *
451 * @param friend_number The friend number of the friend for which to set the
452 * audio bit rate.
453 * @param audio_bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable
454 * audio sending.
455 * @param force True if the bit rate change is forceful.
456 *
457 */
458 bool set(uint32_t friend_number, uint32_t audio_bit_rate, bool force) with error for set_bit_rate;
459 }
460}
461namespace video {
462 namespace bit_rate {
463 event status {
464 /**
465 * The function type for the ${event status} callback.
466 *
467 * @param friend_number The friend number of the friend for which to set the
468 * video bit rate.
469 * @param stable Is the stream stable enough to keep the bit rate.
470 * Upon successful, non forceful, bit rate change, this is set to
471 * true and 'bit_rate' is set to new bit rate.
472 * The stable is set to false with bit_rate set to the unstable
473 * bit rate when either current stream is unstable with said bit rate
474 * or the non forceful change failed.
475 * @param bit_rate The bit rate in Kb/sec.
476 */
477 typedef void(uint32_t friend_number, bool stable, uint32_t bit_rate);
478 }
479 /**
480 * Set the video bit rate to be used in subsequent video frames. If the passed
481 * bit rate is the same as the current bit rate this function will return true
482 * without calling a callback. If there is an active non forceful setup with the
483 * passed video bit rate and the new set request is forceful, the bit rate is
484 * forcefully set and the previous non forceful request is cancelled. The active
485 * non forceful setup will be canceled in favour of new non forceful setup.
486 *
487 * @param friend_number The friend number of the friend for which to set the
488 * video bit rate.
489 * @param audio_bit_rate The new video bit rate in Kb/sec. Set to 0 to disable
490 * video sending.
491 * @param force True if the bit rate change is forceful.
492 *
493 */
494 bool set(uint32_t friend_number, uint32_t audio_bit_rate, bool force) with error for set_bit_rate;
495 }
496}
497/*******************************************************************************
498 *
499 * :: A/V sending
500 *
501 ******************************************************************************/
502error for send_frame {
503 /**
504 * In case of video, one of Y, U, or V was NULL. In case of audio, the samples
505 * data pointer was NULL.
506 */
507 NULL,
508 /**
509 * The friend_number passed did not designate a valid friend.
510 */
511 FRIEND_NOT_FOUND,
512 /**
513 * This client is currently not in a call with the friend.
514 */
515 FRIEND_NOT_IN_CALL,
516 /**
517 * One of the frame parameters was invalid. E.g. the resolution may be too
518 * small or too large, or the audio sampling rate may be unsupported.
519 */
520 INVALID,
521 /**
522 * Failed to push frame through rtp interface.
523 */
524 RTP_FAILED,
525}
526namespace audio {
527 /**
528 * Send an audio frame to a friend.
529 *
530 * The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]...
531 * Meaning: sample 1 for channel 1, sample 1 for channel 2, ...
532 * For mono audio, this has no meaning, every sample is subsequent. For stereo,
533 * this means the expected format is LRLRLR... with samples for left and right
534 * alternating.
535 *
536 * @param friend_number The friend number of the friend to which to send an
537 * audio frame.
538 * @param pcm An array of audio samples. The size of this array must be
539 * sample_count * channels.
540 * @param sample_count Number of samples in this frame. Valid numbers here are
541 * ((sample rate) * (audio length) / 1000), where audio length can be
542 * 2.5, 5, 10, 20, 40 or 60 millseconds.
543 * @param channels Number of audio channels. Supported values are 1 and 2.
544 * @param sampling_rate Audio sampling rate used in this frame. Valid sampling
545 * rates are 8000, 12000, 16000, 24000, or 48000.
546 */
547 bool send_frame(uint32_t friend_number, const int16_t *pcm, size_t sample_count,
548 uint8_t channels, uint32_t sampling_rate) with error for send_frame;
549}
550namespace video {
551 /**
552 * Send a video frame to a friend.
553 *
554 * Y - plane should be of size: height * width
555 * U - plane should be of size: (height/2) * (width/2)
556 * V - plane should be of size: (height/2) * (width/2)
557 *
558 * @param friend_number The friend number of the friend to which to send a video
559 * frame.
560 * @param width Width of the frame in pixels.
561 * @param height Height of the frame in pixels.
562 * @param y Y (Luminance) plane data.
563 * @param u U (Chroma) plane data.
564 * @param v V (Chroma) plane data.
565 * @param a A (Alpha) plane data.
566 */
567 bool send_frame(uint32_t friend_number, uint16_t width, uint16_t height,
568 const uint8_t *y, const uint8_t *u, const uint8_t *v, const uint8_t *a) with error for send_frame;
569}
570/*******************************************************************************
571 *
572 * :: A/V receiving
573 *
574 ******************************************************************************/
575namespace audio {
576 event receive_frame {
577 /**
578 * The function type for the ${event receive_frame} callback.
579 *
580 * @param friend_number The friend number of the friend who sent an audio frame.
581 * @param pcm An array of audio samples (sample_count * channels elements).
582 * @param sample_count The number of audio samples per channel in the PCM array.
583 * @param channels Number of audio channels.
584 * @param sampling_rate Sampling rate used in this frame.
585 *
586 */
587 typedef void(uint32_t friend_number, const int16_t *pcm, size_t sample_count,
588 uint8_t channels, uint32_t sampling_rate);
589 }
590}
591namespace video {
592 event receive_frame {
593 /**
594 * The function type for the ${event receive_frame} callback.
595 *
596 * @param friend_number The friend number of the friend who sent a video frame.
597 * @param width Width of the frame in pixels.
598 * @param height Height of the frame in pixels.
599 * @param y
600 * @param u
601 * @param v Plane data.
602 * The size of plane data is derived from width and height where
603 * Y = MAX(width, abs(ystride)) * height,
604 * U = MAX(width/2, abs(ustride)) * (height/2) and
605 * V = MAX(width/2, abs(vstride)) * (height/2).
606 * A = MAX(width, abs(astride)) * height.
607 * @param ystride
608 * @param ustride
609 * @param vstride
610 * @param astride Strides data. Strides represent padding for each plane
611 * that may or may not be present. You must handle strides in
612 * your image processing code. Strides are negative if the
613 * image is bottom-up hence why you MUST abs() it when
614 * calculating plane buffer size.
615 */
616 typedef void(uint32_t friend_number, uint16_t width, uint16_t height,
617 const uint8_t *y, const uint8_t *u, const uint8_t *v, const uint8_t *a,
618 int32_t ystride, int32_t ustride, int32_t vstride, int32_t astride);
619 }
620}
621
622}
623%{
624#endif
625%} \ No newline at end of file