diff options
Diffstat (limited to 'protocols/Tox/include/toxav.h')
-rw-r--r-- | protocols/Tox/include/toxav.h | 274 |
1 files changed, 148 insertions, 126 deletions
diff --git a/protocols/Tox/include/toxav.h b/protocols/Tox/include/toxav.h index ea58625403..2e48d599ef 100644 --- a/protocols/Tox/include/toxav.h +++ b/protocols/Tox/include/toxav.h @@ -1,8 +1,8 @@ -/* toxav.h +/* + * Copyright © 2016-2017 The TokTok team. + * Copyright © 2013-2015 Tox project. * - * Copyright (C) 2013-2015 Tox project All Rights Reserved. - * - * This file is part of Tox. + * This file is part of Tox, the free peer to peer instant messenger. * * Tox is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,14 +15,12 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Tox. If not, see <http://www.gnu.org/licenses/>. - * + * along with Tox. If not, see <http://www.gnu.org/licenses/>. */ - #ifndef TOXAV_H #define TOXAV_H -//#include <stdbool.h> +#include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -93,101 +91,38 @@ typedef struct ToxAV ToxAV; /******************************************************************************* * - * :: API version + * :: Creation and destruction * ******************************************************************************/ -/** - * The major version number. Incremented when the API or ABI changes in an - * incompatible way. - */ -#define TOXAV_VERSION_MAJOR 0u - -/** - * The minor version number. Incremented when functionality is added without - * breaking the API or ABI. Set to 0 when the major version number is - * incremented. - */ -#define TOXAV_VERSION_MINOR 0u -/** - * The patch or revision number. Incremented when bugfixes are applied without - * changing any functionality or API or ABI. - */ -#define TOXAV_VERSION_PATCH 0u -/** - * A macro to check at preprocessing time whether the client code is compatible - * with the installed version of ToxAV. - */ -#define TOXAV_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ - (TOXAV_VERSION_MAJOR == MAJOR && \ - (TOXAV_VERSION_MINOR > MINOR || \ - (TOXAV_VERSION_MINOR == MINOR && \ - TOXAV_VERSION_PATCH >= PATCH))) -/** - * A macro to make compilation fail if the client code is not compatible with - * the installed version of ToxAV. - */ -#define TOXAV_VERSION_REQUIRE(MAJOR, MINOR, PATCH) \ - typedef char toxav_required_version[TOXAV_IS_COMPATIBLE(MAJOR, MINOR, PATCH) ? 1 : -1] - -/** - * A convenience macro to call toxav_version_is_compatible with the currently - * compiling API version. - */ -#define TOXAV_VERSION_IS_ABI_COMPATIBLE() \ - toxav_version_is_compatible(TOXAV_VERSION_MAJOR, TOXAV_VERSION_MINOR, TOXAV_VERSION_PATCH) - -/** - * Return the major version number of the library. Can be used to display the - * ToxAV library version or to check whether the client is compatible with the - * dynamically linked version of ToxAV. - */ -uint32_t toxav_version_major(void); - -/** - * Return the minor version number of the library. - */ -uint32_t toxav_version_minor(void); - -/** - * Return the patch number of the library. - */ -uint32_t toxav_version_patch(void); - -/** - * Return whether the compiled library version is compatible with the passed - * version numbers. - */ -bool toxav_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); - - -/******************************************************************************* - * - * :: Creation and destruction - * - ******************************************************************************/ typedef enum TOXAV_ERR_NEW { + /** * The function returned successfully. */ TOXAV_ERR_NEW_OK, + /** * One of the arguments to the function was NULL when it was not expected. */ TOXAV_ERR_NEW_NULL, + /** * Memory allocation failure while trying to allocate structures required for * the A/V session. */ TOXAV_ERR_NEW_MALLOC, + /** * Attempted to create a second session for the same Tox instance. */ TOXAV_ERR_NEW_MULTIPLE, + } TOXAV_ERR_NEW; + /** * Start new A/V session. There can only be only one session per Tox instance. */ @@ -200,12 +135,12 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error); * notifying peers. After calling this function, no other functions may be * called and the av pointer becomes invalid. */ -void toxav_kill(ToxAV *toxAV); +void toxav_kill(ToxAV *av); /** * Returns the Tox instance the A/V object was created for. */ -Tox *toxav_get_tox(const ToxAV *toxAV); +Tox *toxav_get_tox(const ToxAV *av); /******************************************************************************* @@ -213,18 +148,21 @@ Tox *toxav_get_tox(const ToxAV *toxAV); * :: A/V event loop * ******************************************************************************/ + + + /** * Returns the interval in milliseconds when the next toxav_iterate call should * be. If no call is active at the moment, this function returns 200. */ -uint32_t toxav_iteration_interval(const ToxAV *toxAV); +uint32_t toxav_iteration_interval(const ToxAV *av); /** * Main loop for the session. This function needs to be called in intervals of * toxav_iteration_interval() milliseconds. It is best called in the separate * thread from tox_iterate. */ -void toxav_iterate(ToxAV *toxAV); +void toxav_iterate(ToxAV *av); /******************************************************************************* @@ -232,39 +170,51 @@ void toxav_iterate(ToxAV *toxAV); * :: Call setup * ******************************************************************************/ + + + typedef enum TOXAV_ERR_CALL { + /** * The function returned successfully. */ TOXAV_ERR_CALL_OK, + /** * A resource allocation error occurred while trying to create the structures * required for the call. */ TOXAV_ERR_CALL_MALLOC, + /** * Synchronization error occurred. */ TOXAV_ERR_CALL_SYNC, + /** * The friend number did not designate a valid friend. */ TOXAV_ERR_CALL_FRIEND_NOT_FOUND, + /** * The friend was valid, but not currently connected. */ TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED, + /** * Attempted to call a friend while already in an audio or video call with * them. */ TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL, + /** * Audio or video bit rate is invalid. */ TOXAV_ERR_CALL_INVALID_BIT_RATE, + } TOXAV_ERR_CALL; + /** * Call a friend. This will start ringing the friend. * @@ -279,8 +229,8 @@ typedef enum TOXAV_ERR_CALL { * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable * video sending. */ -bool toxav_call(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, - uint32_t video_bit_rate, TOXAV_ERR_CALL *error); +bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, + TOXAV_ERR_CALL *error); /** * The function type for the call callback. @@ -289,45 +239,53 @@ bool toxav_call(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, * @param audio_enabled True if friend is sending audio. * @param video_enabled True if friend is sending video. */ -typedef void toxav_call_cb(ToxAV *toxAV, uint32_t friend_number, bool audio_enabled, - bool video_enabled, void *user_data); +typedef void toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data); + /** * Set the callback for the `call` event. Pass NULL to unset. * */ -void toxav_callback_call(ToxAV *toxAV, toxav_call_cb *callback, void *user_data); +void toxav_callback_call(ToxAV *av, toxav_call_cb *callback, void *user_data); typedef enum TOXAV_ERR_ANSWER { + /** * The function returned successfully. */ TOXAV_ERR_ANSWER_OK, + /** * Synchronization error occurred. */ TOXAV_ERR_ANSWER_SYNC, + /** * Failed to initialize codecs for call session. Note that codec initiation * will fail if there is no receive callback registered for either audio or * video. */ TOXAV_ERR_ANSWER_CODEC_INITIALIZATION, + /** * The friend number did not designate a valid friend. */ TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND, + /** * The friend was valid, but they are not currently trying to initiate a call. * This is also returned if this client is already in a call with the friend. */ TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING, + /** * Audio or video bit rate is invalid. */ TOXAV_ERR_ANSWER_INVALID_BIT_RATE, + } TOXAV_ERR_ANSWER; + /** * Accept an incoming call. * @@ -341,7 +299,7 @@ typedef enum TOXAV_ERR_ANSWER { * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable * video sending. */ -bool toxav_answer(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, +bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_ANSWER *error); @@ -350,7 +308,16 @@ bool toxav_answer(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, * :: Call state graph * ******************************************************************************/ + + + enum TOXAV_FRIEND_CALL_STATE { + + /** + * The empty bit mask. None of the bits specified below are set. + */ + TOXAV_FRIEND_CALL_STATE_NONE = 0, + /** * Set by the AV core if an error occurred on the remote end or if friend * timed out. This is the final state after which no more state @@ -358,30 +325,37 @@ enum TOXAV_FRIEND_CALL_STATE { * in combination with other call states. */ TOXAV_FRIEND_CALL_STATE_ERROR = 1, + /** * The call has finished. This is the final state after which no more state * transitions can occur for the call. This call state will never be * triggered in combination with other call states. */ TOXAV_FRIEND_CALL_STATE_FINISHED = 2, + /** * The flag that marks that friend is sending audio. */ TOXAV_FRIEND_CALL_STATE_SENDING_A = 4, + /** * The flag that marks that friend is sending video. */ TOXAV_FRIEND_CALL_STATE_SENDING_V = 8, + /** * The flag that marks that friend is receiving audio. */ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A = 16, + /** * The flag that marks that friend is receiving video. */ TOXAV_FRIEND_CALL_STATE_ACCEPTING_V = 32, + }; + /** * The function type for the call_state callback. * @@ -391,81 +365,102 @@ enum TOXAV_FRIEND_CALL_STATE { * paused. The bitmask represents all the activities currently performed by the * friend. */ -typedef void toxav_call_state_cb(ToxAV *toxAV, uint32_t friend_number, uint32_t state, void *user_data); +typedef void toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data); + /** * Set the callback for the `call_state` event. Pass NULL to unset. * */ -void toxav_callback_call_state(ToxAV *toxAV, toxav_call_state_cb *callback, void *user_data); +void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *user_data); + /******************************************************************************* * * :: Call control * ******************************************************************************/ + + + typedef enum TOXAV_CALL_CONTROL { + /** * Resume a previously paused call. Only valid if the pause was caused by this * client, if not, this control is ignored. Not valid before the call is accepted. */ TOXAV_CALL_CONTROL_RESUME, + /** * Put a call on hold. Not valid before the call is accepted. */ TOXAV_CALL_CONTROL_PAUSE, + /** * Reject a call if it was not answered, yet. Cancel a call after it was * answered. */ TOXAV_CALL_CONTROL_CANCEL, + /** * Request that the friend stops sending audio. Regardless of the friend's * compliance, this will cause the audio_receive_frame event to stop being * triggered on receiving an audio frame from the friend. */ TOXAV_CALL_CONTROL_MUTE_AUDIO, + /** * Calling this control will notify client to start sending audio again. */ TOXAV_CALL_CONTROL_UNMUTE_AUDIO, + /** * Request that the friend stops sending video. Regardless of the friend's * compliance, this will cause the video_receive_frame event to stop being * triggered on receiving a video frame from the friend. */ TOXAV_CALL_CONTROL_HIDE_VIDEO, + /** * Calling this control will notify client to start sending video again. */ TOXAV_CALL_CONTROL_SHOW_VIDEO, + } TOXAV_CALL_CONTROL; + typedef enum TOXAV_ERR_CALL_CONTROL { + /** * The function returned successfully. */ TOXAV_ERR_CALL_CONTROL_OK, + /** * Synchronization error occurred. */ TOXAV_ERR_CALL_CONTROL_SYNC, + /** * The friend_number passed did not designate a valid friend. */ TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND, + /** * This client is currently not in a call with the friend. Before the call is * answered, only CANCEL is a valid control. */ TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL, + /** * Happens if user tried to pause an already paused call or if trying to * resume a call that is not paused. */ TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION, + } TOXAV_ERR_CALL_CONTROL; + /** * Sends a call control command to a friend. * @@ -475,8 +470,7 @@ typedef enum TOXAV_ERR_CALL_CONTROL { * * @return true on success. */ -bool toxav_call_control(ToxAV *toxAV, uint32_t friend_number, TOXAV_CALL_CONTROL control, - TOXAV_ERR_CALL_CONTROL *error); +bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error); /******************************************************************************* @@ -484,33 +478,44 @@ bool toxav_call_control(ToxAV *toxAV, uint32_t friend_number, TOXAV_CALL_CONTROL * :: Controlling bit rates * ******************************************************************************/ + + + typedef enum TOXAV_ERR_BIT_RATE_SET { + /** * The function returned successfully. */ TOXAV_ERR_BIT_RATE_SET_OK, + /** * Synchronization error occurred. */ TOXAV_ERR_BIT_RATE_SET_SYNC, + /** * The audio bit rate passed was not one of the supported values. */ TOXAV_ERR_BIT_RATE_SET_INVALID_AUDIO_BIT_RATE, + /** * The video bit rate passed was not one of the supported values. */ TOXAV_ERR_BIT_RATE_SET_INVALID_VIDEO_BIT_RATE, + /** * The friend_number passed did not designate a valid friend. */ TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND, + /** * This client is currently not in a call with the friend. */ TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL, + } TOXAV_ERR_BIT_RATE_SET; + /** * Set the bit rate to be used in subsequent audio/video frames. * @@ -522,8 +527,8 @@ typedef enum TOXAV_ERR_BIT_RATE_SET { * video sending. Set to -1 to leave unchanged. * */ -bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_rate, - int32_t video_bit_rate, TOXAV_ERR_BIT_RATE_SET *error); +bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rate, int32_t video_bit_rate, + TOXAV_ERR_BIT_RATE_SET *error); /** * The function type for the bit_rate_status callback. The event is triggered @@ -535,14 +540,15 @@ bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_ * @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec. * @param video_bit_rate Suggested maximum video bit rate in Kb/sec. */ -typedef void toxav_bit_rate_status_cb(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, +typedef void toxav_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, void *user_data); + /** * Set the callback for the `bit_rate_status` event. Pass NULL to unset. * */ -void toxav_callback_bit_rate_status(ToxAV *toxAV, toxav_bit_rate_status_cb *callback, void *user_data); +void toxav_callback_bit_rate_status(ToxAV *av, toxav_bit_rate_status_cb *callback, void *user_data); /******************************************************************************* @@ -550,44 +556,57 @@ void toxav_callback_bit_rate_status(ToxAV *toxAV, toxav_bit_rate_status_cb *call * :: A/V sending * ******************************************************************************/ + + + typedef enum TOXAV_ERR_SEND_FRAME { + /** * The function returned successfully. */ TOXAV_ERR_SEND_FRAME_OK, + /** * In case of video, one of Y, U, or V was NULL. In case of audio, the samples * data pointer was NULL. */ TOXAV_ERR_SEND_FRAME_NULL, + /** * The friend_number passed did not designate a valid friend. */ TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND, + /** * This client is currently not in a call with the friend. */ TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL, + /** * Synchronization error occurred. */ TOXAV_ERR_SEND_FRAME_SYNC, + /** * One of the frame parameters was invalid. E.g. the resolution may be too * small or too large, or the audio sampling rate may be unsupported. */ TOXAV_ERR_SEND_FRAME_INVALID, + /** * Either friend turned off audio or video receiving or we turned off sending * for the said payload. */ TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED, + /** * Failed to push frame through rtp interface. */ TOXAV_ERR_SEND_FRAME_RTP_FAILED, + } TOXAV_ERR_SEND_FRAME; + /** * Send an audio frame to a friend. * @@ -608,9 +627,8 @@ typedef enum TOXAV_ERR_SEND_FRAME { * @param sampling_rate Audio sampling rate used in this frame. Valid sampling * rates are 8000, 12000, 16000, 24000, or 48000. */ -bool toxav_audio_send_frame(ToxAV *toxAV, uint32_t friend_number, const int16_t *pcm, - size_t sample_count, uint8_t channels, uint32_t sampling_rate, - TOXAV_ERR_SEND_FRAME *error); +bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, + uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME *error); /** * Send a video frame to a friend. @@ -627,9 +645,8 @@ bool toxav_audio_send_frame(ToxAV *toxAV, uint32_t friend_number, const int16_t * @param u U (Chroma) plane data. * @param v V (Chroma) plane data. */ -bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width, - uint16_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, - TOXAV_ERR_SEND_FRAME *error); +bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y, + const uint8_t *u, const uint8_t *v, TOXAV_ERR_SEND_FRAME *error); /******************************************************************************* @@ -637,6 +654,9 @@ bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width * :: A/V receiving * ******************************************************************************/ + + + /** * The function type for the audio_receive_frame callback. The callback can be * called multiple times per single iteration depending on the amount of queued @@ -649,49 +669,51 @@ bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width * @param sampling_rate Sampling rate used in this frame. * */ -typedef void toxav_audio_receive_frame_cb(ToxAV *toxAV, uint32_t friend_number, const int16_t *pcm, - size_t sample_count, uint8_t channels, uint32_t sampling_rate, - void *user_data); +typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, + uint8_t channels, uint32_t sampling_rate, void *user_data); + /** * Set the callback for the `audio_receive_frame` event. Pass NULL to unset. * */ -void toxav_callback_audio_receive_frame(ToxAV *toxAV, toxav_audio_receive_frame_cb *callback, void *user_data); +void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb *callback, void *user_data); /** * The function type for the video_receive_frame callback. * + * The size of plane data is derived from width and height as documented + * below. + * + * Strides represent padding for each plane that may or may not be present. + * You must handle strides in your image processing code. Strides are + * negative if the image is bottom-up hence why you MUST abs() it when + * calculating plane buffer size. + * * @param friend_number The friend number of the friend who sent a video frame. * @param width Width of the frame in pixels. * @param height Height of the frame in pixels. - * @param y - * @param u - * @param v Plane data. - * The size of plane data is derived from width and height where - * Y = MAX(width, abs(ystride)) * height, - * U = MAX(width/2, abs(ustride)) * (height/2) and - * V = MAX(width/2, abs(vstride)) * (height/2). - * @param ystride - * @param ustride - * @param vstride Strides data. Strides represent padding for each plane - * that may or may not be present. You must handle strides in - * your image processing code. Strides are negative if the - * image is bottom-up hence why you MUST abs() it when - * calculating plane buffer size. - */ -typedef void toxav_video_receive_frame_cb(ToxAV *toxAV, uint32_t friend_number, uint16_t width, - uint16_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, - int32_t ystride, int32_t ustride, int32_t vstride, void *user_data); + * @param y Luminosity plane. Size = MAX(width, abs(ystride)) * height. + * @param u U chroma plane. Size = MAX(width/2, abs(ustride)) * (height/2). + * @param v V chroma plane. Size = MAX(width/2, abs(vstride)) * (height/2). + * + * @param ystride Luminosity plane stride. + * @param ustride U chroma plane stride. + * @param vstride V chroma plane stride. + */ +typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, + const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data); + /** * Set the callback for the `video_receive_frame` event. Pass NULL to unset. * */ -void toxav_callback_video_receive_frame(ToxAV *toxAV, toxav_video_receive_frame_cb *callback, void *user_data); +void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data); /** - * NOTE Compatibility with old toxav group calls TODO remove + * NOTE Compatibility with old toxav group calls. TODO(iphydf): remove */ /* Create a new toxav group. * |