mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
androidmeida: replace with new surfacetexture for ahcsrc
GstAmcSurfaceTexture is more clear and simple than GstAGSurfaceTexture. https://bugzilla.gnome.org/show_bug.cgi?id=763099
This commit is contained in:
parent
4810c7de70
commit
c8e34e93b2
8 changed files with 30 additions and 216 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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__ */
|
||||
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue