1 /* SPDX-License-Identifier: GPL-3.0-or-later 2 * Copyright © 2016-2018 The TokTok team. 3 * Copyright © 2013-2015 Tox project. 4 */ 5 #ifndef C_TOXCORE_TOXAV_MSI_H 6 #define C_TOXCORE_TOXAV_MSI_H 7 8 #include "audio.h" 9 #include "video.h" 10 11 #include "../toxcore/Messenger.h" 12 #include "../toxcore/logger.h" 13 14 #include <inttypes.h> 15 #include <pthread.h> 16 17 /** 18 * Error codes. 19 */ 20 typedef enum MSIError { 21 MSI_E_NONE, 22 MSI_E_INVALID_MESSAGE, 23 MSI_E_INVALID_PARAM, 24 MSI_E_INVALID_STATE, 25 MSI_E_STRAY_MESSAGE, 26 MSI_E_SYSTEM, 27 MSI_E_HANDLE, 28 MSI_E_UNDISCLOSED, /* NOTE: must be last enum otherwise parsing will not work */ 29 } MSIError; 30 31 /** 32 * Supported capabilities 33 */ 34 typedef enum MSICapabilities { 35 MSI_CAP_S_AUDIO = 4, /* sending audio */ 36 MSI_CAP_S_VIDEO = 8, /* sending video */ 37 MSI_CAP_R_AUDIO = 16, /* receiving audio */ 38 MSI_CAP_R_VIDEO = 32, /* receiving video */ 39 } MSICapabilities; 40 41 42 /** 43 * Call state identifiers. 44 */ 45 typedef enum MSICallState { 46 MSI_CALL_INACTIVE, /* Default */ 47 MSI_CALL_ACTIVE, 48 MSI_CALL_REQUESTING, /* when sending call invite */ 49 MSI_CALL_REQUESTED, /* when getting call invite */ 50 } MSICallState; 51 52 /** 53 * Callbacks ids that handle the states 54 */ 55 typedef enum MSICallbackID { 56 MSI_ON_INVITE, /* Incoming call */ 57 MSI_ON_START, /* Call (RTP transmission) started */ 58 MSI_ON_END, /* Call that was active ended */ 59 MSI_ON_ERROR, /* On protocol error */ 60 MSI_ON_PEERTIMEOUT, /* Peer timed out; stop the call */ 61 MSI_ON_CAPABILITIES, /* Peer requested capabilities change */ 62 } MSICallbackID; 63 64 /** 65 * The call struct. Please do not modify outside msi.c 66 */ 67 typedef struct MSICall_s { 68 struct MSISession_s *session; /* Session pointer */ 69 70 MSICallState state; 71 uint8_t peer_capabilities; /* Peer capabilities */ 72 uint8_t self_capabilities; /* Self capabilities */ 73 uint16_t peer_vfpsz; /* Video frame piece size */ 74 uint32_t friend_number; /* Index of this call in MSISession */ 75 MSIError error; /* Last error */ 76 77 struct ToxAVCall_s *av_call; /* Pointer to av call handler */ 78 79 struct MSICall_s *next; 80 struct MSICall_s *prev; 81 } MSICall; 82 83 84 /** 85 * Expected return on success is 0, if any other number is 86 * returned the call is considered errored and will be handled 87 * as such which means it will be terminated without any notice. 88 */ 89 typedef int msi_action_cb(void *av, MSICall *call); 90 91 /** 92 * Control session struct. Please do not modify outside msi.c 93 */ 94 typedef struct MSISession_s { 95 /* Call handlers */ 96 MSICall **calls; 97 uint32_t calls_tail; 98 uint32_t calls_head; 99 100 void *av; 101 Messenger *messenger; 102 103 pthread_mutex_t mutex[1]; 104 msi_action_cb *callbacks[7]; 105 } MSISession; 106 107 /** 108 * Start the control session. 109 */ 110 MSISession *msi_new(Messenger *m); 111 /** 112 * Terminate control session. NOTE: all calls will be freed 113 */ 114 int msi_kill(MSISession *session, const Logger *log); 115 /** 116 * Callback setter. 117 */ 118 void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id); 119 /** 120 * Send invite request to friend_number. 121 */ 122 int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities); 123 /** 124 * Hangup call. NOTE: `call` will be freed 125 */ 126 int msi_hangup(MSICall *call); 127 /** 128 * Answer call request. 129 */ 130 int msi_answer(MSICall *call, uint8_t capabilities); 131 /** 132 * Change capabilities of the call. 133 */ 134 int msi_change_capabilities(MSICall *call, uint8_t capabilities); 135 136 #endif // C_TOXCORE_TOXAV_MSI_H 137