Merge branch 'ghost-avswitch'

This commit is contained in:
irungentoo 2016-09-28 15:14:33 -04:00
commit dcf2aaa530
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 191 additions and 44 deletions

View File

@ -1,6 +1,6 @@
%{ %{
/* toxav.h /* toxav.h
* *
* Copyright (C) 2013-2015 Tox project All Rights Reserved. * Copyright (C) 2013-2015 Tox project All Rights Reserved.
* *
* This file is part of Tox. * This file is part of Tox.
@ -17,7 +17,7 @@
* *
* You should have received a copy of the GNU General Public License * 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 #ifndef TOXAV_H
@ -33,39 +33,39 @@ extern "C" {
%} %}
/** \page av Public audio/video API for Tox clients. /** \page av Public audio/video API for Tox clients.
* *
* This API can handle multiple calls. Each call has its state, in very rare * This API can handle multiple calls. Each call has its state, in very rare
* occasions the library can change the state of the call without apps knowledge. * occasions the library can change the state of the call without apps knowledge.
* *
*/ */
/** \subsection events Events and callbacks /** \subsection events Events and callbacks
* *
* As in Core API, events are handled by callbacks. One callback can be * As in Core API, events are handled by callbacks. One callback can be
* registered per event. All events have a callback function type named * registered per event. All events have a callback function type named
* `toxav_{event}_cb` and a function to register it named `tox_callback_{event}`. * `toxav_{event}_cb` and a function to register it named `toxav_callback_{event}`.
* Passing a NULL callback will result in no callback being registered for that * Passing a NULL callback will result in no callback being registered for that
* event. Only one callback per event can be registered, so if a client needs * event. Only one callback per event can be registered, so if a client needs
* multiple event listeners, it needs to implement the dispatch functionality * multiple event listeners, it needs to implement the dispatch functionality
* itself. Unlike Core API, lack of some event handlers will cause the the * itself. Unlike Core API, lack of some event handlers will cause the the
* library to drop calls before they are started. Hanging up call from a * library to drop calls before they are started. Hanging up call from a
* callback causes undefined behaviour. * callback causes undefined behaviour.
* *
*/ */
/** \subsection threading Threading implications /** \subsection threading Threading implications
* *
* Unlike the Core API, this API is fully thread-safe. The library will ensure * Unlike the Core API, this API is fully thread-safe. The library will ensure
* the proper synchronization of parallel calls. * the proper synchronization of parallel calls.
* *
* A common way to run ToxAV (multiple or single instance) is to have a thread, * A common way to run ToxAV (multiple or single instance) is to have a thread,
* separate from tox instance thread, running a simple ${toxAV.iterate} loop, * separate from tox instance thread, running a simple ${toxAV.iterate} loop,
* sleeping for ${toxAV.iteration_interval} * milliseconds on each iteration. * sleeping for ${toxAV.iteration_interval} * milliseconds on each iteration.
* *
* An important thing to note is that events are triggered from both tox and * An important thing to note is that events are triggered from both tox and
* toxav thread (see above). audio and video receive frame events are triggered * toxav thread (see above). Audio and video receive frame events are triggered
* from toxav thread while all the other events are triggered from tox thread. * from toxav thread while all the other events are triggered from tox thread.
* *
* Tox thread has priority with mutex mechanisms. Any api function can * Tox thread has priority with mutex mechanisms. Any api function can
* fail if mutexes are held by tox thread in which case they will set SYNC * fail if mutexes are held by tox thread in which case they will set SYNC
* error code. * error code.
@ -87,9 +87,9 @@ class toxAV {
* The ToxAV instance type. Each ToxAV instance can be bound to only one Tox * The ToxAV instance type. Each ToxAV instance can be bound to only one Tox
* instance, and Tox instance can have only one ToxAV instance. One must make * instance, and Tox instance can have only one ToxAV instance. One must make
* sure to close ToxAV instance prior closing Tox instance otherwise undefined * sure to close ToxAV instance prior closing Tox instance otherwise undefined
* behaviour occurs. Upon closing of ToxAV instance, all active calls will be * behaviour occurs. Upon closing of ToxAV instance, all active calls will be
* forcibly terminated without notifying peers. * forcibly terminated without notifying peers.
* *
*/ */
struct this; struct this;
/******************************************************************************* /*******************************************************************************
@ -166,7 +166,7 @@ static namespace version {
} }
/******************************************************************************* /*******************************************************************************
* *
* :: Creation and destruction * :: Creation and destruction
* *
******************************************************************************/ ******************************************************************************/
@ -433,9 +433,10 @@ bool call_control (uint32_t friend_number, CALL_CONTROL control) {
******************************************************************************/ ******************************************************************************/
namespace bit_rate { namespace bit_rate {
/** /**
* Set the audio bit rate to be used in subsequent audio/video frames. * Set the bit rate to be used in subsequent audio/video frames.
* *
* @param friend_number The friend number. * @param friend_number The friend number of the friend for which to set the
* bit rate.
* @param audio_bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable * @param audio_bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable
* audio sending. Set to -1 to leave unchanged. * audio sending. Set to -1 to leave unchanged.
* @param video_bit_rate The new video bit rate in Kb/sec. Set to 0 to disable * @param video_bit_rate The new video bit rate in Kb/sec. Set to 0 to disable
@ -448,9 +449,13 @@ namespace bit_rate {
*/ */
SYNC, SYNC,
/** /**
* The bit rate passed was not one of the supported values. * The audio bit rate passed was not one of the supported values.
*/ */
INVALID, INVALID_AUDIO_BIT_RATE,
/**
* The video bit rate passed was not one of the supported values.
*/
INVALID_VIDEO_BIT_RATE,
/** /**
* The friend_number passed did not designate a valid friend. * The friend_number passed did not designate a valid friend.
*/ */
@ -466,7 +471,8 @@ namespace bit_rate {
* when the network becomes too saturated for current bit rates at which * when the network becomes too saturated for current bit rates at which
* point core suggests new bit rates. * point core suggests new bit rates.
* *
* @param friend_number The friend number. * @param friend_number The friend number of the friend for which to set the
* bit rate.
* @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec. * @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec.
* @param video_bit_rate Suggested maximum video bit rate in Kb/sec. * @param video_bit_rate Suggested maximum video bit rate in Kb/sec.
*/ */
@ -607,7 +613,53 @@ namespace video {
} }
} }
%{ %{
/**
* NOTE Compatibility with old toxav group calls TODO remove
*/
/* Create a new toxav group.
*
* return group number on success.
* return -1 on failure.
*
* Audio data callback format:
* audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata)
*
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
*/
int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t,
unsigned int, void *), void *userdata);
/* Join a AV group (you need to have been invited first.)
*
* returns group number on success
* returns -1 on failure.
*
* Audio data callback format (same as the one for toxav_add_av_groupchat()):
* audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata)
*
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
*/
int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length,
void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata);
/* Send audio to the group chat.
*
* return 0 on success.
* return -1 on failure.
*
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
*
* Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000)
* Valid number of channels are 1 or 2.
* Valid sample rates are 8000, 12000, 16000, 24000, or 48000.
*
* Recommended values are: samples = 960, channels = 1, sample_rate = 48000
*/
int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
unsigned int sample_rate);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -96,6 +96,9 @@ typedef struct ToxAV ToxAV;
* :: API version * :: API version
* *
******************************************************************************/ ******************************************************************************/
/** /**
* The major version number. Incremented when the API or ABI changes in an * The major version number. Incremented when the API or ABI changes in an
* incompatible way. * incompatible way.
@ -168,26 +171,35 @@ bool toxav_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
* :: Creation and destruction * :: Creation and destruction
* *
******************************************************************************/ ******************************************************************************/
typedef enum TOXAV_ERR_NEW { typedef enum TOXAV_ERR_NEW {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_NEW_OK, TOXAV_ERR_NEW_OK,
/** /**
* One of the arguments to the function was NULL when it was not expected. * One of the arguments to the function was NULL when it was not expected.
*/ */
TOXAV_ERR_NEW_NULL, TOXAV_ERR_NEW_NULL,
/** /**
* Memory allocation failure while trying to allocate structures required for * Memory allocation failure while trying to allocate structures required for
* the A/V session. * the A/V session.
*/ */
TOXAV_ERR_NEW_MALLOC, TOXAV_ERR_NEW_MALLOC,
/** /**
* Attempted to create a second session for the same Tox instance. * Attempted to create a second session for the same Tox instance.
*/ */
TOXAV_ERR_NEW_MULTIPLE, TOXAV_ERR_NEW_MULTIPLE,
} TOXAV_ERR_NEW; } TOXAV_ERR_NEW;
/** /**
* Start new A/V session. There can only be only one session per Tox instance. * Start new A/V session. There can only be only one session per Tox instance.
*/ */
@ -213,6 +225,9 @@ Tox *toxav_get_tox(const ToxAV *toxAV);
* :: A/V event loop * :: A/V event loop
* *
******************************************************************************/ ******************************************************************************/
/** /**
* Returns the interval in milliseconds when the next toxav_iterate call should * 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. * be. If no call is active at the moment, this function returns 200.
@ -232,39 +247,51 @@ void toxav_iterate(ToxAV *toxAV);
* :: Call setup * :: Call setup
* *
******************************************************************************/ ******************************************************************************/
typedef enum TOXAV_ERR_CALL { typedef enum TOXAV_ERR_CALL {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_CALL_OK, TOXAV_ERR_CALL_OK,
/** /**
* A resource allocation error occurred while trying to create the structures * A resource allocation error occurred while trying to create the structures
* required for the call. * required for the call.
*/ */
TOXAV_ERR_CALL_MALLOC, TOXAV_ERR_CALL_MALLOC,
/** /**
* Synchronization error occurred. * Synchronization error occurred.
*/ */
TOXAV_ERR_CALL_SYNC, TOXAV_ERR_CALL_SYNC,
/** /**
* The friend number did not designate a valid friend. * The friend number did not designate a valid friend.
*/ */
TOXAV_ERR_CALL_FRIEND_NOT_FOUND, TOXAV_ERR_CALL_FRIEND_NOT_FOUND,
/** /**
* The friend was valid, but not currently connected. * The friend was valid, but not currently connected.
*/ */
TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED, TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED,
/** /**
* Attempted to call a friend while already in an audio or video call with * Attempted to call a friend while already in an audio or video call with
* them. * them.
*/ */
TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL, TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL,
/** /**
* Audio or video bit rate is invalid. * Audio or video bit rate is invalid.
*/ */
TOXAV_ERR_CALL_INVALID_BIT_RATE, TOXAV_ERR_CALL_INVALID_BIT_RATE,
} TOXAV_ERR_CALL; } TOXAV_ERR_CALL;
/** /**
* Call a friend. This will start ringing the friend. * Call a friend. This will start ringing the friend.
* *
@ -279,8 +306,8 @@ typedef enum TOXAV_ERR_CALL {
* @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
* video sending. * video sending.
*/ */
bool toxav_call(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, bool toxav_call(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate,
uint32_t video_bit_rate, TOXAV_ERR_CALL *error); TOXAV_ERR_CALL *error);
/** /**
* The function type for the call callback. * The function type for the call callback.
@ -289,8 +316,9 @@ bool toxav_call(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate,
* @param audio_enabled True if friend is sending audio. * @param audio_enabled True if friend is sending audio.
* @param video_enabled True if friend is sending video. * @param video_enabled True if friend is sending video.
*/ */
typedef void toxav_call_cb(ToxAV *toxAV, uint32_t friend_number, bool audio_enabled, typedef void toxav_call_cb(ToxAV *toxAV, uint32_t friend_number, bool audio_enabled, bool video_enabled,
bool video_enabled, void *user_data); void *user_data);
/** /**
* Set the callback for the `call` event. Pass NULL to unset. * Set the callback for the `call` event. Pass NULL to unset.
@ -299,35 +327,43 @@ typedef void toxav_call_cb(ToxAV *toxAV, uint32_t friend_number, bool audio_enab
void toxav_callback_call(ToxAV *toxAV, toxav_call_cb *callback, void *user_data); void toxav_callback_call(ToxAV *toxAV, toxav_call_cb *callback, void *user_data);
typedef enum TOXAV_ERR_ANSWER { typedef enum TOXAV_ERR_ANSWER {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_ANSWER_OK, TOXAV_ERR_ANSWER_OK,
/** /**
* Synchronization error occurred. * Synchronization error occurred.
*/ */
TOXAV_ERR_ANSWER_SYNC, TOXAV_ERR_ANSWER_SYNC,
/** /**
* Failed to initialize codecs for call session. Note that codec initiation * Failed to initialize codecs for call session. Note that codec initiation
* will fail if there is no receive callback registered for either audio or * will fail if there is no receive callback registered for either audio or
* video. * video.
*/ */
TOXAV_ERR_ANSWER_CODEC_INITIALIZATION, TOXAV_ERR_ANSWER_CODEC_INITIALIZATION,
/** /**
* The friend number did not designate a valid friend. * The friend number did not designate a valid friend.
*/ */
TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND, TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND,
/** /**
* The friend was valid, but they are not currently trying to initiate a call. * 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. * This is also returned if this client is already in a call with the friend.
*/ */
TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING, TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING,
/** /**
* Audio or video bit rate is invalid. * Audio or video bit rate is invalid.
*/ */
TOXAV_ERR_ANSWER_INVALID_BIT_RATE, TOXAV_ERR_ANSWER_INVALID_BIT_RATE,
} TOXAV_ERR_ANSWER; } TOXAV_ERR_ANSWER;
/** /**
* Accept an incoming call. * Accept an incoming call.
* *
@ -350,7 +386,11 @@ bool toxav_answer(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate,
* :: Call state graph * :: Call state graph
* *
******************************************************************************/ ******************************************************************************/
enum TOXAV_FRIEND_CALL_STATE { enum TOXAV_FRIEND_CALL_STATE {
/** /**
* Set by the AV core if an error occurred on the remote end or if friend * 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 * timed out. This is the final state after which no more state
@ -358,30 +398,37 @@ enum TOXAV_FRIEND_CALL_STATE {
* in combination with other call states. * in combination with other call states.
*/ */
TOXAV_FRIEND_CALL_STATE_ERROR = 1, TOXAV_FRIEND_CALL_STATE_ERROR = 1,
/** /**
* The call has finished. This is the final state after which no more state * 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 * transitions can occur for the call. This call state will never be
* triggered in combination with other call states. * triggered in combination with other call states.
*/ */
TOXAV_FRIEND_CALL_STATE_FINISHED = 2, TOXAV_FRIEND_CALL_STATE_FINISHED = 2,
/** /**
* The flag that marks that friend is sending audio. * The flag that marks that friend is sending audio.
*/ */
TOXAV_FRIEND_CALL_STATE_SENDING_A = 4, TOXAV_FRIEND_CALL_STATE_SENDING_A = 4,
/** /**
* The flag that marks that friend is sending video. * The flag that marks that friend is sending video.
*/ */
TOXAV_FRIEND_CALL_STATE_SENDING_V = 8, TOXAV_FRIEND_CALL_STATE_SENDING_V = 8,
/** /**
* The flag that marks that friend is receiving audio. * The flag that marks that friend is receiving audio.
*/ */
TOXAV_FRIEND_CALL_STATE_ACCEPTING_A = 16, TOXAV_FRIEND_CALL_STATE_ACCEPTING_A = 16,
/** /**
* The flag that marks that friend is receiving video. * The flag that marks that friend is receiving video.
*/ */
TOXAV_FRIEND_CALL_STATE_ACCEPTING_V = 32, TOXAV_FRIEND_CALL_STATE_ACCEPTING_V = 32,
}; };
/** /**
* The function type for the call_state callback. * The function type for the call_state callback.
* *
@ -393,79 +440,100 @@ enum TOXAV_FRIEND_CALL_STATE {
*/ */
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 *toxAV, uint32_t friend_number, uint32_t state, void *user_data);
/** /**
* Set the callback for the `call_state` event. Pass NULL to unset. * 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 *toxAV, toxav_call_state_cb *callback, void *user_data);
/******************************************************************************* /*******************************************************************************
* *
* :: Call control * :: Call control
* *
******************************************************************************/ ******************************************************************************/
typedef enum TOXAV_CALL_CONTROL { typedef enum TOXAV_CALL_CONTROL {
/** /**
* Resume a previously paused call. Only valid if the pause was caused by this * 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. * client, if not, this control is ignored. Not valid before the call is accepted.
*/ */
TOXAV_CALL_CONTROL_RESUME, TOXAV_CALL_CONTROL_RESUME,
/** /**
* Put a call on hold. Not valid before the call is accepted. * Put a call on hold. Not valid before the call is accepted.
*/ */
TOXAV_CALL_CONTROL_PAUSE, TOXAV_CALL_CONTROL_PAUSE,
/** /**
* Reject a call if it was not answered, yet. Cancel a call after it was * Reject a call if it was not answered, yet. Cancel a call after it was
* answered. * answered.
*/ */
TOXAV_CALL_CONTROL_CANCEL, TOXAV_CALL_CONTROL_CANCEL,
/** /**
* Request that the friend stops sending audio. Regardless of the friend's * Request that the friend stops sending audio. Regardless of the friend's
* compliance, this will cause the audio_receive_frame event to stop being * compliance, this will cause the audio_receive_frame event to stop being
* triggered on receiving an audio frame from the friend. * triggered on receiving an audio frame from the friend.
*/ */
TOXAV_CALL_CONTROL_MUTE_AUDIO, TOXAV_CALL_CONTROL_MUTE_AUDIO,
/** /**
* Calling this control will notify client to start sending audio again. * Calling this control will notify client to start sending audio again.
*/ */
TOXAV_CALL_CONTROL_UNMUTE_AUDIO, TOXAV_CALL_CONTROL_UNMUTE_AUDIO,
/** /**
* Request that the friend stops sending video. Regardless of the friend's * Request that the friend stops sending video. Regardless of the friend's
* compliance, this will cause the video_receive_frame event to stop being * compliance, this will cause the video_receive_frame event to stop being
* triggered on receiving a video frame from the friend. * triggered on receiving a video frame from the friend.
*/ */
TOXAV_CALL_CONTROL_HIDE_VIDEO, TOXAV_CALL_CONTROL_HIDE_VIDEO,
/** /**
* Calling this control will notify client to start sending video again. * Calling this control will notify client to start sending video again.
*/ */
TOXAV_CALL_CONTROL_SHOW_VIDEO, TOXAV_CALL_CONTROL_SHOW_VIDEO,
} TOXAV_CALL_CONTROL; } TOXAV_CALL_CONTROL;
typedef enum TOXAV_ERR_CALL_CONTROL { typedef enum TOXAV_ERR_CALL_CONTROL {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_CALL_CONTROL_OK, TOXAV_ERR_CALL_CONTROL_OK,
/** /**
* Synchronization error occurred. * Synchronization error occurred.
*/ */
TOXAV_ERR_CALL_CONTROL_SYNC, TOXAV_ERR_CALL_CONTROL_SYNC,
/** /**
* The friend_number passed did not designate a valid friend. * The friend_number passed did not designate a valid friend.
*/ */
TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND, TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND,
/** /**
* This client is currently not in a call with the friend. Before the call is * This client is currently not in a call with the friend. Before the call is
* answered, only CANCEL is a valid control. * answered, only CANCEL is a valid control.
*/ */
TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL, TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL,
/** /**
* Happens if user tried to pause an already paused call or if trying to * Happens if user tried to pause an already paused call or if trying to
* resume a call that is not paused. * resume a call that is not paused.
*/ */
TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION, TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION,
} TOXAV_ERR_CALL_CONTROL; } TOXAV_ERR_CALL_CONTROL;
/** /**
* Sends a call control command to a friend. * Sends a call control command to a friend.
* *
@ -484,33 +552,44 @@ bool toxav_call_control(ToxAV *toxAV, uint32_t friend_number, TOXAV_CALL_CONTROL
* :: Controlling bit rates * :: Controlling bit rates
* *
******************************************************************************/ ******************************************************************************/
typedef enum TOXAV_ERR_BIT_RATE_SET { typedef enum TOXAV_ERR_BIT_RATE_SET {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_BIT_RATE_SET_OK, TOXAV_ERR_BIT_RATE_SET_OK,
/** /**
* Synchronization error occurred. * Synchronization error occurred.
*/ */
TOXAV_ERR_BIT_RATE_SET_SYNC, TOXAV_ERR_BIT_RATE_SET_SYNC,
/** /**
* The audio bit rate passed was not one of the supported values. * The audio bit rate passed was not one of the supported values.
*/ */
TOXAV_ERR_BIT_RATE_SET_INVALID_AUDIO_BIT_RATE, TOXAV_ERR_BIT_RATE_SET_INVALID_AUDIO_BIT_RATE,
/** /**
* The video bit rate passed was not one of the supported values. * The video bit rate passed was not one of the supported values.
*/ */
TOXAV_ERR_BIT_RATE_SET_INVALID_VIDEO_BIT_RATE, TOXAV_ERR_BIT_RATE_SET_INVALID_VIDEO_BIT_RATE,
/** /**
* The friend_number passed did not designate a valid friend. * The friend_number passed did not designate a valid friend.
*/ */
TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND, TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND,
/** /**
* This client is currently not in a call with the friend. * 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_FRIEND_NOT_IN_CALL,
} TOXAV_ERR_BIT_RATE_SET; } TOXAV_ERR_BIT_RATE_SET;
/** /**
* Set the bit rate to be used in subsequent audio/video frames. * Set the bit rate to be used in subsequent audio/video frames.
* *
@ -522,8 +601,8 @@ typedef enum TOXAV_ERR_BIT_RATE_SET {
* video sending. Set to -1 to leave unchanged. * video sending. Set to -1 to leave unchanged.
* *
*/ */
bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_rate, bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_rate, int32_t video_bit_rate,
int32_t video_bit_rate, TOXAV_ERR_BIT_RATE_SET *error); TOXAV_ERR_BIT_RATE_SET *error);
/** /**
* The function type for the bit_rate_status callback. The event is triggered * The function type for the bit_rate_status callback. The event is triggered
@ -538,6 +617,7 @@ bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_
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 *toxAV, uint32_t friend_number, uint32_t audio_bit_rate,
uint32_t video_bit_rate, void *user_data); uint32_t video_bit_rate, void *user_data);
/** /**
* Set the callback for the `bit_rate_status` event. Pass NULL to unset. * Set the callback for the `bit_rate_status` event. Pass NULL to unset.
* *
@ -550,44 +630,57 @@ void toxav_callback_bit_rate_status(ToxAV *toxAV, toxav_bit_rate_status_cb *call
* :: A/V sending * :: A/V sending
* *
******************************************************************************/ ******************************************************************************/
typedef enum TOXAV_ERR_SEND_FRAME { typedef enum TOXAV_ERR_SEND_FRAME {
/** /**
* The function returned successfully. * The function returned successfully.
*/ */
TOXAV_ERR_SEND_FRAME_OK, TOXAV_ERR_SEND_FRAME_OK,
/** /**
* In case of video, one of Y, U, or V was NULL. In case of audio, the samples * In case of video, one of Y, U, or V was NULL. In case of audio, the samples
* data pointer was NULL. * data pointer was NULL.
*/ */
TOXAV_ERR_SEND_FRAME_NULL, TOXAV_ERR_SEND_FRAME_NULL,
/** /**
* The friend_number passed did not designate a valid friend. * The friend_number passed did not designate a valid friend.
*/ */
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND, TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND,
/** /**
* This client is currently not in a call with the friend. * This client is currently not in a call with the friend.
*/ */
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL, TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL,
/** /**
* Synchronization error occurred. * Synchronization error occurred.
*/ */
TOXAV_ERR_SEND_FRAME_SYNC, TOXAV_ERR_SEND_FRAME_SYNC,
/** /**
* One of the frame parameters was invalid. E.g. the resolution may be too * 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. * small or too large, or the audio sampling rate may be unsupported.
*/ */
TOXAV_ERR_SEND_FRAME_INVALID, TOXAV_ERR_SEND_FRAME_INVALID,
/** /**
* Either friend turned off audio or video receiving or we turned off sending * Either friend turned off audio or video receiving or we turned off sending
* for the said payload. * for the said payload.
*/ */
TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED, TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED,
/** /**
* Failed to push frame through rtp interface. * Failed to push frame through rtp interface.
*/ */
TOXAV_ERR_SEND_FRAME_RTP_FAILED, TOXAV_ERR_SEND_FRAME_RTP_FAILED,
} TOXAV_ERR_SEND_FRAME; } TOXAV_ERR_SEND_FRAME;
/** /**
* Send an audio frame to a friend. * Send an audio frame to a friend.
* *
@ -608,9 +701,8 @@ typedef enum TOXAV_ERR_SEND_FRAME {
* @param sampling_rate Audio sampling rate used in this frame. Valid sampling * @param sampling_rate Audio sampling rate used in this frame. Valid sampling
* rates are 8000, 12000, 16000, 24000, or 48000. * rates are 8000, 12000, 16000, 24000, or 48000.
*/ */
bool toxav_audio_send_frame(ToxAV *toxAV, uint32_t friend_number, const int16_t *pcm, bool toxav_audio_send_frame(ToxAV *toxAV, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
size_t sample_count, uint8_t channels, uint32_t sampling_rate, uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME *error);
TOXAV_ERR_SEND_FRAME *error);
/** /**
* Send a video frame to a friend. * Send a video frame to a friend.
@ -627,9 +719,8 @@ bool toxav_audio_send_frame(ToxAV *toxAV, uint32_t friend_number, const int16_t
* @param u U (Chroma) plane data. * @param u U (Chroma) plane data.
* @param v V (Chroma) plane data. * @param v V (Chroma) plane data.
*/ */
bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width, bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y,
uint16_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, const uint8_t *u, const uint8_t *v, TOXAV_ERR_SEND_FRAME *error);
TOXAV_ERR_SEND_FRAME *error);
/******************************************************************************* /*******************************************************************************
@ -637,6 +728,9 @@ bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width
* :: A/V receiving * :: A/V receiving
* *
******************************************************************************/ ******************************************************************************/
/** /**
* The function type for the audio_receive_frame callback. The callback can be * 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 * called multiple times per single iteration depending on the amount of queued
@ -649,9 +743,9 @@ bool toxav_video_send_frame(ToxAV *toxAV, uint32_t friend_number, uint16_t width
* @param sampling_rate Sampling rate used in this frame. * @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, typedef void toxav_audio_receive_frame_cb(ToxAV *toxAV, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
size_t sample_count, uint8_t channels, uint32_t sampling_rate, uint8_t channels, uint32_t sampling_rate, void *user_data);
void *user_data);
/** /**
* Set the callback for the `audio_receive_frame` event. Pass NULL to unset. * Set the callback for the `audio_receive_frame` event. Pass NULL to unset.
@ -680,9 +774,10 @@ void toxav_callback_audio_receive_frame(ToxAV *toxAV, toxav_audio_receive_frame_
* image is bottom-up hence why you MUST abs() it when * image is bottom-up hence why you MUST abs() it when
* calculating plane buffer size. * calculating plane buffer size.
*/ */
typedef void toxav_video_receive_frame_cb(ToxAV *toxAV, uint32_t friend_number, uint16_t width, typedef void toxav_video_receive_frame_cb(ToxAV *toxAV, uint32_t friend_number, uint16_t width, uint16_t height,
uint16_t height, const uint8_t *y, const uint8_t *u, const uint8_t *v, const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride,
int32_t ystride, int32_t ustride, int32_t vstride, void *user_data); void *user_data);
/** /**
* Set the callback for the `video_receive_frame` event. Pass NULL to unset. * Set the callback for the `video_receive_frame` event. Pass NULL to unset.