-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
3,651 additions
and
1,016 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#include "AndroidVideo.h" | ||
#include "AndroidInterface.h" | ||
#include "QGCLoggingCategory.h" | ||
|
||
QGC_LOGGING_CATEGORY(AndroidVideoLog, "qgc.android.androidvideo") | ||
|
||
static jobject _context = NULL; | ||
static jobject _class_loader = NULL; | ||
static JavaVM *_java_vm = NULL; | ||
static GstClockTime _priv_gst_info_start_time; | ||
|
||
static void gst_android_load_gio_modules() | ||
{ | ||
|
||
} | ||
|
||
GST_API jobject gst_android_get_application_context(); | ||
GST_API jobject gst_android_get_application_class_loader(); | ||
GST_API JavaVM* gst_android_get_java_vm(); | ||
|
||
jobject gst_android_get_application_context() | ||
{ | ||
return _context; | ||
} | ||
|
||
jobject gst_android_get_application_class_loader() | ||
{ | ||
return _class_loader; | ||
} | ||
|
||
JavaVM *gst_android_get_java_vm() | ||
{ | ||
return _java_vm; | ||
} | ||
|
||
static void gst_android_init(JNIEnv *env, jobject context) | ||
{ | ||
gchar* cache_dir; | ||
gchar* files_dir; | ||
gchar* registry; | ||
GError* error = NULL; | ||
|
||
if (!initialize(env, context)) { | ||
qCDebug(AndroidVideoLog) << "GStreamer failed to initialize"; | ||
return; | ||
} | ||
|
||
if (gst_is_initialized()) { | ||
qCDebug(AndroidVideoLog) << "GStreamer already initialized"; | ||
return; | ||
} | ||
|
||
/*if ( !get_application_dirs(env, context, &cache_dir, &files_dir) ) { | ||
__android_log_print ( | ||
ANDROID_LOG_ERROR, | ||
"GStreamer", | ||
"Failed to get application dirs" | ||
); | ||
}*/ | ||
|
||
/*if (cache_dir) { | ||
g_setenv("TMP", cache_dir, TRUE); | ||
g_setenv("TEMP", cache_dir, TRUE); | ||
g_setenv("TMPDIR", cache_dir, TRUE); | ||
g_setenv("XDG_RUNTIME_DIR", cache_dir, TRUE); | ||
g_setenv("XDG_CACHE_HOME", cache_dir, TRUE); | ||
registry = g_build_filename(cache_dir, "registry.bin", NULL); | ||
g_setenv("GST_REGISTRY", registry, TRUE); | ||
g_free(registry); | ||
g_setenv("GST_REGISTRY_REUSE_PLUGIN_SCANNER", "no", TRUE); | ||
// GST_PLUGIN_SCANNER | ||
// GST_PLUGIN_SYSTEM_PATH_1_0 | ||
// GST_PLUGIN_PATH_1_0 | ||
}*/ | ||
|
||
/*if (files_dir) { | ||
gchar *fontconfig, *certs; | ||
g_setenv("HOME", files_dir, TRUE); | ||
g_setenv("XDG_DATA_DIRS", files_dir, TRUE); | ||
g_setenv("XDG_CONFIG_DIRS", files_dir, TRUE); | ||
g_setenv("XDG_CONFIG_HOME", files_dir, TRUE); | ||
g_setenv("XDG_DATA_HOME", files_dir, TRUE); | ||
fontconfig = g_build_filename(files_dir, "fontconfig", NULL); | ||
g_setenv("FONTCONFIG_PATH", fontconfig, TRUE); | ||
g_free(fontconfig); | ||
certs = g_build_filename( | ||
files_dir, | ||
"ssl", | ||
"certs", | ||
"ca-certificates.crt", | ||
NULL | ||
); | ||
g_setenv ("CA_CERTIFICATES", certs, TRUE); | ||
g_free (certs); | ||
}*/ | ||
|
||
// g_free(cache_dir); | ||
// g_free(files_dir); | ||
|
||
/* Set GLib print handlers */ | ||
// g_set_print_handler (glib_print_handler); | ||
// g_set_printerr_handler (glib_printerr_handler); | ||
// g_log_set_default_handler (glib_log_handler, NULL); | ||
|
||
/* Set GStreamer log handlers */ | ||
gst_debug_remove_log_function(NULL); | ||
|
||
/* Set desired log-level here */ | ||
gst_debug_set_default_threshold(GST_LEVEL_ERROR); | ||
|
||
gst_debug_add_log_function((GstLogFunction)gst_debug_logcat, NULL, NULL); | ||
|
||
/* get time we started for debugging messages */ | ||
_priv_gst_info_start_time = gst_util_get_timestamp(); | ||
} | ||
|
||
static void gst_android_init_jni(JNIEnv* env, jobject gstreamer, jobject context) | ||
{ | ||
gst_android_init(env, context); | ||
} | ||
|
||
namespace AndroidVideo | ||
{ | ||
|
||
jint setNativeMethods() | ||
{ | ||
qCDebug(GStreamerLog) << Q_FUNC_INFO; | ||
|
||
static constexpr JNINativeMethod javaMethods[] { | ||
{"nativeInit", "(Landroid/content/Context;)V", (void *) gst_android_init_jni} | ||
}; | ||
|
||
QJniEnvironment jniEnv; | ||
(void) jniEnv.checkAndClearExceptions(); | ||
|
||
jclass objectClass = jniEnv->FindClass("org/freedesktop/gstreamer/GStreamer"); | ||
if (!objectClass) { | ||
qCWarning(GStreamerLog) << "Couldn't find class:" << "org/freedesktop/gstreamer/GStreamer"; | ||
return JNI_ERR; | ||
} | ||
|
||
const jint val = jniEnv->RegisterNatives(objectClass, javaMethods, sizeof(javaMethods) / sizeof(javaMethods[0])); | ||
if (val < 0) { | ||
qCWarning(GStreamerLog) << "Error registering methods:" << val; | ||
} else { | ||
qCDebug(GStreamerLog) << "Main Native Functions Registered"; | ||
} | ||
|
||
(void) jniEnv.checkAndClearExceptions(); | ||
|
||
return JNI_OK; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <QtCore/QString> | ||
#include <QtCore/QByteArray> | ||
#include <QtCore/QLoggingCategory> | ||
|
||
#include <jni.h> | ||
|
||
Q_DECLARE_LOGGING_CATEGORY(AndroidVideoLog); | ||
|
||
namespace AndroidVideo { | ||
jint setNativeMethods(); | ||
} |
Oops, something went wrong.