toxcore/toxav/msi.h

160 lines
4.0 KiB
C
Raw Normal View History

/** msi.h
2014-02-17 09:01:30 +08:00
*
* Copyright (C) 2013-2015 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 MSI_H
#define MSI_H
#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"
/** Preconfigured values for video splitting */
#define D_MVFSZ 40000 /* 256KiB */
#define D_MVFPSZ 500 /* 1.25 KiB*/
/**
* Error codes.
*/
typedef enum {
msi_ErrUndisclosed,
} MSIError;
/**
* Supported capabilities
*/
typedef enum {
msi_CapSAudio = 1, /* sending audio */
msi_CapSVideo = 2, /* sending video */
msi_CapRAudio = 4, /* receiving audio */
msi_CapRVideo = 8, /* receiving video */
} MSICapabilities;
/**
2014-11-18 07:46:46 +08:00
* Call state identifiers.
*/
typedef enum {
msi_CallInactive, /* Default */
msi_CallActive,
2015-01-25 06:29:54 +08:00
msi_CallRequesting, /* when sending call invite */
msi_CallRequested, /* when getting call invite */
} MSICallState;
/**
2014-11-18 07:46:46 +08:00
* Callbacks ids that handle the states
*/
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_OnReject, /* The side that was invited rejected the call */
msi_OnEnd, /* Call that was active ended */
msi_OnError, /* Call that was active ended */
2014-11-29 20:42:19 +08:00
msi_OnPeerTimeout, /* Peer timed out; stop the call */
msi_OnCapabilities, /* Peer requested capabilities change */
} MSICallbackID;
/**
* The call struct. Please do not modify outside msi.c
*/
typedef struct MSICall_s {
struct MSISession_s *session; /* Session pointer */
2015-01-18 01:22:20 +08:00
MSICallState state;
uint8_t peer_capabilities; /* Peer capabilities */
uint8_t self_capabilities; /* Self capabilities */
uint16_t peer_mvfsz; /* Max video frame size */
uint16_t peer_mvfpsz; /* Max video frame part size */
uint32_t friend_id; /* Index of this call in MSISession */
struct MSICall_s* next;
struct MSICall_s* prev;
} MSICall;
/**
* Msi callback type. 'agent' is a pointer to ToxAv
*/
typedef void ( *MSICallbackType ) ( void *agent, MSICall* call);
/**
* Control session struct. Please do not modify outside msi.c
*/
2015-01-18 01:22:20 +08:00
typedef struct MSISession_s {
2014-04-28 01:21:26 +08:00
/* Call handlers */
MSICall **calls;
uint32_t calls_tail;
uint32_t calls_head;
void *agent_handler;
Messenger *messenger_handle;
2014-02-17 09:01:30 +08:00
2014-11-29 20:42:19 +08:00
pthread_mutex_t mutex[1];
MSICallbackType callbacks[8];
} MSISession;
/**
2014-11-18 07:46:46 +08:00
* Start the control session.
*/
2014-11-18 07:46:46 +08:00
MSISession *msi_new ( Messenger *messenger, int32_t max_calls );
/**
* Terminate control session. NOTE: all calls will be freed
*/
2014-11-18 07:46:46 +08:00
int msi_kill ( MSISession *session );
/**
2014-11-18 07:46:46 +08:00
* Callback setter.
*/
void msi_register_callback(MSISession *session, MSICallbackType callback, MSICallbackID id);
/**
2014-11-18 07:46:46 +08:00
* Send invite request to friend_id.
*/
int msi_invite ( MSISession* session, MSICall** call, uint32_t friend_id, uint8_t capabilities );
/**
* Hangup call. NOTE: 'call' will be freed
*/
int msi_hangup ( MSICall* call );
/**
* Answer call request.
*/
int msi_answer ( MSICall* call, uint8_t capabilities );
/**
* Reject incoming call. NOTE: 'call' will be freed
*/
int msi_reject ( MSICall* call );
/**
* Change capabilities of the call.
*/
int msi_change_capabilities ( MSICall* call, uint8_t capabilities );
#endif /* MSI_H */