gstreamer/sys/androidmedia/gst-android-graphics-surfacetexture.c

145 lines
3.7 KiB
C
Raw Normal View History

/*
* Copyright (C) 2012, Collabora Ltd.
* Copyright (C) 2012, Cisco Systems, Inc.
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
*
2015-12-24 03:51:13 +00:00
* Copyright (C) 2015, Collabora Ltd.
* Author: Justin Kim <justin.kim@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2015-12-24 03:51:13 +00:00
#include "gstjniutils.h"
#include "gst-android-graphics-surfacetexture.h"
static struct
{
jclass klass;
jmethodID constructor;
jmethodID release;
2012-10-17 23:42:59 +00:00
} android_graphics_surfacetexture = {
0};
static gboolean
2012-10-17 23:42:59 +00:00
_init_classes (void)
{
2015-12-24 03:51:13 +00:00
JNIEnv *env;
GError *err = NULL;
env = gst_amc_jni_get_env ();
/* android.graphics.SurfaceTexture */
2015-12-24 03:51:13 +00:00
android_graphics_surfacetexture.klass =
gst_amc_jni_get_class (env, &err, "android/graphics/SurfaceTexture");
if (!android_graphics_surfacetexture.klass) {
GST_ERROR ("Failed to get android.graphics.SurfaceTexture class: %s",
err->message);
g_clear_error (&err);
return FALSE;
}
android_graphics_surfacetexture.constructor =
gst_amc_jni_get_method_id (env, &err,
android_graphics_surfacetexture.klass, "<init>", "(I)V");
android_graphics_surfacetexture.release =
gst_amc_jni_get_method_id (env, &err,
android_graphics_surfacetexture.klass, "release", "()V");
return TRUE;
}
gboolean
2012-10-17 23:42:59 +00:00
gst_android_graphics_surfacetexture_init (void)
{
if (!_init_classes ()) {
gst_android_graphics_surfacetexture_deinit ();
return FALSE;
}
return TRUE;
}
void
2012-10-17 23:42:59 +00:00
gst_android_graphics_surfacetexture_deinit (void)
{
2015-12-24 03:51:13 +00:00
JNIEnv *env = gst_amc_jni_get_env ();
if (android_graphics_surfacetexture.klass)
(*env)->DeleteGlobalRef (env, android_graphics_surfacetexture.klass);
android_graphics_surfacetexture.klass = NULL;
}
/* android.graphics.SurfaceTexture */
GstAGSurfaceTexture *
gst_ag_surfacetexture_new (gint texture_id)
{
2015-12-24 03:51:13 +00:00
JNIEnv *env = gst_amc_jni_get_env ();
jobject object = NULL;
GstAGSurfaceTexture *tex = NULL;
object = (*env)->NewObject (env,
android_graphics_surfacetexture.klass,
android_graphics_surfacetexture.constructor, texture_id);
if ((*env)->ExceptionCheck (env) || !object) {
GST_ERROR ("Failed to call Java method");
(*env)->ExceptionClear (env);
return NULL;
}
tex = g_slice_new0 (GstAGSurfaceTexture);
tex->object = (*env)->NewGlobalRef (env, object);
if (!tex->object) {
GST_ERROR ("Failed to create global reference");
(*env)->ExceptionClear (env);
g_slice_free (GstAGSurfaceTexture, tex);
tex = NULL;
}
(*env)->DeleteLocalRef (env, object);
return tex;
}
void
gst_ag_surfacetexture_release (GstAGSurfaceTexture * self)
{
2015-12-24 03:51:13 +00:00
JNIEnv *env;
GError *err = NULL;
env = gst_amc_jni_get_env ();
if (!gst_amc_jni_call_void_method (env, &err, self->object,
android_graphics_surfacetexture.release)) {
GST_ERROR ("Failed to call release: %s", err->message);
g_clear_error (&err);
}
}
void
gst_ag_surfacetexture_free (GstAGSurfaceTexture * self)
{
2015-12-24 03:51:13 +00:00
JNIEnv *env = gst_amc_jni_get_env ();
(*env)->DeleteGlobalRef (env, self->object);
g_slice_free (GstAGSurfaceTexture, self);
}