Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/public' into tdesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Dec 27, 2017
2 parents 5519789 + 55c2202 commit 0b53884
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ bld/

# Visual Studio 2015 cache/options directory
.vs/

xcuserdata/
17 changes: 17 additions & 0 deletions EchoCanceller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
running=true;

start_thread(bufferFarendThread, EchoCanceller::StartBufferFarendThread, this);
}else{
aec=NULL;
}

if(enableNS){
Expand All @@ -92,6 +94,8 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
WebRtcNs_Init((NsHandle*)ns, 48000);
WebRtcNs_set_policy((NsHandle*)ns, 1);
#endif*/
}else{
ns=NULL;
}

if(enableAGC){
Expand All @@ -103,6 +107,8 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
WebRtcAgc_Init(agc, 0, 255, kAgcModeAdaptiveDigital, 48000);
WebRtcAgc_set_config(agc, agcConfig);
agcMicLevel=0;
}else{
agc=NULL;
}
#endif
}
Expand Down Expand Up @@ -354,6 +360,17 @@ void EchoCanceller::ProcessInput(unsigned char* data, unsigned char* out, size_t
memcpy(samplesOut, bufIn->ibuf_const()->bands(0)[0], 960*2);
}

void EchoCanceller::SetAECStrength(int strength){
if(aec){
#ifndef TGVOIP_USE_DESKTOP_DSP
AecmConfig cfg;
cfg.cngMode=AecmFalse;
cfg.echoMode=(int16_t) strength;
WebRtcAecm_set_config(aec, cfg);
#endif
}
}

