2014-02-10 06:06:44 +08:00
|
|
|
/** toxav.h
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-10 06:06:44 +08:00
|
|
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Tox.
|
|
|
|
*
|
|
|
|
* Tox is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tox is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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/>.
|
|
|
|
*
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 05:36:15 +08:00
|
|
|
* Report bugs/suggestions at #tox-dev @ freenode.net:6667
|
2014-02-10 06:06:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __TOXAV
|
|
|
|
#define __TOXAV
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2014-02-16 03:44:33 +08:00
|
|
|
/* vpx_image_t */
|
|
|
|
#include <vpx/vpx_image.h>
|
|
|
|
|
2014-02-17 09:01:30 +08:00
|
|
|
typedef void *( *ToxAVCallback ) ( void *arg );
|
2014-02-10 06:06:44 +08:00
|
|
|
typedef struct _ToxAv ToxAv;
|
|
|
|
|
|
|
|
#ifndef __TOX_DEFINED__
|
|
|
|
#define __TOX_DEFINED__
|
|
|
|
typedef struct Tox Tox;
|
|
|
|
#endif
|
|
|
|
|
2014-02-16 03:44:33 +08:00
|
|
|
#define RTP_PAYLOAD_SIZE 65535
|
|
|
|
|
|
|
|
/* Default video bitrate in bytes/s */
|
|
|
|
#define VIDEO_BITRATE 10*1000*100
|
|
|
|
|
|
|
|
/* Default audio bitrate in bits/s */
|
|
|
|
#define AUDIO_BITRATE 64000
|
|
|
|
|
|
|
|
/* Number of audio channels. */
|
|
|
|
#define AUDIO_CHANNELS 1
|
|
|
|
|
|
|
|
/* Audio frame duration in miliseconds */
|
|
|
|
#define AUDIO_FRAME_DURATION 20
|
|
|
|
|
|
|
|
/* Audio sample rate recommended to be 48kHz for Opus */
|
|
|
|
#define AUDIO_SAMPLE_RATE 48000
|
|
|
|
|
|
|
|
/* The amount of samples in one audio frame */
|
|
|
|
#define AUDIO_FRAME_SIZE AUDIO_SAMPLE_RATE*AUDIO_FRAME_DURATION/1000
|
|
|
|
|
|
|
|
/* Assume 60 fps*/
|
|
|
|
#define MAX_ENCODE_TIME_US ((1000 / 60) * 1000)
|
|
|
|
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-17 09:01:30 +08:00
|
|
|
/**
|
2014-02-16 04:29:41 +08:00
|
|
|
* @brief Callbacks ids that handle the call states.
|
2014-02-10 06:06:44 +08:00
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/* Requests */
|
|
|
|
OnInvite,
|
|
|
|
OnStart,
|
|
|
|
OnCancel,
|
|
|
|
OnReject,
|
|
|
|
OnEnd,
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-02-10 06:06:44 +08:00
|
|
|
/* Responses */
|
|
|
|
OnRinging,
|
|
|
|
OnStarting,
|
|
|
|
OnEnding,
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-02-10 06:06:44 +08:00
|
|
|
/* Protocol */
|
|
|
|
OnError,
|
2014-02-16 03:44:33 +08:00
|
|
|
OnRequestTimeout
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-02-10 06:06:44 +08:00
|
|
|
} ToxAvCallbackID;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call type identifier.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
TypeAudio = 70,
|
|
|
|
TypeVideo
|
|
|
|
} ToxAvCallType;
|
|
|
|
|
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Error indicators.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
*/
|
2014-02-10 06:06:44 +08:00
|
|
|
typedef enum {
|
|
|
|
ErrorNone = 0,
|
|
|
|
ErrorInternal = -1, /* Internal error */
|
|
|
|
ErrorAlreadyInCall = -2, /* Already has an active call */
|
|
|
|
ErrorNoCall = -3, /* Trying to perform call action while not in a call */
|
|
|
|
ErrorInvalidState = -4, /* Trying to perform call action while in invalid state*/
|
|
|
|
ErrorNoRtpSession = -5, /* Trying to perform rtp action on invalid session */
|
|
|
|
ErrorAudioPacketLost = -6, /* Indicating packet loss */
|
|
|
|
ErrorStartingAudioRtp = -7, /* Error in toxav_prepare_transmission() */
|
|
|
|
ErrorStartingVideoRtp = -8 , /* Error in toxav_prepare_transmission() */
|
|
|
|
ErrorNoTransmission = -9, /* Returned in toxav_kill_transmission() */
|
|
|
|
ErrorTerminatingAudioRtp = -10, /* Returned in toxav_kill_transmission() */
|
|
|
|
ErrorTerminatingVideoRtp = -11, /* Returned in toxav_kill_transmission() */
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-02-10 06:06:44 +08:00
|
|
|
} ToxAvError;
|
|
|
|
|
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Start new A/V session. There can only be one session at the time. If you register more
|
|
|
|
* it will result in undefined behaviour.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param messenger The messenger handle.
|
|
|
|
* @param useragent The agent handling A/V session (i.e. phone).
|
|
|
|
* @param ua_name Useragent name.
|
|
|
|
* @param video_width Width of video frame.
|
|
|
|
* @param video_height Height of video frame.
|
|
|
|
* @return ToxAv*
|
|
|
|
* @retval NULL On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
ToxAv *toxav_new(Tox *messenger, void *useragent, const char *ua_name, uint16_t video_width, uint16_t video_height);
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remove A/V session.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
void toxav_kill(ToxAv *av);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Register callback for call state.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param callback The callback
|
|
|
|
* @param id One of the ToxAvCallbackID values
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-02-10 06:06:44 +08:00
|
|
|
void toxav_register_callstate_callback (ToxAVCallback callback, ToxAvCallbackID id);
|
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Call user. Use its friend_id.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param user The user.
|
|
|
|
* @param call_type Call type.
|
|
|
|
* @param ringing_seconds Ringing timeout.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_call(ToxAv *av, int user, ToxAvCallType call_type, int ringing_seconds);
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Hangup active call.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_hangup(ToxAv *av);
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Answer incomming call.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param call_type Answer with...
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_answer(ToxAv *av, ToxAvCallType call_type );
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reject incomming call.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param reason Optional reason. Set NULL if none.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_reject(ToxAv *av, const char *reason);
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Cancel outgoing request.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param reason Optional reason.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_cancel(ToxAv *av, const char *reason);
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_stop_call(ToxAv *av);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Must be call before any RTP transmission occurs.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_prepare_transmission(ToxAv *av);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Call this at the end of the transmission.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
2014-02-10 06:06:44 +08:00
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_kill_transmission(ToxAv *av);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Receive decoded video packet.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param output Storage.
|
2014-02-17 09:01:30 +08:00
|
|
|
* @return int
|
2014-02-16 04:29:41 +08:00
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On Error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_recv_video ( ToxAv *av, vpx_image_t **output);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Receive decoded audio frame.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param frame_size ...
|
2014-02-17 09:01:30 +08:00
|
|
|
* @param dest Destination of the packet. Make sure it has enough space for
|
2014-02-16 04:29:41 +08:00
|
|
|
* RTP_PAYLOAD_SIZE bytes.
|
|
|
|
* @return int
|
|
|
|
* @retval >=0 Size of received packet.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_recv_audio( ToxAv *av, int frame_size, int16_t *dest );
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Encode and send video packet.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param input The packet.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_send_video ( ToxAv *av, vpx_image_t *input);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Encode and send audio frame.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param frame The frame.
|
|
|
|
* @param frame_size It's size.
|
|
|
|
* @return int
|
|
|
|
* @retval 0 Success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_send_audio ( ToxAv *av, const int16_t *frame, int frame_size);
|
2014-02-10 06:06:44 +08:00
|
|
|
|
2014-02-16 04:29:41 +08:00
|
|
|
/**
|
|
|
|
* @brief Get peer transmission type. It can either be audio or video.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @param peer The peer
|
|
|
|
* @return int
|
|
|
|
* @retval ToxAvCallType On success.
|
|
|
|
* @retval ToxAvError On error.
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int toxav_get_peer_transmission_type ( ToxAv *av, int peer );
|
2014-02-16 04:29:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get reference to an object that is handling av session.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-02-16 04:29:41 +08:00
|
|
|
* @param av Handler.
|
|
|
|
* @return void*
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
void *toxav_get_agent_handler ( ToxAv *av );
|
2014-02-10 06:06:44 +08:00
|
|
|
|
|
|
|
#endif /* __TOXAV */
|