summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosep Torra <n770galaxy@gmail.com>2013-05-06 10:35:55 +0200
committerJosep Torra <n770galaxy@gmail.com>2013-05-07 14:02:37 +0200
commit07b2fe65d3bcf72d38bbf24453d493d38c359d9c (patch)
treeaeb35e2d58b43d96d81d3d6c1bf56355857f83f6
parent61a05b3a46a797a402b37a53fc320322382a380c (diff)
egl: allow a delegate call to eglTerminate for display wrapperegl
Add a destroy notify function on our gst_egl_display wrapper. Update example code to use the new API.
-rw-r--r--examples/egl/testegl.c16
-rw-r--r--gst/egl/egl.c22
-rw-r--r--gst/egl/egl.h3
3 files changed, 30 insertions, 11 deletions
diff --git a/examples/egl/testegl.c b/examples/egl/testegl.c
index ea82141..6338bb2 100644
--- a/examples/egl/testegl.c
+++ b/examples/egl/testegl.c
@@ -680,7 +680,7 @@ flush_start (APP_STATE_T * state)
g_cond_broadcast (state->cond);
g_mutex_unlock (state->lock);
- while ((object = g_async_queue_try_pop (state->queue))) {
+ while ((object = GST_MINI_OBJECT_CAST (g_async_queue_try_pop (state->queue)))) {
gst_mini_object_unref (object);
}
@@ -753,7 +753,7 @@ handle_queued_objects (APP_STATE_T * state)
return FALSE;
}
- while ((object = g_async_queue_try_pop (state->queue))) {
+ while ((object = GST_MINI_OBJECT_CAST (g_async_queue_try_pop (state->queue)))) {
g_mutex_lock (state->lock);
if (state->flushing) {
@@ -1179,6 +1179,15 @@ close_ogl (void)
//==============================================================================
+static void
+terminate_display (gpointer user_data)
+{
+ APP_STATE_T *state = (APP_STATE_T *) user_data;
+
+ if (state->display != EGL_NO_DISPLAY)
+ eglTerminate (state->display);
+}
+
int
main (int argc, char **argv)
{
@@ -1230,7 +1239,8 @@ main (int argc, char **argv)
TRACE_VC_MEMORY ("after init_ogl");
/* Wrap the EGL display */
- state->gst_display = gst_egl_display_new (state->display);
+ state->gst_display = gst_egl_display_new (state->display, state,
+ terminate_display);
/* Setup the model world */
init_model_proj (state);
diff --git a/gst/egl/egl.c b/gst/egl/egl.c
index d05fae1..eb9fa78 100644
--- a/gst/egl/egl.c
+++ b/gst/egl/egl.c
@@ -128,7 +128,9 @@ struct _GstEGLDisplay
volatile gint refcount;
EGLDisplay display;
- EGLContext context;
+
+ gpointer user_data;
+ GDestroyNotify destroy_data;
};
/**
@@ -521,6 +523,8 @@ G_DEFINE_BOXED_TYPE (GstEGLImageMemoryPool, gst_egl_image_memory_pool,
/**
* gst_egl_display_new:
* @display: a #EGLDisplay display
+ * @user_data: user data passed to the callback
+ * @destroy_data: #GDestroyNotify for user_data
*
* Create a new #GstEGLDisplay that wraps and refcount @display.
*
@@ -528,13 +532,16 @@ G_DEFINE_BOXED_TYPE (GstEGLImageMemoryPool, gst_egl_image_memory_pool,
*
*/
GstEGLDisplay *
-gst_egl_display_new (EGLDisplay display)
+gst_egl_display_new (EGLDisplay display, gpointer user_data,
+ GDestroyNotify destroy_data)
{
GstEGLDisplay *gdisplay;
gdisplay = g_slice_new (GstEGLDisplay);
- gdisplay->display = display;
gdisplay->refcount = 1;
+ gdisplay->display = display;
+ gdisplay->user_data = user_data;
+ gdisplay->destroy_data = destroy_data;
return gdisplay;
}
@@ -560,8 +567,8 @@ gst_egl_display_ref (GstEGLDisplay * display)
* gst_egl_display_unref:
* @display: a #GstEGLDisplay
*
- * Decrease the refcount of @display and when the refcount
- * is 0 terminates the wrapped EGL display.
+ * Decrease the refcount of @display and calls provided destroy function on
+ * last reference.
*
*/
void
@@ -570,8 +577,9 @@ gst_egl_display_unref (GstEGLDisplay * display)
g_return_if_fail (display != NULL);
if (g_atomic_int_dec_and_test (&display->refcount)) {
- if (display->display != EGL_NO_DISPLAY)
- eglTerminate (display->display);
+ if (display->destroy_data) {
+ display->destroy_data (display->user_data);
+ }
g_slice_free (GstEGLDisplay, display);
}
}
diff --git a/gst/egl/egl.h b/gst/egl/egl.h
index 917d28f..f854263 100644
--- a/gst/egl/egl.h
+++ b/gst/egl/egl.h
@@ -69,7 +69,8 @@ GstBuffer *gst_egl_image_memory_pool_acquire_buffer (GstEGLImageMemoryPool *
pool, gint idx, gpointer user_data, GDestroyNotify destroy_data);
/* EGLDisplay wrapper with refcount, connection is closed after last ref is gone */
-GstEGLDisplay *gst_egl_display_new (EGLDisplay display);
+GstEGLDisplay * gst_egl_display_new (EGLDisplay display, gpointer user_data,
+ GDestroyNotify destroy_data);
GstEGLDisplay *gst_egl_display_ref (GstEGLDisplay * display);
void gst_egl_display_unref (GstEGLDisplay * display);
EGLDisplay gst_egl_display_get (GstEGLDisplay * display);