2017-01-14 23:46:31 +08:00
|
|
|
/*
|
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.
|
2014-02-17 09:01:30 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* This file is part of Tox, the free peer to peer instant messenger.
|
2014-01-25 08:32:33 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* 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.
|
2014-01-25 08:32:33 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* 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.
|
2014-01-25 08:32:33 +08:00
|
|
|
*
|
2017-01-14 23:46:31 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-02-17 06:30:20 +08:00
|
|
|
#ifndef MSI_H
|
|
|
|
#define MSI_H
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2015-04-21 08:31:12 +08:00
|
|
|
#include "audio.h"
|
|
|
|
#include "video.h"
|
2014-02-16 03:44:33 +08:00
|
|
|
|
2016-09-11 22:47:51 +08:00
|
|
|
#include "../toxcore/Messenger.h"
|
2016-11-15 15:53:47 +08:00
|
|
|
#include "../toxcore/logger.h"
|
2016-09-11 22:47:51 +08:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2015-02-17 06:30:20 +08:00
|
|
|
/**
|
|
|
|
* Error codes.
|
|
|
|
*/
|
2018-08-13 04:53:10 +08:00
|
|
|
typedef enum MSIError {
|
2018-08-12 20:53:12 +08:00
|
|
|
MSI_E_NONE,
|
|
|
|
MSI_E_INVALID_MESSAGE,
|
|
|
|
MSI_E_INVALID_PARAM,
|
|
|
|
MSI_E_INVALID_STATE,
|
|
|
|
MSI_E_STRAY_MESSAGE,
|
|
|
|
MSI_E_SYSTEM,
|
|
|
|
MSI_E_HANDLE,
|
|
|
|
MSI_E_UNDISCLOSED, /* NOTE: must be last enum otherwise parsing will not work */
|
2015-02-17 06:30:20 +08:00
|
|
|
} MSIError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supported capabilities
|
|
|
|
*/
|
2018-08-13 04:53:10 +08:00
|
|
|
typedef enum MSICapabilities {
|
2018-08-12 20:53:12 +08:00
|
|
|
MSI_CAP_S_AUDIO = 4, /* sending audio */
|
|
|
|
MSI_CAP_S_VIDEO = 8, /* sending video */
|
|
|
|
MSI_CAP_R_AUDIO = 16, /* receiving audio */
|
|
|
|
MSI_CAP_R_VIDEO = 32, /* receiving video */
|
2015-02-17 06:30:20 +08:00
|
|
|
} MSICapabilities;
|
|
|
|
|
2014-01-25 08:32:33 +08:00
|
|
|
|
|
|
|
/**
|
2014-11-18 07:46:46 +08:00
|
|
|
* Call state identifiers.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2018-08-13 04:53:10 +08:00
|
|
|
typedef enum MSICallState {
|
2018-08-12 20:53:12 +08:00
|
|
|
MSI_CALL_INACTIVE, /* Default */
|
|
|
|
MSI_CALL_ACTIVE,
|
|
|
|
MSI_CALL_REQUESTING, /* when sending call invite */
|
|
|
|
MSI_CALL_REQUESTED, /* when getting call invite */
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICallState;
|
|
|
|
|
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
|
|
|
*/
|
2018-08-13 04:53:10 +08:00
|
|
|
typedef enum MSICallbackID {
|
2018-08-12 20:53:12 +08:00
|
|
|
MSI_ON_INVITE, /* Incoming call */
|
|
|
|
MSI_ON_START, /* Call (RTP transmission) started */
|
|
|
|
MSI_ON_END, /* Call that was active ended */
|
|
|
|
MSI_ON_ERROR, /* On protocol error */
|
|
|
|
MSI_ON_PEERTIMEOUT, /* Peer timed out; stop the call */
|
|
|
|
MSI_ON_CAPABILITIES, /* Peer requested capabilities change */
|
2014-07-21 07:10:57 +08:00
|
|
|
} MSICallbackID;
|
|
|
|
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* The call struct. Please do not modify outside msi.c
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-02-17 06:30:20 +08:00
|
|
|
typedef struct MSICall_s {
|
2015-02-18 06:34:40 +08:00
|
|
|
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-18 06:34:40 +08:00
|
|
|
uint8_t peer_capabilities; /* Peer capabilities */
|
|
|
|
uint8_t self_capabilities; /* Self capabilities */
|
2015-02-20 07:23:38 +08:00
|
|
|
uint16_t peer_vfpsz; /* Video frame piece size */
|
2015-10-11 05:54:23 +08:00
|
|
|
uint32_t friend_number; /* Index of this call in MSISession */
|
2015-02-19 06:23:46 +08:00
|
|
|
MSIError error; /* Last error */
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2018-08-13 04:53:10 +08:00
|
|
|
struct ToxAVCall_s *av_call; /* Pointer to av call handler */
|
2015-10-11 05:54:23 +08:00
|
|
|
|
|
|
|
struct MSICall_s *next;
|
|
|
|
struct MSICall_s *prev;
|
2014-01-25 08:32:33 +08:00
|
|
|
} MSICall;
|
|
|
|
|
|
|
|
|
2015-02-18 06:34:40 +08:00
|
|
|
/**
|
2015-02-21 08:07:22 +08:00
|
|
|
* Expected return on success is 0, if any other number is
|
|
|
|
* returned the call is considered errored and will be handled
|
|
|
|
* as such which means it will be terminated without any notice.
|
2015-02-18 06:34:40 +08:00
|
|
|
*/
|
2016-09-20 04:49:04 +08:00
|
|
|
typedef int msi_action_cb(void *av, MSICall *call);
|
2015-02-18 06:34:40 +08:00
|
|
|
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* Control session struct. Please do not modify outside msi.c
|
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;
|
2015-02-17 06:30:20 +08:00
|
|
|
uint32_t calls_tail;
|
|
|
|
uint32_t calls_head;
|
2015-10-11 05:54:23 +08:00
|
|
|
|
2015-02-19 06:23:46 +08:00
|
|
|
void *av;
|
|
|
|
Messenger *messenger;
|
2014-02-17 09:01:30 +08:00
|
|
|
|
2014-11-29 20:42:19 +08:00
|
|
|
pthread_mutex_t mutex[1];
|
2015-10-11 05:54:23 +08:00
|
|
|
msi_action_cb *callbacks[7];
|
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
|
|
|
*/
|
2015-10-11 05:54:23 +08:00
|
|
|
MSISession *msi_new(Messenger *m);
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* Terminate control session. NOTE: all calls will be freed
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2018-06-24 01:16:28 +08:00
|
|
|
int msi_kill(MSISession *session, const Logger *log);
|
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-10-11 05:54:23 +08:00
|
|
|
void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id);
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-04-29 07:01:25 +08:00
|
|
|
* Send invite request to friend_number.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-10-11 05:54:23 +08:00
|
|
|
int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities);
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* Hangup call. NOTE: 'call' will be freed
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-10-11 05:54:23 +08:00
|
|
|
int msi_hangup(MSICall *call);
|
2014-07-21 07:10:57 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* Answer call request.
|
2014-07-21 07:10:57 +08:00
|
|
|
*/
|
2015-10-11 05:54:23 +08:00
|
|
|
int msi_answer(MSICall *call, uint8_t capabilities);
|
2014-01-25 08:32:33 +08:00
|
|
|
/**
|
2015-02-17 06:30:20 +08:00
|
|
|
* Change capabilities of the call.
|
2014-01-25 08:32:33 +08:00
|
|
|
*/
|
2015-10-11 05:54:23 +08:00
|
|
|
int msi_change_capabilities(MSICall *call, uint8_t capabilities);
|
2014-01-25 08:32:33 +08:00
|
|
|
|
2015-02-17 06:30:20 +08:00
|
|
|
#endif /* MSI_H */
|