extern void init_filter_nnfw (void);
#endif
#if defined (ENABLE_SNPE)
-extern void _init_filter_snpe (void);
+extern void init_filter_snpe (JNIEnv * env, jobject context);
#endif
/**
}
/**
- * @brief Set additional environment
- */
-static gboolean
-nns_set_env (JNIEnv * env, jobject context)
-{
- gboolean ret = TRUE;
-
-#if defined (ENABLE_SNPE)
- gboolean snpe_failed = TRUE;
-
- jclass context_class = NULL;
- jmethodID get_application_info_method_id = NULL;
- jobject application_info_object = NULL;
- jclass application_info_object_class = NULL;
- jfieldID native_library_dir_field_id = NULL;
- jstring native_library_dir_path = NULL;
-
- const gchar *native_library_dir_path_str;
- gchar *new_path;
-
- context_class = (*env)->GetObjectClass (env, context);
- if (!context_class) {
- nns_loge ("Failed to get context class.");
- goto snpe_done;
- }
-
- get_application_info_method_id = (*env)->GetMethodID (env, context_class,
- "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
- if (!get_application_info_method_id) {
- nns_loge ("Failed to get method ID for `ApplicationInfo()`.");
- goto snpe_done;
- }
-
- application_info_object = (*env)->CallObjectMethod (env, context,
- get_application_info_method_id);
- if ((*env)->ExceptionCheck (env)) {
- (*env)->ExceptionDescribe (env);
- (*env)->ExceptionClear (env);
- nns_loge ("Failed to call method `ApplicationInfo()`.");
- goto snpe_done;
- }
-
- application_info_object_class = (*env)->GetObjectClass (env,
- application_info_object);
- if (!application_info_object_class) {
- nns_loge ("Failed to get `ApplicationInfo` object class");
- goto snpe_done;
- }
-
- native_library_dir_field_id = (*env)->GetFieldID (env,
- application_info_object_class,
- "nativeLibraryDir", "Ljava/lang/String;");
- if (!native_library_dir_field_id) {
- nns_loge ("Failed to get field ID for `nativeLibraryDir`.");
- goto snpe_done;
- }
-
- native_library_dir_path = (*env)->GetObjectField (env,
- application_info_object, native_library_dir_field_id);
- if (!native_library_dir_path) {
- nns_loge ("Failed to get field `nativeLibraryDir`.");
- goto snpe_done;
- }
-
- native_library_dir_path_str = (*env)->GetStringUTFChars (env,
- native_library_dir_path, NULL);
- if ((*env)->ExceptionCheck (env)) {
- (*env)->ExceptionDescribe (env);
- (*env)->ExceptionClear (env);
- nns_loge ("Failed to get string `nativeLibraryDir`");
- goto snpe_done;
- }
-
- new_path = g_strconcat (native_library_dir_path_str,
- ";/system/lib/rfsa/adsp;/system/vendor/lib/rfsa/adsp;/dsp", NULL);
-
- /* See https://developer.qualcomm.com/docs/snpe/dsp_runtime.html for details */
- nns_logi ("Set env ADSP_LIBRARY_PATH for snpe DSP/AIP runtime: %s",
- new_path);
- g_setenv ("ADSP_LIBRARY_PATH", new_path, TRUE);
-
- g_free (new_path);
- (*env)->ReleaseStringUTFChars (env, native_library_dir_path,
- native_library_dir_path_str);
-
- snpe_failed = FALSE;
-
-snpe_done:
- ret = ret && !(snpe_failed);
-
- if (native_library_dir_path) {
- (*env)->DeleteLocalRef (env, native_library_dir_path);
- }
-
- if (application_info_object_class) {
- (*env)->DeleteLocalRef (env, application_info_object_class);
- }
-
- if (application_info_object) {
- (*env)->DeleteLocalRef (env, application_info_object);
- }
-
- if (context_class) {
- (*env)->DeleteLocalRef (env, context_class);
- }
-
-#endif
-
- return ret;
-}
-
-/**
* @brief Initialize NNStreamer, register required plugins.
*/
jboolean
goto done;
}
- if (!nns_set_env (env, context)) {
- nns_loge ("Failed to set extra env");
- goto done;
- }
-
if (nns_is_initilaized == FALSE) {
/* register nnstreamer plugins */
#if !defined (NNS_SINGLE_ONLY)
init_filter_nnfw ();
#endif
#if defined (ENABLE_SNPE)
- _init_filter_snpe ();
+ init_filter_snpe (env, context);
#endif
nns_is_initilaized = TRUE;
#include <DlSystem/ITensorFactory.hpp>
#include <DlSystem/TensorMap.hpp>
+#if defined(__ANDROID__)
+#include <jni.h>
+#endif
+
/**
* @brief Macro for debug mode.
*/
namespace tensor_filter_snpe {
extern "C" {
- void _init_filter_snpe (void) __attribute__ ((constructor));
- void _fini_filter_snpe (void) __attribute__ ((destructor));
+#if defined(__ANDROID__)
+ void init_filter_snpe (JNIEnv * env, jobject context);
+#else
+ void init_filter_snpe (void) __attribute__ ((constructor));
+#endif
+ void fini_filter_snpe (void) __attribute__ ((destructor));
}
class snpe_subplugin final : public tensor_filter_subplugin {
tensor_filter_subplugin::unregister_subplugin (registeredRepresentation);
}
-void _init_filter_snpe ()
+#if defined(__ANDROID__)
+/**
+ * @brief Set additional environment (ADSP_LIBRARY_PATH) for snpe
+ */
+static gboolean _snpe_set_env (JNIEnv * env, jobject context)
+{
+ gboolean snpe_failed = TRUE;
+ jclass context_class = NULL;
+ jmethodID get_application_info_method_id = NULL;
+ jobject application_info_object = NULL;
+ jclass application_info_object_class = NULL;
+ jfieldID native_library_dir_field_id = NULL;
+ jstring native_library_dir_path = NULL;
+
+ const gchar *native_library_dir_path_str;
+ gchar *new_path;
+
+ context_class = env->GetObjectClass (context);
+ if (!context_class) {
+ nns_loge ("Failed to get context class.");
+ goto done;
+ }
+
+ get_application_info_method_id = env->GetMethodID (context_class,
+ "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
+ if (!get_application_info_method_id) {
+ nns_loge ("Failed to get method ID for `ApplicationInfo()`.");
+ goto done;
+ }
+
+ application_info_object = env->CallObjectMethod (context,
+ get_application_info_method_id);
+ if (env->ExceptionCheck ()) {
+ env->ExceptionDescribe ();
+ env->ExceptionClear ();
+ nns_loge ("Failed to call method `ApplicationInfo()`.");
+ goto done;
+ }
+
+ application_info_object_class = env->GetObjectClass (application_info_object);
+ if (!application_info_object_class) {
+ nns_loge ("Failed to get `ApplicationInfo` object class");
+ goto done;
+ }
+
+ native_library_dir_field_id = env->GetFieldID (application_info_object_class,
+ "nativeLibraryDir", "Ljava/lang/String;");
+ if (!native_library_dir_field_id) {
+ nns_loge ("Failed to get field ID for `nativeLibraryDir`.");
+ goto done;
+ }
+
+ native_library_dir_path = static_cast<jstring>(env->GetObjectField(
+ application_info_object, native_library_dir_field_id));
+ if (!native_library_dir_path) {
+ nns_loge ("Failed to get field `nativeLibraryDir`.");
+ goto done;
+ }
+
+ native_library_dir_path_str = env->GetStringUTFChars (native_library_dir_path,
+ NULL);
+ if (env->ExceptionCheck ()) {
+ env->ExceptionDescribe ();
+ env->ExceptionClear ();
+ nns_loge ("Failed to get string `nativeLibraryDir`");
+ goto done;
+ }
+
+ new_path = g_strconcat (native_library_dir_path_str,
+ ";/system/lib/rfsa/adsp;/system/vendor/lib/rfsa/adsp;/dsp", NULL);
+
+ /* See https://developer.qualcomm.com/docs/snpe/dsp_runtime.html for details */
+ nns_logi ("Set env ADSP_LIBRARY_PATH for snpe DSP/AIP runtime: %s",
+ new_path);
+ g_setenv ("ADSP_LIBRARY_PATH", new_path, TRUE);
+
+ g_free (new_path);
+ env->ReleaseStringUTFChars (native_library_dir_path,
+ native_library_dir_path_str);
+
+ snpe_failed = FALSE;
+
+done:
+
+ if (native_library_dir_path) {
+ env->DeleteLocalRef (native_library_dir_path);
+ }
+
+ if (application_info_object_class) {
+ env->DeleteLocalRef (application_info_object_class);
+ }
+
+ if (application_info_object) {
+ env->DeleteLocalRef (application_info_object);
+ }
+
+ if (context_class) {
+ env->DeleteLocalRef (context_class);
+ }
+
+ return !(snpe_failed);
+}
+
+void init_filter_snpe (JNIEnv * env, jobject context)
{
if (nnstreamer_filter_find ("snap")) {
nns_loge ("Cannot use SNPE and SNAP both. Won't register this SNPE subplugin.");
return;
}
+
+ if (!_snpe_set_env (env, context)) {
+ nns_loge ("Failed to set extra env");
+ return;
+ }
+
snpe_subplugin::init_filter_snpe ();
}
+#else
+void init_filter_snpe ()
+{
+ snpe_subplugin::init_filter_snpe ();
+}
+#endif
-void _fini_filter_snpe ()
+void fini_filter_snpe ()
{
snpe_subplugin::fini_filter_snpe ();
}