| 6 |
| 7 | #include <jni.h> |
| 8 | #include <string.h> |
| 9 | #include <map> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | #include "../../VoIPServerConfig.h" |
| 13 | #include "../../VoIPController.h" |
| 14 | #include "../../os/android/AudioOutputOpenSLES.h" |
| 15 | #include "../../os/android/AudioInputOpenSLES.h" |
| 16 | #include "../../os/android/AudioInputAndroid.h" |
| 17 | #include "../../os/android/AudioOutputAndroid.h" |
| 18 | #include "../../os/android/VideoSourceAndroid.h" |
| 19 | #include "../../os/android/VideoRendererAndroid.h" |
| 20 | #include "../../audio/Resampler.h" |
| 21 | #include "../../os/android/JNIUtilities.h" |
| 22 | #include "../../PrivateDefines.h" |
| 23 | #include "../../logging.h" |
| 24 |
| 25 | #ifdef TGVOIP_HAS_CONFIG |
| 26 | #include <tgvoip_config.h> |
| 27 | #endif |
| 28 |
| 29 | JavaVM* sharedJVM; |
| 30 | jfieldID audioRecordInstanceFld=NULL; |
| 31 | jfieldID audioTrackInstanceFld=NULL; |
| 32 | jmethodID setStateMethod=NULL; |
| 33 | jmethodID setSignalBarsMethod=NULL; |
| 34 | jmethodID setSelfStreamsMethod=NULL; |
| 35 | jmethodID setParticipantAudioEnabledMethod=NULL; |
| 36 | jmethodID groupCallKeyReceivedMethod=NULL; |
| 37 | jmethodID groupCallKeySentMethod=NULL; |
| 38 | jmethodID callUpgradeRequestReceivedMethod=NULL; |
| 39 | jclass jniUtilitiesClass=NULL; |
| 40 |
| 41 | struct ImplDataAndroid{ |
| 42 | jobject javaObject; |
| 43 | std::string persistentStateFile=""; |
| 44 | }; |
| 45 |
| 46 | #ifndef TGVOIP_PACKAGE_PATH |
| 47 | #define TGVOIP_PACKAGE_PATH "org/telegram/messenger/voip" |
| 48 | #endif |
| 49 |
| 50 | #ifndef TGVOIP_PEER_TAG_VARIABLE_NAME |
| 51 | #define TGVOIP_PEER_TAG_VARIABLE_NAME "peer_tag" |
| 52 | #endif |
| 53 |
| 54 | #ifndef TGVOIP_ENDPOINT_CLASS |
| 55 | #define TGVOIP_ENDPOINT_CLASS "org/telegram/tgnet/TLRPC$TL_phoneConnection" |
| 56 | #endif |
| 57 |
| 58 | using namespace tgvoip; |
| 59 | using namespace tgvoip::audio; |
| 60 |
| 61 | namespace tgvoip { |
| 62 | #pragma mark - Callbacks |
| 63 |
| 64 | void updateConnectionState(VoIPController *cntrlr, int state){ |
| 65 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 66 | jni::AttachAndCallVoidMethod(setStateMethod, impl->javaObject, state); |
| 67 | } |
| 68 |
| 69 | void updateSignalBarCount(VoIPController *cntrlr, int count){ |
| 70 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 71 | jni::AttachAndCallVoidMethod(setSignalBarsMethod, impl->javaObject, count); |
| 72 | } |
| 73 |
| 74 | void updateGroupCallStreams(VoIPGroupController *cntrlr, unsigned char *streams, size_t len){ |
| 75 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 76 | if(!impl->javaObject) |
| 77 | return; |
| 78 | jni::DoWithJNI([streams, len, &impl](JNIEnv* env){ |
| 79 | if(setSelfStreamsMethod){ |
| 80 | jbyteArray jstreams=env->NewByteArray(static_cast<jsize>(len)); |
| 81 | jbyte *el=env->GetByteArrayElements(jstreams, NULL); |
| 82 | memcpy(el, streams, len); |
| 83 | env->ReleaseByteArrayElements(jstreams, el, 0); |
| 84 | env->CallVoidMethod(impl->javaObject, setSelfStreamsMethod, jstreams); |
| 85 | } |
| 86 | }); |
| 87 | } |
| 88 |
| 89 | void groupCallKeyReceived(VoIPController *cntrlr, const unsigned char *key){ |
| 90 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 91 | if(!impl->javaObject) |
| 92 | return; |
| 93 | jni::DoWithJNI([key, &impl](JNIEnv* env){ |
| 94 | if(groupCallKeyReceivedMethod){ |
| 95 | jbyteArray jkey=env->NewByteArray(256); |
| 96 | jbyte *el=env->GetByteArrayElements(jkey, NULL); |
| 97 | memcpy(el, key, 256); |
| 98 | env->ReleaseByteArrayElements(jkey, el, 0); |
| 99 | env->CallVoidMethod(impl->javaObject, groupCallKeyReceivedMethod, jkey); |
| 100 | } |
| 101 | }); |
| 102 | } |
| 103 |
| 104 | void groupCallKeySent(VoIPController *cntrlr){ |
| 105 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 106 | jni::AttachAndCallVoidMethod(groupCallKeySentMethod, impl->javaObject); |
| 107 | } |
| 108 |
| 109 | void callUpgradeRequestReceived(VoIPController* cntrlr){ |
| 110 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 111 | jni::AttachAndCallVoidMethod(callUpgradeRequestReceivedMethod, impl->javaObject); |
| 112 | } |
| 113 |
| 114 | void updateParticipantAudioState(VoIPGroupController *cntrlr, int32_t userID, bool enabled){ |
| 115 | ImplDataAndroid *impl=(ImplDataAndroid *) cntrlr->implData; |
| 116 | jni::AttachAndCallVoidMethod(setParticipantAudioEnabledMethod, impl->javaObject, userID, enabled); |
| 117 | } |
| 118 |
| 119 | #pragma mark - VoIPController |
| 120 |
| 121 | uint32_t AndroidCodecToFOURCC(std::string mime){ |
| 122 | if(mime=="video/avc") |
| 123 | return CODEC_AVC; |
| 124 | else if(mime=="video/hevc") |
| 125 | return CODEC_HEVC; |
| 126 | else if(mime=="video/x-vnd.on2.vp8") |
| 127 | return CODEC_VP8; |
| 128 | else if(mime=="video/x-vnd.on2.vp9") |
| 129 | return CODEC_VP9; |
| 130 | return 0; |
| 131 | } |
| 132 |
| 133 | jlong VoIPController_nativeInit(JNIEnv* env, jobject thiz, jstring persistentStateFile) { |
| 134 | ImplDataAndroid* impl=new ImplDataAndroid(); |
| 135 | impl->javaObject=env->NewGlobalRef(thiz); |
| 136 | if(persistentStateFile){ |
| 137 | impl->persistentStateFile=jni::JavaStringToStdString(env, persistentStateFile); |
| 138 | } |
| 139 | VoIPController* cntrlr=new VoIPController(); |
| 140 | cntrlr->implData=impl; |
| 141 | VoIPController::Callbacks callbacks; |
| 142 | callbacks.connectionStateChanged=updateConnectionState; |
| 143 | callbacks.signalBarCountChanged=updateSignalBarCount; |
| 144 | callbacks.groupCallKeyReceived=groupCallKeyReceived; |
| 145 | callbacks.groupCallKeySent=groupCallKeySent; |
| 146 | callbacks.upgradeToGroupCallRequested=callUpgradeRequestReceived; |
| 147 | cntrlr->SetCallbacks(callbacks); |
| 148 | if(!impl->persistentStateFile.empty()){ |
| 149 | FILE* f=fopen(impl->persistentStateFile.c_str(), "r"); |
| 150 | if(f){ |
| 151 | fseek(f, 0, SEEK_END); |
| 152 | size_t len=static_cast<size_t>(ftell(f)); |
| 153 | fseek(f, 0, SEEK_SET); |
| 154 | if(len<1024*512 && len>0){ |
| 155 | char *fbuf=static_cast<char *>(malloc(len)); |
| 156 | fread(fbuf, 1, len, f); |
| 157 | std::vector<uint8_t> state(fbuf, fbuf+len); |
| 158 | free(fbuf); |
| 159 | cntrlr->SetPersistentState(state); |
| 160 | } |
| 161 | fclose(f); |
| 162 | } |
| 163 | } |
| 164 | /*if(video::VideoRendererAndroid::availableDecoders.empty() || video::VideoSourceAndroid::availableEncoders.empty()){ |
| 165 | video::VideoRendererAndroid::availableDecoders.clear(); |
| 166 | video::VideoSourceAndroid::availableEncoders.clear(); |
| 167 | jmethodID getCodecsMethod=env->GetStaticMethodID(jniUtilitiesClass, "getSupportedVideoCodecs", "()[[Ljava/lang/String;"); |
| 168 | jobjectArray codecs=static_cast<jobjectArray>(env->CallStaticObjectMethod(jniUtilitiesClass, getCodecsMethod)); |
| 169 | jobjectArray encoders=static_cast<jobjectArray>(env->GetObjectArrayElement(codecs, 0)); |
| 170 | jobjectArray decoders=static_cast<jobjectArray>(env->GetObjectArrayElement(codecs, 1)); |
| 171 | for(jsize i=0;i<env->GetArrayLength(encoders);i++){ |
| 172 | std::string codec=jni::JavaStringToStdString(env, static_cast<jstring>(env->GetObjectArrayElement(encoders, i))); |
| 173 | uint32_t id=AndroidCodecToFOURCC(codec); |
| 174 | if(id) |
| 175 | video::VideoSourceAndroid::availableEncoders.push_back(id); |
| 176 | } |
| 177 | for(jsize i=0;i<env->GetArrayLength(decoders);i++){ |
| 178 | std::string codec=jni::JavaStringToStdString(env, static_cast<jstring>(env->GetObjectArrayElement(decoders, i))); |
| 179 | uint32_t id=AndroidCodecToFOURCC(codec); |
| 180 | if(id) |
| 181 | video::VideoRendererAndroid::availableDecoders.push_back(id); |
| 182 | } |
| 183 | jmethodID getMaxResolutionMethod=env->GetStaticMethodID(jniUtilitiesClass, "getMaxVideoResolution", "()I"); |
| 184 | video::VideoRendererAndroid::maxResolution=env->CallStaticIntMethod(jniUtilitiesClass, getMaxResolutionMethod); |
| 185 | }*/ |
| 186 | return (jlong)(intptr_t)cntrlr; |
| 187 | } |
| 188 |
| 189 | void VoIPController_nativeStart(JNIEnv* env, jobject thiz, jlong inst){ |
| 190 | ((VoIPController*)(intptr_t)inst)->Start(); |
| 191 | } |
| 192 |
| 193 | void VoIPController_nativeConnect(JNIEnv* env, jobject thiz, jlong inst){ |
| 194 | ((VoIPController*)(intptr_t)inst)->Connect(); |
| 195 | } |
| 196 |
| 197 | void VoIPController_nativeSetProxy(JNIEnv* env, jobject thiz, jlong inst, jstring _address, jint port, jstring _username, jstring _password){ |
| 198 | ((VoIPController*)(intptr_t)inst)->SetProxy(PROXY_SOCKS5, jni::JavaStringToStdString(env, _address), (uint16_t)port, jni::JavaStringToStdString(env, _username), jni::JavaStringToStdString(env, _password)); |
| 199 | } |
| 200 |
| 201 | void VoIPController_nativeSetEncryptionKey(JNIEnv* env, jobject thiz, jlong inst, jbyteArray key, jboolean isOutgoing){ |
| 202 | jbyte* akey=env->GetByteArrayElements(key, NULL); |
| 203 | ((VoIPController*)(intptr_t)inst)->SetEncryptionKey((char *) akey, isOutgoing); |
| 204 | env->ReleaseByteArrayElements(key, akey, JNI_ABORT); |
| 205 | } |
| 206 |
| 207 | void VoIPController_nativeSetRemoteEndpoints(JNIEnv* env, jobject thiz, jlong inst, jobjectArray endpoints, jboolean allowP2p, jboolean tcp, jint connectionMaxLayer){ |
| 208 | size_t len=(size_t) env->GetArrayLength(endpoints); |
| 209 | std::vector<Endpoint> eps; |
| 210 | /*public String ip; |
| 211 | public String ipv6; |
| 212 | public int port; |
| 213 | public byte[] peer_tag;*/ |
| 214 | jclass epClass=env->GetObjectClass(env->GetObjectArrayElement(endpoints, 0)); |
| 215 | jfieldID ipFld=env->GetFieldID(epClass, "ip", "Ljava/lang/String;"); |
| 216 | jfieldID ipv6Fld=env->GetFieldID(epClass, "ipv6", "Ljava/lang/String;"); |
| 217 | jfieldID portFld=env->GetFieldID(epClass, "port", "I"); |
| 218 | jfieldID peerTagFld=env->GetFieldID(epClass, TGVOIP_PEER_TAG_VARIABLE_NAME, "[B"); |
| 219 | jfieldID idFld=env->GetFieldID(epClass, "id", "J"); |
| 220 | int i; |
| 221 | for(i=0;i<len;i++){ |
| 222 | jobject endpoint=env->GetObjectArrayElement(endpoints, i); |
| 223 | jstring ip=(jstring) env->GetObjectField(endpoint, ipFld); |
| 224 | jstring ipv6=(jstring) env->GetObjectField(endpoint, ipv6Fld); |
| 225 | jint port=env->GetIntField(endpoint, portFld); |
| 226 | jlong id=env->GetLongField(endpoint, idFld); |
| 227 | jbyteArray peerTag=(jbyteArray) env->GetObjectField(endpoint, peerTagFld); |
| 228 | IPv4Address v4addr(jni::JavaStringToStdString(env, ip)); |
| 229 | IPv6Address v6addr("::0"); |
| 230 | if(ipv6 && env->GetStringLength(ipv6)){ |
| 231 | v6addr=IPv6Address(jni::JavaStringToStdString(env, ipv6)); |
| 232 | } |
| 233 | unsigned char pTag[16]; |
| 234 | if(peerTag && env->GetArrayLength(peerTag)){ |
| 235 | jbyte* peerTagBytes=env->GetByteArrayElements(peerTag, NULL); |
| 236 | memcpy(pTag, peerTagBytes, 16); |
| 237 | env->ReleaseByteArrayElements(peerTag, peerTagBytes, JNI_ABORT); |
| 238 | } |
| 239 | eps.push_back(Endpoint((int64_t)id, (uint16_t)port, v4addr, v6addr, tcp ? Endpoint::Type::TCP_RELAY : Endpoint::Type::UDP_RELAY, pTag)); |
| 240 | } |
| 241 | ((VoIPController*)(intptr_t)inst)->SetRemoteEndpoints(eps, allowP2p, connectionMaxLayer); |
| 242 | } |
| 243 |
| 244 | void VoIPController_nativeSetNativeBufferSize(JNIEnv* env, jclass thiz, jint size){ |
| 245 | AudioOutputOpenSLES::nativeBufferSize=(unsigned int) size; |
| 246 | AudioInputOpenSLES::nativeBufferSize=(unsigned int) size; |
| 247 | } |
| 248 |
| 249 | void VoIPController_nativeRelease(JNIEnv* env, jobject thiz, jlong inst){ |
| 250 | //env->DeleteGlobalRef(AudioInputAndroid::jniClass); |
| 251 |
| 252 | VoIPController* ctlr=((VoIPController*)(intptr_t)inst); |
| 253 | ImplDataAndroid* impl=(ImplDataAndroid*)ctlr->implData; |
| 254 | ctlr->Stop(); |
| 255 | std::vector<uint8_t> state=ctlr->GetPersistentState(); |
| 256 | delete ctlr; |
| 257 | env->DeleteGlobalRef(impl->javaObject); |
| 258 | if(!impl->persistentStateFile.empty()){ |
| 259 | FILE* f=fopen(impl->persistentStateFile.c_str(), "w"); |
| 260 | if(f){ |
| 261 | fwrite(state.data(), 1, state.size(), f); |
| 262 | fclose(f); |
| 263 | } |
| 264 | } |
| 265 | delete impl; |
| 266 | } |
| 267 |
| 268 | jstring VoIPController_nativeGetDebugString(JNIEnv* env, jobject thiz, jlong inst){ |
| 269 | std::string str=((VoIPController*)(intptr_t)inst)->GetDebugString(); |
| 270 | return env->NewStringUTF(str.c_str()); |
| 271 | } |
| 272 |
| 273 | void VoIPController_nativeSetNetworkType(JNIEnv* env, jobject thiz, jlong inst, jint type){ |
| 274 | ((VoIPController*)(intptr_t)inst)->SetNetworkType(type); |
| 275 | } |
| 276 |
| 277 | void VoIPController_nativeSetMicMute(JNIEnv* env, jobject thiz, jlong inst, jboolean mute){ |
| 278 | ((VoIPController*)(intptr_t)inst)->SetMicMute(mute); |
| 279 | } |
| 280 |
| 281 | void VoIPController_nativeSetConfig(JNIEnv* env, jobject thiz, jlong inst, jdouble recvTimeout, jdouble initTimeout, jint dataSavingMode, jboolean enableAEC, jboolean enableNS, jboolean enableAGC, jstring logFilePath, jstring statsDumpPath, jboolean logPacketStats){ |
| 282 | VoIPController::Config cfg; |
| 283 | cfg.initTimeout=initTimeout; |
| 284 | cfg.recvTimeout=recvTimeout; |
| 285 | cfg.dataSaving=dataSavingMode; |
| 286 | cfg.enableAEC=enableAEC; |
| 287 | cfg.enableNS=enableNS; |
| 288 | cfg.enableAGC=enableAGC; |
| 289 | cfg.enableCallUpgrade=false; |
| 290 | cfg.logPacketStats=logPacketStats; |
| 291 | if(logFilePath){ |
| 292 | cfg.logFilePath=jni::JavaStringToStdString(env, logFilePath); |
| 293 | } |
| 294 | if(statsDumpPath){ |
| 295 | cfg.statsDumpFilePath=jni::JavaStringToStdString(env, statsDumpPath); |
| 296 | } |
| 297 |
| 298 | ((VoIPController*)(intptr_t)inst)->SetConfig(cfg); |
| 299 | } |
| 300 |
| 301 | void VoIPController_nativeDebugCtl(JNIEnv* env, jobject thiz, jlong inst, jint request, jint param){ |
| 302 | ((VoIPController*)(intptr_t)inst)->DebugCtl(request, param); |
| 303 | } |
| 304 |
| 305 | jstring VoIPController_nativeGetVersion(JNIEnv* env, jclass clasz){ |
| 306 | return env->NewStringUTF(VoIPController::GetVersion()); |
| 307 | } |
| 308 |
| 309 | jlong VoIPController_nativeGetPreferredRelayID(JNIEnv* env, jclass clasz, jlong inst){ |
| 310 | return ((VoIPController*)(intptr_t)inst)->GetPreferredRelayID(); |
| 311 | } |
| 312 |
| 313 | jint VoIPController_nativeGetLastError(JNIEnv* env, jclass clasz, jlong inst){ |
| 314 | return ((VoIPController*)(intptr_t)inst)->GetLastError(); |
| 315 | } |
| 316 |
| 317 | void VoIPController_nativeGetStats(JNIEnv* env, jclass clasz, jlong inst, jobject stats){ |
| 318 | VoIPController::TrafficStats _stats; |
| 319 | ((VoIPController*)(intptr_t)inst)->GetStats(&_stats); |
| 320 | jclass cls=env->GetObjectClass(stats); |
| 321 | env->SetLongField(stats, env->GetFieldID(cls, "bytesSentWifi", "J"), _stats.bytesSentWifi); |
| 322 | env->SetLongField(stats, env->GetFieldID(cls, "bytesSentMobile", "J"), _stats.bytesSentMobile); |
| 323 | env->SetLongField(stats, env->GetFieldID(cls, "bytesRecvdWifi", "J"), _stats.bytesRecvdWifi); |
| 324 | env->SetLongField(stats, env->GetFieldID(cls, "bytesRecvdMobile", "J"), _stats.bytesRecvdMobile); |
| 325 | } |
| 326 |
| 327 | jstring VoIPController_nativeGetDebugLog(JNIEnv* env, jobject thiz, jlong inst){ |
| 328 | VoIPController* ctlr=((VoIPController*)(intptr_t)inst); |
| 329 | std::string log=ctlr->GetDebugLog(); |
| 330 | return env->NewStringUTF(log.c_str()); |
| 331 | } |
| 332 |
| 333 | void VoIPController_nativeSetAudioOutputGainControlEnabled(JNIEnv* env, jclass clasz, jlong inst, jboolean enabled){ |
| 334 | ((VoIPController*)(intptr_t)inst)->SetAudioOutputGainControlEnabled(enabled); |
| 335 | } |
| 336 |
| 337 | void VoIPController_nativeSetEchoCancellationStrength(JNIEnv* env, jclass cls, jlong inst, jint strength){ |
| 338 | ((VoIPController*)(intptr_t)inst)->SetEchoCancellationStrength(strength); |
| 339 | } |
| 340 |
| 341 | jint VoIPController_nativeGetPeerCapabilities(JNIEnv* env, jclass cls, jlong inst){ |
| 342 | return ((VoIPController*)(intptr_t)inst)->GetPeerCapabilities(); |
| 343 | } |
| 344 |
| 345 | void VoIPController_nativeSendGroupCallKey(JNIEnv* env, jclass cls, jlong inst, jbyteArray _key){ |
| 346 | jbyte* key=env->GetByteArrayElements(_key, NULL); |
| 347 | ((VoIPController*)(intptr_t)inst)->SendGroupCallKey((unsigned char *) key); |
| 348 | env->ReleaseByteArrayElements(_key, key, JNI_ABORT); |
| 349 | } |
| 350 |
| 351 | void VoIPController_nativeRequestCallUpgrade(JNIEnv* env, jclass cls, jlong inst){ |
| 352 | ((VoIPController*)(intptr_t)inst)->RequestCallUpgrade(); |
| 353 | } |
| 354 |
| 355 | void VoIPController_nativeSetVideoSource(JNIEnv* env, jobject thiz, jlong inst, jlong source){ |
| 356 | ((VoIPController*)(intptr_t)inst)->SetVideoSource((video::VideoSource*)(intptr_t)source); |
| 357 | } |
| 358 |
| 359 | void VoIPController_nativeSetVideoRenderer(JNIEnv* env, jobject thiz, jlong inst, jlong renderer){ |
| 360 | ((VoIPController*)(intptr_t)inst)->SetVideoRenderer((video::VideoRenderer*)(intptr_t)renderer); |
| 361 | } |
| 362 |
| 363 | jboolean VoIPController_nativeNeedRate(JNIEnv* env, jclass cls, jlong inst){ |
| 364 | return static_cast<jboolean>(((VoIPController*)(intptr_t)inst)->NeedRate()); |
| 365 | } |
| 366 |
| 367 | jint VoIPController_getConnectionMaxLayer(JNIEnv* env, jclass cls){ |
| 368 | return VoIPController::GetConnectionMaxLayer(); |
| 369 | } |
| 370 |
| 371 | #pragma mark - AudioRecordJNI |
| 372 |
| 373 | void AudioRecordJNI_nativeCallback(JNIEnv* env, jobject thiz, jobject buffer){ |
| 374 | jlong inst=env->GetLongField(thiz, audioRecordInstanceFld); |
| 375 | AudioInputAndroid* in=(AudioInputAndroid*)(intptr_t)inst; |
| 376 | in->HandleCallback(env, buffer); |
| 377 | } |
| 378 |
| 379 | #pragma mark - AudioTrackJNI |
| 380 |
| 381 | void AudioTrackJNI_nativeCallback(JNIEnv* env, jobject thiz, jbyteArray buffer){ |
| 382 | jlong inst=env->GetLongField(thiz, audioTrackInstanceFld); |
| 383 | AudioOutputAndroid* in=(AudioOutputAndroid*)(intptr_t)inst; |
| 384 | in->HandleCallback(env, buffer); |
| 385 | } |
| 386 |
| 387 | #pragma mark - VoIPServerConfig |
| 388 |
| 389 | void VoIPServerConfig_nativeSetConfig(JNIEnv* env, jclass clasz, jstring jsonString){ |
| 390 | ServerConfig::GetSharedInstance()->Update(jni::JavaStringToStdString(env, jsonString)); |
| 391 | } |
| 392 |
| 393 | #pragma mark - Resampler |
| 394 |
| 395 | jint Resampler_convert44to48(JNIEnv* env, jclass cls, jobject from, jobject to){ |
| 396 | return (jint)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)); |
| 397 | } |
| 398 |
| 399 | jint Resampler_convert48to44(JNIEnv* env, jclass cls, jobject from, jobject to){ |
| 400 | 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)); |
| 401 | } |
| 402 |
| 403 | #pragma mark - VoIPGroupController |
| 404 |
| 405 | #ifndef TGVOIP_NO_GROUP_CALLS |
| 406 | jlong VoIPGroupController_nativeInit(JNIEnv* env, jobject thiz, jint timeDifference){ |
| 407 | ImplDataAndroid* impl=(ImplDataAndroid*) malloc(sizeof(ImplDataAndroid)); |
| 408 | impl->javaObject=env->NewGlobalRef(thiz); |
| 409 | VoIPGroupController* cntrlr=new VoIPGroupController(timeDifference); |
| 410 | cntrlr->implData=impl; |
| 411 |
| 412 | VoIPGroupController::Callbacks callbacks; |
| 413 | callbacks.connectionStateChanged=updateConnectionState; |
| 414 | callbacks.updateStreams=updateGroupCallStreams; |
| 415 | callbacks.participantAudioStateChanged=updateParticipantAudioState; |
| 416 | callbacks.signalBarCountChanged=NULL; |
| 417 | cntrlr->SetCallbacks(callbacks); |
| 418 |
| 419 | return (jlong)(intptr_t)cntrlr; |
| 420 | } |
| 421 |
| 422 | void VoIPGroupController_nativeSetGroupCallInfo(JNIEnv* env, jclass cls, jlong inst, jbyteArray _encryptionKey, jbyteArray _reflectorGroupTag, jbyteArray _reflectorSelfTag, jbyteArray _reflectorSelfSecret, jbyteArray _reflectorSelfTagHash, jint selfUserID, jstring reflectorAddress, jstring reflectorAddressV6, jint reflectorPort){ |
| 423 | VoIPGroupController* ctlr=((VoIPGroupController*)(intptr_t)inst); |
| 424 | jbyte* encryptionKey=env->GetByteArrayElements(_encryptionKey, NULL); |
| 425 | jbyte* reflectorGroupTag=env->GetByteArrayElements(_reflectorGroupTag, NULL); |
| 426 | jbyte* reflectorSelfTag=env->GetByteArrayElements(_reflectorSelfTag, NULL); |
| 427 | jbyte* reflectorSelfSecret=env->GetByteArrayElements(_reflectorSelfSecret, NULL); |
| 428 | jbyte* reflectorSelfTagHash=env->GetByteArrayElements(_reflectorSelfTagHash, NULL); |
| 429 |
| 430 |
| 431 | const char* ipChars=env->GetStringUTFChars(reflectorAddress, NULL); |
| 432 | std::string ipLiteral(ipChars); |
| 433 | IPv4Address v4addr(ipLiteral); |
| 434 | IPv6Address v6addr("::0"); |
| 435 | env->ReleaseStringUTFChars(reflectorAddress, ipChars); |
| 436 | if(reflectorAddressV6 && env->GetStringLength(reflectorAddressV6)){ |
| 437 | const char* ipv6Chars=env->GetStringUTFChars(reflectorAddressV6, NULL); |
| 438 | v6addr=IPv6Address(ipv6Chars); |
| 439 | env->ReleaseStringUTFChars(reflectorAddressV6, ipv6Chars); |
| 440 | } |
| 441 | ctlr->SetGroupCallInfo((unsigned char *) encryptionKey, (unsigned char *) reflectorGroupTag, (unsigned char *) reflectorSelfTag, (unsigned char *) reflectorSelfSecret, (unsigned char*) reflectorSelfTagHash, selfUserID, v4addr, v6addr, (uint16_t)reflectorPort); |
| 442 |
| 443 | env->ReleaseByteArrayElements(_encryptionKey, encryptionKey, JNI_ABORT); |
| 444 | env->ReleaseByteArrayElements(_reflectorGroupTag, reflectorGroupTag, JNI_ABORT); |
| 445 | env->ReleaseByteArrayElements(_reflectorSelfTag, reflectorSelfTag, JNI_ABORT); |
| 446 | env->ReleaseByteArrayElements(_reflectorSelfSecret, reflectorSelfSecret, JNI_ABORT); |
| 447 | env->ReleaseByteArrayElements(_reflectorSelfTagHash, reflectorSelfTagHash, JNI_ABORT); |
| 448 | } |
| 449 |
| 450 | void VoIPGroupController_nativeAddGroupCallParticipant(JNIEnv* env, jclass cls, jlong inst, jint userID, jbyteArray _memberTagHash, jbyteArray _streams){ |
| 451 | VoIPGroupController* ctlr=((VoIPGroupController*)(intptr_t)inst); |
| 452 | jbyte* memberTagHash=env->GetByteArrayElements(_memberTagHash, NULL); |
| 453 | jbyte* streams=_streams ? env->GetByteArrayElements(_streams, NULL) : NULL; |
| 454 |
| 455 | ctlr->AddGroupCallParticipant(userID, (unsigned char *) memberTagHash, (unsigned char *) streams, (size_t) env->GetArrayLength(_streams)); |
| 456 |
| 457 | env->ReleaseByteArrayElements(_memberTagHash, memberTagHash, JNI_ABORT); |
| 458 | if(_streams) |
| 459 | env->ReleaseByteArrayElements(_streams, streams, JNI_ABORT); |
| 460 |
| 461 | } |
| 462 |
| 463 | void VoIPGroupController_nativeRemoveGroupCallParticipant(JNIEnv* env, jclass cls, jlong inst, jint userID){ |
| 464 | VoIPGroupController* ctlr=((VoIPGroupController*)(intptr_t)inst); |
| 465 | ctlr->RemoveGroupCallParticipant(userID); |
| 466 | } |
| 467 |
| 468 | jfloat VoIPGroupController_nativeGetParticipantAudioLevel(JNIEnv* env, jclass cls, jlong inst, jint userID){ |
| 469 | return ((VoIPGroupController*)(intptr_t)inst)->GetParticipantAudioLevel(userID); |
| 470 | } |
| 471 |
| 472 | void VoIPGroupController_nativeSetParticipantVolume(JNIEnv* env, jclass cls, jlong inst, jint userID, jfloat volume){ |
| 473 | ((VoIPGroupController*)(intptr_t)inst)->SetParticipantVolume(userID, volume); |
| 474 | } |
| 475 |
| 476 | jbyteArray VoIPGroupController_getInitialStreams(JNIEnv* env, jclass cls){ |
| 477 | unsigned char buf[1024]; |
| 478 | size_t len=VoIPGroupController::GetInitialStreams(buf, sizeof(buf)); |
| 479 | jbyteArray arr=env->NewByteArray(len); |
| 480 | jbyte* arrElems=env->GetByteArrayElements(arr, NULL); |
| 481 | memcpy(arrElems, buf, len); |
| 482 | env->ReleaseByteArrayElements(arr, arrElems, 0); |
| 483 | return arr; |
| 484 | } |
| 485 |
| 486 | void VoIPGroupController_nativeSetParticipantStreams(JNIEnv* env, jclass cls, jlong inst, jint userID, jbyteArray _streams){ |
| 487 | jbyte* streams=env->GetByteArrayElements(_streams, NULL); |
| 488 |
| 489 | ((VoIPGroupController*)(intptr_t)inst)->SetParticipantStreams(userID, (unsigned char *) streams, (size_t) env->GetArrayLength(_streams)); |
| 490 |
| 491 | env->ReleaseByteArrayElements(_streams, streams, JNI_ABORT); |
| 492 | } |
| 493 | #endif |
| 494 |
| 495 | #pragma mark - VideoSource |
| 496 |
| 497 | jlong VideoSource_nativeInit(JNIEnv* env, jobject thiz){ |
| 498 | return (jlong)(intptr_t)new video::VideoSourceAndroid(env->NewGlobalRef(thiz)); |
| 499 | } |
| 500 |
| 501 | void VideoSource_nativeRelease(JNIEnv* env, jobject thiz, jlong inst){ |
| 502 | delete (video::VideoSource*)(intptr_t)inst; |
| 503 | } |
| 504 |
| 505 | void VideoSource_nativeSetVideoStreamParameters(JNIEnv* env, jobject thiz, jlong inst, jobjectArray _csd, jint width, jint height){ |
| 506 | std::vector<Buffer> csd; |
| 507 | if(_csd){ |
| 508 | for(int i=0; i<env->GetArrayLength(_csd); i++){ |
| 509 | jobject _buf=env->GetObjectArrayElement(_csd, i); |
| 510 | size_t len=static_cast<size_t>(env->GetDirectBufferCapacity(_buf)); |
| 511 | Buffer buf(len); |
| 512 | buf.CopyFrom(env->GetDirectBufferAddress(_buf), 0, len); |
| 513 | csd.push_back(std::move(buf)); |
| 514 | } |
| 515 | } |
| 516 | ((video::VideoSourceAndroid*)(intptr_t)inst)->SetStreamParameters(std::move(csd), width, height); |
| 517 | } |
| 518 |
| 519 | void VideoSource_nativeSendFrame(JNIEnv* env, jobject thiz, jlong inst, jobject buffer, jint offset, jint length, jint flags){ |
| 520 | size_t bufsize=(size_t)env->GetDirectBufferCapacity(buffer); |
| 521 | Buffer buf(static_cast<size_t>(length)); |
| 522 | buf.CopyFrom(((char*)env->GetDirectBufferAddress(buffer))+offset, 0, static_cast<size_t>(length)); |
| 523 | ((video::VideoSourceAndroid*)(intptr_t)inst)->SendFrame(std::move(buf), static_cast<uint32_t>(flags)); |
| 524 | } |
| 525 |
| 526 | void VideoSource_nativeSetRotation(JNIEnv* env, jobject thiz, jlong inst, jint rotation){ |
| 527 | ((video::VideoSourceAndroid*)(intptr_t)inst)->SetRotation((unsigned int)rotation); |
| 528 | } |
| 529 |
| 530 | #pragma mark - VideoRenderer |
| 531 |
| 532 | jlong VideoRenderer_nativeInit(JNIEnv* env, jobject thiz){ |
| 533 | return (jlong)(intptr_t)new video::VideoRendererAndroid(env->NewGlobalRef(thiz)); |
| 534 | } |
| 535 |
| 536 | #pragma mark - VLog |
| 537 |
| 538 | template<int level> void VLog_log(JNIEnv* env, jclass cls, jstring jmsg){ |
| 539 | const char* format="[java] %s"; |
| 540 | std::string msg=jni::JavaStringToStdString(env, jmsg); |
| 541 | switch(level){ |
| 542 | case 0: |
| 543 | LOGV(format, msg.c_str()); |
| 544 | break; |
| 545 | case 1: |
| 546 | LOGD(format, msg.c_str()); |
| 547 | break; |
| 548 | case 2: |
| 549 | LOGI(format, msg.c_str()); |
| 550 | break; |
| 551 | case 3: |
| 552 | LOGW(format, msg.c_str()); |
| 553 | break; |
| 554 | case 4: |
| 555 | LOGE(format, msg.c_str()); |
| 556 | break; |
| 557 | default: |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 |
| 563 | extern "C" void tgvoipRegisterNatives(JNIEnv* env){ |
| 564 | jclass controller=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPController"); |
| 565 | jclass groupController=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPGroupController"); |
| 566 | if(env->ExceptionCheck()){ |
| 567 | env->ExceptionClear(); // is returning NULL from FindClass not enough? |
| 568 | } |
| 569 | jclass audioRecordJNI=env->FindClass(TGVOIP_PACKAGE_PATH "/AudioRecordJNI"); |
| 570 | jclass audioTrackJNI=env->FindClass(TGVOIP_PACKAGE_PATH "/AudioTrackJNI"); |
| 571 | jclass serverConfig=env->FindClass(TGVOIP_PACKAGE_PATH "/VoIPServerConfig"); |
| 572 | jclass resampler=env->FindClass(TGVOIP_PACKAGE_PATH "/Resampler"); |
| 573 | jclass videoSource=env->FindClass(TGVOIP_PACKAGE_PATH "/VideoSource"); |
| 574 | if(env->ExceptionCheck()){ |
| 575 | env->ExceptionClear(); // is returning NULL from FindClass not enough? |
| 576 | } |
| 577 | jclass videoRenderer=env->FindClass(TGVOIP_PACKAGE_PATH "/VideoRenderer"); |
| 578 | if(env->ExceptionCheck()){ |
| 579 | env->ExceptionClear(); // is returning NULL from FindClass not enough? |
| 580 | } |
| 581 | jclass vlog=env->FindClass(TGVOIP_PACKAGE_PATH "/VLog"); |
| 582 | if(env->ExceptionCheck()){ |
| 583 | env->ExceptionClear(); |
| 584 | } |
| 585 | assert(controller && audioRecordJNI && audioTrackJNI && serverConfig && resampler); |
| 586 |
| 587 | audioRecordInstanceFld=env->GetFieldID(audioRecordJNI, "nativeInst", "J"); |
| 588 | audioTrackInstanceFld=env->GetFieldID(audioTrackJNI, "nativeInst", "J"); |
| 589 |
| 590 | env->GetJavaVM(&sharedJVM); |
| 591 | if(!AudioInputAndroid::jniClass){ |
| 592 | jclass cls=env->FindClass(TGVOIP_PACKAGE_PATH "/AudioRecordJNI"); |
| 593 | AudioInputAndroid::jniClass=(jclass) env->NewGlobalRef(cls); |
| 594 | AudioInputAndroid::initMethod=env->GetMethodID(cls, "init", "(IIII)V"); |
| 595 | AudioInputAndroid::releaseMethod=env->GetMethodID(cls, "release", "()V"); |
| 596 | AudioInputAndroid::startMethod=env->GetMethodID(cls, "start", "()Z"); |
| 597 | AudioInputAndroid::stopMethod=env->GetMethodID(cls, "stop", "()V"); |
| 598 | AudioInputAndroid::getEnabledEffectsMaskMethod=env->GetMethodID(cls, "getEnabledEffectsMask", "()I"); |
| 599 |
| 600 | cls=env->FindClass(TGVOIP_PACKAGE_PATH "/AudioTrackJNI"); |
| 601 | AudioOutputAndroid::jniClass=(jclass) env->NewGlobalRef(cls); |
| 602 | AudioOutputAndroid::initMethod=env->GetMethodID(cls, "init", "(IIII)V"); |
| 603 | AudioOutputAndroid::releaseMethod=env->GetMethodID(cls, "release", "()V"); |
| 604 | AudioOutputAndroid::startMethod=env->GetMethodID(cls, "start", "()V"); |
| 605 | AudioOutputAndroid::stopMethod=env->GetMethodID(cls, "stop", "()V"); |
| 606 |
| 607 | if(videoRenderer){ |
| 608 | video::VideoRendererAndroid::decodeAndDisplayMethod=env->GetMethodID(videoRenderer, "decodeAndDisplay", "(Ljava/nio/ByteBuffer;IJ)V"); |
| 609 | video::VideoRendererAndroid::resetMethod=env->GetMethodID(videoRenderer, "reset", "(Ljava/lang/String;II[[B)V"); |
| 610 | video::VideoRendererAndroid::setStreamEnabledMethod=env->GetMethodID(videoRenderer, "setStreamEnabled", "(Z)V"); |
| 611 | video::VideoRendererAndroid::setRotationMethod=env->GetMethodID(videoRenderer, "setRotation", "(I)V"); |
| 612 | } |
| 613 | } |
| 614 |
| 615 | setStateMethod=env->GetMethodID(controller, "handleStateChange", "(I)V"); |
| 616 | setSignalBarsMethod=env->GetMethodID(controller, "handleSignalBarsChange", "(I)V"); |
| 617 | groupCallKeyReceivedMethod=env->GetMethodID(controller, "groupCallKeyReceived", "([B)V"); |
| 618 | groupCallKeySentMethod=env->GetMethodID(controller, "groupCallKeySent", "()V"); |
| 619 | callUpgradeRequestReceivedMethod=env->GetMethodID(controller, "callUpgradeRequestReceived", "()V"); |
| 620 |
| 621 | if(!jniUtilitiesClass) |
| 622 | jniUtilitiesClass=(jclass) env->NewGlobalRef(env->FindClass(TGVOIP_PACKAGE_PATH "/JNIUtilities")); |
| 623 |
| 624 | // VoIPController |
| 625 | JNINativeMethod controllerMethods[]={ |
| 626 | {"nativeInit", "(Ljava/lang/String;)J", (void*)&tgvoip::VoIPController_nativeInit}, |
| 627 | {"nativeStart", "(J)V", (void*)&tgvoip::VoIPController_nativeStart}, |
| 628 | {"nativeConnect", "(J)V", (void*)&tgvoip::VoIPController_nativeConnect}, |
| 629 | {"nativeSetProxy", "(JLjava/lang/String;ILjava/lang/String;Ljava/lang/String;)V", (void*)&tgvoip::VoIPController_nativeSetProxy}, |
| 630 | {"nativeSetEncryptionKey", "(J[BZ)V", (void*)&tgvoip::VoIPController_nativeSetEncryptionKey}, |
| 631 | {"nativeSetRemoteEndpoints", "(J[L" TGVOIP_ENDPOINT_CLASS ";ZZI)V", (void*)&tgvoip::VoIPController_nativeSetRemoteEndpoints}, |
| 632 | {"nativeSetNativeBufferSize", "(I)V", (void*)&tgvoip::VoIPController_nativeSetNativeBufferSize}, |
| 633 | {"nativeRelease", "(J)V", (void*)&tgvoip::VoIPController_nativeRelease}, |
| 634 | {"nativeGetDebugString", "(J)Ljava/lang/String;", (void*)&tgvoip::VoIPController_nativeGetDebugString}, |
| 635 | {"nativeSetNetworkType", "(JI)V", (void*)&tgvoip::VoIPController_nativeSetNetworkType}, |
| 636 | {"nativeSetMicMute", "(JZ)V", (void*)&tgvoip::VoIPController_nativeSetMicMute}, |
| 637 | {"nativeSetConfig", "(JDDIZZZLjava/lang/String;Ljava/lang/String;Z)V", (void*)&tgvoip::VoIPController_nativeSetConfig}, |
| 638 | {"nativeDebugCtl", "(JII)V", (void*)&tgvoip::VoIPController_nativeDebugCtl}, |
| 639 | {"nativeGetVersion", "()Ljava/lang/String;", (void*)&tgvoip::VoIPController_nativeGetVersion}, |
| 640 | {"nativeGetPreferredRelayID", "(J)J", (void*)&tgvoip::VoIPController_nativeGetPreferredRelayID}, |
| 641 | {"nativeGetLastError", "(J)I", (void*)&tgvoip::VoIPController_nativeGetLastError}, |
| 642 | {"nativeGetStats", "(JL" TGVOIP_PACKAGE_PATH "/VoIPController$Stats;)V", (void*)&tgvoip::VoIPController_nativeGetStats}, |
| 643 | {"nativeGetDebugLog", "(J)Ljava/lang/String;", (void*)&tgvoip::VoIPController_nativeGetDebugLog}, |
| 644 | {"nativeSetAudioOutputGainControlEnabled", "(JZ)V", (void*)&tgvoip::VoIPController_nativeSetAudioOutputGainControlEnabled}, |
| 645 | {"nativeSetEchoCancellationStrength", "(JI)V", (void*)&tgvoip::VoIPController_nativeSetEchoCancellationStrength}, |
| 646 | {"nativeGetPeerCapabilities", "(J)I", (void*)&tgvoip::VoIPController_nativeGetPeerCapabilities}, |
| 647 | {"nativeSendGroupCallKey", "(J[B)V", (void*)&tgvoip::VoIPController_nativeSendGroupCallKey}, |
| 648 | {"nativeRequestCallUpgrade", "(J)V", (void*)&tgvoip::VoIPController_nativeRequestCallUpgrade}, |
| 649 | {"nativeNeedRate", "(J)Z", (void*)&tgvoip::VoIPController_nativeNeedRate}, |
| 650 | {"getConnectionMaxLayer", "()I", (void*)&tgvoip::VoIPController_getConnectionMaxLayer}, |
| 651 | {"nativeSetVideoSource", "(JJ)V", (void*)&tgvoip::VoIPController_nativeSetVideoSource}, |
| 652 | {"nativeSetVideoRenderer", "(JJ)V", (void*)&tgvoip::VoIPController_nativeSetVideoRenderer} |
| 653 | }; |
| 654 | env->RegisterNatives(controller, controllerMethods, sizeof(controllerMethods)/sizeof(JNINativeMethod)); |
| 655 |
| 656 | // VoIPGroupController |
| 657 | #ifndef TGVOIP_NO_GROUP_CALLS |
| 658 | if(groupController){ |
| 659 | setStateMethod=env->GetMethodID(groupController, "handleStateChange", "(I)V"); |
| 660 | setParticipantAudioEnabledMethod=env->GetMethodID(groupController, "setParticipantAudioEnabled", "(IZ)V"); |
| 661 | setSelfStreamsMethod=env->GetMethodID(groupController, "setSelfStreams", "([B)V"); |
| 662 |
| 663 | JNINativeMethod groupControllerMethods[]={ |
| 664 | {"nativeInit", "(I)J", (void*)&tgvoip::VoIPGroupController_nativeInit}, |
| 665 | {"nativeSetGroupCallInfo", "(J[B[B[B[B[BILjava/lang/String;Ljava/lang/String;I)V", (void*)&tgvoip::VoIPGroupController_nativeSetGroupCallInfo}, |
| 666 | {"nativeAddGroupCallParticipant", "(JI[B[B)V", (void*)&tgvoip::VoIPGroupController_nativeAddGroupCallParticipant}, |
| 667 | {"nativeRemoveGroupCallParticipant", "(JI)V", (void*)&tgvoip::VoIPGroupController_nativeRemoveGroupCallParticipant}, |
| 668 | {"nativeGetParticipantAudioLevel", "(JI)F", (void*)&tgvoip::VoIPGroupController_nativeGetParticipantAudioLevel}, |
| 669 | {"nativeSetParticipantVolume", "(JIF)V", (void*)&tgvoip::VoIPGroupController_nativeSetParticipantVolume}, |
| 670 | {"getInitialStreams", "()[B", (void*)&tgvoip::VoIPGroupController_getInitialStreams}, |
| 671 | {"nativeSetParticipantStreams", "(JI[B)V", (void*)&tgvoip::VoIPGroupController_nativeSetParticipantStreams} |
| 672 | }; |
| 673 | env->RegisterNatives(groupController, groupControllerMethods, sizeof(groupControllerMethods)/sizeof(JNINativeMethod)); |
| 674 | } |
| 675 | #endif |
| 676 |
| 677 | // AudioRecordJNI |
| 678 | JNINativeMethod audioRecordMethods[]={ |
| 679 | {"nativeCallback", "(Ljava/nio/ByteBuffer;)V", (void*)&tgvoip::AudioRecordJNI_nativeCallback} |
| 680 | }; |
| 681 | env->RegisterNatives(audioRecordJNI, audioRecordMethods, sizeof(audioRecordMethods)/sizeof(JNINativeMethod)); |
| 682 |
| 683 | // AudioTrackJNI |
| 684 | JNINativeMethod audioTrackMethods[]={ |
| 685 | {"nativeCallback", "([B)V", (void*)&tgvoip::AudioTrackJNI_nativeCallback} |
| 686 | }; |
| 687 | env->RegisterNatives(audioTrackJNI, audioTrackMethods, sizeof(audioTrackMethods)/sizeof(JNINativeMethod)); |
| 688 |
| 689 | // VoIPServerConfig |
| 690 | JNINativeMethod serverConfigMethods[]={ |
| 691 | {"nativeSetConfig", "(Ljava/lang/String;)V", (void*)&tgvoip::VoIPServerConfig_nativeSetConfig} |
| 692 | }; |
| 693 | env->RegisterNatives(serverConfig, serverConfigMethods, sizeof(serverConfigMethods)/sizeof(JNINativeMethod)); |
| 694 |
| 695 | // Resampler |
| 696 | JNINativeMethod resamplerMethods[]={ |
| 697 | {"convert44to48", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)I", (void*)&tgvoip::Resampler_convert44to48}, |
| 698 | {"convert48to44", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)I", (void*)&tgvoip::Resampler_convert48to44} |
| 699 | }; |
| 700 | env->RegisterNatives(resampler, resamplerMethods, sizeof(resamplerMethods)/sizeof(JNINativeMethod)); |
| 701 |
| 702 | if(videoSource){ |
| 703 | // VideoSource |
| 704 | JNINativeMethod videoSourceMethods[]={ |
| 705 | {"nativeInit", "()J", (void *) &tgvoip::VideoSource_nativeInit}, |
| 706 | {"nativeRelease", "(J)V", (void *) &tgvoip::VideoSource_nativeRelease}, |
| 707 | {"nativeSetVideoStreamParameters", "(J[Ljava/nio/ByteBuffer;II)V", (void *) &tgvoip::VideoSource_nativeSetVideoStreamParameters}, |
| 708 | {"nativeSendFrame", "(JLjava/nio/ByteBuffer;III)V", (void *) &tgvoip::VideoSource_nativeSendFrame}, |
| 709 | {"nativeSetRotation", "(JI)V", (void*)&tgvoip::VideoSource_nativeSetRotation} |
| 710 | }; |
| 711 | env->RegisterNatives(videoSource, videoSourceMethods, sizeof(videoSourceMethods)/sizeof(JNINativeMethod)); |
| 712 | } |
| 713 |
| 714 | if(videoRenderer){ |
| 715 | // VideoRenderer |
| 716 | JNINativeMethod videoRendererMethods[]={ |
| 717 | {"nativeInit", "()J", (void *) &tgvoip::VideoRenderer_nativeInit} |
| 718 | }; |
| 719 | env->RegisterNatives(videoRenderer, videoRendererMethods, sizeof(videoRendererMethods)/sizeof(JNINativeMethod)); |
| 720 | } |
| 721 |
| 722 | if(vlog){ |
| 723 | // VLog |
| 724 | JNINativeMethod vlogMethods[]={ |
| 725 | {"v", "(Ljava/lang/String;)V", (void *) &tgvoip::VLog_log<0>}, |
| 726 | {"d", "(Ljava/lang/String;)V", (void *) &tgvoip::VLog_log<1>}, |
| 727 | {"i", "(Ljava/lang/String;)V", (void *) &tgvoip::VLog_log<2>}, |
| 728 | {"w", "(Ljava/lang/String;)V", (void *) &tgvoip::VLog_log<3>}, |
| 729 | {"e", "(Ljava/lang/String;)V", (void *) &tgvoip::VLog_log<4>} |
| 730 | }; |
| 731 | env->RegisterNatives(vlog, vlogMethods, sizeof(vlogMethods)/sizeof(JNINativeMethod)); |
| 732 | } |
| 733 | } |
| 734 |