AudioEffect::~AudioEffect(){

}
Expand Down
1 change: 1 addition & 0 deletions EchoCanceller.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EchoCanceller{
void SpeakerOutCallback(unsigned char* data, size_t len);
void Enable(bool enabled);
void ProcessInput(unsigned char* data, unsigned char* out, size_t len);
void SetAECStrength(int strength);

private:
bool enableAEC;
Expand Down
8 changes: 8 additions & 0 deletions VoIPController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ VoIPController::VoIPController() : activeNetItfName(""),
udpSocket=NetworkSocket::Create(PROTO_UDP);
realUdpSocket=udpSocket;
udpConnectivityState=UDP_UNKNOWN;
echoCancellationStrength=1;

outputAGC=NULL;
outputAGCEnabled=false;
Expand Down Expand Up @@ -1147,6 +1148,7 @@ simpleAudioBlock random_id:long random_bytes:string raw_data:string = DecryptedA
audioOutput=tgvoip::audio::AudioOutput::Create(currentAudioOutput);
audioOutput->Configure(48000, 16, 1);
echoCanceller=new EchoCanceller(config.enableAEC, config.enableNS, config.enableAGC);
echoCanceller->SetAECStrength(echoCancellationStrength);
encoder=new OpusEncoder(audioInput);
encoder->SetCallback(AudioInputCallback, this);
encoder->SetOutputFrameDuration(outgoingAudioStream->frameDuration);
Expand Down Expand Up @@ -2472,6 +2474,12 @@ void VoIPController::SetAudioOutputGainControlEnabled(bool enabled){
outputAGC->SetPassThrough(!enabled);
}

void VoIPController::SetEchoCancellationStrength(int strength){
echoCancellationStrength=strength;
if(echoCanceller)
echoCanceller->SetAECStrength(strength);
}

Endpoint::Endpoint(int64_t id, uint16_t port, IPv4Address& _address, IPv6Address& _v6address, char type, unsigned char peerTag[16]) : address(_address), v6address(_v6address){
this->id=id;
this->port=port;
Expand Down
4 changes: 3 additions & 1 deletion VoIPController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "CongestionControl.h"
#include "NetworkSocket.h"

#define LIBTGVOIP_VERSION "1.0.1"
#define LIBTGVOIP_VERSION "1.0.3"

#define STATE_WAIT_INIT 1
#define STATE_WAIT_INIT_ACK 2
Expand Down Expand Up @@ -341,6 +341,7 @@ class VoIPController
* @param enabled I usually pick argument names to be self-explanatory
*/
void SetAudioOutputGainControlEnabled(bool enabled);
void SetEchoCancellationStrength(int strength);

private:
struct PendingOutgoingPacket{
Expand Down Expand Up @@ -464,6 +465,7 @@ class VoIPController
int udpConnectivityState;
double lastUdpPingTime;
int udpPingCount;
int echoCancellationStrength;

int proxyProtocol;
std::string proxyAddress;
Expand Down
4 changes: 4 additions & 0 deletions client/android/tg_voip_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ extern "C" JNIEXPORT void Java_org_telegram_messenger_voip_VoIPController_native
((VoIPController*)(intptr_t)inst)->SetAudioOutputGainControlEnabled(enabled);
}

extern "C" JNIEXPORT void Java_org_telegram_messenger_voip_VoIPController_nativeSetEchoCancellationStrength(JNIEnv* env, jclass cls, jlong inst, jint strength){
((VoIPController*)(intptr_t)inst)->SetEchoCancellationStrength(strength);
}

extern "C" JNIEXPORT jint Java_org_telegram_messenger_voip_Resampler_convert44to48(JNIEnv* env, jclass cls, jobject from, jobject to){
return tgvoip::audio::Resampler::Convert44To48((int16_t *) env->GetDirectBufferAddress(from), (int16_t *) env->GetDirectBufferAddress(to), (size_t) (env->GetDirectBufferCapacity(from)/2), (size_t) (env->GetDirectBufferCapacity(to)/2));
}
Expand Down
1 change: 1 addition & 0 deletions os/linux/AudioInputALSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void AudioInputALSA::Stop(){

void* AudioInputALSA::StartThread(void* arg){
((AudioInputALSA*)arg)->RunThread();
return NULL;
}

void AudioInputALSA::RunThread(){
Expand Down
1 change: 1 addition & 0 deletions os/linux/AudioOutputALSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool AudioOutputALSA::IsPlaying(){

void* AudioOutputALSA::StartThread(void* arg){
((AudioOutputALSA*)arg)->RunThread();
return NULL;
}

void AudioOutputALSA::RunThread(){
Expand Down
11 changes: 2 additions & 9 deletions os/windows/CXWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ VoIPControllerWrapper::VoIPControllerWrapper(){
controller->implData=(void*)this;
controller->SetStateCallback(VoIPControllerWrapper::OnStateChanged);
controller->SetSignalBarsCountCallback(VoIPControllerWrapper::OnSignalBarsChanged);
stateCallback=nullptr;
}

VoIPControllerWrapper::~VoIPControllerWrapper(){
Expand Down Expand Up @@ -86,10 +85,6 @@ void VoIPControllerWrapper::SetNetworkType(NetworkType type){
controller->SetNetworkType((int)type);
}

void VoIPControllerWrapper::SetStateCallback(IStateCallback^ callback){
stateCallback=callback;
}

void VoIPControllerWrapper::SetMicMute(bool mute){
controller->SetMicMute(mute);
}
Expand Down Expand Up @@ -142,13 +137,11 @@ void VoIPControllerWrapper::OnSignalBarsChanged(VoIPController* c, int count){
}

void VoIPControllerWrapper::OnStateChangedInternal(int state){
if(stateCallback)
stateCallback->OnCallStateChanged((CallState)state);
CallStateChanged(this, (CallState)state);
}

void VoIPControllerWrapper::OnSignalBarsChangedInternal(int count){
if(stateCallback)
stateCallback->OnSignalBarsChanged(count);
SignalBarsChanged(this, count);
}

void VoIPControllerWrapper::SetConfig(double initTimeout, double recvTimeout, DataSavingMode dataSavingMode, bool enableAEC, bool enableNS, bool enableAGC, Platform::String^ logFilePath, Platform::String^ statsDumpFilePath){
Expand Down
15 changes: 9 additions & 6 deletions os/windows/CXWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ namespace libtgvoip{
SOCKS5
};

public interface class IStateCallback{
void OnCallStateChanged(CallState newState);
void OnSignalBarsChanged(int count);
};
ref class VoIPControllerWrapper;
public delegate void CallStateChangedEventHandler(VoIPControllerWrapper^ sender, CallState newState);

ref class VoIPControllerWrapper;
public delegate void SignalBarsChangedEventHandler(VoIPControllerWrapper^ sender, int newCount);

public ref class VoIPControllerWrapper sealed{
public:
Expand All @@ -71,7 +72,6 @@ namespace libtgvoip{
void Connect();
void SetPublicEndpoints(const Platform::Array<Endpoint^>^ endpoints, bool allowP2P);
void SetNetworkType(NetworkType type);
void SetStateCallback(IStateCallback^ callback);
void SetMicMute(bool mute);
void SetEncryptionKey(const Platform::Array<uint8>^ key, bool isOutgoing);
void SetConfig(double initTimeout, double recvTimeout, DataSavingMode dataSavingMode, bool enableAEC, bool enableNS, bool enableAGC, Platform::String^ logFilePath, Platform::String^ statsDumpFilePath);
Expand All @@ -85,13 +85,16 @@ namespace libtgvoip{
static void UpdateServerConfig(Platform::String^ json);
static void SwitchSpeaker(bool external);
//static Platform::String^ TestAesIge();

event CallStateChangedEventHandler^ CallStateChanged;
event SignalBarsChangedEventHandler^ SignalBarsChanged;

private:
static void OnStateChanged(tgvoip::VoIPController* c, int state);
static void OnSignalBarsChanged(tgvoip::VoIPController* c, int count);
void OnStateChangedInternal(int state);
void OnSignalBarsChangedInternal(int count);
tgvoip::VoIPController* controller;
IStateCallback^ stateCallback;
};

ref class MicrosoftCryptoImpl{
Expand Down

0 comments on commit 0b53884

Please sign in to comment.