2008-06-19 23:38:36 +00:00
|
|
|
/*
|
2008-05-19 16:57:39 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
2008-05-19 16:57:39 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2008-08-11 07:52:16 +00:00
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2008-05-19 16:57:39 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-05-19 16:57:39 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 15:08:11 +00:00
|
|
|
#include <stdio.h>
|
2009-10-16 14:29:08 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
#include <gst/gst.h>
|
2009-04-19 22:52:41 +00:00
|
|
|
#include <gst/video/gstvideosink.h>
|
2012-09-16 11:23:09 +00:00
|
|
|
#include "gstgldownload.h"
|
|
|
|
#include "gstglmemory.h"
|
2013-01-09 13:30:03 +00:00
|
|
|
#include "gstglfeature.h"
|
2013-01-16 04:21:44 +00:00
|
|
|
#include "gstglapi.h"
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
#include "gstgldisplay.h"
|
2009-08-03 15:52:31 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
#define USING_OPENGL(display) (display->gl_api & GST_GL_API_OPENGL)
|
|
|
|
#define USING_OPENGL3(display) (display->gl_api & GST_GL_API_OPENGL3)
|
|
|
|
#define USING_GLES(display) (display->gl_api & GST_GL_API_GLES)
|
|
|
|
#define USING_GLES2(display) (display->gl_api & GST_GL_API_GLES2)
|
|
|
|
#define USING_GLES3(display) (display->gl_api & GST_GL_API_GLES3)
|
2008-09-13 01:32:04 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_display_debug
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2008-09-13 01:32:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display");
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDisplay, gst_gl_display, G_TYPE_OBJECT,
|
2009-02-11 06:39:14 +00:00
|
|
|
DEBUG_INIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
#define GST_GL_DISPLAY_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_DISPLAY, GstGLDisplayPrivate))
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_display_finalize (GObject * object);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
|
|
|
/* Called in the gl thread, protected by lock and unlock */
|
2009-02-11 06:39:14 +00:00
|
|
|
gpointer gst_gl_display_thread_create_context (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_destroy_context (GstGLDisplay * display);
|
|
|
|
void gst_gl_display_thread_run_generic (GstGLDisplay * display);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
struct _GstGLDisplayPrivate
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window;
|
2013-01-09 14:44:54 +00:00
|
|
|
|
|
|
|
/* generic gl code */
|
|
|
|
GstGLDisplayThreadFunc generic_callback;
|
|
|
|
gpointer data;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
|
|
--------------------- For klass GstGLDisplay ---------------
|
|
|
|
----------------------------------------------------------*/
|
2008-05-18 11:12:46 +00:00
|
|
|
static void
|
|
|
|
gst_gl_display_class_init (GstGLDisplayClass * klass)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLDisplayPrivate));
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_display_init (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
display->priv = GST_GL_DISPLAY_GET_PRIVATE (display);
|
|
|
|
|
|
|
|
/* thread safe */
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_init (&display->mutex);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
display->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_memory_init ();
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_finalize (GObject * object)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLDisplay *display = GST_GL_DISPLAY (object);
|
2008-08-01 09:00:49 +00:00
|
|
|
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_clear (&display->mutex);
|
|
|
|
|
2011-11-24 15:02:32 +00:00
|
|
|
if (display->error_message) {
|
|
|
|
g_free (display->error_message);
|
|
|
|
display->error_message = NULL;
|
|
|
|
}
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
if (display->gl_vtable) {
|
|
|
|
g_slice_free (GstGLFuncs, display->gl_vtable);
|
|
|
|
display->gl_vtable = NULL;
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (display->priv->window) {
|
|
|
|
gst_object_unref (display->priv->window);
|
|
|
|
display->priv->window = NULL;
|
2012-12-19 03:32:20 +00:00
|
|
|
}
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_display_parent_class)->finalize (object);
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
//------------------------------------------------------------
|
|
|
|
//------------------ BEGIN GL THREAD PROCS -------------------
|
|
|
|
//------------------------------------------------------------
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called in the gl thread */
|
2008-06-13 00:01:26 +00:00
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
void
|
2013-06-11 15:04:55 +00:00
|
|
|
gst_gl_display_set_error (GstGLDisplay * display, const char *format, ...)
|
2008-06-13 00:01:26 +00:00
|
|
|
{
|
2013-06-11 15:04:55 +00:00
|
|
|
va_list args;
|
2008-06-13 00:01:26 +00:00
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
if (display->error_message)
|
|
|
|
g_free (display->error_message);
|
2008-06-13 00:01:26 +00:00
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
va_start (args, format);
|
|
|
|
display->error_message = g_strdup_vprintf (format, args);
|
|
|
|
va_end (args);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
GST_WARNING ("%s", display->error_message);
|
2012-07-06 08:51:02 +00:00
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
void
|
2013-06-11 15:04:55 +00:00
|
|
|
gst_gl_display_thread_run_generic (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2013-06-11 15:04:55 +00:00
|
|
|
GST_TRACE ("running function:%p data:%p",
|
|
|
|
display->priv->generic_callback, display->priv->data);
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
display->priv->generic_callback (display, display->priv->data);
|
2008-08-11 17:01:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
/*------------------------------------------------------------
|
|
|
|
--------------------- BEGIN PUBLIC -------------------------
|
|
|
|
----------------------------------------------------------*/
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_lock (GstGLDisplay * display)
|
|
|
|
{
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_lock (&display->mutex);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_unlock (GstGLDisplay * display)
|
|
|
|
{
|
2013-02-18 10:40:34 +00:00
|
|
|
g_mutex_unlock (&display->mutex);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 17:27:43 +00:00
|
|
|
/* Called by the first gl element of a video/x-raw-gl flow */
|
2009-02-11 06:39:14 +00:00
|
|
|
GstGLDisplay *
|
2008-05-18 11:12:46 +00:00
|
|
|
gst_gl_display_new (void)
|
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
return g_object_new (GST_GL_TYPE_DISPLAY, NULL);
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 17:01:33 +00:00
|
|
|
void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_thread_add (GstGLDisplay * display,
|
|
|
|
GstGLDisplayThreadFunc func, gpointer data)
|
2008-08-11 07:00:40 +00:00
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_DISPLAY (display));
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (display->priv->window));
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
2008-08-11 07:00:40 +00:00
|
|
|
gst_gl_display_lock (display);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2013-01-09 14:44:54 +00:00
|
|
|
display->priv->data = data;
|
|
|
|
display->priv->generic_callback = func;
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
gst_gl_window_send_message (display->priv->window,
|
2009-02-11 06:39:14 +00:00
|
|
|
GST_GL_WINDOW_CB (gst_gl_display_thread_run_generic), display);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2008-08-11 07:00:40 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
2008-05-18 11:12:46 +00:00
|
|
|
|
2013-06-11 15:04:55 +00:00
|
|
|
guintptr
|
2009-10-22 23:11:27 +00:00
|
|
|
gst_gl_display_get_internal_gl_context (GstGLDisplay * display)
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), 0);
|
|
|
|
g_return_val_if_fail (GST_GL_IS_WINDOW (display->priv->window), 0);
|
|
|
|
|
|
|
|
return gst_gl_window_get_gl_context (display->priv->window);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate)
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_DISPLAY (display));
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (display->priv->window));
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
if (!activate)
|
|
|
|
gst_gl_display_lock (display);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
gst_gl_window_activate (display->priv->window, activate);
|
|
|
|
|
2009-10-22 23:11:27 +00:00
|
|
|
if (activate)
|
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLAPI
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_display_get_gl_api (GstGLDisplay * display)
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
return display->gl_api;
|
|
|
|
}
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
gpointer
|
|
|
|
gst_gl_display_get_gl_vtable (GstGLDisplay * display)
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
gpointer gl;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
|
|
|
|
|
|
|
gl = display->gl_vtable;
|
|
|
|
|
|
|
|
return gl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_display_set_window (GstGLDisplay * display, GstGLWindow * window)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_GL_DISPLAY (display));
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
gst_gl_display_lock (display);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
if (display->priv->window)
|
|
|
|
gst_object_unref (display->priv->window);
|
|
|
|
|
|
|
|
display->priv->window = gst_object_ref (window);
|
|
|
|
|
|
|
|
gst_gl_display_unlock (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_display_get_window (GstGLDisplay * display)
|
2013-01-16 04:21:44 +00:00
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
gst_gl_display_lock (display);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
|
|
|
window =
|
|
|
|
display->priv->window ? gst_object_ref (display->priv->window) : NULL;
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gst_gl_display_unlock (display);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
return window;
|
2013-01-16 04:21:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_display_get_window_unlocked (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
|
|
|
|
|
|
|
return display->priv->window ? gst_object_ref (display->priv->window) : NULL;
|
|
|
|
}
|