summaryrefslogtreecommitdiff
path: root/other/apidsl/toxav.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'other/apidsl/toxav.in.h')
-rw-r--r--other/apidsl/toxav.in.h637
1 files changed, 0 insertions, 637 deletions
diff --git a/other/apidsl/toxav.in.h b/other/apidsl/toxav.in.h
deleted file mode 100644
index 6e3e9c17..00000000
--- a/other/apidsl/toxav.in.h
+++ /dev/null
@@ -1,637 +0,0 @@
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 `toxav_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 synchronization 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 * An important thing to note is that events are triggered from both tox and
66 * toxav thread (see above). Audio and video receive frame events are triggered
67 * from toxav thread while all the other events are triggered from tox thread.
68 *
69 * Tox thread has priority with mutex mechanisms. Any api function can
70 * fail if mutexes are held by tox thread in which case they will set SYNC
71 * error code.
72 */
73
74/**
75 * External Tox type.
76 */
77class tox {
78 struct this;
79}
80
81/**
82 * ToxAV.
83 */
84class toxAV {
85
86/**
87 * The ToxAV instance type. Each ToxAV instance can be bound to only one Tox
88 * instance, and Tox instance can have only one ToxAV instance. One must make
89 * sure to close ToxAV instance prior closing Tox instance otherwise undefined
90 * behaviour occurs. Upon closing of ToxAV instance, all active calls will be
91 * forcibly terminated without notifying peers.
92 *
93 */
94struct this;
95
96/*******************************************************************************
97 *
98 * :: Creation and destruction
99 *
100 ******************************************************************************/
101
102
103/**
104 * Start new A/V session. There can only be only one session per Tox instance.
105 */
106static this new(tox::this *tox) {
107 NULL,
108 /**
109 * Memory allocation failure while trying to allocate structures required for
110 * the A/V session.
111 */
112 MALLOC,
113 /**
114 * Attempted to create a second session for the same Tox instance.
115 */
116 MULTIPLE,
117}
118
119/**
120 * Releases all resources associated with the A/V session.
121 *
122 * If any calls were ongoing, these will be forcibly terminated without
123 * notifying peers. After calling this function, no other functions may be
124 * called and the av pointer becomes invalid.
125 */
126void kill();
127
128/**
129 * Returns the Tox instance the A/V object was created for.
130 */
131tox::this *tox { get(); }
132
133
134/*******************************************************************************
135 *
136 * :: A/V event loop
137 *
138 ******************************************************************************/
139
140
141/**
142 * Returns the interval in milliseconds when the next toxav_iterate call should
143 * be. If no call is active at the moment, this function returns 200.
144 */
145const uint32_t iteration_interval();
146
147/**
148 * Main loop for the session. This function needs to be called in intervals of
149 * toxav_iteration_interval() milliseconds. It is best called in the separate
150 * thread from tox_iterate.
151 */
152void iterate();
153
154
155/*******************************************************************************
156 *
157 * :: Call setup
158 *
159 ******************************************************************************/
160
161
162/**
163 * Call a friend. This will start ringing the friend.
164 *
165 * It is the client's responsibility to stop ringing after a certain timeout,
166 * if such behaviour is desired. If the client does not stop ringing, the
167 * library will not stop until the friend is disconnected. Audio and video
168 * receiving are both enabled by default.
169 *
170 * @param friend_number The friend number of the friend that should be called.
171 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
172 * audio sending.
173 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
174 * video sending.
175 */
176bool call(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) {
177 /**
178 * A resource allocation error occurred while trying to create the structures
179 * required for the call.
180 */
181 MALLOC,
182 /**
183 * Synchronization error occurred.
184 */
185 SYNC,
186 /**
187 * The friend number did not designate a valid friend.
188 */
189 FRIEND_NOT_FOUND,
190 /**
191 * The friend was valid, but not currently connected.
192 */
193 FRIEND_NOT_CONNECTED,
194 /**
195 * Attempted to call a friend while already in an audio or video call with
196 * them.
197 */
198 FRIEND_ALREADY_IN_CALL,
199 /**
200 * Audio or video bit rate is invalid.
201 */
202 INVALID_BIT_RATE,
203}
204
205event call {
206 /**
207 * The function type for the ${event call} callback.
208 *
209 * @param friend_number The friend number from which the call is incoming.
210 * @param audio_enabled True if friend is sending audio.
211 * @param video_enabled True if friend is sending video.
212 */
213 typedef void(uint32_t friend_number, bool audio_enabled, bool video_enabled);
214}
215
216/**
217 * Accept an incoming call.
218 *
219 * If answering fails for any reason, the call will still be pending and it is
220 * possible to try and answer it later. Audio and video receiving are both
221 * enabled by default.
222 *
223 * @param friend_number The friend number of the friend that is calling.
224 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
225 * audio sending.
226 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
227 * video sending.
228 */
229bool answer(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) {
230 /**
231 * Synchronization error occurred.
232 */
233 SYNC,
234 /**
235 * Failed to initialize codecs for call session. Note that codec initiation
236 * will fail if there is no receive callback registered for either audio or
237 * video.
238 */
239 CODEC_INITIALIZATION,
240 /**
241 * The friend number did not designate a valid friend.
242 */
243 FRIEND_NOT_FOUND,
244 /**
245 * The friend was valid, but they are not currently trying to initiate a call.
246 * This is also returned if this client is already in a call with the friend.
247 */
248 FRIEND_NOT_CALLING,
249 /**
250 * Audio or video bit rate is invalid.
251 */
252 INVALID_BIT_RATE,
253}
254
255
256/*******************************************************************************
257 *
258 * :: Call state graph
259 *
260 ******************************************************************************/
261
262
263bitmask FRIEND_CALL_STATE {
264 /**
265 * Set by the AV core if an error occurred on the remote end or if friend
266 * timed out. This is the final state after which no more state
267 * transitions can occur for the call. This call state will never be triggered
268 * in combination with other call states.
269 */
270 ERROR,
271 /**
272 * The call has finished. This is the final state after which no more state
273 * transitions can occur for the call. This call state will never be
274 * triggered in combination with other call states.
275 */
276 FINISHED,
277 /**
278 * The flag that marks that friend is sending audio.
279 */
280 SENDING_A,
281 /**
282 * The flag that marks that friend is sending video.
283 */
284 SENDING_V,
285 /**
286 * The flag that marks that friend is receiving audio.
287 */
288 ACCEPTING_A,
289 /**
290 * The flag that marks that friend is receiving video.
291 */
292 ACCEPTING_V,
293}
294
295event call_state {
296 /**
297 * The function type for the ${event call_state} callback.
298 *
299 * @param friend_number The friend number for which the call state changed.
300 * @param state The bitmask of the new call state which is guaranteed to be
301 * different than the previous state. The state is set to 0 when the call is
302 * paused. The bitmask represents all the activities currently performed by the
303 * friend.
304 */
305 typedef void(uint32_t friend_number, uint32_t state);
306}
307
308
309/*******************************************************************************
310 *
311 * :: Call control
312 *
313 ******************************************************************************/
314
315
316enum class CALL_CONTROL {
317 /**
318 * Resume a previously paused call. Only valid if the pause was caused by this
319 * client, if not, this control is ignored. Not valid before the call is accepted.
320 */
321 RESUME,
322 /**
323 * Put a call on hold. Not valid before the call is accepted.
324 */
325 PAUSE,
326 /**
327 * Reject a call if it was not answered, yet. Cancel a call after it was
328 * answered.
329 */
330 CANCEL,
331 /**
332 * Request that the friend stops sending audio. Regardless of the friend's
333 * compliance, this will cause the ${event audio.receive_frame} event to stop being
334 * triggered on receiving an audio frame from the friend.
335 */
336 MUTE_AUDIO,
337 /**
338 * Calling this control will notify client to start sending audio again.
339 */
340 UNMUTE_AUDIO,
341 /**
342 * Request that the friend stops sending video. Regardless of the friend's
343 * compliance, this will cause the ${event video.receive_frame} event to stop being
344 * triggered on receiving a video frame from the friend.
345 */
346 HIDE_VIDEO,
347 /**
348 * Calling this control will notify client to start sending video again.
349 */
350 SHOW_VIDEO,
351}
352
353/**
354 * Sends a call control command to a friend.
355 *
356 * @param friend_number The friend number of the friend this client is in a call
357 * with.
358 * @param control The control command to send.
359 *
360 * @return true on success.
361 */
362bool call_control(uint32_t friend_number, CALL_CONTROL control) {
363 /**
364 * Synchronization error occurred.
365 */
366 SYNC,
367 /**
368 * The friend_number passed did not designate a valid friend.
369 */
370 FRIEND_NOT_FOUND,
371 /**
372 * This client is currently not in a call with the friend. Before the call is
373 * answered, only CANCEL is a valid control.
374 */
375 FRIEND_NOT_IN_CALL,
376 /**
377 * Happens if user tried to pause an already paused call or if trying to
378 * resume a call that is not paused.
379 */
380 INVALID_TRANSITION,
381}
382
383
384/*******************************************************************************
385 *
386 * :: Controlling bit rates
387 *
388 ******************************************************************************/
389
390
391namespace bit_rate {
392 /**
393 * Set the bit rate to be used in subsequent audio/video frames.
394 *
395 * @param friend_number The friend number of the friend for which to set the
396 * bit rate.
397 * @param audio_bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable
398 * audio sending. Set to -1 to leave unchanged.
399 * @param video_bit_rate The new video bit rate in Kb/sec. Set to 0 to disable
400 * video sending. Set to -1 to leave unchanged.
401 *
402 */
403 bool set(uint32_t friend_number, int32_t audio_bit_rate, int32_t video_bit_rate) {
404 /**
405 * Synchronization error occurred.
406 */
407 SYNC,
408 /**
409 * The audio bit rate passed was not one of the supported values.
410 */
411 INVALID_AUDIO_BIT_RATE,
412 /**
413 * The video bit rate passed was not one of the supported values.
414 */
415 INVALID_VIDEO_BIT_RATE,
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 }
425
426 event status {
427 /**
428 * The function type for the ${event status} callback. The event is triggered
429 * when the network becomes too saturated for current bit rates at which
430 * point core suggests new bit rates.
431 *
432 * @param friend_number The friend number of the friend for which to set the
433 * bit rate.
434 * @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec.
435 * @param video_bit_rate Suggested maximum video bit rate in Kb/sec.
436 */
437 typedef void(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate);
438 }
439}
440
441
442/*******************************************************************************
443 *
444 * :: A/V sending
445 *
446 ******************************************************************************/
447
448
449error for send_frame {
450 /**
451 * In case of video, one of Y, U, or V was NULL. In case of audio, the samples
452 * data pointer was NULL.
453 */
454 NULL,
455 /**
456 * The friend_number passed did not designate a valid friend.
457 */
458 FRIEND_NOT_FOUND,
459 /**
460 * This client is currently not in a call with the friend.
461 */
462 FRIEND_NOT_IN_CALL,
463 /**
464 * Synchronization error occurred.
465 */
466 SYNC,
467 /**
468 * One of the frame parameters was invalid. E.g. the resolution may be too
469 * small or too large, or the audio sampling rate may be unsupported.
470 */
471 INVALID,
472 /**
473 * Either friend turned off audio or video receiving or we turned off sending
474 * for the said payload.
475 */
476 PAYLOAD_TYPE_DISABLED,
477 /**
478 * Failed to push frame through rtp interface.
479 */
480 RTP_FAILED,
481}
482
483namespace audio {
484 /**
485 * Send an audio frame to a friend.
486 *
487 * The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]...
488 * Meaning: sample 1 for channel 1, sample 1 for channel 2, ...
489 * For mono audio, this has no meaning, every sample is subsequent. For stereo,
490 * this means the expected format is LRLRLR... with samples for left and right
491 * alternating.
492 *
493 * @param friend_number The friend number of the friend to which to send an
494 * audio frame.
495 * @param pcm An array of audio samples. The size of this array must be
496 * sample_count * channels.
497 * @param sample_count Number of samples in this frame. Valid numbers here are
498 * ((sample rate) * (audio length) / 1000), where audio length can be
499 * 2.5, 5, 10, 20, 40 or 60 millseconds.
500 * @param channels Number of audio channels. Supported values are 1 and 2.
501 * @param sampling_rate Audio sampling rate used in this frame. Valid sampling
502 * rates are 8000, 12000, 16000, 24000, or 48000.
503 */
504 bool send_frame(uint32_t friend_number, const int16_t *pcm, size_t sample_count,
505 uint8_t channels, uint32_t sampling_rate) with error for send_frame;
506}
507
508namespace video {
509 /**
510 * Send a video frame to a friend.
511 *
512 * Y - plane should be of size: height * width
513 * U - plane should be of size: (height/2) * (width/2)
514 * V - plane should be of size: (height/2) * (width/2)
515 *
516 * @param friend_number The friend number of the friend to which to send a video
517 * frame.
518 * @param width Width of the frame in pixels.
519 * @param height Height of the frame in pixels.
520 * @param y Y (Luminance) plane data.
521 * @param u U (Chroma) plane data.
522 * @param v V (Chroma) plane data.
523 */
524 bool send_frame(uint32_t friend_number, uint16_t width, uint16_t height,
525 const uint8_t *y, const uint8_t *u, const uint8_t *v) with error for send_frame;
526}
527
528
529/*******************************************************************************
530 *
531 * :: A/V receiving
532 *
533 ******************************************************************************/
534
535
536namespace audio {
537 event receive_frame {
538 /**
539 * The function type for the ${event receive_frame} callback. The callback can be
540 * called multiple times per single iteration depending on the amount of queued
541 * frames in the buffer. The received format is the same as in send function.
542 *
543 * @param friend_number The friend number of the friend who sent an audio frame.
544 * @param pcm An array of audio samples (sample_count * channels elements).
545 * @param sample_count The number of audio samples per channel in the PCM array.
546 * @param channels Number of audio channels.
547 * @param sampling_rate Sampling rate used in this frame.
548 *
549 */
550 typedef void(uint32_t friend_number, const int16_t *pcm, size_t sample_count,
551 uint8_t channels, uint32_t sampling_rate);
552 }
553}
554
555namespace video {
556 event receive_frame {
557 /**
558 * The function type for the ${event receive_frame} callback.
559 *
560 * The size of plane data is derived from width and height as documented
561 * below.
562 *
563 * Strides represent padding for each plane that may or may not be present.
564 * You must handle strides in your image processing code. Strides are
565 * negative if the image is bottom-up hence why you MUST abs() it when
566 * calculating plane buffer size.
567 *
568 * @param friend_number The friend number of the friend who sent a video frame.
569 * @param width Width of the frame in pixels.
570 * @param height Height of the frame in pixels.
571 * @param y Luminosity plane. Size = MAX(width, abs(ystride)) * height.
572 * @param u U chroma plane. Size = MAX(width/2, abs(ustride)) * (height/2).
573 * @param v V chroma plane. Size = MAX(width/2, abs(vstride)) * (height/2).
574 *
575 * @param ystride Luminosity plane stride.
576 * @param ustride U chroma plane stride.
577 * @param vstride V chroma plane stride.
578 */
579 typedef void(uint32_t friend_number, uint16_t width, uint16_t height,
580 const uint8_t *y, const uint8_t *u, const uint8_t *v,
581 int32_t ystride, int32_t ustride, int32_t vstride);
582 }
583}
584
585}
586
587%{
588/**
589 * NOTE Compatibility with old toxav group calls. TODO(iphydf): remove
590 */
591/* Create a new toxav group.
592 *
593 * return group number on success.
594 * return -1 on failure.
595 *
596 * Audio data callback format:
597 * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata)
598 *
599 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
600 */
601int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t,
602 unsigned int, void *), void *userdata);
603
604/* Join a AV group (you need to have been invited first.)
605 *
606 * returns group number on success
607 * returns -1 on failure.
608 *
609 * Audio data callback format (same as the one for toxav_add_av_groupchat()):
610 * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata)
611 *
612 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
613 */
614int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length,
615 void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata);
616
617/* Send audio to the group chat.
618 *
619 * return 0 on success.
620 * return -1 on failure.
621 *
622 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
623 *
624 * Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000)
625 * Valid number of channels are 1 or 2.
626 * Valid sample rates are 8000, 12000, 16000, 24000, or 48000.
627 *
628 * Recommended values are: samples = 960, channels = 1, sample_rate = 48000
629 */
630int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
631 unsigned int sample_rate);
632
633#ifdef __cplusplus
634}
635#endif
636#endif /* TOXAV_H */
637%}