| #include <vector> |
| 6 | #include <string> |
| 7 | #include <memory> |
| 8 |
| 9 | struct TgVoipProxy { |
| 10 | std::string host; |
| 11 | uint16_t port; |
| 12 | std::string login; |
| 13 | std::string password; |
| 14 | }; |
| 15 |
| 16 | enum class TgVoipEndpointType { |
| 17 | Inet, |
| 18 | Lan, |
| 19 | UdpRelay, |
| 20 | TcpRelay |
| 21 | }; |
| 22 |
| 23 | struct TgVoipEndpoint { |
| 24 | int64_t endpointId; |
| 25 | std::string host; |
| 26 | uint16_t port; |
| 27 | TgVoipEndpointType type; |
| 28 | unsigned char peerTag[16]; |
| 29 | }; |
| 30 |
| 31 | enum class TgVoipNetworkType { |
| 32 | Unknown, |
| 33 | Gprs, |
| 34 | Edge, |
| 35 | ThirdGeneration, |
| 36 | Hspa, |
| 37 | Lte, |
| 38 | WiFi, |
| 39 | Ethernet, |
| 40 | OtherHighSpeed, |
| 41 | OtherLowSpeed, |
| 42 | OtherMobile, |
| 43 | Dialup |
| 44 | }; |
| 45 |
| 46 | enum class TgVoipDataSaving { |
| 47 | Never, |
| 48 | Mobile, |
| 49 | Always |
| 50 | }; |
| 51 |
| 52 | struct TgVoipPersistentState { |
| 53 | std::vector<uint8_t> value; |
| 54 | }; |
| 55 |
| 56 | #ifdef TGVOIP_USE_CUSTOM_CRYPTO |
| 57 | struct TgVoipCrypto { |
| 58 | void (*rand_bytes)(uint8_t* buffer, size_t length); |
| 59 | void (*sha1)(uint8_t* msg, size_t length, uint8_t* output); |
| 60 | void (*sha256)(uint8_t* msg, size_t length, uint8_t* output); |
| 61 | void (*aes_ige_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv); |
| 62 | void (*aes_ige_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv); |
| 63 | void (*aes_ctr_encrypt)(uint8_t* inout, size_t length, uint8_t* key, uint8_t* iv, uint8_t* ecount, uint32_t* num); |
| 64 | void (*aes_cbc_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv); |
| 65 | void (*aes_cbc_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv); |
| 66 | }; |
| 67 | #endif |
| 68 |
| 69 | struct TgVoipConfig { |
| 70 | double initializationTimeout; |
| 71 | double receiveTimeout; |
| 72 | TgVoipDataSaving dataSaving; |
| 73 | bool enableP2P; |
| 74 | bool enableAEC; |
| 75 | bool enableNS; |
| 76 | bool enableAGC; |
| 77 | bool enableCallUpgrade; |
| 78 | std::string logPath; |
| 79 | int maxApiLayer; |
| 80 | }; |
| 81 |
| 82 | struct TgVoipEncryptionKey { |
| 83 | std::vector<uint8_t> value; |
| 84 | bool isOutgoing; |
| 85 | }; |
| 86 |
| 87 | enum class TgVoipState { |
| 88 | WaitInit, |
| 89 | WaitInitAck, |
| 90 | Estabilished, |
| 91 | Failed, |
| 92 | Reconnecting |
| 93 | }; |
| 94 |
| 95 | struct TgVoipTrafficStats { |
| 96 | uint64_t bytesSentWifi; |
| 97 | uint64_t bytesReceivedWifi; |
| 98 | uint64_t bytesSentMobile; |
| 99 | uint64_t bytesReceivedMobile; |
| 100 | }; |
| 101 |
| 102 | struct TgVoipFinalState { |
| 103 | TgVoipPersistentState persistentState; |
| 104 | std::string debugLog; |
| 105 | TgVoipTrafficStats trafficStats; |
| 106 | bool isRatingSuggested; |
| 107 | }; |
| 108 |
| 109 | struct TgVoipAudioDataCallbacks { |
| 110 | std::function<void(int16_t*, size_t)> input; |
| 111 | std::function<void(int16_t*, size_t)> output; |
| 112 | std::function<void(int16_t*, size_t)> preprocessed; |
| 113 | }; |
| 114 |
| 115 | class TgVoip { |
| 116 | protected: |
| 117 | TgVoip() = default; |
| 118 |
| 119 | public: |
| 120 | static void setLoggingFunction(std::function<void(std::string const &)> loggingFunction); |
| 121 | static void setGlobalServerConfig(std::string const &serverConfig); |
| 122 | static int getConnectionMaxLayer(); |
| 123 | static std::string getVersion(); |
| 124 | static TgVoip *makeInstance( |
| 125 | TgVoipConfig const &config, |
| 126 | TgVoipPersistentState const &persistentState, |
| 127 | std::vector<TgVoipEndpoint> const &endpoints, |
| 128 | std::unique_ptr<TgVoipProxy> const &proxy, |
| 129 | TgVoipNetworkType initialNetworkType, |
| 130 | TgVoipEncryptionKey const &encryptionKey |
| 131 | #ifdef TGVOIP_USE_CUSTOM_CRYPTO |
| 132 | , |
| 133 | TgVoipCrypto const &crypto |
| 134 | #endif |
| 135 | #ifdef TGVOIP_USE_CALLBACK_AUDIO_IO |
| 136 | , |
| 137 | TgVoipAudioDataCallbacks const &audioDataCallbacks |
| 138 | #endif |
| 139 | ); |
| 140 |
| 141 | virtual ~TgVoip(); |
| 142 |
| 143 | virtual void setNetworkType(TgVoipNetworkType networkType) = 0; |
| 144 | virtual void setMuteMicrophone(bool muteMicrophone) = 0; |
| 145 | virtual void setAudioOutputGainControlEnabled(bool enabled) = 0; |
| 146 | virtual void setEchoCancellationStrength(int strength) = 0; |
| 147 |
| 148 | virtual std::string getLastError() = 0; |
| 149 | virtual std::string getDebugInfo() = 0; |
| 150 | virtual int64_t getPreferredRelayId() = 0; |
| 151 | virtual TgVoipTrafficStats getTrafficStats() = 0; |
| 152 | virtual TgVoipPersistentState getPersistentState() = 0; |
| 153 |
| 154 | virtual void setOnStateUpdated(std::function<void(TgVoipState)> onStateUpdated) = 0; |
| 155 | virtual void setOnSignalBarsUpdated(std::function<void(int)> onSignalBarsUpdated) = 0; |
| 156 |
| 157 | virtual TgVoipFinalState stop() = 0; |
| 158 | }; |
| 159 |
| 160 | #endif |
| 161 |