diff options
author | Justin Kim <justin.kim@collabora.com> | 2016-03-03 15:50:49 +0900 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-05-06 09:18:00 +0300 |
commit | c8e34e93b27f632f0dd227c2b32053ce80b66a33 (patch) | |
tree | 09e87357ccb07dc6d82a15814ccf136530dc9cb1 /sys/androidmedia | |
parent | 4810c7de70e7bb0053d43484ba0b67614e578ba0 (diff) |
androidmeida: replace with new surfacetexture for ahcsrc
GstAmcSurfaceTexture is more clear and simple than GstAGSurfaceTexture.
https://bugzilla.gnome.org/show_bug.cgi?id=763099
Diffstat (limited to 'sys/androidmedia')
-rw-r--r-- | sys/androidmedia/Makefile.am | 2 | ||||
-rw-r--r-- | sys/androidmedia/gst-android-graphics-surfacetexture.c | 144 | ||||
-rw-r--r-- | sys/androidmedia/gst-android-graphics-surfacetexture.h | 54 | ||||
-rw-r--r-- | sys/androidmedia/gst-android-hardware-camera.c | 4 | ||||
-rw-r--r-- | sys/androidmedia/gst-android-hardware-camera.h | 4 | ||||
-rw-r--r-- | sys/androidmedia/gstahcsrc.c | 29 | ||||
-rw-r--r-- | sys/androidmedia/gstahcsrc.h | 3 | ||||
-rw-r--r-- | sys/androidmedia/gstamc.c | 6 |
8 files changed, 30 insertions, 216 deletions
diff --git a/sys/androidmedia/Makefile.am b/sys/androidmedia/Makefile.am index 7ad9b6e93..3bb4ea36e 100644 --- a/sys/androidmedia/Makefile.am +++ b/sys/androidmedia/Makefile.am @@ -9,7 +9,6 @@ libgstandroidmedia_la_SOURCES = \ gstamcvideodec.c \ gstamcvideoenc.c \ gst-android-graphics-imageformat.c \ - gst-android-graphics-surfacetexture.c \ gst-android-hardware-camera.c \ gstjniutils.c @@ -23,7 +22,6 @@ noinst_HEADERS = \ gstamcvideodec.h \ gstamcvideoenc.h \ gst-android-graphics-imageformat.h \ - gst-android-graphics-surfacetexture.h \ gst-android-hardware-camera.h \ gstjniutils.h diff --git a/sys/androidmedia/gst-android-graphics-surfacetexture.c b/sys/androidmedia/gst-android-graphics-surfacetexture.c deleted file mode 100644 index 84993a8c8..000000000 --- a/sys/androidmedia/gst-android-graphics-surfacetexture.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2012, Collabora Ltd. - * Copyright (C) 2012, Cisco Systems, Inc. - * Author: Youness Alaoui <youness.alaoui@collabora.co.uk> - * - * 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 - -#include "gstjniutils.h" - -#include "gst-android-graphics-surfacetexture.h" - -static struct -{ - jclass klass; - jmethodID constructor; - jmethodID release; -} android_graphics_surfacetexture = { -0}; - -static gboolean -_init_classes (void) -{ - JNIEnv *env; - GError *err = NULL; - - env = gst_amc_jni_get_env (); - - /* android.graphics.SurfaceTexture */ - 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 -gst_android_graphics_surfacetexture_init (void) -{ - if (!_init_classes ()) { - gst_android_graphics_surfacetexture_deinit (); - return FALSE; - } - - return TRUE; -} - -void -gst_android_graphics_surfacetexture_deinit (void) -{ - 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) -{ - 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) -{ - 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) -{ - JNIEnv *env = gst_amc_jni_get_env (); - - (*env)->DeleteGlobalRef (env, self->object); - g_slice_free (GstAGSurfaceTexture, self); -} diff --git a/sys/androidmedia/gst-android-graphics-surfacetexture.h b/sys/androidmedia/gst-android-graphics-surfacetexture.h deleted file mode 100644 index 3bb80ca5d..000000000 --- a/sys/androidmedia/gst-android-graphics-surfacetexture.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2012, Collabora Ltd. - * Copyright (C) 2012, Cisco Systems, Inc. - * Author: Youness Alaoui <youness.alaoui@collabora.co.uk> - * - * 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 - * - */ - -#ifndef __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__ -#define __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__ - -#include <gst/gst.h> -#include <jni.h> - - -G_BEGIN_DECLS - -typedef struct _GstAGSurfaceTexture GstAGSurfaceTexture; - -/* android.graphics.SurfaceTexture */ -struct _GstAGSurfaceTexture { - /* < private > */ - jobject object; /* global reference */ -}; - - -gboolean gst_android_graphics_surfacetexture_init (void); -void gst_android_graphics_surfacetexture_deinit (void); - -/* android.graphics.SurfaceTexture */ -GstAGSurfaceTexture *gst_ag_surfacetexture_new (gint texture_id); -void gst_ag_surfacetexture_release (GstAGSurfaceTexture *self); -void gst_ag_surfacetexture_free (GstAGSurfaceTexture *self); - -G_END_DECLS - -#endif /* __GST_ANDROID_GRAPHICS_SURFACETEXTURE_H__ */ - diff --git a/sys/androidmedia/gst-android-hardware-camera.c b/sys/androidmedia/gst-android-hardware-camera.c index 876800b70..6b32ed5ce 100644 --- a/sys/androidmedia/gst-android-hardware-camera.c +++ b/sys/androidmedia/gst-android-hardware-camera.c @@ -2498,13 +2498,13 @@ done: void gst_ah_camera_set_preview_texture (GstAHCamera * self, - GstAGSurfaceTexture * surfaceTexture) + GstAmcSurfaceTexture * surfaceTexture) { JNIEnv *env = gst_amc_jni_get_env (); GError *err = NULL; gst_amc_jni_call_void_method (env, &err, self->object, - android_hardware_camera.setPreviewTexture, surfaceTexture->object); + android_hardware_camera.setPreviewTexture, surfaceTexture->jobject); if (err) { GST_ERROR ("Failed to call android.hardware.Camera.setPreviewTexture: %s", err->message); diff --git a/sys/androidmedia/gst-android-hardware-camera.h b/sys/androidmedia/gst-android-hardware-camera.h index 44e784265..ab2e25a73 100644 --- a/sys/androidmedia/gst-android-hardware-camera.h +++ b/sys/androidmedia/gst-android-hardware-camera.h @@ -28,8 +28,8 @@ #include <gst/gst.h> #include <jni.h> -#include "gst-android-graphics-surfacetexture.h" #include "gst-android-graphics-imageformat.h" +#include "gstamcsurfacetexture.h" G_BEGIN_DECLS @@ -150,7 +150,7 @@ gboolean gst_ah_camera_set_error_callback (GstAHCamera * self, gboolean gst_ah_camera_set_preview_callback_with_buffer (GstAHCamera * self, GstAHCPreviewCallback cb, gpointer user_data); void gst_ah_camera_set_preview_texture (GstAHCamera * self, - GstAGSurfaceTexture * surfaceTexture); + GstAmcSurfaceTexture * surfaceTexture); gboolean gst_ah_camera_start_preview (GstAHCamera * self); gboolean gst_ah_camera_start_smooth_zoom (GstAHCamera * self, gint value); gboolean gst_ah_camera_stop_preview (GstAHCamera * self); diff --git a/sys/androidmedia/gstahcsrc.c b/sys/androidmedia/gstahcsrc.c index 856f8f3fc..1a02938d1 100644 --- a/sys/androidmedia/gstahcsrc.c +++ b/sys/androidmedia/gstahcsrc.c @@ -2173,6 +2173,8 @@ gst_ahc_src_on_error (gint error, gpointer user_data) static gboolean gst_ahc_src_open (GstAHCSrc * self) { + GError *err = NULL; + GST_DEBUG_OBJECT (self, "Opening camera"); self->camera = gst_ah_camera_open (self->device); @@ -2180,7 +2182,13 @@ gst_ahc_src_open (GstAHCSrc * self) if (self->camera) { GST_DEBUG_OBJECT (self, "Opened camera"); - self->texture = gst_ag_surfacetexture_new (0); + self->texture = gst_amc_surface_texture_new (&err); + if (self->texture == NULL) { + GST_ERROR_OBJECT (self, + "Failed to create surface texture object: %s", err->message); + g_clear_error (&err); + goto failed_surfacetexutre; + } gst_ah_camera_set_preview_texture (self->camera, self->texture); self->buffer_size = 0; } else { @@ -2198,11 +2206,20 @@ gst_ahc_src_open (GstAHCSrc * self) } return (self->camera != NULL); + +failed_surfacetexutre: + gst_ah_camera_release (self->camera); + gst_ah_camera_free (self->camera); + self->camera = NULL; + + return FALSE; } static void gst_ahc_src_close (GstAHCSrc * self) { + GError *err = NULL; + if (self->camera) { gst_ah_camera_set_error_callback (self->camera, NULL, NULL); gst_ah_camera_set_preview_callback_with_buffer (self->camera, NULL, NULL); @@ -2211,11 +2228,13 @@ gst_ahc_src_close (GstAHCSrc * self) } self->camera = NULL; - if (self->texture) { - gst_ag_surfacetexture_release (self->texture); - gst_ag_surfacetexture_free (self->texture); + if (self->texture && !gst_amc_surface_texture_release (self->texture, &err)) { + GST_ERROR_OBJECT (self, + "Failed to release surface texture object: %s", err->message); + g_clear_error (&err); } - self->texture = NULL; + + g_clear_object (&self->texture); } static GstStateChangeReturn diff --git a/sys/androidmedia/gstahcsrc.h b/sys/androidmedia/gstahcsrc.h index 4790989fe..dc80beba2 100644 --- a/sys/androidmedia/gstahcsrc.h +++ b/sys/androidmedia/gstahcsrc.h @@ -30,6 +30,7 @@ #include <gst/base/gstdataqueue.h> #include "gst-android-hardware-camera.h" +#include "gstamcsurfacetexture.h" G_BEGIN_DECLS @@ -59,7 +60,7 @@ struct _GstAHCSrc GstPushSrc parent; GstAHCamera *camera; - GstAGSurfaceTexture *texture; + GstAmcSurfaceTexture *texture; GList *data; GstDataQueue *queue; gint buffer_size; diff --git a/sys/androidmedia/gstamc.c b/sys/androidmedia/gstamc.c index c86e51975..fc69214fb 100644 --- a/sys/androidmedia/gstamc.c +++ b/sys/androidmedia/gstamc.c @@ -3328,11 +3328,6 @@ plugin_init (GstPlugin * plugin) if (!register_codecs (plugin)) return FALSE; - if (!gst_android_graphics_surfacetexture_init ()) { - GST_ERROR ("Failed to init android surface texture"); - return FALSE; - } - if (!gst_android_graphics_imageformat_init ()) { GST_ERROR ("Failed to init android image format"); goto failed_surfacetexture; @@ -3354,7 +3349,6 @@ failed_hardware_camera: failed_graphics_imageformat: gst_android_graphics_imageformat_deinit (); failed_surfacetexture: - gst_android_graphics_surfacetexture_deinit (); return FALSE; } |