1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-03 10:07:45 +01:00

Merge branch 'public' of https://github.com/grishka/libtgvoip into HEAD

This commit is contained in:
Daniil Gentili 2017-08-21 18:18:48 +02:00
commit dafdf34911
5 changed files with 110 additions and 4 deletions

View File

@ -74,6 +74,9 @@
#define TLID_UDP_REFLECTOR_SELF_INFO 0xc01572c7
#define PAD4(x) (4-(x+(x<=253 ? 1 : 0))%4)
#define MAX(a,b) (a>b ? a : b)
#define MIN(a,b) (a<b ? a : b)
inline int pad4(int x){
int r=PAD4(x);
if(r==4)
@ -223,6 +226,9 @@ VoIPController::VoIPController() : activeNetItfName(""),
proxyPort=0;
resolvedProxyAddress=NULL;
signalBarCount=0;
signalBarCountCallback=NULL;
selectCanceller=SocketSelectCanceller::Create();
udpSocket=NetworkSocket::Create(PROTO_UDP);
realUdpSocket=udpSocket;
@ -1370,10 +1376,14 @@ void VoIPController::RunTickThread(){
#else
Sleep(100);
#endif
int prevSignalBarCount=signalBarCount;
signalBarCount=4;
tickCount++;
if(connectionInitTime==0)
continue;
double time=GetCurrentTime();
if(state==STATE_RECONNECTING)
signalBarCount=1;
if(tickCount%5==0 && (state==STATE_ESTABLISHED || state==STATE_RECONNECTING)){
memmove(&rttHistory[1], rttHistory, 31*sizeof(double));
rttHistory[0]=GetAverageRTT();
@ -1388,6 +1398,7 @@ void VoIPController::RunTickThread(){
v=v/32;
if(rttHistory[0]>10.0 && rttHistory[8]>10.0 && (networkType==NET_TYPE_EDGE || networkType==NET_TYPE_GPRS)){
waitingForAcks=true;
signalBarCount=1;
}else{
waitingForAcks=false;
}
@ -1470,6 +1481,11 @@ void VoIPController::RunTickThread(){
}else{
encoder->SetPacketLoss(15);
}
if(encoder->GetPacketLoss()>30)
signalBarCount=MIN(signalBarCount, 2);
else if(encoder->GetPacketLoss()>20)
signalBarCount=MIN(signalBarCount, 3);
}
}
@ -1538,8 +1554,24 @@ void VoIPController::RunTickThread(){
}
unlock_mutex(queuedPacketsMutex);
if(jitterBuffer)
if(jitterBuffer){
jitterBuffer->Tick();
double avgDelay=jitterBuffer->GetAverageDelay();
double avgLateCount[3];
jitterBuffer->GetAverageLateCount(avgLateCount);
if(avgDelay>=5)
signalBarCount=1;
else if(avgDelay>=4)
signalBarCount=MIN(signalBarCount, 2);
else if(avgDelay>=3)
signalBarCount=MIN(signalBarCount, 3);
if(avgLateCount[2]>=0.2)
signalBarCount=1;
else if(avgLateCount[2]>=0.1)
signalBarCount=MIN(signalBarCount, 2);
}
lock_mutex(endpointsMutex);
if(state==STATE_ESTABLISHED || state==STATE_RECONNECTING){
@ -1679,6 +1711,12 @@ void VoIPController::RunTickThread(){
setEstablishedAt=0;
}
if(signalBarCount!=prevSignalBarCount){
LOGD("SIGNAL BAR COUNT CHANGED: %d", signalBarCount);
if(signalBarCountCallback)
signalBarCountCallback(this, signalBarCount);
}
if(statsDump){
//fprintf(statsDump, "Time\tRTT\tLISeq\tLASeq\tCWnd\tBitrate\tJitter\tJDelay\tAJDelay\n");
@ -2421,6 +2459,14 @@ void VoIPController::SendUdpPing(Endpoint *endpoint){
udpSocket->Send(&pkt);
}
int VoIPController::GetSignalBarsCount(){
return signalBarCount;
}
void VoIPController::SetSignalBarsCountCallback(void (*f)(VoIPController *, int)){
signalBarCountCallback=f;
}
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;

View File

@ -325,6 +325,16 @@ public:
* @param password Password; empty string if none
*/
void SetProxy(int protocol, std::string address, uint16_t port, std::string username, std::string password);
/**
* Get the number of signal bars to display in the client UI.
* @return the number of signal bars, from 1 to 4
*/
int GetSignalBarsCount();
/**
* Set the callback to be called when the signal bar count changes.
* @param f
*/
void SetSignalBarsCountCallback(void (*f)(VoIPController*, int));
private:
struct PendingOutgoingPacket{
@ -454,6 +464,9 @@ private:
std::string proxyUsername;
std::string proxyPassword;
IPv4Address* resolvedProxyAddress;
int signalBarCount;
void (*signalBarCountCallback)(VoIPController*, int);
/*** server config values ***/
uint32_t maxAudioBitrate;

View File

@ -21,6 +21,7 @@ JavaVM* sharedJVM;
jfieldID audioRecordInstanceFld=NULL;
jfieldID audioTrackInstanceFld=NULL;
jmethodID setStateMethod=NULL;
jmethodID setSignalBarsMethod=NULL;
struct impl_data_android_t{
jobject javaObject;
@ -49,6 +50,26 @@ void updateConnectionState(VoIPController* cntrlr, int state){
}
}
void updateSignalBarCount(VoIPController* cntrlr, int count){
impl_data_android_t* impl=(impl_data_android_t*) cntrlr->implData;
if(!impl->javaObject)
return;
JNIEnv* env=NULL;
bool didAttach=false;
sharedJVM->GetEnv((void**) &env, JNI_VERSION_1_6);
if(!env){
sharedJVM->AttachCurrentThread(&env, NULL);
didAttach=true;
}
if(setSignalBarsMethod)
env->CallVoidMethod(impl->javaObject, setSignalBarsMethod, count);
if(didAttach){
sharedJVM->DetachCurrentThread();
}
}
extern "C" JNIEXPORT jlong Java_org_telegram_messenger_voip_VoIPController_nativeInit(JNIEnv* env, jobject thiz, jint systemVersion){
AudioOutputAndroid::systemVersion=systemVersion;
@ -70,12 +91,14 @@ extern "C" JNIEXPORT jlong Java_org_telegram_messenger_voip_VoIPController_nativ
}
setStateMethod=env->GetMethodID(env->GetObjectClass(thiz), "handleStateChange", "(I)V");
setSignalBarsMethod=env->GetMethodID(env->GetObjectClass(thiz), "handleSignalBarsChange", "(I)V");
impl_data_android_t* impl=(impl_data_android_t*) malloc(sizeof(impl_data_android_t));
impl->javaObject=env->NewGlobalRef(thiz);
VoIPController* cntrlr=new VoIPController();
cntrlr->implData=impl;
cntrlr->SetStateCallback(updateConnectionState);
cntrlr->SetSignalBarsCountCallback(updateSignalBarCount);
return (jlong)(intptr_t)cntrlr;
}

View File

@ -48,6 +48,12 @@
692AB9211E675F7000706ACC /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 692AB91E1E675F7000706ACC /* CoreAudio.framework */; };
695B20621EBD39FF00E31757 /* DarwinSpecific.h in Headers */ = {isa = PBXBuildFile; fileRef = 695B20601EBD39FF00E31757 /* DarwinSpecific.h */; };
695B20631EBD39FF00E31757 /* DarwinSpecific.mm in Sources */ = {isa = PBXBuildFile; fileRef = 695B20611EBD39FF00E31757 /* DarwinSpecific.mm */; };
698848411F4B39F700076DF0 /* AudioInputAudioUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6988483B1F4B39F700076DF0 /* AudioInputAudioUnit.cpp */; };
698848421F4B39F700076DF0 /* AudioInputAudioUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 6988483C1F4B39F700076DF0 /* AudioInputAudioUnit.h */; };
698848431F4B39F700076DF0 /* AudioOutputAudioUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6988483D1F4B39F700076DF0 /* AudioOutputAudioUnit.cpp */; };
698848441F4B39F700076DF0 /* AudioOutputAudioUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 6988483E1F4B39F700076DF0 /* AudioOutputAudioUnit.h */; };
698848451F4B39F700076DF0 /* AudioUnitIO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6988483F1F4B39F700076DF0 /* AudioUnitIO.cpp */; };
698848461F4B39F700076DF0 /* AudioUnitIO.h in Headers */ = {isa = PBXBuildFile; fileRef = 698848401F4B39F700076DF0 /* AudioUnitIO.h */; };
69A6DEB91E96149300000E69 /* array_view.h in Headers */ = {isa = PBXBuildFile; fileRef = 69A6DE231E96149300000E69 /* array_view.h */; };
69A6DEBA1E96149300000E69 /* atomicops.h in Headers */ = {isa = PBXBuildFile; fileRef = 69A6DE241E96149300000E69 /* atomicops.h */; };
69A6DEBB1E96149300000E69 /* basictypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 69A6DE251E96149300000E69 /* basictypes.h */; };
@ -271,8 +277,14 @@
692AB91C1E675F7000706ACC /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
692AB91D1E675F7000706ACC /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
692AB91E1E675F7000706ACC /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
695B20601EBD39FF00E31757 /* DarwinSpecific.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DarwinSpecific.h; path = ../../../../../TDesktop/TBuild/tdesktop/third_party/libtgvoip/os/darwin/DarwinSpecific.h; sourceTree = "<group>"; };
695B20611EBD39FF00E31757 /* DarwinSpecific.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DarwinSpecific.mm; path = ../../../../../TDesktop/TBuild/tdesktop/third_party/libtgvoip/os/darwin/DarwinSpecific.mm; sourceTree = "<group>"; };
695B20601EBD39FF00E31757 /* DarwinSpecific.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinSpecific.h; sourceTree = "<group>"; };
695B20611EBD39FF00E31757 /* DarwinSpecific.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DarwinSpecific.mm; path = ../../../../../libtgvoip/os/darwin/DarwinSpecific.mm; sourceTree = "<group>"; };
6988483B1F4B39F700076DF0 /* AudioInputAudioUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioInputAudioUnit.cpp; path = ../../../../../libtgvoip/os/darwin/AudioInputAudioUnit.cpp; sourceTree = "<group>"; };
6988483C1F4B39F700076DF0 /* AudioInputAudioUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioInputAudioUnit.h; path = ../../../../../libtgvoip/os/darwin/AudioInputAudioUnit.h; sourceTree = "<group>"; };
6988483D1F4B39F700076DF0 /* AudioOutputAudioUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioOutputAudioUnit.cpp; path = ../../../../../libtgvoip/os/darwin/AudioOutputAudioUnit.cpp; sourceTree = "<group>"; };
6988483E1F4B39F700076DF0 /* AudioOutputAudioUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioOutputAudioUnit.h; path = ../../../../../libtgvoip/os/darwin/AudioOutputAudioUnit.h; sourceTree = "<group>"; };
6988483F1F4B39F700076DF0 /* AudioUnitIO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioUnitIO.cpp; path = ../../../../../libtgvoip/os/darwin/AudioUnitIO.cpp; sourceTree = "<group>"; };
698848401F4B39F700076DF0 /* AudioUnitIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioUnitIO.h; path = ../../../../../libtgvoip/os/darwin/AudioUnitIO.h; sourceTree = "<group>"; };
69A6DE231E96149300000E69 /* array_view.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = array_view.h; sourceTree = "<group>"; };
69A6DE241E96149300000E69 /* atomicops.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = atomicops.h; sourceTree = "<group>"; };
69A6DE251E96149300000E69 /* basictypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = basictypes.h; sourceTree = "<group>"; };
@ -497,6 +509,12 @@
692AB8BD1E6759DD00706ACC /* darwin */ = {
isa = PBXGroup;
children = (
6988483B1F4B39F700076DF0 /* AudioInputAudioUnit.cpp */,
6988483C1F4B39F700076DF0 /* AudioInputAudioUnit.h */,
6988483D1F4B39F700076DF0 /* AudioOutputAudioUnit.cpp */,
6988483E1F4B39F700076DF0 /* AudioOutputAudioUnit.h */,
6988483F1F4B39F700076DF0 /* AudioUnitIO.cpp */,
698848401F4B39F700076DF0 /* AudioUnitIO.h */,
69A6DF3F1E9614B700000E69 /* AudioInputAudioUnitOSX.cpp */,
69A6DF401E9614B700000E69 /* AudioInputAudioUnitOSX.h */,
69A6DF411E9614B700000E69 /* AudioOutputAudioUnitOSX.cpp */,
@ -840,6 +858,7 @@
69A6DF181E96149300000E69 /* gain_control.h in Headers */,
69A6DF231E96149300000E69 /* nsx_core.h in Headers */,
692AB9011E6759DD00706ACC /* threading.h in Headers */,
698848461F4B39F700076DF0 /* AudioUnitIO.h in Headers */,
69A6DF2B1E96149300000E69 /* three_band_filter_bank.h in Headers */,
692AB8EA1E6759DD00706ACC /* MediaStreamItf.h in Headers */,
69A6DF3E1E96149300000E69 /* typedefs.h in Headers */,
@ -900,6 +919,7 @@
69A6DF3C1E96149300000E69 /* metrics.h in Headers */,
692AB8D61E6759DD00706ACC /* BufferPool.h in Headers */,
69A6DF0E1E96149300000E69 /* aecm_core.h in Headers */,
698848421F4B39F700076DF0 /* AudioInputAudioUnit.h in Headers */,
69A6DF2F1E96149300000E69 /* delay_estimator.h in Headers */,
69A6DEC41E96149300000E69 /* stringutils.h in Headers */,
69A6DF1F1E96149300000E69 /* noise_suppression_x.h in Headers */,
@ -914,6 +934,7 @@
69A6DEBB1E96149300000E69 /* basictypes.h in Headers */,
69A6DEE71E96149300000E69 /* spl_inl_mips.h in Headers */,
69A6DF261E96149300000E69 /* nsx_defines.h in Headers */,
698848441F4B39F700076DF0 /* AudioOutputAudioUnit.h in Headers */,
69A6DEC11E96149300000E69 /* safe_conversions_impl.h in Headers */,
69A6DEC01E96149300000E69 /* safe_conversions.h in Headers */,
);
@ -1081,6 +1102,7 @@
692AB8EB1E6759DD00706ACC /* OpusDecoder.cpp in Sources */,
69A6DED81E96149300000E69 /* dot_product_with_scale.c in Sources */,
69A6DF331E96149300000E69 /* ooura_fft.cc in Sources */,
698848451F4B39F700076DF0 /* AudioUnitIO.cpp in Sources */,
69A6DEF11E96149300000E69 /* resample_by_2.c in Sources */,
69A6DEEC1E96149300000E69 /* randomization_functions.c in Sources */,
69A6DEEE1E96149300000E69 /* refl_coef_to_lpc.c in Sources */,
@ -1091,6 +1113,7 @@
69A6DF161E96149300000E69 /* digital_agc.c in Sources */,
69A6DF061E96149300000E69 /* aec_core_neon.cc in Sources */,
69A6DF201E96149300000E69 /* ns_core.c in Sources */,
698848431F4B39F700076DF0 /* AudioOutputAudioUnit.cpp in Sources */,
69A6DF091E96149300000E69 /* aec_resampler.cc in Sources */,
692AB8D11E6759DD00706ACC /* BufferInputStream.cpp in Sources */,
692AB8E91E6759DD00706ACC /* MediaStreamItf.cpp in Sources */,
@ -1123,6 +1146,7 @@
69A6DF251E96149300000E69 /* nsx_core_neon.c in Sources */,
69A6DF081E96149300000E69 /* aec_core_sse2.cc in Sources */,
69A6DEEA1E96149300000E69 /* min_max_operations.c in Sources */,
698848411F4B39F700076DF0 /* AudioInputAudioUnit.cpp in Sources */,
69A6DF361E96149300000E69 /* ooura_fft_sse2.cc in Sources */,
69A6DED51E96149300000E69 /* cross_correlation.c in Sources */,
69A6DF3D1E96149300000E69 /* cpu_features.cc in Sources */,

View File

@ -1,6 +1,6 @@
#import <Foundation/Foundation.h>
#import <ASCommon.h>
extern void TGLogv(NSString *format, va_list args);
void __tgvoip_call_tglog(const char* format, ...){
va_list args;