1 /* 2 * Copyright (C) 2012, Collabora Ltd. 3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk> 4 * Copyright (C) 2013, Fluendo S.A. 5 * Author: Andoni Morales <amorales@fluendo.com> 6 * Copyright (C) 2014, Sebastian Dröge <sebastian@centricular.com> 7 * Copyright (C) 2014, Collabora Ltd. 8 * Author: Matthieu Bouron <matthieu.bouron@collabora.com> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation 13 * version 2.1 of the License. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 */ 25 #ifndef __GST_AMC_JNI_UTILS_H__ 26 #define __GST_AMC_JNI_UTILS_H__ 27 28 #include <jni.h> 29 #include <glib.h> 30 #include <gst/gst.h> 31 32 #if GLIB_SIZEOF_VOID_P == 8 33 #define JLONG_TO_GPOINTER(value) (gpointer)(value) 34 #define GPOINTER_TO_JLONG(value) (jlong)(value) 35 #else 36 #define JLONG_TO_GPOINTER(value) (gpointer)(jint)(value) 37 #define GPOINTER_TO_JLONG(value) (jlong)(jint)(value) 38 #endif 39 40 gint gst_amc_jni_get_android_level(void); 41 42 jclass gst_amc_jni_get_class (JNIEnv * env, 43 GError ** err, 44 const gchar * name); 45 46 jmethodID gst_amc_jni_get_method_id (JNIEnv * env, 47 GError ** err, 48 jclass klass, 49 const gchar * name, 50 const gchar * signature); 51 52 jmethodID gst_amc_jni_get_static_method_id (JNIEnv * env, 53 GError ** err, 54 jclass klass, 55 const gchar * name, 56 const gchar * signature); 57 58 jfieldID gst_amc_jni_get_field_id (JNIEnv * env, 59 GError ** err, 60 jclass klass, 61 const gchar * name, 62 const gchar * type); 63 64 jfieldID gst_amc_jni_get_static_field_id (JNIEnv * env, 65 GError ** err, 66 jclass klass, 67 const gchar * name, 68 const gchar * type); 69 70 jobject gst_amc_jni_new_object (JNIEnv * env, 71 GError ** err, 72 gboolean global, 73 jclass klass, 74 jmethodID constructor, 75 ...); 76 77 jobject gst_amc_jni_new_object_from_static (JNIEnv * env, 78 GError ** err, 79 gboolean global, 80 jclass klass, 81 jmethodID constructor, 82 ...); 83 84 jobject gst_amc_jni_object_make_global (JNIEnv * env, 85 jobject object); 86 87 jobject gst_amc_jni_object_ref (JNIEnv * env, 88 jobject object); 89 90 void gst_amc_jni_object_unref (JNIEnv * env, 91 jobject object); 92 93 void gst_amc_jni_object_local_unref (JNIEnv * env, 94 jobject object); 95 96 gchar *gst_amc_jni_string_to_gchar (JNIEnv * env, 97 jstring string, 98 gboolean release); 99 100 jstring gst_amc_jni_string_from_gchar (JNIEnv * env, 101 GError ** error, 102 gboolean global, 103 const gchar * string); 104 105 G_GNUC_PRINTF (5, 6) 106 void gst_amc_jni_set_error (JNIEnv * env, 107 GError ** error, 108 GQuark domain, 109 gint code, 110 const gchar * format, ...); 111 112 void gst_amc_jni_set_java_vm (JavaVM *java_vm); 113 114 gboolean gst_amc_jni_initialize (void); 115 116 gboolean gst_amc_jni_is_vm_started (void); 117 118 JNIEnv *gst_amc_jni_get_env (void); 119 120 jclass gst_amc_jni_get_application_class (JNIEnv * env, 121 const gchar * name, 122 GError ** err); 123 124 #define DEF_CALL_STATIC_TYPE_METHOD(_type, _name, _jname, _retval) \ 125 gboolean gst_amc_jni_call_static_##_name##_method (JNIEnv *env, GError ** err, jclass klass, jmethodID methodID, _type * value, ...) 126 127 DEF_CALL_STATIC_TYPE_METHOD (gboolean, boolean, Boolean, FALSE); 128 DEF_CALL_STATIC_TYPE_METHOD (gint8, byte, Byte, G_MININT8); 129 DEF_CALL_STATIC_TYPE_METHOD (gshort, short, Short, G_MINSHORT); 130 DEF_CALL_STATIC_TYPE_METHOD (gint, int, Int, G_MININT); 131 DEF_CALL_STATIC_TYPE_METHOD (gchar, char, Char, 0); 132 DEF_CALL_STATIC_TYPE_METHOD (gint64, long, Long, G_MINLONG); 133 DEF_CALL_STATIC_TYPE_METHOD (gfloat, float, Float, G_MINFLOAT); 134 DEF_CALL_STATIC_TYPE_METHOD (gdouble, double, Double, G_MINDOUBLE); 135 DEF_CALL_STATIC_TYPE_METHOD (jobject, object, Object, NULL); 136 137 gboolean gst_amc_jni_call_static_void_method (JNIEnv * env, 138 GError ** error, 139 jclass klass, 140 jmethodID method, ...); 141 142 #define DEF_CALL_TYPE_METHOD(_type, _name, _jname, _retval) \ 143 gboolean gst_amc_jni_call_##_name##_method (JNIEnv *env, GError ** err, jobject obj, jmethodID methodID, _type * value, ...) 144 145 DEF_CALL_TYPE_METHOD (gboolean, boolean, Boolean, FALSE); 146 DEF_CALL_TYPE_METHOD (gint8, byte, Byte, G_MININT8); 147 DEF_CALL_TYPE_METHOD (gshort, short, Short, G_MINSHORT); 148 DEF_CALL_TYPE_METHOD (gint, int, Int, G_MININT); 149 DEF_CALL_TYPE_METHOD (gchar, char, Char, 0); 150 DEF_CALL_TYPE_METHOD (gint64, long, Long, G_MINLONG); 151 DEF_CALL_TYPE_METHOD (gfloat, float, Float, G_MINFLOAT); 152 DEF_CALL_TYPE_METHOD (gdouble, double, Double, G_MINDOUBLE); 153 DEF_CALL_TYPE_METHOD (jobject, object, Object, NULL); 154 155 gboolean gst_amc_jni_call_void_method (JNIEnv * env, 156 GError ** error, 157 jobject obj, 158 jmethodID method, ...); 159 160 #define DEF_GET_TYPE_FIELD(_type, _name, _jname) \ 161 gboolean gst_amc_jni_get_##_name##_field (JNIEnv *env, GError ** err, jobject obj, jfieldID fieldID, _type * value) 162 163 DEF_GET_TYPE_FIELD (gboolean, boolean, Boolean); 164 DEF_GET_TYPE_FIELD (gint8, byte, Byte); 165 DEF_GET_TYPE_FIELD (gshort, short, Short); 166 DEF_GET_TYPE_FIELD (gint, int, Int); 167 DEF_GET_TYPE_FIELD (gchar, char, Char); 168 DEF_GET_TYPE_FIELD (gint64, long, Long); 169 DEF_GET_TYPE_FIELD (gfloat, float, Float); 170 DEF_GET_TYPE_FIELD (gdouble, double, Double); 171 DEF_GET_TYPE_FIELD (jobject, object, Object); 172 173 #define DEF_GET_STATIC_TYPE_FIELD(_type, _name, _jname) \ 174 gboolean gst_amc_jni_get_static_##_name##_field (JNIEnv *env, GError ** err, jclass klass, jfieldID fieldID, _type * value) 175 176 DEF_GET_STATIC_TYPE_FIELD (gboolean, boolean, Boolean); 177 DEF_GET_STATIC_TYPE_FIELD (gint8, byte, Byte); 178 DEF_GET_STATIC_TYPE_FIELD (gshort, short, Short); 179 DEF_GET_STATIC_TYPE_FIELD (gint, int, Int); 180 DEF_GET_STATIC_TYPE_FIELD (gchar, char, Char); 181 DEF_GET_STATIC_TYPE_FIELD (gint64, long, Long); 182 DEF_GET_STATIC_TYPE_FIELD (gfloat, float, Float); 183 DEF_GET_STATIC_TYPE_FIELD (gdouble, double, Double); 184 DEF_GET_STATIC_TYPE_FIELD (jobject, object, Object); 185 186 #endif 187