Added better way to check for H264 support

* Added a function that actually tests, if H264 is working.
This commit is contained in:
Armin Novak 2022-01-26 12:09:50 +01:00 committed by akallabeth
parent 6f3761b8bf
commit 691ba447d2
2 changed files with 39 additions and 5 deletions

View File

@ -24,6 +24,10 @@ import com.freerdp.freerdpcore.presentation.ApplicationSettingsActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LibFreeRDP
{
@ -72,13 +76,30 @@ public class LibFreeRDP
static
{
mHasH264 = tryLoad("openh264");
if (!mHasH264)
mHasH264 = tryLoad("avcodec");
try
{
System.loadLibrary("freerdp-android");
String version = freerdp_get_jni_version();
Pattern pattern = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+).*");
Matcher matcher = pattern.matcher(version);
if (!matcher.matches() || (matcher.groupCount() < 3))
throw new RuntimeException("APK broken: native library version " + version +
" does not meet requirements!");
int major = Integer.parseInt(Objects.requireNonNull(matcher.group(1)));
int minor = Integer.parseInt(Objects.requireNonNull(matcher.group(2)));
int patch = Integer.parseInt(Objects.requireNonNull(matcher.group(3)));
if (major > 2)
mHasH264 = freerdp_has_h264();
else if (minor > 5)
mHasH264 = freerdp_has_h264();
else if ((minor == 5) && (patch >= 1))
mHasH264 = freerdp_has_h264();
else
throw new RuntimeException("APK broken: native library version " + version +
" does not meet requirements!");
Log.i(TAG, "Successfully loaded native library. H264 is " +
(mHasH264 ? "supported" : "not available"));
}
catch (UnsatisfiedLinkError e)
{
@ -92,6 +113,8 @@ public class LibFreeRDP
return mHasH264;
}
private static native boolean freerdp_has_h264();
private static native String freerdp_get_jni_version();
private static native String freerdp_get_version();

View File

@ -31,6 +31,7 @@
#include <freerdp/client/rdpei.h>
#include <freerdp/client/rdpgfx.h>
#include <freerdp/client/cliprdr.h>
#include <freerdp/codec/h264.h>
#include <freerdp/channels/channels.h>
#include <freerdp/client/channels.h>
#include <freerdp/client/cmdline.h>
@ -1029,6 +1030,15 @@ static jstring JNICALL jni_freerdp_get_jni_version(JNIEnv* env, jclass cls)
return (*env)->NewStringUTF(env, FREERDP_JNI_VERSION);
}
static jboolean JNICALL jni_freerdp_has_h264(JNIEnv* env, jclass cls)
{
H264_CONTEXT* ctx = h264_context_new(FALSE);
if (!ctx)
return JNI_FALSE;
h264_context_free(ctx);
return JNI_TRUE;
}
static jstring JNICALL jni_freerdp_get_version(JNIEnv* env, jclass cls)
{
return (*env)->NewStringUTF(env, freerdp_get_version_string());
@ -1061,7 +1071,8 @@ static JNINativeMethod methods[] = {
{ "freerdp_send_cursor_event", "(JIII)Z", &jni_freerdp_send_cursor_event },
{ "freerdp_send_key_event", "(JIZ)Z", &jni_freerdp_send_key_event },
{ "freerdp_send_unicodekey_event", "(JIZ)Z", &jni_freerdp_send_unicodekey_event },
{ "freerdp_send_clipboard_data", "(JLjava/lang/String;)Z", &jni_freerdp_send_clipboard_data }
{ "freerdp_send_clipboard_data", "(JLjava/lang/String;)Z", &jni_freerdp_send_clipboard_data },
{ "freerdp_has_h264", "()Z", &jni_freerdp_has_h264 }
};
static jclass gJavaActivityClass = NULL;