tomato/toxav/msi.h
Green Sky 3b6bb15e86 Squashed 'external/toxcore/c-toxcore/' changes from 11ab1d2a723..d9b8fa6098d
d9b8fa6098d fix: Fake broadcast address for 127.x.x.x
aa649165a57 chore: Add code for future netprof TCP testing
9e5693de5ac chore: add to_string functions for netprof enums
52d915e6a90 cleanup: Heap allocate network profile objects
80fabd4a729 feat: Implement Tox network profiler
05abe083cb6 cleanup: Some random cleanups, mostly related to mem.
5cca24513b8 cleanup: Check that onion IP/Port packing worked.
e092ecd1244 cleanup: Use tox memory allocator in some more places.
3cfe41c7587 fix: Avoid `memcpy`-ing structs into onion ping id data.
e32ac001938 fix: Add more information on why the frame was not sent.
ab887003687 fix: Allow TCP connections to fail `connect` calls.
7603170e663 refactor: Use tox memory in group connection allocations.
5bd8a85eb89 cleanup: Align internal logger with external on type of source line.
e9bf524d9e1 cleanup: Add missing `#include` to sort_test.cc.
d10c966b998 feat: Add `to_string` functions for toxencryptsave errors.
7bfd0dc8003 docs: Update the docs for group join functions
380dde9f2ae test: Add more logging to TCP connection constructor.
0f12f384c8c cleanup: Reduce stack frame sizes to below 4096 bytes.
bc43cec0626 chore: Happy new year!
fbe78f1702e cleanup: Add a `TOX_HIDE_DEPRECATED` check to hide deprecated symbols.
44d9da07e77 refactor: Use tox memory for group moderation/pack allocations.
7f26d520168 refactor: Use tox memory in group chats allocations.
2f62f3d0e77 refactor: Use tox Memory for group allocations.
8a968162041 chore: Add dispatch/events headers to bazel export.
2bbfb35abf6 docs: Output the error code string instead of int. in toxav logging
d55d0e4eaef cleanup: Remove redundant code for checking if group exists
2a6dc643338 chore: Upgrade dependencies for websockify.
fc0650601c1 fix: Allow peers to reconnect to group chats using a password

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: d9b8fa6098de6c074038b6664d2572627540b148
2025-01-18 15:53:06 +01:00

147 lines
4.3 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2025 The TokTok team.
* Copyright © 2013-2015 Tox project.
*/
#ifndef C_TOXCORE_TOXAV_MSI_H
#define C_TOXCORE_TOXAV_MSI_H
#include <pthread.h>
#include <stdint.h>
#include "audio.h"
#include "video.h"
#include "../toxcore/logger.h"
/**
* Error codes.
*/
typedef enum MSIError {
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 */
} MSIError;
/**
* Supported capabilities
*/
typedef enum MSICapabilities {
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 */
} MSICapabilities;
/**
* Call state identifiers.
*/
typedef enum MSICallState {
MSI_CALL_INACTIVE = 0, /* Default */
MSI_CALL_ACTIVE = 1,
MSI_CALL_REQUESTING = 2, /* when sending call invite */
MSI_CALL_REQUESTED = 3, /* when getting call invite */
} MSICallState;
/**
* Callbacks ids that handle the states
*/
typedef enum MSICallbackID {
MSI_ON_INVITE = 0, /* Incoming call */
MSI_ON_START = 1, /* Call (RTP transmission) started */
MSI_ON_END = 2, /* Call that was active ended */
MSI_ON_ERROR = 3, /* On protocol error */
MSI_ON_PEERTIMEOUT = 4, /* Peer timed out; stop the call */
MSI_ON_CAPABILITIES = 5, /* Peer requested capabilities change */
} MSICallbackID;
/**
* The call struct. Please do not modify outside msi.c
*/
typedef struct MSICall {
struct MSISession *session; /* Session pointer */
MSICallState state;
uint8_t peer_capabilities; /* Peer capabilities */
uint8_t self_capabilities; /* Self capabilities */
uint16_t peer_vfpsz; /* Video frame piece size */
uint32_t friend_number; /* Index of this call in MSISession */
MSIError error; /* Last error */
struct ToxAVCall *av_call; /* Pointer to av call handler */
struct MSICall *next;
struct MSICall *prev;
} MSICall;
/**
* 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.
*/
typedef int msi_action_cb(void *object, MSICall *call);
/**
* Control session struct. Please do not modify outside msi.c
*/
typedef struct MSISession {
/* Call handlers */
MSICall **calls;
uint32_t calls_tail;
uint32_t calls_head;
void *av;
Tox *tox;
pthread_mutex_t mutex[1];
msi_action_cb *invite_callback;
msi_action_cb *start_callback;
msi_action_cb *end_callback;
msi_action_cb *error_callback;
msi_action_cb *peertimeout_callback;
msi_action_cb *capabilities_callback;
} MSISession;
/**
* Start the control session.
*/
MSISession *msi_new(const Logger *log, Tox *tox);
/**
* Terminate control session. NOTE: all calls will be freed
*/
int msi_kill(const Logger *log, Tox *tox, MSISession *session);
/**
* Callback setters.
*/
void msi_callback_invite(MSISession *session, msi_action_cb *callback);
void msi_callback_start(MSISession *session, msi_action_cb *callback);
void msi_callback_end(MSISession *session, msi_action_cb *callback);
void msi_callback_error(MSISession *session, msi_action_cb *callback);
void msi_callback_peertimeout(MSISession *session, msi_action_cb *callback);
void msi_callback_capabilities(MSISession *session, msi_action_cb *callback);
/**
* Send invite request to friend_number.
*/
int msi_invite(const Logger *log, MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities);
/**
* Hangup call. NOTE: `call` will be freed
*/
int msi_hangup(const Logger *log, MSICall *call);
/**
* Answer call request.
*/
int msi_answer(const Logger *log, MSICall *call, uint8_t capabilities);
/**
* Change capabilities of the call.
*/
int msi_change_capabilities(const Logger *log, MSICall *call, uint8_t capabilities);
bool check_peer_offline_status(const Logger *log, const Tox *tox, MSISession *session, uint32_t friend_number);
#endif /* C_TOXCORE_TOXAV_MSI_H */