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