2020-03-12 09:10:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-08-26 07:36:42 +08:00
|
|
|
* Copyright © 2016-2018 The TokTok team.
|
2017-01-14 23:46:31 +08:00
|
|
|
* Copyright © 2013-2015 Tox project.
|
2015-02-18 06:34:40 +08:00
|
|
|
*/
|
2018-09-10 03:54:05 +08:00
|
|
|
#ifndef C_TOXCORE_TOXAV_TOXAV_H
|
|
|
|
#define C_TOXCORE_TOXAV_TOXAV_H
|
2015-02-17 06:30:20 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2015-04-20 17:21:55 +08:00
|
|
|
|
2020-04-10 07:56:19 +08:00
|
|
|
//!TOKSTYLE-
|
|
|
|
|
2015-04-20 17:21:55 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2014-06-19 05:52:34 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/** \page av Public audio/video API for Tox clients.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* 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.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
*/
|
|
|
|
/** \subsection events Events and callbacks
|
|
|
|
*
|
2015-11-04 02:42:05 +08:00
|
|
|
* As in Core API, events are handled by callbacks. One callback can be
|
|
|
|
* registered per event. All events have a callback function type named
|
2015-08-19 03:28:25 +08:00
|
|
|
* `toxav_{event}_cb` and a function to register it named `toxav_callback_{event}`.
|
2015-11-04 02:42:05 +08:00
|
|
|
* 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
|
|
|
|
* multiple event listeners, it needs to implement the dispatch functionality
|
|
|
|
* 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
|
2015-05-23 05:22:31 +08:00
|
|
|
* callback causes undefined behaviour.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
*/
|
|
|
|
/** \subsection threading Threading implications
|
|
|
|
*
|
2019-11-14 20:11:13 +08:00
|
|
|
* Only toxav_iterate is thread-safe, all other functions must run from the
|
|
|
|
* tox thread.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2019-02-11 03:28:49 +08:00
|
|
|
* Important exceptions are the `*_iterate` and `*_iterate_interval`
|
|
|
|
* functions. You have to choose either the single thread or the multi thread
|
|
|
|
* functions and read their documentation.
|
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* A common way to run ToxAV (multiple or single instance) is to have a thread,
|
2015-11-04 02:42:05 +08:00
|
|
|
* separate from tox instance thread, running a simple toxav_iterate loop,
|
2015-05-23 05:22:31 +08:00
|
|
|
* sleeping for toxav_iteration_interval * milliseconds on each iteration.
|
|
|
|
*
|
2015-10-11 05:54:23 +08:00
|
|
|
* 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
|
|
|
|
* from toxav thread while all the other events are triggered from tox thread.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-10-11 05:54:23 +08:00
|
|
|
* 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
|
|
|
|
* error code.
|
2014-03-11 07:36:47 +08:00
|
|
|
*/
|
2019-02-11 03:28:49 +08:00
|
|
|
/** \subsection multi-threading Separate audio and video threads
|
|
|
|
*
|
|
|
|
* ToxAV supports either a single thread for audio and video or decoding and
|
|
|
|
* encoding them in separate threads. You have to choose one mode and can not
|
|
|
|
* mix function calls to those different modes.
|
|
|
|
*
|
|
|
|
* For best results use the multi-threaded mode and run the audio thread with
|
|
|
|
* higher priority than the video thread. This prioritizes audio over video.
|
|
|
|
*/
|
2014-04-07 05:59:18 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* External Tox type.
|
2014-04-07 05:59:18 +08:00
|
|
|
*/
|
2015-02-15 06:37:52 +08:00
|
|
|
#ifndef TOX_DEFINED
|
|
|
|
#define TOX_DEFINED
|
2014-02-10 06:06:44 +08:00
|
|
|
typedef struct Tox Tox;
|
2015-05-23 05:22:31 +08:00
|
|
|
#endif /* TOX_DEFINED */
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* ToxAV.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2014-02-10 06:06:44 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* 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
|
|
|
|
* sure to close ToxAV instance prior closing Tox instance otherwise undefined
|
2015-11-04 02:42:05 +08:00
|
|
|
* behaviour occurs. Upon closing of ToxAV instance, all active calls will be
|
2015-05-23 05:22:31 +08:00
|
|
|
* forcibly terminated without notifying peers.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2014-02-10 06:06:44 +08:00
|
|
|
*/
|
2015-05-23 05:22:31 +08:00
|
|
|
#ifndef TOXAV_DEFINED
|
|
|
|
#define TOXAV_DEFINED
|
2015-10-11 06:01:44 +08:00
|
|
|
typedef struct ToxAV ToxAV;
|
2015-05-23 05:22:31 +08:00
|
|
|
#endif /* TOXAV_DEFINED */
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: Creation and destruction
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_ERR_NEW {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_NEW_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* One of the arguments to the function was NULL when it was not expected.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_NEW_NULL,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Memory allocation failure while trying to allocate structures required for
|
|
|
|
* the A/V session.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_NEW_MALLOC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Attempted to create a second session for the same Tox instance.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_NEW_MULTIPLE,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_ERR_NEW;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Start new A/V session. There can only be only one session per Tox instance.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2015-02-15 06:37:52 +08:00
|
|
|
ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Releases all resources associated with the A/V session.
|
|
|
|
*
|
|
|
|
* If any calls were ongoing, these will be forcibly terminated without
|
|
|
|
* notifying peers. After calling this function, no other functions may be
|
|
|
|
* called and the av pointer becomes invalid.
|
2014-11-18 07:46:46 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
void toxav_kill(ToxAV *av);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2014-11-18 07:46:46 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Returns the Tox instance the A/V object was created for.
|
2014-11-18 07:46:46 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
Tox *toxav_get_tox(const ToxAV *av);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2019-02-11 03:28:49 +08:00
|
|
|
* :: A/V event loop, single thread
|
2015-02-15 06:37:52 +08:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-18 07:46:46 +08:00
|
|
|
/**
|
2015-03-26 03:36:35 +08:00
|
|
|
* 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.
|
2019-02-11 03:28:49 +08:00
|
|
|
* This function MUST be called from the same thread as toxav_iterate.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
uint32_t toxav_iteration_interval(const ToxAV *av);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Main loop for the session. This function needs to be called in intervals of
|
2015-11-04 02:42:05 +08:00
|
|
|
* toxav_iteration_interval() milliseconds. It is best called in the separate
|
2015-05-02 04:15:12 +08:00
|
|
|
* thread from tox_iterate.
|
2015-02-15 06:37:52 +08:00
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
void toxav_iterate(ToxAV *av);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
|
2019-02-11 03:28:49 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* :: A/V event loop, multiple threads
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the interval in milliseconds when the next toxav_audio_iterate call
|
|
|
|
* should be. If no call is active at the moment, this function returns 200.
|
|
|
|
* This function MUST be called from the same thread as toxav_audio_iterate.
|
|
|
|
*/
|
|
|
|
uint32_t toxav_audio_iteration_interval(const ToxAV *av);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main loop for the session. This function needs to be called in intervals of
|
|
|
|
* toxav_audio_iteration_interval() milliseconds. It is best called in a
|
|
|
|
* separate thread from tox_iterate and toxav_video_iterate. The thread calling
|
|
|
|
* this function should have higher priority than the one calling
|
|
|
|
* toxav_video_iterate to prioritize audio over video.
|
|
|
|
*/
|
|
|
|
void toxav_audio_iterate(ToxAV *av);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the interval in milliseconds when the next toxav_video_iterate call
|
|
|
|
* should be. If no call is active at the moment, this function returns 200.
|
|
|
|
* This function MUST be called from the same thread as toxav_video_iterate.
|
|
|
|
*/
|
|
|
|
uint32_t toxav_video_iteration_interval(const ToxAV *av);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main loop for the session. This function needs to be called in intervals of
|
|
|
|
* toxav_video_iteration_interval() milliseconds. It is best called in a
|
|
|
|
* separate thread from tox_iterate and toxav_audio_iterate. The thread calling
|
|
|
|
* this function should have lower priority than the one calling
|
|
|
|
* toxav_audio_iterate to prioritize audio over video.
|
|
|
|
*/
|
|
|
|
void toxav_video_iterate(ToxAV *av);
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: Call setup
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_ERR_CALL {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* A resource allocation error occurred while trying to create the structures
|
|
|
|
* required for the call.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_MALLOC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Synchronization error occurred.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_SYNC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend number did not designate a valid friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_FRIEND_NOT_FOUND,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend was valid, but not currently connected.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Attempted to call a friend while already in an audio or video call with
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Audio or video bit rate is invalid.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_INVALID_BIT_RATE,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_ERR_CALL;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Call a friend. This will start ringing the friend.
|
|
|
|
*
|
|
|
|
* It is the client's responsibility to stop ringing after a certain timeout,
|
2015-05-23 05:22:31 +08:00
|
|
|
* if such behaviour is desired. If the client does not stop ringing, the
|
2015-11-04 02:42:05 +08:00
|
|
|
* library will not stop until the friend is disconnected. Audio and video
|
2015-06-28 01:20:52 +08:00
|
|
|
* receiving are both enabled by default.
|
2015-02-15 06:37:52 +08:00
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend that should be called.
|
|
|
|
* @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
|
|
|
|
* audio sending.
|
|
|
|
* @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
|
|
|
|
* video sending.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate,
|
2016-03-09 10:52:31 +08:00
|
|
|
TOXAV_ERR_CALL *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* The function type for the call callback.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* @param friend_number The friend number from which the call is incoming.
|
|
|
|
* @param audio_enabled True if friend is sending audio.
|
|
|
|
* @param video_enabled True if friend is sending video.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
typedef void toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data);
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Set the callback for the `call` event. Pass NULL to unset.
|
|
|
|
*
|
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
void toxav_callback_call(ToxAV *av, toxav_call_cb *callback, void *user_data);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_ERR_ANSWER {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_ANSWER_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Synchronization error occurred.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_ANSWER_SYNC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend number did not designate a valid friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Audio or video bit rate is invalid.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_ANSWER_INVALID_BIT_RATE,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_ERR_ANSWER;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Accept an incoming call.
|
|
|
|
*
|
2015-05-02 04:15:12 +08:00
|
|
|
* If answering fails for any reason, the call will still be pending and it is
|
2015-06-28 01:20:52 +08:00
|
|
|
* possible to try and answer it later. Audio and video receiving are both
|
|
|
|
* enabled by default.
|
2015-02-15 06:37:52 +08:00
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend that is calling.
|
|
|
|
* @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable
|
|
|
|
* audio sending.
|
|
|
|
* @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
|
|
|
|
* video sending.
|
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate,
|
2015-11-04 02:42:05 +08:00
|
|
|
TOXAV_ERR_ANSWER *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: Call state graph
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-27 23:28:07 +08:00
|
|
|
enum TOXAV_FRIEND_CALL_STATE {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2016-11-21 00:38:30 +08:00
|
|
|
/**
|
|
|
|
* The empty bit mask. None of the bits specified below are set.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_NONE = 0,
|
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* transitions can occur for the call. This call state will never be triggered
|
|
|
|
* in combination with other call states.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_ERROR = 1,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The flag that marks that friend is sending audio.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_SENDING_A = 4,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The flag that marks that friend is sending video.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_SENDING_V = 8,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The flag that marks that friend is receiving audio.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_ACCEPTING_A = 16,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The flag that marks that friend is receiving video.
|
|
|
|
*/
|
|
|
|
TOXAV_FRIEND_CALL_STATE_ACCEPTING_V = 32,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-05-13 04:16:00 +08:00
|
|
|
};
|
2015-05-23 05:22:31 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* The function type for the call_state callback.
|
2015-02-15 06:37:52 +08:00
|
|
|
*
|
|
|
|
* @param friend_number The friend number for which the call state changed.
|
2015-07-09 09:40:47 +08:00
|
|
|
* @param state The bitmask of the new call state which is guaranteed to be
|
|
|
|
* different than the previous state. The state is set to 0 when the call is
|
|
|
|
* paused. The bitmask represents all the activities currently performed by the
|
|
|
|
* friend.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
typedef void toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Set the callback for the `call_state` event. Pass NULL to unset.
|
|
|
|
*
|
2014-02-10 06:06:44 +08:00
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *user_data);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: Call control
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_CALL_CONTROL {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Put a call on hold. Not valid before the call is accepted.
|
|
|
|
*/
|
|
|
|
TOXAV_CALL_CONTROL_PAUSE,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Reject a call if it was not answered, yet. Cancel a call after it was
|
|
|
|
* answered.
|
|
|
|
*/
|
|
|
|
TOXAV_CALL_CONTROL_CANCEL,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Calling this control will notify client to start sending audio again.
|
|
|
|
*/
|
|
|
|
TOXAV_CALL_CONTROL_UNMUTE_AUDIO,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Calling this control will notify client to start sending video again.
|
|
|
|
*/
|
|
|
|
TOXAV_CALL_CONTROL_SHOW_VIDEO,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_CALL_CONTROL;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_ERR_CALL_CONTROL {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_CONTROL_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Synchronization error occurred.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_CONTROL_SYNC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend_number passed did not designate a valid friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_ERR_CALL_CONTROL;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Sends a call control command to a friend.
|
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend this client is in a call
|
|
|
|
* with.
|
|
|
|
* @param control The control command to send.
|
|
|
|
*
|
|
|
|
* @return true on success.
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: Controlling bit rates
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
typedef enum TOXAV_ERR_BIT_RATE_SET {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_BIT_RATE_SET_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Synchronization error occurred.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_BIT_RATE_SET_SYNC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
Split bit_rate_set(), one for audio, one for video.
Fixes #572.
As discussed in the issue, there's a risk that toxcore may not hold the
maximum bitrates libvpx supports, if toxcore insists on using integer
type. I initially proposed to have another flag in set(), so that we can
use unsigned type instead. iphydf came up with a better solution, that is
splitting the original functions, one for audio, one for video. Now, we
could safely replace int32_t with uint32_t.
Also: clean video_bit_rate_invalid()
Though this is not a part of issue #572, as it's used in the
toxav_bit_rate_set(), i cleaned the code. As mannol said, there should be
a check. Uint32_t is large enough to hold the maximum bitrates libvpx
supports, but user may pass a value larger than uint while smaller than
uint32_t. Thanks to the reminding from nurupo, it's no longer a stub
function.
Bitrate error enums are shared for both audio and video
https://github.com/TokTok/c-toxcore/pull/578#issuecomment-360095609, just
as iphydf said.
2018-01-14 21:46:06 +08:00
|
|
|
* The bit rate passed was not one of the supported values.
|
2015-11-04 02:42:05 +08:00
|
|
|
*/
|
Split bit_rate_set(), one for audio, one for video.
Fixes #572.
As discussed in the issue, there's a risk that toxcore may not hold the
maximum bitrates libvpx supports, if toxcore insists on using integer
type. I initially proposed to have another flag in set(), so that we can
use unsigned type instead. iphydf came up with a better solution, that is
splitting the original functions, one for audio, one for video. Now, we
could safely replace int32_t with uint32_t.
Also: clean video_bit_rate_invalid()
Though this is not a part of issue #572, as it's used in the
toxav_bit_rate_set(), i cleaned the code. As mannol said, there should be
a check. Uint32_t is large enough to hold the maximum bitrates libvpx
supports, but user may pass a value larger than uint while smaller than
uint32_t. Thanks to the reminding from nurupo, it's no longer a stub
function.
Bitrate error enums are shared for both audio and video
https://github.com/TokTok/c-toxcore/pull/578#issuecomment-360095609, just
as iphydf said.
2018-01-14 21:46:06 +08:00
|
|
|
TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend_number passed did not designate a valid friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* This client is currently not in a call with the friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
} TOXAV_ERR_BIT_RATE_SET;
|
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: A/V sending
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
typedef enum TOXAV_ERR_SEND_FRAME {
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The function returned successfully.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_OK,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* The friend_number passed did not designate a valid friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* This client is currently not in a call with the friend.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Synchronization error occurred.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_SYNC,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* 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,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Either friend turned off audio or video receiving or we turned off sending
|
|
|
|
* for the said payload.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-11-04 02:42:05 +08:00
|
|
|
/**
|
|
|
|
* Failed to push frame through rtp interface.
|
|
|
|
*/
|
|
|
|
TOXAV_ERR_SEND_FRAME_RTP_FAILED,
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
} TOXAV_ERR_SEND_FRAME;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2016-03-09 10:52:31 +08:00
|
|
|
|
2014-11-18 07:46:46 +08:00
|
|
|
/**
|
2015-02-15 06:37:52 +08:00
|
|
|
* Send an audio frame to a friend.
|
2014-11-11 06:59:14 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]...
|
|
|
|
* Meaning: sample 1 for channel 1, sample 1 for channel 2, ...
|
|
|
|
* For mono audio, this has no meaning, every sample is subsequent. For stereo,
|
|
|
|
* this means the expected format is LRLRLR... with samples for left and right
|
|
|
|
* alternating.
|
2014-11-12 03:39:25 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* @param friend_number The friend number of the friend to which to send an
|
|
|
|
* audio frame.
|
|
|
|
* @param pcm An array of audio samples. The size of this array must be
|
|
|
|
* sample_count * channels.
|
|
|
|
* @param sample_count Number of samples in this frame. Valid numbers here are
|
|
|
|
* ((sample rate) * (audio length) / 1000), where audio length can be
|
|
|
|
* 2.5, 5, 10, 20, 40 or 60 millseconds.
|
2015-05-02 04:15:12 +08:00
|
|
|
* @param channels Number of audio channels. Supported values are 1 and 2.
|
2015-02-15 06:37:52 +08:00
|
|
|
* @param sampling_rate Audio sampling rate used in this frame. Valid sampling
|
|
|
|
* rates are 8000, 12000, 16000, 24000, or 48000.
|
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
|
2016-03-09 10:52:31 +08:00
|
|
|
uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2018-01-28 19:14:04 +08:00
|
|
|
/**
|
|
|
|
* Set the bit rate to be used in subsequent video frames.
|
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend for which to set the
|
|
|
|
* bit rate.
|
|
|
|
* @param bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable.
|
|
|
|
*
|
|
|
|
* @return true on success.
|
|
|
|
*/
|
|
|
|
bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, TOXAV_ERR_BIT_RATE_SET *error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function type for the audio_bit_rate callback. The event is triggered
|
|
|
|
* when the network becomes too saturated for current bit rates at which
|
|
|
|
* point core suggests new bit rates.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
typedef void toxav_audio_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, void *user_data);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the callback for the `audio_bit_rate` event. Pass NULL to unset.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, void *user_data);
|
|
|
|
|
2015-05-23 05:22:31 +08:00
|
|
|
/**
|
|
|
|
* Send a video frame to a friend.
|
2014-11-11 22:48:52 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* Y - plane should be of size: height * width
|
|
|
|
* U - plane should be of size: (height/2) * (width/2)
|
|
|
|
* V - plane should be of size: (height/2) * (width/2)
|
2014-11-12 03:39:25 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* @param friend_number The friend number of the friend to which to send a video
|
|
|
|
* frame.
|
|
|
|
* @param width Width of the frame in pixels.
|
|
|
|
* @param height Height of the frame in pixels.
|
|
|
|
* @param y Y (Luminance) plane data.
|
|
|
|
* @param u U (Chroma) plane data.
|
|
|
|
* @param v V (Chroma) plane data.
|
2014-11-11 06:59:14 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y,
|
2016-03-09 10:52:31 +08:00
|
|
|
const uint8_t *u, const uint8_t *v, TOXAV_ERR_SEND_FRAME *error);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2018-01-28 19:14:04 +08:00
|
|
|
/**
|
|
|
|
* Set the bit rate to be used in subsequent video frames.
|
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend for which to set the
|
|
|
|
* bit rate.
|
|
|
|
* @param bit_rate The new video bit rate in Kb/sec. Set to 0 to disable.
|
|
|
|
*
|
|
|
|
* @return true on success.
|
|
|
|
*/
|
|
|
|
bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, TOXAV_ERR_BIT_RATE_SET *error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function type for the video_bit_rate callback. The event is triggered
|
|
|
|
* when the network becomes too saturated for current bit rates at which
|
|
|
|
* point core suggests new bit rates.
|
|
|
|
*
|
|
|
|
* @param friend_number The friend number of the friend for which to set the
|
|
|
|
* bit rate.
|
|
|
|
* @param video_bit_rate Suggested maximum video bit rate in Kb/sec.
|
|
|
|
*/
|
|
|
|
typedef void toxav_video_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the callback for the `video_bit_rate` event. Pass NULL to unset.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, void *user_data);
|
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/*******************************************************************************
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* :: A/V receiving
|
2014-11-11 06:59:14 +08:00
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
******************************************************************************/
|
2016-03-09 10:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/**
|
2015-06-27 22:12:33 +08:00
|
|
|
* 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
|
2015-07-09 09:40:47 +08:00
|
|
|
* frames in the buffer. The received format is the same as in send function.
|
2015-11-04 02:42:05 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
* @param friend_number The friend number of the friend who sent an audio frame.
|
|
|
|
* @param pcm An array of audio samples (sample_count * channels elements).
|
|
|
|
* @param sample_count The number of audio samples per channel in the PCM array.
|
|
|
|
* @param channels Number of audio channels.
|
|
|
|
* @param sampling_rate Sampling rate used in this frame.
|
2014-11-12 03:39:25 +08:00
|
|
|
*
|
2014-11-11 06:59:14 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
|
2016-03-09 10:52:31 +08:00
|
|
|
uint8_t channels, uint32_t sampling_rate, void *user_data);
|
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-05-23 05:22:31 +08:00
|
|
|
/**
|
|
|
|
* Set the callback for the `audio_receive_frame` event. Pass NULL to unset.
|
2014-11-12 03:39:25 +08:00
|
|
|
*
|
2015-05-23 05:22:31 +08:00
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb *callback, void *user_data);
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-05-23 05:22:31 +08:00
|
|
|
/**
|
|
|
|
* The function type for the video_receive_frame callback.
|
2014-11-11 22:48:52 +08:00
|
|
|
*
|
2016-09-30 21:52:10 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2015-02-15 06:37:52 +08:00
|
|
|
* @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.
|
2016-09-30 21:52:10 +08:00
|
|
|
* @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.
|
2014-11-11 06:59:14 +08:00
|
|
|
*/
|
2016-09-01 07:38:58 +08:00
|
|
|
typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
|
2016-03-09 10:52:31 +08:00
|
|
|
const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride,
|
|
|
|
void *user_data);
|
|
|
|
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-02-15 06:37:52 +08:00
|
|
|
/**
|
2015-05-23 05:22:31 +08:00
|
|
|
* Set the callback for the `video_receive_frame` event. Pass NULL to unset.
|
2014-11-12 03:39:25 +08:00
|
|
|
*
|
2014-11-11 06:59:14 +08:00
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data);
|
2015-06-06 04:18:21 +08:00
|
|
|
|
2015-10-13 04:30:55 +08:00
|
|
|
/**
|
2016-09-12 23:48:35 +08:00
|
|
|
* NOTE Compatibility with old toxav group calls. TODO(iphydf): remove
|
2018-08-13 06:01:42 +08:00
|
|
|
*
|
|
|
|
* TODO(iphydf): Use proper new API guidelines for these. E.g. don't use inline
|
|
|
|
* function types, don't have per-callback userdata, especially don't have one
|
|
|
|
* userdata per group.
|
2015-10-13 04:30:55 +08:00
|
|
|
*/
|
|
|
|
/* Create a new toxav group.
|
|
|
|
*
|
|
|
|
* return group number on success.
|
|
|
|
* return -1 on failure.
|
|
|
|
*
|
|
|
|
* Audio data callback format:
|
2018-02-20 05:58:03 +08:00
|
|
|
* audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata)
|
2015-10-13 04:30:55 +08:00
|
|
|
*
|
|
|
|
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
|
|
|
|
*/
|
2018-08-13 06:01:42 +08:00
|
|
|
int toxav_add_av_groupchat(Tox *tox,
|
|
|
|
void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *),
|
|
|
|
void *userdata);
|
2015-10-13 04:30:55 +08:00
|
|
|
|
|
|
|
/* 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()):
|
2018-02-20 05:58:03 +08:00
|
|
|
* audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata)
|
2015-10-13 04:30:55 +08:00
|
|
|
*
|
|
|
|
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
|
|
|
|
*/
|
2018-02-20 05:58:03 +08:00
|
|
|
int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length,
|
|
|
|
void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *),
|
|
|
|
void *userdata);
|
2015-10-13 04:30:55 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2018-02-20 05:58:03 +08:00
|
|
|
int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
|
|
|
uint32_t sample_rate);
|
2015-10-13 04:30:55 +08:00
|
|
|
|
2019-02-10 08:00:00 +08:00
|
|
|
/* Enable A/V in a groupchat.
|
2019-02-10 08:00:00 +08:00
|
|
|
*
|
|
|
|
* A/V must be enabled on a groupchat for audio to be sent to it and for
|
|
|
|
* received audio to be handled.
|
|
|
|
*
|
|
|
|
* An A/V group created with toxav_add_av_groupchat or toxav_join_av_groupchat
|
|
|
|
* will start with A/V enabled.
|
|
|
|
*
|
|
|
|
* An A/V group loaded from a savefile will start with A/V disabled.
|
2019-02-10 08:00:00 +08:00
|
|
|
*
|
|
|
|
* return 0 on success.
|
|
|
|
* return -1 on failure.
|
|
|
|
*
|
|
|
|
* Audio data callback format (same as the one for toxav_add_av_groupchat()):
|
|
|
|
* audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata)
|
|
|
|
*
|
|
|
|
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
|
|
|
|
*/
|
|
|
|
int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber,
|
|
|
|
void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *),
|
|
|
|
void *userdata);
|
|
|
|
|
|
|
|
/* Disable A/V in a groupchat.
|
|
|
|
*
|
|
|
|
* return 0 on success.
|
|
|
|
* return -1 on failure.
|
|
|
|
*/
|
|
|
|
int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber);
|
|
|
|
|
2019-02-10 08:00:00 +08:00
|
|
|
/* Return whether A/V is enabled in the groupchat.
|
|
|
|
*/
|
|
|
|
bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
|
|
|
|
|
2015-06-06 04:18:21 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2015-04-20 17:21:55 +08:00
|
|
|
#endif
|
2018-08-13 06:01:42 +08:00
|
|
|
|
|
|
|
typedef void toxav_group_audio_cb(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm,
|
|
|
|
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *user_data);
|
|
|
|
|
|
|
|
typedef TOXAV_ERR_CALL Toxav_Err_Call;
|
|
|
|
typedef TOXAV_ERR_NEW Toxav_Err_New;
|
|
|
|
typedef TOXAV_ERR_ANSWER Toxav_Err_Answer;
|
|
|
|
typedef TOXAV_ERR_CALL_CONTROL Toxav_Err_Call_Control;
|
|
|
|
typedef TOXAV_ERR_BIT_RATE_SET Toxav_Err_Bit_Rate_Set;
|
|
|
|
typedef TOXAV_ERR_SEND_FRAME Toxav_Err_Send_Frame;
|
|
|
|
typedef TOXAV_CALL_CONTROL Toxav_Call_Control;
|
|
|
|
|
2020-04-10 07:56:19 +08:00
|
|
|
//!TOKSTYLE+
|
|
|
|
|
2018-09-10 03:54:05 +08:00
|
|
|
#endif // C_TOXCORE_TOXAV_TOXAV_H
|