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-11-29 20:42:19 +08:00
|
|
|
#include "codec.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];
|
2015-02-16 05:41:10 +08:00
|
|
|
typedef void ( *MSICallbackType ) ( void *agent, int32_t call_idx);
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Call type identifier. Also used as rtp callback prefix.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2014-11-29 20:42:19 +08:00
|
|
|
msi_TypeAudio = 192,
|
|
|
|
msi_TypeVideo
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICallType;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Call state identifiers.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2015-01-25 06:29:54 +08:00
|
|
|
msi_CallRequesting, /* when sending call invite */
|
|
|
|
msi_CallRequested, /* when getting call invite */
|
2014-11-29 20:42:19 +08:00
|
|
|
msi_CallActive,
|
|
|
|
msi_CallHold,
|
|
|
|
msi_CallOver
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
} MSICallState;
|
|
|
|
|
|
|
|
|
2014-07-27 01:29:49 +08:00
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Encoding settings.
|
2014-07-27 01:29:49 +08:00
|
|
|
*/
|
2015-01-18 01:22:20 +08:00
|
|
|
typedef struct {
|
2014-07-27 01:29:49 +08:00
|
|
|
MSICallType call_type;
|
2014-07-27 09:26:32 +08:00
|
|
|
|
2014-07-27 01:29:49 +08:00
|
|
|
uint32_t video_bitrate; /* In kbits/s */
|
|
|
|
uint16_t max_video_width; /* In px */
|
|
|
|
uint16_t max_video_height; /* In px */
|
2014-07-27 09:26:32 +08:00
|
|
|
|
2014-07-27 01:29:49 +08:00
|
|
|
uint32_t audio_bitrate; /* In bits/s */
|
|
|
|
uint16_t audio_frame_duration; /* In ms */
|
|
|
|
uint32_t audio_sample_rate; /* In Hz */
|
|
|
|
uint32_t audio_channels;
|
|
|
|
} MSICSettings;
|
|
|
|
|
2015-02-16 05:41:10 +08:00
|
|
|
/**
|
|
|
|
* Active capabilities masks
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
msi_SendingAudio = 1,
|
|
|
|
msi_SendingVideo = 2,
|
|
|
|
msi_RecvingAudio = 4,
|
|
|
|
msi_RecvingVideo = 8,
|
|
|
|
} MSICapMask;
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Callbacks ids that handle the states
|
2014-07-21 07:10:57 +08:00
|
|
|
*/
|
|
|
|
typedef enum {
|
2014-11-29 20:42:19 +08:00
|
|
|
msi_OnInvite, /* Incoming call */
|
|
|
|
msi_OnRinging, /* When peer is ready to accept/reject the call */
|
|
|
|
msi_OnStart, /* Call (RTP transmission) started */
|
|
|
|
msi_OnCancel, /* The side that initiated call canceled invite */
|
|
|
|
msi_OnReject, /* The side that was invited rejected the call */
|
|
|
|
msi_OnEnd, /* Call that was active ended */
|
|
|
|
msi_OnRequestTimeout, /* When the requested action didn't get response in specified time */
|
|
|
|
msi_OnPeerTimeout, /* Peer timed out; stop the call */
|
|
|
|
msi_OnPeerCSChange, /* Peer requested Csettings change */
|
|
|
|
msi_OnSelfCSChange /* Csettings change confirmation */
|
2014-07-21 07:10:57 +08:00
|
|
|
} MSICallbackID;
|
|
|
|
|
|
|
|
/**
|
2014-11-29 20:42:19 +08:00
|
|
|
* Errors
|
2014-07-21 07:10:57 +08:00
|
|
|
*/
|
2014-11-29 20:42:19 +08:00
|
|
|
typedef enum {
|
|
|
|
msi_ErrorNoCall = -20, /* Trying to perform call action while not in a call */
|
|
|
|
msi_ErrorInvalidState = -21, /* Trying to perform call action while in invalid state*/
|
|
|
|
msi_ErrorAlreadyInCallWithPeer = -22, /* Trying to call peer when already in a call with peer */
|
|
|
|
msi_ErrorReachedCallLimit = -23, /* Cannot handle more calls */
|
|
|
|
} MSIError;
|
2014-07-21 07:10:57 +08:00
|
|
|
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* The call struct.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-02-16 05:41:10 +08:00
|
|
|
typedef struct {
|
|
|
|
struct MSISession_s *session; /* Session pointer */
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2015-01-18 01:22:20 +08:00
|
|
|
MSICallState state;
|
2015-02-16 05:41:10 +08:00
|
|
|
uint8_t caps; /* Active capabilities */
|
|
|
|
|
|
|
|
uint32_t friend_id; /* Index of this call in MSISession */
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICall;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Control session struct
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-01-18 01:22:20 +08:00
|
|
|
typedef struct MSISession_s {
|
2014-04-28 01:21:26 +08:00
|
|
|
/* Call handlers */
|
2014-07-21 07:10:57 +08:00
|
|
|
MSICall **calls;
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-07-22 23:20:55 +08:00
|
|
|
void *agent_handler;
|
2014-07-21 07:10:57 +08:00
|
|
|
Messenger *messenger_handle;
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-11-29 20:42:19 +08:00
|
|
|
pthread_mutex_t mutex[1];
|
2015-02-16 05:41:10 +08:00
|
|
|
MSICallbackType callbacks[10];
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSISession;
|
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Start the control session.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-11-18 07:46:46 +08:00
|
|
|
MSISession *msi_new ( Messenger *messenger, int32_t max_calls );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Terminate control session.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-11-18 07:46:46 +08:00
|
|
|
int msi_kill ( MSISession *session );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Callback setter.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-02-16 05:41:10 +08:00
|
|
|
void msi_register_callback(MSISession *session, MSICallbackType callback, MSICallbackID id);
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Send invite request to friend_id.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-11-25 09:24:59 +08:00
|
|
|
int msi_invite ( MSISession *session,
|
|
|
|
int32_t *call_index,
|
|
|
|
const MSICSettings *csettings,
|
2014-11-18 07:46:46 +08:00
|
|
|
uint32_t rngsec,
|
2014-07-27 09:26:32 +08:00
|
|
|
uint32_t friend_id );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Hangup active call.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Answer active call request.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-11-25 09:24:59 +08:00
|
|
|
int msi_answer ( MSISession *session, int32_t call_index, const MSICSettings *csettings );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Cancel request.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Reject incoming call.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-07-21 07:10:57 +08:00
|
|
|
int msi_reject ( MSISession *session, int32_t call_index, const char *reason );
|
|
|
|
|
|
|
|
/**
|
2014-11-25 09:24:59 +08:00
|
|
|
* Terminate the call.
|
2014-07-21 07:10:57 +08:00
|
|
|
*/
|
2014-11-18 07:46:46 +08:00
|
|
|
int msi_stopcall ( MSISession *session, int32_t call_index );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2014-07-21 07:10:57 +08:00
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Change codec settings of the current call.
|
2014-07-21 07:10:57 +08:00
|
|
|
*/
|
2014-11-25 09:24:59 +08:00
|
|
|
int msi_change_csettings ( MSISession *session, int32_t call_index, const MSICSettings *csettings );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-25 09:24:59 +08:00
|
|
|
* Main msi loop
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2014-11-25 09:24:59 +08:00
|
|
|
void msi_do( MSISession *session );
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
#endif /* __TOXMSI */
|