2013-07-10 09:31:17 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
|
|
|
* Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: - Window resize handling
|
|
|
|
* - Event handling input event handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
#include <gst/gst.h>
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-07-10 09:31:17 +00:00
|
|
|
#include "gstglwindow_android_egl.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_debug
|
|
|
|
|
|
|
|
#define gst_gl_window_android_egl_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstGLWindowAndroidEGL, gst_gl_window_android_egl,
|
|
|
|
GST_GL_TYPE_WINDOW);
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
static guintptr gst_gl_window_android_egl_get_display (GstGLWindow * window);
|
2013-08-21 03:57:56 +00:00
|
|
|
static guintptr gst_gl_window_android_egl_get_window_handle (GstGLWindow *
|
|
|
|
window);
|
2013-07-10 09:31:17 +00:00
|
|
|
static void gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
|
|
|
static void gst_gl_window_android_egl_draw (GstGLWindow * window, guint width,
|
|
|
|
guint height);
|
|
|
|
static void gst_gl_window_android_egl_run (GstGLWindow * window);
|
2013-10-01 13:47:54 +00:00
|
|
|
static void gst_gl_window_android_egl_quit (GstGLWindow * window);
|
2013-09-25 02:26:57 +00:00
|
|
|
static void gst_gl_window_android_egl_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy);
|
2013-08-21 03:57:56 +00:00
|
|
|
static gboolean gst_gl_window_android_egl_open (GstGLWindow * window,
|
|
|
|
GError ** error);
|
2013-07-10 09:31:17 +00:00
|
|
|
static void gst_gl_window_android_egl_close (GstGLWindow * window);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_class_init (GstGLWindowAndroidEGLClass * klass)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
window_class->get_display =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_display);
|
2013-08-21 03:57:56 +00:00
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_get_window_handle);
|
2013-07-10 09:31:17 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_set_window_handle);
|
|
|
|
window_class->draw_unlocked =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_draw);
|
|
|
|
window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_run);
|
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_quit);
|
2013-09-25 02:26:57 +00:00
|
|
|
window_class->send_message_async =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_send_message_async);
|
2013-08-21 03:57:56 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_open);
|
2013-07-10 09:31:17 +00:00
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_android_egl_close);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_init (GstGLWindowAndroidEGL * window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
GstGLWindowAndroidEGL *
|
|
|
|
gst_gl_window_android_egl_new (void)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window;
|
|
|
|
|
|
|
|
GST_DEBUG ("creating Android EGL window");
|
|
|
|
|
|
|
|
window = g_object_new (GST_GL_TYPE_WINDOW_ANDROID_EGL, NULL);
|
|
|
|
|
|
|
|
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_window_android_egl_open (GstGLWindow * window, GError ** error)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl;
|
|
|
|
|
|
|
|
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
window_egl->main_context = g_main_context_new ();
|
|
|
|
window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-21 03:57:56 +00:00
|
|
|
gst_gl_window_android_egl_close (GstGLWindow * window)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl;
|
|
|
|
|
|
|
|
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
g_main_loop_unref (window_egl->loop);
|
|
|
|
g_main_context_unref (window_egl->main_context);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_run (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl;
|
|
|
|
|
|
|
|
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
GST_LOG ("starting main loop");
|
|
|
|
g_main_loop_run (window_egl->loop);
|
|
|
|
GST_LOG ("exiting main loop");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-01 13:47:54 +00:00
|
|
|
gst_gl_window_android_egl_quit (GstGLWindow * window)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl;
|
|
|
|
|
|
|
|
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
GST_LOG ("sending quit");
|
|
|
|
|
|
|
|
g_main_loop_quit (window_egl->loop);
|
|
|
|
|
|
|
|
GST_LOG ("quit sent");
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _GstGLMessage
|
|
|
|
{
|
|
|
|
GstGLWindowCB callback;
|
|
|
|
gpointer data;
|
2013-09-25 02:26:57 +00:00
|
|
|
GDestroyNotify destroy;
|
2013-07-10 09:31:17 +00:00
|
|
|
} GstGLMessage;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_run_message (GstGLMessage * message)
|
|
|
|
{
|
|
|
|
if (message->callback)
|
|
|
|
message->callback (message->data);
|
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
if (message->destroy)
|
|
|
|
message->destroy (message->data);
|
|
|
|
|
|
|
|
g_slice_free (GstGLMessage, message);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-25 02:26:57 +00:00
|
|
|
gst_gl_window_android_egl_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy)
|
2013-07-10 09:31:17 +00:00
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl;
|
2013-09-25 02:26:57 +00:00
|
|
|
GstGLMessage *message;
|
2013-07-10 09:31:17 +00:00
|
|
|
|
|
|
|
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
2013-09-25 02:26:57 +00:00
|
|
|
message = g_slice_new (GstGLMessage);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
message->callback = callback;
|
|
|
|
message->data = data;
|
|
|
|
message->destroy = destroy;
|
2013-07-10 09:31:17 +00:00
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
g_main_context_invoke (window_egl->main_context, (GSourceFunc) _run_message,
|
|
|
|
message);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
window_egl->native_window = (EGLNativeWindowType) handle;
|
|
|
|
}
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_window_android_egl_get_window_handle (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
|
|
|
|
return (guintptr) window_egl->native_window;
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:31:17 +00:00
|
|
|
struct draw
|
|
|
|
{
|
|
|
|
GstGLWindowAndroidEGL *window;
|
|
|
|
guint width, height;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
|
|
|
struct draw *draw_data = data;
|
|
|
|
GstGLWindowAndroidEGL *window_egl = draw_data->window;
|
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_egl);
|
2013-10-01 13:47:54 +00:00
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
|
|
|
GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
2013-07-10 09:31:17 +00:00
|
|
|
|
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
|
|
|
|
2013-08-21 03:57:56 +00:00
|
|
|
context_class->swap_buffers (context);
|
2013-10-01 13:47:54 +00:00
|
|
|
|
|
|
|
gst_object_unref (context);
|
2013-07-10 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_android_egl_draw (GstGLWindow * window, guint width, guint height)
|
|
|
|
{
|
|
|
|
struct draw draw_data;
|
|
|
|
|
|
|
|
draw_data.window = GST_GL_WINDOW_ANDROID_EGL (window);
|
|
|
|
draw_data.width = width;
|
|
|
|
draw_data.height = height;
|
|
|
|
|
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, &draw_data);
|
|
|
|
}
|
2013-10-01 13:47:54 +00:00
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_window_android_egl_get_display (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|