From f3afe0612f0d01b5999f6e3dc6b7c74ae7fca773 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 25 Jan 2020 18:24:38 +0100 Subject: [PATCH] Finish moving --- controller/{voip => controller}/Crypto.cpp | 12 ++ controller/{voip => controller}/Init.cpp | 0 controller/{voip => controller}/PublicAPI.cpp | 189 ++++-------------- controller/{voip => controller}/Time.cpp | 0 controller/{voip => media}/Audio.cpp | 1 - controller/{ => media}/MediaStreamItf.cpp | 0 controller/{ => media}/MediaStreamItf.h | 0 controller/{voip => media}/Video.cpp | 0 controller/protocol/Bandwidth.cpp | 174 ++++++++++++++++ controller/{voip => protocol}/Endpoints.cpp | 66 +++--- controller/{voip => protocol}/Loop.cpp | 0 controller/{voip => protocol}/NetworkAPI.cpp | 0 controller/{voip => protocol}/Tick.cpp | 0 controller/voip/Bandwidth.cpp | 85 -------- 14 files changed, 267 insertions(+), 260 deletions(-) rename controller/{voip => controller}/Crypto.cpp (82%) rename controller/{voip => controller}/Init.cpp (100%) rename controller/{voip => controller}/PublicAPI.cpp (81%) rename controller/{voip => controller}/Time.cpp (100%) rename controller/{voip => media}/Audio.cpp (99%) rename controller/{ => media}/MediaStreamItf.cpp (100%) rename controller/{ => media}/MediaStreamItf.h (100%) rename controller/{voip => media}/Video.cpp (100%) create mode 100644 controller/protocol/Bandwidth.cpp rename controller/{voip => protocol}/Endpoints.cpp (72%) rename controller/{voip => protocol}/Loop.cpp (100%) rename controller/{voip => protocol}/NetworkAPI.cpp (100%) rename controller/{voip => protocol}/Tick.cpp (100%) delete mode 100644 controller/voip/Bandwidth.cpp diff --git a/controller/voip/Crypto.cpp b/controller/controller/Crypto.cpp similarity index 82% rename from controller/voip/Crypto.cpp rename to controller/controller/Crypto.cpp index e6adeaa..a001fcb 100644 --- a/controller/voip/Crypto.cpp +++ b/controller/controller/Crypto.cpp @@ -3,6 +3,18 @@ using namespace tgvoip; using namespace std; +void VoIPController::SetEncryptionKey(std::vector key, bool isOutgoing) +{ + memcpy(encryptionKey, key.data(), 256); + uint8_t sha1[SHA1_LENGTH]; + crypto.sha1((uint8_t *)encryptionKey, 256, sha1); + memcpy(keyFingerprint, sha1 + (SHA1_LENGTH - 8), 8); + uint8_t sha256[SHA256_LENGTH]; + crypto.sha256((uint8_t *)encryptionKey, 256, sha256); + memcpy(callID, sha256 + (SHA256_LENGTH - 16), 16); + this->isOutgoing = isOutgoing; +} + void VoIPController::KDF(unsigned char *msgKey, size_t x, unsigned char *aesKey, unsigned char *aesIv) { uint8_t sA[SHA1_LENGTH], sB[SHA1_LENGTH], sC[SHA1_LENGTH], sD[SHA1_LENGTH]; diff --git a/controller/voip/Init.cpp b/controller/controller/Init.cpp similarity index 100% rename from controller/voip/Init.cpp rename to controller/controller/Init.cpp diff --git a/controller/voip/PublicAPI.cpp b/controller/controller/PublicAPI.cpp similarity index 81% rename from controller/voip/PublicAPI.cpp rename to controller/controller/PublicAPI.cpp index 301db95..d95baf8 100644 --- a/controller/voip/PublicAPI.cpp +++ b/controller/controller/PublicAPI.cpp @@ -167,142 +167,6 @@ bool VoIPController::NeedRate() return needRate && ServerConfig::GetSharedInstance()->GetBoolean("bad_call_rating", false); } -void VoIPController::SetRemoteEndpoints(vector endpoints, bool allowP2p, int32_t connectionMaxLayer) -{ - LOGW("Set remote endpoints, allowP2P=%d, connectionMaxLayer=%u", allowP2p ? 1 : 0, connectionMaxLayer); - assert(!runReceiver); - preferredRelay = 0; - - this->endpoints.clear(); - didAddTcpRelays = false; - useTCP = true; - for (auto it = endpoints.begin(); it != endpoints.end(); ++it) - { - if (this->endpoints.find(it->id) != this->endpoints.end()) - LOGE("Endpoint IDs are not unique!"); - this->endpoints[it->id] = *it; - if (currentEndpoint == 0) - currentEndpoint = it->id; - - if (it->type == Endpoint::Type::UDP_RELAY) - useTCP = false; - else if (it->type == Endpoint::Type::TCP_RELAY) - didAddTcpRelays = true; - - LOGV("Adding endpoint: %s:%d, %s", it->address.ToString().c_str(), it->port, it->type == Endpoint::Type::UDP_RELAY ? "UDP" : "TCP"); - } - preferredRelay = currentEndpoint; - this->allowP2p = allowP2p; - this->connectionMaxLayer = connectionMaxLayer; - if (connectionMaxLayer >= 74) - { - useMTProto2 = true; - } - AddIPv6Relays(); -} - - - -void VoIPController::SetEncryptionKey(std::vector key, bool isOutgoing) -{ - memcpy(encryptionKey, key.data(), 256); - uint8_t sha1[SHA1_LENGTH]; - crypto.sha1((uint8_t *)encryptionKey, 256, sha1); - memcpy(keyFingerprint, sha1 + (SHA1_LENGTH - 8), 8); - uint8_t sha256[SHA256_LENGTH]; - crypto.sha256((uint8_t *)encryptionKey, 256, sha256); - memcpy(callID, sha256 + (SHA256_LENGTH - 16), 16); - this->isOutgoing = isOutgoing; -} - -void VoIPController::SetNetworkType(int type) -{ - networkType = type; - UpdateDataSavingState(); - UpdateAudioBitrateLimit(); - myIPv6 = NetworkAddress::Empty(); - string itfName = udpSocket->GetLocalInterfaceInfo(NULL, &myIPv6); - LOGI("set network type: %s, active interface %s", NetworkTypeToString(type).c_str(), itfName.c_str()); - LOGI("Local IPv6 address: %s", myIPv6.ToString().c_str()); - if (IS_MOBILE_NETWORK(networkType)) - { - CellularCarrierInfo carrier = GetCarrierInfo(); - if (!carrier.name.empty()) - { - LOGI("Carrier: %s [%s; mcc=%s, mnc=%s]", carrier.name.c_str(), carrier.countryCode.c_str(), carrier.mcc.c_str(), carrier.mnc.c_str()); - } - } - if (itfName != activeNetItfName) - { - udpSocket->OnActiveInterfaceChanged(); - LOGI("Active network interface changed: %s -> %s", activeNetItfName.c_str(), itfName.c_str()); - bool isFirstChange = activeNetItfName.length() == 0 && state != STATE_ESTABLISHED && state != STATE_RECONNECTING; - activeNetItfName = itfName; - if (isFirstChange) - return; - messageThread.Post([this] { - wasNetworkHandover = true; - if (currentEndpoint) - { - const Endpoint &_currentEndpoint = endpoints.at(currentEndpoint); - const Endpoint &_preferredRelay = endpoints.at(preferredRelay); - if (_currentEndpoint.type != Endpoint::Type::UDP_RELAY) - { - if (_preferredRelay.type == Endpoint::Type::UDP_RELAY) - currentEndpoint = preferredRelay; - MutexGuard m(endpointsMutex); - constexpr int64_t lanID = static_cast(FOURCC('L', 'A', 'N', '4')) << 32; - endpoints.erase(lanID); - for (pair &e : endpoints) - { - Endpoint &endpoint = e.second; - if (endpoint.type == Endpoint::Type::UDP_RELAY && useTCP) - { - useTCP = false; - if (_preferredRelay.type == Endpoint::Type::TCP_RELAY) - { - preferredRelay = currentEndpoint = endpoint.id; - } - } - else if (endpoint.type == Endpoint::Type::TCP_RELAY && endpoint.socket) - { - endpoint.socket->Close(); - } - endpoint.averageRTT = 0; - endpoint.rtts.Reset(); - } - } - } - lastUdpPingTime = 0; - if (proxyProtocol == PROXY_SOCKS5) - InitUDPProxy(); - if (allowP2p && currentEndpoint) - { - SendPublicEndpointsRequest(); - } - BufferOutputStream s(4); - s.WriteInt32(dataSavingMode ? INIT_FLAG_DATA_SAVING_ENABLED : 0); - if (peerVersion < 6) - { - SendPacketReliably(PKT_NETWORK_CHANGED, s.GetBuffer(), s.GetLength(), 1, 20); - } - else - { - Buffer buf(move(s)); - SendExtra(buf, EXTRA_TYPE_NETWORK_CHANGED); - } - needReInitUdpProxy = true; - selectCanceller->CancelSelect(); - didSendIPv6Endpoint = false; - - AddIPv6Relays(); - ResetUdpAvailability(); - ResetEndpointPingStats(); - }); - } -} - - void VoIPController::SetMicMute(bool mute) { if (micMuted == mute) @@ -458,11 +322,6 @@ const char *VoIPController::GetVersion() return LIBTGVOIP_VERSION; } -int64_t VoIPController::GetPreferredRelayID() -{ - return preferredRelay; -} - int VoIPController::GetLastError() { return lastError; @@ -728,15 +587,6 @@ void VoIPController::SetEchoCancellationStrength(int strength) echoCanceller->SetAECStrength(strength); } -#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) -void VoIPController::SetAudioDataCallbacks(std::function input, std::function output, std::function preproc = nullptr) -{ - audioInputDataCallback = input; - audioOutputDataCallback = output; - audioPreprocDataCallback = preproc; -} -#endif - int VoIPController::GetConnectionState() { return state; @@ -825,6 +675,7 @@ vector VoIPController::GetPersistentState() return vector(jstr, jstr + strlen(jstr)); } + void VoIPController::SetOutputVolume(float level) { outputVolume->SetLevel(level); @@ -846,3 +697,41 @@ void VoIPController::SetAudioOutputDuckingEnabled(bool enabled) } } #endif + + +#if defined(TGVOIP_USE_CALLBACK_AUDIO_IO) +void VoIPController::SetAudioDataCallbacks(std::function input, std::function output, std::function preproc = nullptr) +{ + audioInputDataCallback = input; + audioOutputDataCallback = output; + audioPreprocDataCallback = preproc; +} +#endif + + +CellularCarrierInfo VoIPController::GetCarrierInfo() +{ +#if defined(__APPLE__) && TARGET_OS_IOS + return DarwinSpecific::GetCarrierInfo(); +#elif defined(__ANDROID__) + CellularCarrierInfo carrier; + jni::DoWithJNI([&carrier](JNIEnv *env) { + jmethodID getCarrierInfoMethod = env->GetStaticMethodID(jniUtilitiesClass, "getCarrierInfo", "()[Ljava/lang/String;"); + jobjectArray jinfo = (jobjectArray)env->CallStaticObjectMethod(jniUtilitiesClass, getCarrierInfoMethod); + if (jinfo && env->GetArrayLength(jinfo) == 4) + { + carrier.name = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 0)); + carrier.countryCode = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 1)); + carrier.mcc = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 2)); + carrier.mnc = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 3)); + } + else + { + LOGW("Failed to get carrier info"); + } + }); + return carrier; +#else + return CellularCarrierInfo(); +#endif +} \ No newline at end of file diff --git a/controller/voip/Time.cpp b/controller/controller/Time.cpp similarity index 100% rename from controller/voip/Time.cpp rename to controller/controller/Time.cpp diff --git a/controller/voip/Audio.cpp b/controller/media/Audio.cpp similarity index 99% rename from controller/voip/Audio.cpp rename to controller/media/Audio.cpp index b091907..e5675ea 100644 --- a/controller/voip/Audio.cpp +++ b/controller/media/Audio.cpp @@ -241,4 +241,3 @@ void VoIPController::UpdateAudioOutputState() } } } - diff --git a/controller/MediaStreamItf.cpp b/controller/media/MediaStreamItf.cpp similarity index 100% rename from controller/MediaStreamItf.cpp rename to controller/media/MediaStreamItf.cpp diff --git a/controller/MediaStreamItf.h b/controller/media/MediaStreamItf.h similarity index 100% rename from controller/MediaStreamItf.h rename to controller/media/MediaStreamItf.h diff --git a/controller/voip/Video.cpp b/controller/media/Video.cpp similarity index 100% rename from controller/voip/Video.cpp rename to controller/media/Video.cpp diff --git a/controller/protocol/Bandwidth.cpp b/controller/protocol/Bandwidth.cpp new file mode 100644 index 0000000..c0fc1f8 --- /dev/null +++ b/controller/protocol/Bandwidth.cpp @@ -0,0 +1,174 @@ +#include "../../VoIPController.h" + +using namespace tgvoip; +using namespace std; + + + +#pragma mark - Bandwidth management + +void VoIPController::UpdateAudioBitrateLimit() +{ + if (encoder) + { + if (dataSavingMode || dataSavingRequestedByPeer) + { + maxBitrate = maxAudioBitrateSaving; + encoder->SetBitrate(initAudioBitrateSaving); + } + else if (networkType == NET_TYPE_GPRS) + { + maxBitrate = maxAudioBitrateGPRS; + encoder->SetBitrate(initAudioBitrateGPRS); + } + else if (networkType == NET_TYPE_EDGE) + { + maxBitrate = maxAudioBitrateEDGE; + encoder->SetBitrate(initAudioBitrateEDGE); + } + else + { + maxBitrate = maxAudioBitrate; + encoder->SetBitrate(initAudioBitrate); + } + encoder->SetVadMode(dataSavingMode || dataSavingRequestedByPeer); + if (echoCanceller) + echoCanceller->SetVoiceDetectionEnabled(dataSavingMode || dataSavingRequestedByPeer); + } +} + +void VoIPController::UpdateDataSavingState() +{ + if (config.dataSaving == DATA_SAVING_ALWAYS) + { + dataSavingMode = true; + } + else if (config.dataSaving == DATA_SAVING_MOBILE) + { + dataSavingMode = networkType == NET_TYPE_GPRS || networkType == NET_TYPE_EDGE || + networkType == NET_TYPE_3G || networkType == NET_TYPE_HSPA || networkType == NET_TYPE_LTE || networkType == NET_TYPE_OTHER_MOBILE; + } + else + { + dataSavingMode = false; + } + LOGI("update data saving mode, config %d, enabled %d, reqd by peer %d", config.dataSaving, dataSavingMode, dataSavingRequestedByPeer); +} + + +double VoIPController::GetAverageRTT() +{ + ENFORCE_MSG_THREAD; + + if (lastSentSeq >= lastRemoteAckSeq) + { + uint32_t diff = lastSentSeq - lastRemoteAckSeq; + //LOGV("rtt diff=%u", diff); + if (diff < 32) + { + double res = 0; + int count = 0; + for (const auto &packet : recentOutgoingPackets) + { + if (packet.ackTime > 0) + { + res += (packet.ackTime - packet.sendTime); + count++; + } + } + if (count > 0) + res /= count; + return res; + } + } + return 999; +} + + +void VoIPController::SetNetworkType(int type) +{ + networkType = type; + UpdateDataSavingState(); + UpdateAudioBitrateLimit(); + myIPv6 = NetworkAddress::Empty(); + string itfName = udpSocket->GetLocalInterfaceInfo(NULL, &myIPv6); + LOGI("set network type: %s, active interface %s", NetworkTypeToString(type).c_str(), itfName.c_str()); + LOGI("Local IPv6 address: %s", myIPv6.ToString().c_str()); + if (IS_MOBILE_NETWORK(networkType)) + { + CellularCarrierInfo carrier = GetCarrierInfo(); + if (!carrier.name.empty()) + { + LOGI("Carrier: %s [%s; mcc=%s, mnc=%s]", carrier.name.c_str(), carrier.countryCode.c_str(), carrier.mcc.c_str(), carrier.mnc.c_str()); + } + } + if (itfName != activeNetItfName) + { + udpSocket->OnActiveInterfaceChanged(); + LOGI("Active network interface changed: %s -> %s", activeNetItfName.c_str(), itfName.c_str()); + bool isFirstChange = activeNetItfName.length() == 0 && state != STATE_ESTABLISHED && state != STATE_RECONNECTING; + activeNetItfName = itfName; + if (isFirstChange) + return; + messageThread.Post([this] { + wasNetworkHandover = true; + if (currentEndpoint) + { + const Endpoint &_currentEndpoint = endpoints.at(currentEndpoint); + const Endpoint &_preferredRelay = endpoints.at(preferredRelay); + if (_currentEndpoint.type != Endpoint::Type::UDP_RELAY) + { + if (_preferredRelay.type == Endpoint::Type::UDP_RELAY) + currentEndpoint = preferredRelay; + MutexGuard m(endpointsMutex); + constexpr int64_t lanID = static_cast(FOURCC('L', 'A', 'N', '4')) << 32; + endpoints.erase(lanID); + for (pair &e : endpoints) + { + Endpoint &endpoint = e.second; + if (endpoint.type == Endpoint::Type::UDP_RELAY && useTCP) + { + useTCP = false; + if (_preferredRelay.type == Endpoint::Type::TCP_RELAY) + { + preferredRelay = currentEndpoint = endpoint.id; + } + } + else if (endpoint.type == Endpoint::Type::TCP_RELAY && endpoint.socket) + { + endpoint.socket->Close(); + } + endpoint.averageRTT = 0; + endpoint.rtts.Reset(); + } + } + } + lastUdpPingTime = 0; + if (proxyProtocol == PROXY_SOCKS5) + InitUDPProxy(); + if (allowP2p && currentEndpoint) + { + SendPublicEndpointsRequest(); + } + BufferOutputStream s(4); + s.WriteInt32(dataSavingMode ? INIT_FLAG_DATA_SAVING_ENABLED : 0); + if (peerVersion < 6) + { + SendPacketReliably(PKT_NETWORK_CHANGED, s.GetBuffer(), s.GetLength(), 1, 20); + } + else + { + Buffer buf(move(s)); + SendExtra(buf, EXTRA_TYPE_NETWORK_CHANGED); + } + needReInitUdpProxy = true; + selectCanceller->CancelSelect(); + didSendIPv6Endpoint = false; + + AddIPv6Relays(); + ResetUdpAvailability(); + ResetEndpointPingStats(); + }); + } +} + diff --git a/controller/voip/Endpoints.cpp b/controller/protocol/Endpoints.cpp similarity index 72% rename from controller/voip/Endpoints.cpp rename to controller/protocol/Endpoints.cpp index 151c27a..90de7fc 100644 --- a/controller/voip/Endpoints.cpp +++ b/controller/protocol/Endpoints.cpp @@ -25,33 +25,51 @@ shared_ptr VoIPController::GetStreamByID(unsigned char i return s; } -CellularCarrierInfo VoIPController::GetCarrierInfo() + +int64_t VoIPController::GetPreferredRelayID() { -#if defined(__APPLE__) && TARGET_OS_IOS - return DarwinSpecific::GetCarrierInfo(); -#elif defined(__ANDROID__) - CellularCarrierInfo carrier; - jni::DoWithJNI([&carrier](JNIEnv *env) { - jmethodID getCarrierInfoMethod = env->GetStaticMethodID(jniUtilitiesClass, "getCarrierInfo", "()[Ljava/lang/String;"); - jobjectArray jinfo = (jobjectArray)env->CallStaticObjectMethod(jniUtilitiesClass, getCarrierInfoMethod); - if (jinfo && env->GetArrayLength(jinfo) == 4) - { - carrier.name = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 0)); - carrier.countryCode = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 1)); - carrier.mcc = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 2)); - carrier.mnc = jni::JavaStringToStdString(env, (jstring)env->GetObjectArrayElement(jinfo, 3)); - } - else - { - LOGW("Failed to get carrier info"); - } - }); - return carrier; -#else - return CellularCarrierInfo(); -#endif + return preferredRelay; } + +void VoIPController::SetRemoteEndpoints(vector endpoints, bool allowP2p, int32_t connectionMaxLayer) +{ + LOGW("Set remote endpoints, allowP2P=%d, connectionMaxLayer=%u", allowP2p ? 1 : 0, connectionMaxLayer); + assert(!runReceiver); + preferredRelay = 0; + + this->endpoints.clear(); + didAddTcpRelays = false; + useTCP = true; + for (auto it = endpoints.begin(); it != endpoints.end(); ++it) + { + if (this->endpoints.find(it->id) != this->endpoints.end()) + LOGE("Endpoint IDs are not unique!"); + this->endpoints[it->id] = *it; + if (currentEndpoint == 0) + currentEndpoint = it->id; + + if (it->type == Endpoint::Type::UDP_RELAY) + useTCP = false; + else if (it->type == Endpoint::Type::TCP_RELAY) + didAddTcpRelays = true; + + LOGV("Adding endpoint: %s:%d, %s", it->address.ToString().c_str(), it->port, it->type == Endpoint::Type::UDP_RELAY ? "UDP" : "TCP"); + } + preferredRelay = currentEndpoint; + this->allowP2p = allowP2p; + this->connectionMaxLayer = connectionMaxLayer; + if (connectionMaxLayer >= 74) + { + useMTProto2 = true; + } + AddIPv6Relays(); +} + + + + + void VoIPController::AddIPv6Relays() { if (!myIPv6.IsEmpty() && !didAddIPv6Relays) diff --git a/controller/voip/Loop.cpp b/controller/protocol/Loop.cpp similarity index 100% rename from controller/voip/Loop.cpp rename to controller/protocol/Loop.cpp diff --git a/controller/voip/NetworkAPI.cpp b/controller/protocol/NetworkAPI.cpp similarity index 100% rename from controller/voip/NetworkAPI.cpp rename to controller/protocol/NetworkAPI.cpp diff --git a/controller/voip/Tick.cpp b/controller/protocol/Tick.cpp similarity index 100% rename from controller/voip/Tick.cpp rename to controller/protocol/Tick.cpp diff --git a/controller/voip/Bandwidth.cpp b/controller/voip/Bandwidth.cpp deleted file mode 100644 index af61d5f..0000000 --- a/controller/voip/Bandwidth.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "../../VoIPController.h" - -using namespace tgvoip; -using namespace std; - - - -#pragma mark - Bandwidth management - -void VoIPController::UpdateAudioBitrateLimit() -{ - if (encoder) - { - if (dataSavingMode || dataSavingRequestedByPeer) - { - maxBitrate = maxAudioBitrateSaving; - encoder->SetBitrate(initAudioBitrateSaving); - } - else if (networkType == NET_TYPE_GPRS) - { - maxBitrate = maxAudioBitrateGPRS; - encoder->SetBitrate(initAudioBitrateGPRS); - } - else if (networkType == NET_TYPE_EDGE) - { - maxBitrate = maxAudioBitrateEDGE; - encoder->SetBitrate(initAudioBitrateEDGE); - } - else - { - maxBitrate = maxAudioBitrate; - encoder->SetBitrate(initAudioBitrate); - } - encoder->SetVadMode(dataSavingMode || dataSavingRequestedByPeer); - if (echoCanceller) - echoCanceller->SetVoiceDetectionEnabled(dataSavingMode || dataSavingRequestedByPeer); - } -} - -void VoIPController::UpdateDataSavingState() -{ - if (config.dataSaving == DATA_SAVING_ALWAYS) - { - dataSavingMode = true; - } - else if (config.dataSaving == DATA_SAVING_MOBILE) - { - dataSavingMode = networkType == NET_TYPE_GPRS || networkType == NET_TYPE_EDGE || - networkType == NET_TYPE_3G || networkType == NET_TYPE_HSPA || networkType == NET_TYPE_LTE || networkType == NET_TYPE_OTHER_MOBILE; - } - else - { - dataSavingMode = false; - } - LOGI("update data saving mode, config %d, enabled %d, reqd by peer %d", config.dataSaving, dataSavingMode, dataSavingRequestedByPeer); -} - - -double VoIPController::GetAverageRTT() -{ - ENFORCE_MSG_THREAD; - - if (lastSentSeq >= lastRemoteAckSeq) - { - uint32_t diff = lastSentSeq - lastRemoteAckSeq; - //LOGV("rtt diff=%u", diff); - if (diff < 32) - { - double res = 0; - int count = 0; - for (const auto &packet : recentOutgoingPackets) - { - if (packet.ackTime > 0) - { - res += (packet.ackTime - packet.sendTime); - count++; - } - } - if (count > 0) - res /= count; - return res; - } - } - return 999; -} \ No newline at end of file