1
0
mirror of https://github.com/danog/libtgvoip.git synced 2025-01-22 21:11:36 +01:00

Merge commit '6d03dd9ae4bf48d7344341cdd2d055ebd3a6a42e' into public

This commit is contained in:
Peter 2018-12-19 18:36:05 +03:00
commit a7546d438a
4 changed files with 91 additions and 13 deletions

View File

@ -13,6 +13,7 @@
#include "audio/AudioOutput.h"
#include "audio/AudioInput.h"
#include "logging.h"
#include "VoIPServerConfig.h"
#include <string.h>
#include <stdio.h>
@ -43,11 +44,33 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
config.gain_controller2.enabled = enableAGC;
apm->ApplyConfig(config);
apm->noise_suppression()->set_level(webrtc::NoiseSuppression::Level::kHigh);
webrtc::NoiseSuppression::Level nsLevel;
#ifdef __APPLE__
switch(ServerConfig::GetSharedInstance()->GetInt("webrtc_ns_level_vpio", 0)){
#else
switch(ServerConfig::GetSharedInstance()->GetInt("webrtc_ns_level", 2)){
#endif
case 0:
nsLevel=webrtc::NoiseSuppression::Level::kLow;
break;
case 1:
nsLevel=webrtc::NoiseSuppression::Level::kModerate;
break;
case 3:
nsLevel=webrtc::NoiseSuppression::Level::kVeryHigh;
break;
case 2:
default:
nsLevel=webrtc::NoiseSuppression::Level::kHigh;
break;
}
apm->noise_suppression()->set_level(nsLevel);
apm->noise_suppression()->Enable(enableNS);
if(enableAGC){
apm->gain_control()->set_mode(webrtc::GainControl::Mode::kAdaptiveDigital);
apm->gain_control()->set_target_level_dbfs(9);
apm->gain_control()->set_target_level_dbfs(ServerConfig::GetSharedInstance()->GetInt("webrtc_agc_target_level", 9));
apm->gain_control()->enable_limiter(ServerConfig::GetSharedInstance()->GetBoolean("webrtc_agc_enable_limiter", true));
apm->gain_control()->set_compression_gain_db(ServerConfig::GetSharedInstance()->GetInt("webrtc_agc_compression_gain", 20));
}
apm->voice_detection()->set_likelihood(webrtc::VoiceDetection::Likelihood::kVeryLowLikelihood);

View File

@ -1989,6 +1989,10 @@ simpleAudioBlock random_id:long random_bytes:string raw_data:string = DecryptedA
}
}
#ifdef LOG_PACKETS
LOGV("Received: from=%s:%u, seq=%u, length=%u, type=%s", srcEndpoint.GetAddress().ToString().c_str(), srcEndpoint.port, pseq, packet.length, GetPacketTypeString(type).c_str());
#endif
//LOGV("acks: %u -> %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf", lastRemoteAckSeq, remoteAcks[0], remoteAcks[1], remoteAcks[2], remoteAcks[3], remoteAcks[4], remoteAcks[5], remoteAcks[6], remoteAcks[7]);
//LOGD("recv: %u -> %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf, %.2lf", lastRemoteSeq, recvPacketTimes[0], recvPacketTimes[1], recvPacketTimes[2], recvPacketTimes[3], recvPacketTimes[4], recvPacketTimes[5], recvPacketTimes[6], recvPacketTimes[7]);
//LOGI("RTT = %.3lf", GetAverageRTT());
@ -2265,6 +2269,9 @@ simpleAudioBlock random_id:long random_bytes:string raw_data:string = DecryptedA
if(type==PKT_PONG){
if(packetInnerLen>=4){
uint32_t pingSeq=(uint32_t) in.ReadInt32();
#ifdef LOG_PACKETS
LOGD("Received pong for ping in seq %u", pingSeq);
#endif
if(pingSeq==srcEndpoint.lastPingSeq){
srcEndpoint.rtts.Add(GetCurrentTime()-srcEndpoint.lastPingTime);
srcEndpoint.averageRTT=srcEndpoint.rtts.NonZeroAverage();
@ -2615,6 +2622,9 @@ void VoIPController::SendPacket(unsigned char *data, size_t len, Endpoint& ep, P
}
}
//LOGV("Sending %d bytes to %s:%d", out.GetLength(), ep.address.ToString().c_str(), ep.port);
#ifdef LOG_PACKETS
LOGV("Sending: to=%s:%u, seq=%u, length=%u, type=%s", ep.GetAddress().ToString().c_str(), ep.port, srcPacket.seq, out.GetLength(), GetPacketTypeString(srcPacket.type).c_str());
#endif
NetworkPacket pkt={0};
pkt.address=&ep.GetAddress();
@ -2670,6 +2680,34 @@ std::string VoIPController::NetworkTypeToString(int type){
}
}
std::string VoIPController::GetPacketTypeString(unsigned char type){
switch(type){
case PKT_INIT:
return "init";
case PKT_INIT_ACK:
return "init_ack";
case PKT_STREAM_STATE:
return "stream_state";
case PKT_STREAM_DATA:
return "stream_data";
case PKT_PING:
return "ping";
case PKT_PONG:
return "pong";
case PKT_LAN_ENDPOINT:
return "lan_endpoint";
case PKT_NETWORK_CHANGED:
return "network_changed";
case PKT_NOP:
return "nop";
case PKT_STREAM_EC:
return "stream_ec";
}
char buf[255];
snprintf(buf, sizeof(buf), "unknown(%u)", type);
return string(buf);
}
void VoIPController::AddIPv6Relays(){
if(!myIPv6.IsEmpty() && !didAddIPv6Relays){
unordered_map<string, vector<Endpoint>> endpointsByAddress;
@ -3431,6 +3469,8 @@ void VoIPController::UpdateQueuedPackets(){
}
void VoIPController::SendNopPacket(){
if(state!=STATE_ESTABLISHED)
return;
SendOrEnqueuePacket(PendingOutgoingPacket{
/*.seq=*/(firstSentPing=GenerateOutSeq()),
/*.type=*/PKT_NOP,

View File

@ -39,7 +39,7 @@
#include "MessageThread.h"
#include "utils.h"
#define LIBTGVOIP_VERSION "2.4"
#define LIBTGVOIP_VERSION "2.4.1"
#ifdef _WIN32
#undef GetCurrentTime
@ -403,13 +403,11 @@ namespace tgvoip{
double ackTime;
};
struct PendingOutgoingPacket{
#if defined(_MSC_VER) && _MSC_VER <= 1800 // VS2013 doesn't support auto-generating move constructors
//TGVOIP_DISALLOW_COPY_AND_ASSIGN(PendingOutgoingPacket);
PendingOutgoingPacket(uint32_t seq, unsigned char type, size_t len, Buffer&& data, int64_t endpoint){
this->seq=seq;
this->type=type;
this->len=len;
this->data=data;
this->data=std::move(data);
this->endpoint=endpoint;
}
PendingOutgoingPacket(PendingOutgoingPacket&& other){
@ -419,7 +417,17 @@ namespace tgvoip{
data=std::move(other.data);
endpoint=other.endpoint;
}
#endif
PendingOutgoingPacket& operator=(PendingOutgoingPacket&& other){
if(this!=&other){
seq=other.seq;
type=other.type;
len=other.len;
data=std::move(other.data);
endpoint=other.endpoint;
}
return *this;
}
TGVOIP_DISALLOW_COPY_AND_ASSIGN(PendingOutgoingPacket);
uint32_t seq;
unsigned char type;
size_t len;
@ -553,6 +561,7 @@ namespace tgvoip{
void SendNopPacket();
void TickJitterBufferAngCongestionControl();
void ResetUdpAvailability();
std::string GetPacketTypeString(unsigned char type);
int state;
std::map<int64_t, Endpoint> endpoints;

View File

@ -73,11 +73,17 @@ CellularCarrierInfo DarwinSpecific::GetCarrierInfo(){
#if TARGET_OS_IOS
CTTelephonyNetworkInfo* netinfo=[CTTelephonyNetworkInfo new];
CTCarrier* carrier=[netinfo subscriberCellularProvider];
if(carrier && [carrier carrierName]){
info.name=[[carrier carrierName] cStringUsingEncoding:NSUTF8StringEncoding];
info.mcc=[[carrier mobileCountryCode] cStringUsingEncoding:NSUTF8StringEncoding];
info.mnc=[[carrier mobileNetworkCode] cStringUsingEncoding:NSUTF8StringEncoding];
info.countryCode=[[[carrier isoCountryCode] uppercaseString] cStringUsingEncoding:NSUTF8StringEncoding];
if(carrier){
NSString* name=[carrier carrierName];
NSString* mcc=[carrier mobileCountryCode];
NSString* mnc=[carrier mobileNetworkCode];
NSString* countryCode=[carrier isoCountryCode];
if(name && mcc && mnc && countryCode){
info.name=[name cStringUsingEncoding:NSUTF8StringEncoding];
info.mcc=[mcc cStringUsingEncoding:NSUTF8StringEncoding];
info.mnc=[mnc cStringUsingEncoding:NSUTF8StringEncoding];
info.countryCode=[[countryCode uppercaseString] cStringUsingEncoding:NSUTF8StringEncoding];
}
}
#endif
return info;