2014-07-21 07:10:57 +08:00
|
|
|
/** msi.h
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TOXMSI
|
|
|
|
#define __TOXMSI
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2014-02-16 03:44:33 +08:00
|
|
|
#include "../toxcore/Messenger.h"
|
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
typedef uint8_t MSICallIDType[12];
|
|
|
|
typedef uint8_t MSIReasonStrType[255];
|
|
|
|
typedef void ( *MSICallbackType ) ( void* agent, int32_t call_idx, void *arg );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call type identifier. Also used as rtp callback prefix.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2014-05-22 03:28:14 +08:00
|
|
|
type_audio = 192,
|
2014-02-01 19:52:48 +08:00
|
|
|
type_video
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICallType;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call state identifiers.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
call_inviting, /* when sending call invite */
|
|
|
|
call_starting, /* when getting call invite */
|
|
|
|
call_active,
|
2014-06-27 05:05:13 +08:00
|
|
|
call_hold,
|
|
|
|
call_hanged_up
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
} MSICallState;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
/**
|
|
|
|
* @brief Callbacks ids that handle the states
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
/* Requests */
|
|
|
|
MSI_OnInvite,
|
|
|
|
MSI_OnStart,
|
|
|
|
MSI_OnCancel,
|
|
|
|
MSI_OnReject,
|
|
|
|
MSI_OnEnd,
|
|
|
|
|
|
|
|
/* Responses */
|
|
|
|
MSI_OnRinging,
|
|
|
|
MSI_OnStarting,
|
|
|
|
MSI_OnEnding,
|
|
|
|
|
|
|
|
/* Protocol */
|
|
|
|
MSI_OnRequestTimeout,
|
|
|
|
MSI_OnPeerTimeout,
|
|
|
|
MSI_OnMediaChange
|
|
|
|
} MSICallbackID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callbacks container
|
|
|
|
*/
|
|
|
|
typedef struct _MSICallbackCont {
|
|
|
|
MSICallbackType function;
|
|
|
|
void *data;
|
|
|
|
} MSICallbackCont;
|
|
|
|
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
|
|
|
* @brief The call struct.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-04-28 01:21:26 +08:00
|
|
|
typedef struct _MSICall { /* Call info structure */
|
2014-05-26 00:27:48 +08:00
|
|
|
struct _MSISession *session; /* Session pointer */
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-04-28 01:21:26 +08:00
|
|
|
MSICallState state;
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-04-28 01:21:26 +08:00
|
|
|
MSICallType type_local; /* Type of payload user is ending */
|
|
|
|
MSICallType *type_peer; /* Type of payload others are sending */
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
MSICallIDType id; /* Random value identifying the call */
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-04-28 01:21:26 +08:00
|
|
|
int ringing_tout_ms; /* Ringing timeout in ms */
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-04-28 01:21:26 +08:00
|
|
|
int request_timer_id; /* Timer id for outgoing request/action */
|
|
|
|
int ringing_timer_id; /* Timer id for ringing timeout */
|
2014-02-17 09:01:30 +08:00
|
|
|
|
|
|
|
|
2014-07-05 23:36:12 +08:00
|
|
|
pthread_mutex_t mutex; /* */
|
2014-05-20 06:27:02 +08:00
|
|
|
uint32_t *peers;
|
2014-04-28 01:21:26 +08:00
|
|
|
uint16_t peer_count;
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-05-17 01:56:40 +08:00
|
|
|
int32_t call_idx; /* Index of this call in MSISession */
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICall;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Control session struct
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
|
|
|
typedef struct _MSISession {
|
|
|
|
|
2014-04-28 01:21:26 +08:00
|
|
|
/* Call handlers */
|
2014-07-21 07:10:57 +08:00
|
|
|
MSICall **calls;
|
|
|
|
int32_t max_calls;
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
void *agent_handler;
|
|
|
|
Messenger *messenger_handle;
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
uint32_t frequ;
|
|
|
|
uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-07-05 23:36:12 +08:00
|
|
|
pthread_mutex_t mutex;
|
2014-07-03 23:13:11 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
void *timer_handler;
|
|
|
|
MSICallbackCont callbacks[11]; /* Callbacks used by this session */
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSISession;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callback setter.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-07-21 07:10:57 +08:00
|
|
|
* @param session The container.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param callback The callback.
|
|
|
|
* @param id The id.
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-07-21 07:10:57 +08:00
|
|
|
void msi_register_callback(MSISession *session, MSICallbackType callback, MSICallbackID id, void *userdata);
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Start the control session.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param messenger Tox* object.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param max_calls Amount of calls possible
|
2014-01-25 08:32:33 +08:00
|
|
|
* @return MSISession* The created session.
|
2014-04-17 00:08:44 +08:00
|
|
|
* @retval NULL Error occurred.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-05-17 01:56:40 +08:00
|
|
|
MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Terminate control session.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session The session
|
|
|
|
* @return int
|
|
|
|
*/
|
2014-02-17 09:01:30 +08:00
|
|
|
int msi_terminate_session ( MSISession *session );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send invite request to friend_id.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index Set to new call index.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param call_type Type of the call. Audio or Video(both audio and video)
|
|
|
|
* @param rngsec Ringing timeout.
|
|
|
|
* @param friend_id The friend.
|
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-26 00:27:48 +08:00
|
|
|
int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Hangup active call.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index To which call is this action handled.
|
2014-02-17 09:01:30 +08:00
|
|
|
* @return int
|
2014-04-17 00:08:44 +08:00
|
|
|
* @retval -1 Error occurred.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @retval 0 Success.
|
|
|
|
*/
|
2014-05-17 01:56:40 +08:00
|
|
|
int msi_hangup ( MSISession *session, int32_t call_index );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Answer active call request.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index To which call is this action handled.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param call_type Answer with Audio or Video(both).
|
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-17 01:56:40 +08:00
|
|
|
int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Cancel request.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index To which call is this action handled.
|
2014-02-10 06:06:44 +08:00
|
|
|
* @param peer To which peer.
|
|
|
|
* @param reason Set optional reason header. Pass NULL if none.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-26 00:27:48 +08:00
|
|
|
int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reject request.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index To which call is this action handled.
|
2014-02-05 06:08:34 +08:00
|
|
|
* @param reason Set optional reason header. Pass NULL if none.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-07-21 07:10:57 +08:00
|
|
|
int msi_reject ( MSISession *session, int32_t call_index, const char *reason );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send invite request to friend_id.
|
|
|
|
*
|
|
|
|
* @param session Control session.
|
|
|
|
* @param call_index Call index.
|
|
|
|
* @param call_type Type of the call. Audio or Video(both audio and video)
|
|
|
|
* @param rngsec Ringing timeout.
|
|
|
|
* @param friend_id The friend.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
int msi_change_type ( MSISession *session, int32_t call_index, MSICallType call_type );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Terminate the current call.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2014-01-25 08:32:33 +08:00
|
|
|
* @param session Control session.
|
2014-04-28 01:21:26 +08:00
|
|
|
* @param call_index To which call is this action handled.
|
2014-01-25 08:32:33 +08:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-17 01:56:40 +08:00
|
|
|
int msi_stopcall ( MSISession *session, int32_t call_index );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
#endif /* __TOXMSI */
|