1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-26 20:24:38 +01:00
libtgvoip/TgVoip.h

185 lines
4.2 KiB
C
Raw Normal View History

2019-12-24 19:57:22 +01:00
#ifndef __TGVOIP_H
#define __TGVOIP_H
#include <functional>
#include <vector>
#include <string>
#include <memory>
2020-01-22 12:43:51 +01:00
struct TgVoipProxy
{
2019-12-24 19:57:22 +01:00
std::string host;
uint16_t port;
std::string login;
std::string password;
};
2020-01-22 12:43:51 +01:00
enum class TgVoipEndpointType
{
2019-12-24 19:57:22 +01:00
Inet,
Lan,
UdpRelay,
TcpRelay
};
2020-03-10 19:36:27 +01:00
struct TgVoipEdpointHost
2020-03-10 16:30:57 +01:00
{
std::string ipv4;
std::string ipv6;
};
2020-01-22 12:43:51 +01:00
struct TgVoipEndpoint
{
2019-12-24 19:57:22 +01:00
int64_t endpointId;
2020-03-10 19:36:27 +01:00
TgVoipEdpointHost host;
2019-12-24 19:57:22 +01:00
uint16_t port;
TgVoipEndpointType type;
unsigned char peerTag[16];
};
2020-01-22 12:43:51 +01:00
enum class TgVoipNetworkType
{
2019-12-24 19:57:22 +01:00
Unknown,
Gprs,
Edge,
ThirdGeneration,
Hspa,
Lte,
WiFi,
Ethernet,
OtherHighSpeed,
OtherLowSpeed,
OtherMobile,
Dialup
};
2020-01-22 12:43:51 +01:00
enum class TgVoipDataSaving
{
2019-12-24 19:57:22 +01:00
Never,
Mobile,
Always
};
2020-01-22 12:43:51 +01:00
struct TgVoipPersistentState
{
2019-12-24 19:57:22 +01:00
std::vector<uint8_t> value;
};
#ifdef TGVOIP_USE_CUSTOM_CRYPTO
2020-01-22 12:43:51 +01:00
struct TgVoipCrypto
{
void (*rand_bytes)(uint8_t *buffer, size_t length);
void (*sha1)(uint8_t *msg, size_t length, uint8_t *output);
void (*sha256)(uint8_t *msg, size_t length, uint8_t *output);
void (*aes_ige_encrypt)(uint8_t *in, uint8_t *out, size_t length, uint8_t *key, uint8_t *iv);
void (*aes_ige_decrypt)(uint8_t *in, uint8_t *out, size_t length, uint8_t *key, uint8_t *iv);
void (*aes_ctr_encrypt)(uint8_t *inout, size_t length, uint8_t *key, uint8_t *iv, uint8_t *ecount, uint32_t *num);
void (*aes_cbc_encrypt)(uint8_t *in, uint8_t *out, size_t length, uint8_t *key, uint8_t *iv);
void (*aes_cbc_decrypt)(uint8_t *in, uint8_t *out, size_t length, uint8_t *key, uint8_t *iv);
2019-12-24 19:57:22 +01:00
};
#endif
2019-12-24 19:57:22 +01:00
2020-01-22 12:43:51 +01:00
struct TgVoipConfig
{
2019-12-24 19:57:22 +01:00
double initializationTimeout;
double receiveTimeout;
TgVoipDataSaving dataSaving;
bool enableP2P;
bool enableAEC;
bool enableNS;
bool enableAGC;
bool enableCallUpgrade;
2020-03-10 19:36:27 +01:00
#ifndef _WIN32
2019-12-24 19:57:22 +01:00
std::string logPath;
2020-03-10 19:36:27 +01:00
#else
std::wstring logPath;
#endif
2019-12-24 19:57:22 +01:00
int maxApiLayer;
};
2020-01-22 12:43:51 +01:00
struct TgVoipEncryptionKey
{
2019-12-24 19:57:22 +01:00
std::vector<uint8_t> value;
bool isOutgoing;
};
2020-01-22 12:43:51 +01:00
enum class TgVoipState
{
2019-12-24 19:57:22 +01:00
WaitInit,
WaitInitAck,
Estabilished,
Failed,
Reconnecting
};
2020-01-22 12:43:51 +01:00
struct TgVoipTrafficStats
{
2019-12-24 19:57:22 +01:00
uint64_t bytesSentWifi;
uint64_t bytesReceivedWifi;
uint64_t bytesSentMobile;
uint64_t bytesReceivedMobile;
};
2020-01-22 12:43:51 +01:00
struct TgVoipFinalState
{
2019-12-24 19:57:22 +01:00
TgVoipPersistentState persistentState;
std::string debugLog;
TgVoipTrafficStats trafficStats;
bool isRatingSuggested;
};
2020-01-22 12:43:51 +01:00
struct TgVoipAudioDataCallbacks
{
std::function<void(int16_t *, size_t)> input;
std::function<void(int16_t *, size_t)> output;
std::function<void(int16_t *, size_t)> preprocessed;
2019-12-24 19:57:22 +01:00
};
2020-01-22 12:43:51 +01:00
class TgVoip
{
2019-12-24 19:57:22 +01:00
protected:
TgVoip() = default;
2020-01-22 12:43:51 +01:00
2019-12-24 19:57:22 +01:00
public:
static void setLoggingFunction(std::function<void(std::string const &)> loggingFunction);
static void setGlobalServerConfig(std::string const &serverConfig);
2020-03-10 16:30:57 +01:00
static int getConnectionMaxLayer();
static std::string getVersion();
2019-12-24 19:57:22 +01:00
static TgVoip *makeInstance(
TgVoipConfig const &config,
TgVoipPersistentState const &persistentState,
std::vector<TgVoipEndpoint> const &endpoints,
std::unique_ptr<TgVoipProxy> const &proxy,
TgVoipNetworkType initialNetworkType,
TgVoipEncryptionKey const &encryptionKey
#ifdef TGVOIP_USE_CUSTOM_CRYPTO
,
TgVoipCrypto const &crypto
2020-01-22 12:43:51 +01:00
#endif
#ifdef TGVOIP_USE_CALLBACK_AUDIO_IO
2019-12-24 19:57:22 +01:00
,
TgVoipAudioDataCallbacks const &audioDataCallbacks
#endif
);
2020-01-22 12:43:51 +01:00
2019-12-24 19:57:22 +01:00
virtual ~TgVoip();
2020-01-22 12:43:51 +01:00
2019-12-24 19:57:22 +01:00
virtual void setNetworkType(TgVoipNetworkType networkType) = 0;
virtual void setMuteMicrophone(bool muteMicrophone) = 0;
2020-03-10 16:30:57 +01:00
virtual void setAudioOutputGainControlEnabled(bool enabled) = 0;
virtual void setEchoCancellationStrength(int strength) = 0;
2020-01-22 12:43:51 +01:00
2020-03-10 16:30:57 +01:00
virtual std::string getLastError() = 0;
2019-12-24 19:57:22 +01:00
virtual std::string getDebugInfo() = 0;
2020-03-10 16:30:57 +01:00
virtual int64_t getPreferredRelayId() = 0;
virtual TgVoipTrafficStats getTrafficStats() = 0;
virtual TgVoipPersistentState getPersistentState() = 0;
2020-01-22 12:43:51 +01:00
2019-12-24 19:57:22 +01:00
virtual void setOnStateUpdated(std::function<void(TgVoipState)> onStateUpdated) = 0;
virtual void setOnSignalBarsUpdated(std::function<void(int)> onSignalBarsUpdated) = 0;
2020-01-22 12:43:51 +01:00
2019-12-24 19:57:22 +01:00
virtual TgVoipFinalState stop() = 0;
};
#endif