Add Java bindings to STUN code in moonlight-common-c

This commit is contained in:
Cameron Gutman 2018-10-26 23:15:06 -07:00
parent 16c4b2532d
commit c9cf485025
5 changed files with 35 additions and 1 deletions

View File

@ -347,4 +347,8 @@ public class NvConnection {
MoonBridge.sendMouseScroll(scrollClicks); MoonBridge.sendMouseScroll(scrollClicks);
} }
} }
public static String findExternalAddressForMdns() {
return MoonBridge.findExternalAddressIP4("stun.stunprotocol.org", 3478);
}
} }

View File

@ -203,5 +203,7 @@ public class MoonBridge {
public static native String getStageName(int stage); public static native String getStageName(int stage);
public static native String findExternalAddressIP4(String stunHostName, int stunPort);
public static native void init(); public static native void init();
} }

View File

@ -23,6 +23,7 @@ LOCAL_SRC_FILES := moonlight-common-c/src/AudioStream.c \
moonlight-common-c/src/RtspConnection.c \ moonlight-common-c/src/RtspConnection.c \
moonlight-common-c/src/RtspParser.c \ moonlight-common-c/src/RtspParser.c \
moonlight-common-c/src/SdpGenerator.c \ moonlight-common-c/src/SdpGenerator.c \
moonlight-common-c/src/SimpleStun.c \
moonlight-common-c/src/VideoDepacketizer.c \ moonlight-common-c/src/VideoDepacketizer.c \
moonlight-common-c/src/VideoStream.c \ moonlight-common-c/src/VideoStream.c \
moonlight-common-c/reedsolomon/rs.c \ moonlight-common-c/reedsolomon/rs.c \

@ -1 +1 @@
Subproject commit 558ba488e8eb7a614b6d9a93968c7c69683f942d Subproject commit 0eed722635f411ebfef662501e35733f6fb24e0c

View File

@ -1,6 +1,9 @@
#include <Limelight.h> #include <Limelight.h>
#include <jni.h> #include <jni.h>
#include <android/log.h>
#include <arpa/inet.h>
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_limelight_nvstream_jni_MoonBridge_sendMouseMove(JNIEnv *env, jclass clazz, jshort deltaX, jshort deltaY) { Java_com_limelight_nvstream_jni_MoonBridge_sendMouseMove(JNIEnv *env, jclass clazz, jshort deltaX, jshort deltaY) {
@ -53,4 +56,28 @@ Java_com_limelight_nvstream_jni_MoonBridge_interruptConnection(JNIEnv *env, jcla
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_com_limelight_nvstream_jni_MoonBridge_getStageName(JNIEnv *env, jclass clazz, jint stage) { Java_com_limelight_nvstream_jni_MoonBridge_getStageName(JNIEnv *env, jclass clazz, jint stage) {
return (*env)->NewStringUTF(env, LiGetStageName(stage)); return (*env)->NewStringUTF(env, LiGetStageName(stage));
}
JNIEXPORT jstring JNICALL
Java_com_limelight_nvstream_jni_MoonBridge_findExternalAddressIP4(JNIEnv *env, jclass clazz, jstring stunHostName, jint stunPort) {
int err;
struct in_addr wanAddr;
const char* stunHostNameStr = (*env)->GetStringUTFChars(env, stunHostName, NULL);
err = LiFindExternalAddressIP4(stunHostNameStr, stunPort, &wanAddr.s_addr);
(*env)->ReleaseStringUTFChars(env, stunHostName, stunHostNameStr);
if (err == 0) {
char addrStr[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &wanAddr, addrStr, sizeof(addrStr));
__android_log_print(ANDROID_LOG_INFO, "moonlight-common-c", "Resolved WAN address to %s", addrStr);
return (*env)->NewStringUTF(env, addrStr);
}
else {
__android_log_print(ANDROID_LOG_ERROR, "moonlight-common-c", "STUN failed to get WAN address: %d", err);
return NULL;
}
} }