From 5629256fbf724e0e5bbf59e615722c25a07a6fc9 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 29 Mar 2020 18:05:35 +0200 Subject: [PATCH] Various android bugfixes --- Android.mk | 53 +++++++++++++++++------------ TgVoip.cpp | 6 ++++ client/android/tg_voip_jni.cpp | 24 +++++++------ controller/audio/OpusDecoder.cpp | 11 ++++-- controller/net/JitterBuffer.h | 2 +- controller/protocol/NetworkAPI.cpp | 8 ++--- os/android/AudioOutputAndroid.h | 4 +-- os/android/VideoRendererAndroid.cpp | 10 +++--- os/android/VideoSourceAndroid.cpp | 10 +++--- 9 files changed, 76 insertions(+), 52 deletions(-) diff --git a/Android.mk b/Android.mk index 1325503..ffbc12b 100644 --- a/Android.mk +++ b/Android.mk @@ -20,31 +20,34 @@ endif LOCAL_CFLAGS += $(TGVOIP_ADDITIONAL_CFLAGS) -LOCAL_SRC_FILES := \ -./tools/logging.cpp \ +LOCAL_SRC_FILES := ./TgVoip.cpp \ ./VoIPController.cpp \ ./tools/Buffers.cpp \ -./tools/BlockingQueue.cpp \ -./audio/AudioInput.cpp \ -./os/android/AudioInputOpenSLES.cpp \ -./controller/MediaStreamItf.cpp \ -./audio/AudioOutput.cpp \ -./controller/audio/OpusEncoder.cpp \ -./os/android/AudioOutputOpenSLES.cpp \ -./controller/net/JitterBuffer.cpp \ -./controller/audio/OpusDecoder.cpp \ -./os/android/OpenSLEngineWrapper.cpp \ -./os/android/AudioInputAndroid.cpp \ -./os/android/AudioOutputAndroid.cpp \ -./controller/audio/EchoCanceller.cpp \ ./controller/net/CongestionControl.cpp \ -./VoIPServerConfig.cpp \ -./audio/Resampler.cpp \ -./controller/net/NetworkSocket.cpp \ -./os/posix/NetworkSocketPosix.cpp \ -./controller/PacketReassembler.cpp \ +./controller/audio/EchoCanceller.cpp \ +./controller/net/JitterBuffer.cpp \ +./tools/logging.cpp \ +./controller/media/MediaStreamItf.cpp \ ./tools/MessageThread.cpp \ -./tools/json11.cpp \ +./controller/net/NetworkSocket.cpp \ +./controller/net/Endpoint.cpp \ +./controller/audio/OpusDecoder.cpp \ +./controller/audio/OpusEncoder.cpp \ +./controller/audio/AudioPacketSender.cpp \ +./controller/net/PacketReassembler.cpp \ +./controller/protocol/packets/PacketManager.cpp \ +./controller/protocol/packets/PacketSender.cpp \ +./controller/protocol/packets/PacketStructs.cpp \ +./controller/protocol/Stream.cpp \ +./controller/protocol/protocol/Extra.cpp \ +./VoIPServerConfig.cpp \ +./audio/AudioIO.cpp \ +./audio/AudioInput.cpp \ +./audio/AudioOutput.cpp \ +./audio/Resampler.cpp \ +./audio/AudioInputTester.cpp \ +./os/posix/NetworkSocketPosix.cpp \ +\ ./audio/AudioIO.cpp \ ./video/VideoRenderer.cpp \ ./video/VideoSource.cpp \ @@ -55,7 +58,13 @@ LOCAL_SRC_FILES := \ ./video/cm256/gf256.$(CPP_NEON) \ ./os/android/VideoSourceAndroid.cpp \ ./os/android/VideoRendererAndroid.cpp \ -./client/android/tg_voip_jni.cpp +./client/android/tg_voip_jni.cpp \ +./os/android/AudioInputOpenSLES.cpp \ +./os/android/AudioOutputOpenSLES.cpp \ +./os/android/OpenSLEngineWrapper.cpp \ +./os/android/AudioInputAndroid.cpp \ +./os/android/AudioOutputAndroid.cpp \ +./tools/json11.cpp # WebRTC signal processing diff --git a/TgVoip.cpp b/TgVoip.cpp index 98eb279..ba977f7 100755 --- a/TgVoip.cpp +++ b/TgVoip.cpp @@ -11,7 +11,9 @@ extern "C" { #include +#ifndef ANDROID #include +#endif #include #include } @@ -49,7 +51,11 @@ void tgvoip_openssl_aes_ctr_encrypt(uint8_t *inout, size_t length, uint8_t *key, { AES_KEY akey; AES_set_encrypt_key(key, 32 * 8, &akey); +#ifdef ANDROID + AES_ctr128_encrypt(inout, inout, length, &akey, iv, ecount, num); +#else CRYPTO_ctr128_encrypt(inout, inout, length, &akey, iv, ecount, num, (block128_f)AES_encrypt); +#endif } void tgvoip_openssl_aes_cbc_encrypt(uint8_t *in, uint8_t *out, size_t length, uint8_t *key, uint8_t *iv) diff --git a/client/android/tg_voip_jni.cpp b/client/android/tg_voip_jni.cpp index 68ccf82..6691e06 100644 --- a/client/android/tg_voip_jni.cpp +++ b/client/android/tg_voip_jni.cpp @@ -19,13 +19,15 @@ #include "../../os/android/VideoRendererAndroid.h" #include "../../audio/Resampler.h" #include "../../os/android/JNIUtilities.h" -#include "../../controller/PrivateDefines.h" +#include "../../VoIPController.h" #include "../../tools/logging.h" #ifdef TGVOIP_HAS_CONFIG #include #endif +#define TGVOIP_NO_GROUP_CALLS 1 + JavaVM* sharedJVM; jfieldID audioRecordInstanceFld=NULL; jfieldID audioTrackInstanceFld=NULL; @@ -71,6 +73,7 @@ namespace tgvoip { jni::AttachAndCallVoidMethod(setSignalBarsMethod, impl->javaObject, count); } + /* void updateGroupCallStreams(VoIPGroupController *cntrlr, unsigned char *streams, size_t len){ ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; if(!impl->javaObject) @@ -84,7 +87,7 @@ namespace tgvoip { env->CallVoidMethod(impl->javaObject, setSelfStreamsMethod, jstreams); } }); - } + }*/ void groupCallKeyReceived(VoIPController *cntrlr, const unsigned char *key){ ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; @@ -110,23 +113,24 @@ namespace tgvoip { ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; jni::AttachAndCallVoidMethod(callUpgradeRequestReceivedMethod, impl->javaObject); } + /* void updateParticipantAudioState(VoIPGroupController *cntrlr, int32_t userID, bool enabled){ ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; jni::AttachAndCallVoidMethod(setParticipantAudioEnabledMethod, impl->javaObject, userID, enabled); - } + }*/ #pragma mark - VoIPController uint32_t AndroidCodecToFOURCC(std::string mime){ if(mime=="video/avc") - return CODEC_AVC; + return Codec::Avc; else if(mime=="video/hevc") - return CODEC_HEVC; + return Codec::Hevc; else if(mime=="video/x-vnd.on2.vp8") - return CODEC_VP8; + return Codec::Vp8; else if(mime=="video/x-vnd.on2.vp9") - return CODEC_VP9; + return Codec::Vp9; return 0; } @@ -202,7 +206,7 @@ namespace tgvoip { void VoIPController_nativeSetEncryptionKey(JNIEnv* env, jobject thiz, jlong inst, jbyteArray key, jboolean isOutgoing){ jbyte* akey=env->GetByteArrayElements(key, NULL); - ((VoIPController*)(intptr_t)inst)->SetEncryptionKey((char *) akey, isOutgoing); + ((VoIPController*)(intptr_t)inst)->SetEncryptionKey(std::vector(akey, akey+256), isOutgoing); env->ReleaseByteArrayElements(key, akey, JNI_ABORT); } @@ -304,7 +308,6 @@ namespace tgvoip { } void VoIPController_nativeDebugCtl(JNIEnv* env, jobject thiz, jlong inst, jint request, jint param){ - ((VoIPController*)(intptr_t)inst)->DebugCtl(request, param); } jstring VoIPController_nativeGetVersion(JNIEnv* env, jclass clasz){ @@ -405,6 +408,7 @@ namespace tgvoip { return (jint)tgvoip::audio::Resampler::Convert48To44((int16_t *) env->GetDirectBufferAddress(from), (int16_t *) env->GetDirectBufferAddress(to), (size_t) (env->GetDirectBufferCapacity(from)/2), (size_t) (env->GetDirectBufferCapacity(to)/2)); } + #pragma mark - VoIPGroupController #ifndef TGVOIP_NO_GROUP_CALLS @@ -571,7 +575,7 @@ namespace tgvoip { extern "C" void tgvoipRegisterNatives(JNIEnv* env){ jclass controller=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPController"); - jclass groupController=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPGroupController"); + //jclass groupController=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPGroupController"); if(env->ExceptionCheck()){ env->ExceptionClear(); // is returning NULL from FindClass not enough? } diff --git a/controller/audio/OpusDecoder.cpp b/controller/audio/OpusDecoder.cpp index 7155025..0b3ee2d 100755 --- a/controller/audio/OpusDecoder.cpp +++ b/controller/audio/OpusDecoder.cpp @@ -7,8 +7,9 @@ #include "controller/audio/OpusDecoder.h" #include "audio/Resampler.h" #include "tools/logging.h" -#include -#include +#include +#include +#include #include #if defined HAVE_CONFIG_H || defined TGVOIP_USE_INSTALLED_OPUS @@ -52,7 +53,11 @@ void tgvoip::OpusDecoder::Initialize(bool isAsync, bool needEC) ecDec = opus_decoder_create(48000, 1, NULL); else ecDec = NULL; - buffer = reinterpret_cast(aligned_alloc(2, 8192)); +#ifdef ANDROID + buffer = reinterpret_cast(std::malloc(8192)); +#else + buffer = reinterpret_cast(std::aligned_alloc(2, 8192)); +#endif lastDecoded = NULL; outputBufferSize = 0; echoCanceller = NULL; diff --git a/controller/net/JitterBuffer.h b/controller/net/JitterBuffer.h index c2f4d2a..3bbb3bc 100644 --- a/controller/net/JitterBuffer.h +++ b/controller/net/JitterBuffer.h @@ -71,7 +71,7 @@ private: //BufferPool bufferPool; Mutex mutex; uint32_t step; - std::array slots{0}; + std::array slots; std::atomic nextFetchTimestamp{0}; // What frame to read next (protected for GetSeqTooLate) std::atomic minDelay{6}; uint32_t minMinDelay; diff --git a/controller/protocol/NetworkAPI.cpp b/controller/protocol/NetworkAPI.cpp index a84c8fa..0c8d83c 100644 --- a/controller/protocol/NetworkAPI.cpp +++ b/controller/protocol/NetworkAPI.cpp @@ -477,12 +477,12 @@ void VoIPController::SendExtra(Wrapped &&extra, int64_t endpointId) auto type = extra.getID(); LOGV("Sending extra type %s", extra.print().c_str()); - for (auto &extra : currentExtras) + for (auto &curExtra : currentExtras) { - if (extra.data.getID() == type && extra.endpointId == endpointId) + if (curExtra.data.getID() == type && curExtra.endpointId == endpointId) { - extra.seqs.Reset(); - extra.data = std::move(extra.data); + curExtra.seqs.Reset(); + curExtra.data = std::move(extra); return; } } diff --git a/os/android/AudioOutputAndroid.h b/os/android/AudioOutputAndroid.h index dded47f..1608ff0 100644 --- a/os/android/AudioOutputAndroid.h +++ b/os/android/AudioOutputAndroid.h @@ -17,8 +17,8 @@ public: AudioOutputAndroid(); virtual ~AudioOutputAndroid(); - virtual void Start(); - virtual void Stop(); + virtual void Start() override; + virtual void Stop() override; virtual bool IsPlaying() override; void HandleCallback(JNIEnv* env, jbyteArray buffer); static jmethodID initMethod; diff --git a/os/android/VideoRendererAndroid.cpp b/os/android/VideoRendererAndroid.cpp index 13b8c58..beb00c0 100644 --- a/os/android/VideoRendererAndroid.cpp +++ b/os/android/VideoRendererAndroid.cpp @@ -4,7 +4,7 @@ #include "VideoRendererAndroid.h" #include "JNIUtilities.h" -#include "../../controller/PrivateDefines.h" +#include "../../VoIPController.h" #include "../../tools/logging.h" using namespace tgvoip; @@ -112,16 +112,16 @@ void VideoRendererAndroid::RunThread(){ } std::string codecStr=""; switch(codec){ - case CODEC_AVC: + case Codec::Avc: codecStr="video/avc"; break; - case CODEC_HEVC: + case Codec::Hevc: codecStr="video/hevc"; break; - case CODEC_VP8: + case Codec::Vp8: codecStr="video/x-vnd.on2.vp8"; break; - case CODEC_VP9: + case Codec::Vp9: codecStr="video/x-vnd.on2.vp9"; break; } diff --git a/os/android/VideoSourceAndroid.cpp b/os/android/VideoSourceAndroid.cpp index 3ddb480..23bb6e1 100644 --- a/os/android/VideoSourceAndroid.cpp +++ b/os/android/VideoSourceAndroid.cpp @@ -5,7 +5,7 @@ #include "VideoSourceAndroid.h" #include "JNIUtilities.h" #include "../../tools/logging.h" -#include "../../controller/PrivateDefines.h" +#include "../../VoIPController.h" using namespace tgvoip; using namespace tgvoip::video; @@ -58,16 +58,16 @@ void VideoSourceAndroid::Reset(uint32_t codec, int maxResolution){ jni::DoWithJNI([&](JNIEnv* env){ std::string codecStr=""; switch(codec){ - case CODEC_AVC: + case Codec::Avc: codecStr="video/avc"; break; - case CODEC_HEVC: + case Codec::Hevc: codecStr="video/hevc"; break; - case CODEC_VP8: + case Codec::Vp8: codecStr="video/x-vnd.on2.vp8"; break; - case CODEC_VP9: + case Codec::Vp9: codecStr="video/x-vnd.on2.vp9"; break; }