mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
[387/906] glmixer: add a glmixer base element
glmixer can be seen as a glfilter except it handles N requested sink pads. Each sink pad and the src pad are video/x-raw-gl. glmixer is responsible for managing different framerates from inputs. It uses OpenGL context sharing. It means that each input is in its own OpenGL context shared together and shared with the OpenGL context of the ouput gl chain. Also add a glmosaic which is an example of implementation of glmixer. For now glmosaic is a cube but it will be fixed in the next commits. For now the glmixer has some weird behaviours in some configurations but it will be improved in the next commits. The autotools builds is temporarly broken since those changes have been made on win32.
This commit is contained in:
parent
1dad35ef93
commit
db7d436bd8
20 changed files with 2145 additions and 67 deletions
|
@ -70,6 +70,7 @@ void gst_gl_display_thread_init_download (GstGLDisplay * display);
|
|||
void gst_gl_display_thread_do_download (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_gen_fbo (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_use_fbo (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_use_fbo_v2 (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_del_fbo (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_gen_shader (GstGLDisplay * display);
|
||||
void gst_gl_display_thread_del_shader (GstGLDisplay * display);
|
||||
|
@ -123,7 +124,6 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
|
|||
//gl context
|
||||
display->gl_thread = NULL;
|
||||
display->gl_window = NULL;
|
||||
display->visible = FALSE;
|
||||
display->isAlive = TRUE;
|
||||
display->texture_pool = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
|
||||
|
@ -182,6 +182,7 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
|
|||
display->use_fbo_width = 0;
|
||||
display->use_fbo_height = 0;
|
||||
display->use_fbo_scene_cb = NULL;
|
||||
display->use_fbo_scene_cb_v2 = NULL;
|
||||
display->use_fbo_proj_param1 = 0;
|
||||
display->use_fbo_proj_param2 = 0;
|
||||
display->use_fbo_proj_param3 = 0;
|
||||
|
@ -522,6 +523,8 @@ gst_gl_display_finalize (GObject * object)
|
|||
display->clientDrawCallback = NULL;
|
||||
if (display->use_fbo_scene_cb)
|
||||
display->use_fbo_scene_cb = NULL;
|
||||
if (display->use_fbo_scene_cb_v2)
|
||||
display->use_fbo_scene_cb_v2 = NULL;
|
||||
if (display->use_fbo_stuff)
|
||||
display->use_fbo_stuff = NULL;
|
||||
}
|
||||
|
@ -538,9 +541,7 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
|
|||
GLenum err = 0;
|
||||
|
||||
gst_gl_display_lock (display);
|
||||
display->gl_window =
|
||||
gst_gl_window_new (display->upload_width, display->upload_height,
|
||||
display->external_gl_context);
|
||||
display->gl_window = gst_gl_window_new (display->external_gl_context);
|
||||
|
||||
if (!display->gl_window) {
|
||||
display->isAlive = FALSE;
|
||||
|
@ -1654,6 +1655,47 @@ gst_gl_display_thread_use_fbo (GstGLDisplay * display)
|
|||
}
|
||||
|
||||
|
||||
/* Called in a gl thread
|
||||
* Need full shader support */
|
||||
void
|
||||
gst_gl_display_thread_use_fbo_v2 (GstGLDisplay * display)
|
||||
{
|
||||
GLint viewport_dim[4];
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->use_fbo);
|
||||
|
||||
//setup a texture to render to
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture);
|
||||
|
||||
//attach the texture to the FBO to renderer to
|
||||
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture, 0);
|
||||
|
||||
glGetIntegerv (GL_VIEWPORT, viewport_dim);
|
||||
|
||||
glViewport (0, 0, display->use_fbo_width, display->use_fbo_height);
|
||||
|
||||
#ifndef OPENGL_ES2
|
||||
glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
|
||||
#endif
|
||||
|
||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//the opengl scene
|
||||
display->use_fbo_scene_cb_v2 (display->use_fbo_stuff);
|
||||
|
||||
#ifndef OPENGL_ES2
|
||||
glDrawBuffer (GL_NONE);
|
||||
#endif
|
||||
|
||||
glViewport (viewport_dim[0], viewport_dim[1],
|
||||
viewport_dim[2], viewport_dim[3]);
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Called in the gl thread */
|
||||
void
|
||||
gst_gl_display_thread_del_fbo (GstGLDisplay * display)
|
||||
|
@ -1807,7 +1849,8 @@ gst_gl_display_on_draw (GstGLDisplay * display)
|
|||
display->redisplay_texture_width, display->redisplay_texture_height);
|
||||
|
||||
if (doRedisplay && display->gl_window)
|
||||
gst_gl_window_draw_unlocked (display->gl_window);
|
||||
gst_gl_window_draw_unlocked (display->gl_window,
|
||||
display->redisplay_texture_width, display->redisplay_texture_height);
|
||||
}
|
||||
//default opengl scene
|
||||
else {
|
||||
|
@ -2064,24 +2107,22 @@ gst_gl_display_new (void)
|
|||
}
|
||||
|
||||
|
||||
/* Create an opengl context (one context for one GstGLDisplay)
|
||||
* Called by the first gl element of a video/x-raw-gl flow */
|
||||
/* Create an opengl context (one context for one GstGLDisplay) */
|
||||
void
|
||||
gst_gl_display_create_context (GstGLDisplay * display,
|
||||
GLint width, GLint height, gulong external_gl_context)
|
||||
gst_gl_display_create_context (GstGLDisplay * display, gulong external_gl_context)
|
||||
{
|
||||
gst_gl_display_lock (display);
|
||||
|
||||
display->upload_width = width;
|
||||
display->upload_height = height;
|
||||
display->external_gl_context = external_gl_context;
|
||||
if (!display->gl_window) {
|
||||
display->external_gl_context = external_gl_context;
|
||||
|
||||
display->gl_thread = g_thread_create (
|
||||
(GThreadFunc) gst_gl_display_thread_create_context, display, TRUE, NULL);
|
||||
display->gl_thread = g_thread_create (
|
||||
(GThreadFunc) gst_gl_display_thread_create_context, display, TRUE, NULL);
|
||||
|
||||
g_cond_wait (display->cond_create_context, display->mutex);
|
||||
g_cond_wait (display->cond_create_context, display->mutex);
|
||||
|
||||
GST_INFO ("gl thread created");
|
||||
GST_INFO ("gl thread created");
|
||||
}
|
||||
|
||||
gst_gl_display_unlock (display);
|
||||
}
|
||||
|
@ -2112,7 +2153,7 @@ gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
|
|||
}
|
||||
display->keep_aspect_ratio = keep_aspect_ratio;
|
||||
if (display->gl_window)
|
||||
gst_gl_window_draw (display->gl_window);
|
||||
gst_gl_window_draw (display->gl_window, width, height);
|
||||
}
|
||||
gst_gl_display_unlock (display);
|
||||
|
||||
|
@ -2327,6 +2368,30 @@ gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
|
|||
return isAlive;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
|
||||
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
|
||||
GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff)
|
||||
{
|
||||
gboolean isAlive = TRUE;
|
||||
|
||||
gst_gl_display_lock (display);
|
||||
isAlive = display->isAlive;
|
||||
if (isAlive) {
|
||||
display->use_fbo = fbo;
|
||||
display->use_depth_buffer = depth_buffer;
|
||||
display->use_fbo_texture = texture_fbo;
|
||||
display->use_fbo_width = texture_fbo_width;
|
||||
display->use_fbo_height = texture_fbo_height;
|
||||
display->use_fbo_scene_cb_v2 = cb;
|
||||
display->use_fbo_stuff = stuff;
|
||||
gst_gl_window_send_message (display->gl_window,
|
||||
GST_GL_WINDOW_CB (gst_gl_display_thread_use_fbo_v2), display);
|
||||
}
|
||||
gst_gl_display_unlock (display);
|
||||
|
||||
return isAlive;
|
||||
}
|
||||
|
||||
/* Called by gltestsrc and glfilter */
|
||||
void
|
||||
|
@ -2402,6 +2467,27 @@ gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb)
|
|||
gst_gl_display_unlock (display);
|
||||
}
|
||||
|
||||
gulong
|
||||
gst_gl_display_get_internal_gl_context (GstGLDisplay * display)
|
||||
{
|
||||
gulong external_gl_context = 0;
|
||||
gst_gl_display_lock (display);
|
||||
external_gl_context =
|
||||
gst_gl_window_get_internal_gl_context (display->gl_window);
|
||||
gst_gl_display_unlock (display);
|
||||
return external_gl_context;
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate)
|
||||
{
|
||||
if (!activate)
|
||||
gst_gl_display_lock (display);
|
||||
gst_gl_window_activate_gl_context (display->gl_window, activate);
|
||||
if (activate)
|
||||
gst_gl_display_unlock (display);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//------------------------ END PUBLIC ------------------------
|
||||
|
|
|
@ -73,6 +73,7 @@ typedef void (*GstGLDisplayThreadFunc) (GstGLDisplay * display, gpointer data);
|
|||
|
||||
//opengl scene callback
|
||||
typedef void (*GLCB) (gint, gint, guint, gpointer stuff);
|
||||
typedef void (*GLCB_V2) (gpointer stuff);
|
||||
|
||||
struct _GstGLDisplay
|
||||
{
|
||||
|
@ -84,7 +85,6 @@ struct _GstGLDisplay
|
|||
//gl context
|
||||
GThread *gl_thread;
|
||||
GstGLWindow *gl_window;
|
||||
gboolean visible;
|
||||
gboolean isAlive;
|
||||
GHashTable *texture_pool;
|
||||
|
||||
|
@ -149,6 +149,7 @@ struct _GstGLDisplay
|
|||
GLuint use_fbo_width;
|
||||
GLuint use_fbo_height;
|
||||
GLCB use_fbo_scene_cb;
|
||||
GLCB_V2 use_fbo_scene_cb_v2;
|
||||
gdouble use_fbo_proj_param1;
|
||||
gdouble use_fbo_proj_param2;
|
||||
gdouble use_fbo_proj_param3;
|
||||
|
@ -237,7 +238,7 @@ GType gst_gl_display_get_type (void);
|
|||
GstGLDisplay *gst_gl_display_new (void);
|
||||
|
||||
void gst_gl_display_create_context (GstGLDisplay * display,
|
||||
GLint width, GLint height, gulong external_gl_context);
|
||||
gulong external_gl_context);
|
||||
gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture,
|
||||
gint width, gint height, gboolean keep_aspect_ratio);
|
||||
|
||||
|
@ -267,6 +268,9 @@ gboolean gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
|
|||
gint input_texture_height, GLuint input_texture, gdouble proj_param1,
|
||||
gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
|
||||
GstGLDisplayProjection projection, gpointer * stuff);
|
||||
gboolean gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
|
||||
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
|
||||
GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff);
|
||||
void gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo,
|
||||
GLuint depth_buffer);
|
||||
|
||||
|
@ -280,4 +284,7 @@ void gst_gl_display_set_client_reshape_callback (GstGLDisplay * display,
|
|||
CRCB cb);
|
||||
void gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb);
|
||||
|
||||
gulong gst_gl_display_get_internal_gl_context (GstGLDisplay * display);
|
||||
void gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
#define glUniformMatrix4fvARB glUniformMatrix4fv
|
||||
#define glGetUniformLocationARB glGetUniformLocation
|
||||
#define glGetAttribLocationARB glGetAttribLocation
|
||||
#define glBindAttribLocationARB glBindAttribLocation
|
||||
|
||||
/* UNSUPPORTED */
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ gst_gl_filter_src_query (GstPad * pad, GstQuery * query)
|
|||
/* this gl filter is a sink in terms of the gl chain */
|
||||
gst_structure_set (structure, "gstgldisplay", G_TYPE_POINTER, filter->display, NULL);
|
||||
} else {
|
||||
/* at least one gl element is before in our gl chain */
|
||||
/* at least one gl element is after in our gl chain */
|
||||
res = g_strcmp0 (gst_element_get_name (parent), gst_structure_get_name (structure)) == 0;
|
||||
}
|
||||
if (!res)
|
||||
|
@ -222,11 +222,13 @@ gst_gl_filter_start (GstBaseTransform * bt)
|
|||
if (isPerformed) {
|
||||
const GValue *id_value = gst_structure_get_value (structure, "gstgldisplay");
|
||||
if (G_VALUE_HOLDS_POINTER (id_value))
|
||||
/* at least one gl element is before in our gl chain */
|
||||
/* at least one gl element is after in our gl chain */
|
||||
filter->display = g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
|
||||
else
|
||||
else {
|
||||
/* this gl filter is a sink in terms of the gl chain */
|
||||
filter->display = gst_gl_display_new ();
|
||||
gst_gl_display_create_context (filter->display, 0);
|
||||
}
|
||||
}
|
||||
|
||||
gst_query_unref (query);
|
||||
|
|
1294
gst-libs/gst/gl/gstglmixer.c
Normal file
1294
gst-libs/gst/gl/gstglmixer.c
Normal file
File diff suppressed because it is too large
Load diff
107
gst-libs/gst/gl/gstglmixer.h
Normal file
107
gst-libs/gst/gl/gstglmixer.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_GL_MIXER_H__
|
||||
#define __GST_GL_MIXER_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include "gstglmixerpad.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_GL_MIXER (gst_gl_mixer_get_type())
|
||||
#define GST_GL_MIXER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_MIXER, GstGLMixer))
|
||||
#define GST_GL_MIXER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_MIXER, GstGLMixerClass))
|
||||
#define GST_IS_GL_MIXER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_MIXER))
|
||||
#define GST_IS_GL_MIXER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_MIXER))
|
||||
#define GST_GL_MIXER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_GL_MIXER,GstGLMixerClass))
|
||||
|
||||
typedef struct _GstGLMixer GstGLMixer;
|
||||
typedef struct _GstGLMixerClass GstGLMixerClass;
|
||||
|
||||
typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
|
||||
GstCaps* outcaps);
|
||||
typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
|
||||
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
|
||||
GArray *buffers, GstBuffer *outbuf);
|
||||
|
||||
struct _GstGLMixer
|
||||
{
|
||||
GstElement element;
|
||||
|
||||
/* pad */
|
||||
GstPad *srcpad;
|
||||
|
||||
/* Lock to prevent the state to change while blending */
|
||||
GMutex *state_lock;
|
||||
/* Sink pads using Collect Pads from core's base library */
|
||||
GstCollectPads *collect;
|
||||
/* sinkpads, a GSList of GstGLMixerPads */
|
||||
GSList *sinkpads;
|
||||
|
||||
GArray *array_buffers;
|
||||
|
||||
gint numpads;
|
||||
|
||||
GstClockTime last_ts;
|
||||
|
||||
/* the master pad */
|
||||
GstGLMixerPad *master;
|
||||
|
||||
gint width;
|
||||
gint height;
|
||||
gboolean setcaps;
|
||||
gboolean sendseg;
|
||||
|
||||
gint fps_n;
|
||||
gint fps_d;
|
||||
|
||||
/* Next available sinkpad index */
|
||||
gint next_sinkpad;
|
||||
|
||||
/* sink event handling */
|
||||
GstPadEventFunction collect_event;
|
||||
guint64 segment_position;
|
||||
gdouble segment_rate;
|
||||
|
||||
GstGLDisplay *display;
|
||||
GLuint fbo;
|
||||
GLuint depthbuffer;
|
||||
};
|
||||
|
||||
struct _GstGLMixerClass
|
||||
{
|
||||
GstElementClass parent_class;
|
||||
|
||||
GstGLMixerSetCaps set_caps;
|
||||
GstGLMixerReset reset;
|
||||
GstGLMixerProcessFunc process_buffers;
|
||||
};
|
||||
|
||||
GType gst_gl_mixer_get_type(void);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GST_GL_MIXER_H__ */
|
77
gst-libs/gst/gl/gstglmixerpad.h
Normal file
77
gst-libs/gst/gl/gstglmixerpad.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_GL_MIXER_PAD_H__
|
||||
#define __GST_GL_MIXER_PAD_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstcollectpads.h>
|
||||
|
||||
#include "gstglbuffer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_GL_MIXER_PAD (gst_gl_mixer_pad_get_type())
|
||||
#define GST_GL_MIXER_PAD(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_MIXER_PAD, GstGLMixerPad))
|
||||
#define GST_GL_MIXER_PAD_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GL_MIXER_PAD, GstGLMixerPadiClass))
|
||||
#define GST_IS_GL_MIXER_PAD(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_MIXER_PAD))
|
||||
#define GST_IS_GL_MIXER_PAD_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GL_MIXER_PAD))
|
||||
|
||||
typedef struct _GstGLMixerPad GstGLMixerPad;
|
||||
typedef struct _GstGLMixerPadClass GstGLMixerPadClass;
|
||||
typedef struct _GstGLMixerCollect GstGLMixerCollect;
|
||||
|
||||
struct _GstGLMixerCollect
|
||||
{
|
||||
GstCollectData collect; /* we extend the CollectData */
|
||||
|
||||
GstBuffer *buffer; /* the queued buffer for this pad */
|
||||
|
||||
GstGLMixerPad *mixpad;
|
||||
};
|
||||
|
||||
/* all information needed for one video stream */
|
||||
struct _GstGLMixerPad
|
||||
{
|
||||
GstPad parent; /* subclass the pad */
|
||||
|
||||
gint64 queued;
|
||||
|
||||
gint width;
|
||||
gint height;
|
||||
gint fps_n;
|
||||
gint fps_d;
|
||||
|
||||
GstGLDisplay *display;
|
||||
|
||||
GstGLMixerCollect *mixcol;
|
||||
};
|
||||
|
||||
struct _GstGLMixerPadClass
|
||||
{
|
||||
GstPadClass parent_class;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GST_GL_MIXER_PAD_H__ */
|
|
@ -66,6 +66,8 @@ gst_gl_shader_finalize (GObject * object)
|
|||
shader = GST_GL_SHADER (object);
|
||||
priv = shader->priv;
|
||||
|
||||
g_debug ("finalizing shader %ud", priv->program_handle);
|
||||
|
||||
g_free (priv->vertex_src);
|
||||
g_free (priv->fragment_src);
|
||||
|
||||
|
@ -81,6 +83,8 @@ gst_gl_shader_finalize (GObject * object)
|
|||
/* g_debug ("program deletion status:%s", status == GL_TRUE ? "true" : "false" ); */
|
||||
}
|
||||
|
||||
g_debug ("shader deleted %ud", priv->program_handle);
|
||||
|
||||
priv->fragment_handle = 0;
|
||||
priv->vertex_handle = 0;
|
||||
priv->program_handle = 0;
|
||||
|
@ -538,6 +542,18 @@ gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar * name)
|
|||
return glGetAttribLocationARB (priv->program_handle, name);
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_shader_bind_attribute_location (GstGLShader * shader, GLuint index, const gchar * name)
|
||||
{
|
||||
GstGLShaderPrivate *priv;
|
||||
|
||||
priv = shader->priv;
|
||||
|
||||
g_return_if_fail (priv->program_handle != 0);
|
||||
|
||||
glBindAttribLocationARB (priv->program_handle, index, name);
|
||||
}
|
||||
|
||||
GQuark
|
||||
gst_gl_shader_error_quark (void)
|
||||
{
|
||||
|
|
|
@ -99,6 +99,7 @@ void gst_gl_shader_set_uniform_matrix_4fv (GstGLShader * shader, const gchar * n
|
|||
GLsizei count, GLboolean transpose, const GLfloat* value);
|
||||
|
||||
GLint gst_gl_shader_get_attribute_location (GstGLShader *shader, const gchar *name);
|
||||
void gst_gl_shader_bind_attribute_location (GstGLShader * shader, GLuint index, const gchar * name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -79,15 +79,18 @@ struct _GstGLWindowClass {
|
|||
GQuark gst_gl_window_error_quark (void);
|
||||
GType gst_gl_window_get_type (void);
|
||||
|
||||
GstGLWindow * gst_gl_window_new (gint width, gint height, gulong external_gl_context);
|
||||
GstGLWindow * gst_gl_window_new (gulong external_gl_context);
|
||||
|
||||
gulong gst_gl_window_get_internal_gl_context (GstGLWindow *window);
|
||||
void gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate);
|
||||
|
||||
void gst_gl_window_set_external_window_id (GstGLWindow *window, gulong id);
|
||||
void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
|
||||
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback, gpointer data);
|
||||
void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
|
||||
|
||||
void gst_gl_window_draw_unlocked (GstGLWindow *window);
|
||||
void gst_gl_window_draw (GstGLWindow *window);
|
||||
void gst_gl_window_draw_unlocked (GstGLWindow *window, gint width, gint height);
|
||||
void gst_gl_window_draw (GstGLWindow *window, gint width, gint height);
|
||||
void gst_gl_window_run_loop (GstGLWindow *window);
|
||||
void gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ gst_gl_window_init (GstGLWindow * window)
|
|||
|
||||
/* Must be called in the gl thread */
|
||||
GstGLWindow *
|
||||
gst_gl_window_new (gint width, gint height, DWORD_PTR external_gl_context)
|
||||
gst_gl_window_new (DWORD_PTR external_gl_context)
|
||||
{
|
||||
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
|
@ -162,15 +162,11 @@ gst_gl_window_new (gint width, gint height, DWORD_PTR external_gl_context)
|
|||
priv->is_closed = FALSE;
|
||||
priv->visible = FALSE;
|
||||
|
||||
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
|
||||
height +=
|
||||
2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
|
||||
|
||||
priv->internal_win_id = CreateWindowEx (0,
|
||||
"GSTGL",
|
||||
"OpenGL renderer",
|
||||
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
|
||||
x, y, width, height, (HWND) NULL, (HMENU) NULL, hinstance, window);
|
||||
x, y, 0, 0, (HWND) NULL, (HMENU) NULL, hinstance, window);
|
||||
|
||||
if (!priv->internal_win_id) {
|
||||
g_debug ("failed to create gl window: %lud\n", (gulong) priv->internal_win_id);
|
||||
|
@ -193,6 +189,38 @@ gst_gl_window_error_quark (void)
|
|||
return g_quark_from_static_string ("gst-gl-window-error");
|
||||
}
|
||||
|
||||
gulong
|
||||
gst_gl_window_get_internal_gl_context (GstGLWindow *window)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
return (gulong) priv->gl_context;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
callback_activate_gl_context (GstGLWindowPrivate *priv)
|
||||
{
|
||||
if (!wglMakeCurrent (priv->device, priv->gl_context))
|
||||
g_debug ("failed to activate opengl context %lud\n", GetLastError ());
|
||||
}
|
||||
|
||||
void
|
||||
callback_inactivate_gl_context (GstGLWindowPrivate *priv)
|
||||
{
|
||||
if (!wglMakeCurrent (NULL, NULL))
|
||||
g_debug ("failed to inactivate opengl context %lud\n", GetLastError ());
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
if (activate)
|
||||
gst_gl_window_send_message (window, callback_activate_gl_context, priv);
|
||||
else
|
||||
gst_gl_window_send_message (window, callback_inactivate_gl_context, priv);
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id)
|
||||
{
|
||||
|
@ -285,19 +313,30 @@ gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
|
|||
}
|
||||
|
||||
void
|
||||
gst_gl_window_draw_unlocked (GstGLWindow * window)
|
||||
gst_gl_window_draw_unlocked (GstGLWindow * window, gint width, gint height)
|
||||
{
|
||||
gst_gl_window_draw (window);
|
||||
gst_gl_window_draw (window, width, height);
|
||||
}
|
||||
|
||||
/* Thread safe */
|
||||
void
|
||||
gst_gl_window_draw (GstGLWindow * window)
|
||||
gst_gl_window_draw (GstGLWindow * window, gint width, gint height)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
|
||||
if (!priv->visible) {
|
||||
HWND parent_id = GetProp (priv->internal_win_id, "gl_window_parent_id");
|
||||
/* if no parent the real size has to be set now because this has not been done
|
||||
* when at window creation */
|
||||
if (!parent_id) {
|
||||
RECT rect;
|
||||
GetClientRect (priv->internal_win_id, &rect);
|
||||
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
|
||||
height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
|
||||
MoveWindow (priv->internal_win_id, rect.left, rect.top, width, height, FALSE);
|
||||
}
|
||||
ShowWindowAsync (priv->internal_win_id, SW_SHOW);
|
||||
|
||||
priv->visible = TRUE;
|
||||
}
|
||||
|
||||
|
@ -369,11 +408,11 @@ gst_gl_window_set_pixel_format (GstGLWindow * window)
|
|||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 24;
|
||||
pfd.cRedBits = 0;
|
||||
pfd.cRedBits = 8;
|
||||
pfd.cRedShift = 0;
|
||||
pfd.cGreenBits = 0;
|
||||
pfd.cGreenBits = 8;
|
||||
pfd.cGreenShift = 0;
|
||||
pfd.cBlueBits = 0;
|
||||
pfd.cBlueBits = 8;
|
||||
pfd.cBlueShift = 0;
|
||||
pfd.cAlphaBits = 0;
|
||||
pfd.cAlphaShift = 0;
|
||||
|
@ -382,7 +421,7 @@ gst_gl_window_set_pixel_format (GstGLWindow * window)
|
|||
pfd.cAccumGreenBits = 0;
|
||||
pfd.cAccumBlueBits = 0;
|
||||
pfd.cAccumAlphaBits = 0;
|
||||
pfd.cDepthBits = 32;
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.cAuxBuffers = 0;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
|
@ -455,14 +494,15 @@ window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
g_assert (priv->internal_win_id == hWnd);
|
||||
|
||||
g_assert (priv->gl_context == wglGetCurrentContext ());
|
||||
g_assert (!wglGetCurrentContext() || priv->gl_context == wglGetCurrentContext ());
|
||||
|
||||
switch (uMsg) {
|
||||
|
||||
case WM_SIZE:
|
||||
{
|
||||
if (priv->resize_cb)
|
||||
if (priv->resize_cb) {
|
||||
priv->resize_cb (priv->resize_data, LOWORD (lParam), HIWORD (lParam));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ gst_gl_window_init (GstGLWindow * window)
|
|||
|
||||
/* Must be called in the gl thread */
|
||||
GstGLWindow *
|
||||
gst_gl_window_new (gint width, gint height, gulong external_gl_context)
|
||||
gst_gl_window_new (gulong external_gl_context)
|
||||
{
|
||||
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
|
@ -169,12 +169,8 @@ gst_gl_window_new (gint width, gint height, gulong external_gl_context)
|
|||
priv->is_closed = FALSE;
|
||||
priv->visible = FALSE;
|
||||
|
||||
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
|
||||
height +=
|
||||
2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
|
||||
|
||||
priv->internal_win_id = CreateWindow ("GSTGL", "OpenGL renderer", WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, //WS_POPUP | WS_BORDER | WS_SYSMENU | WS_CAPTION
|
||||
x, y, width, height, (HWND) NULL, (HMENU) NULL, hinstance, window);
|
||||
x, y, 0, 0, (HWND) NULL, (HMENU) NULL, hinstance, window);
|
||||
|
||||
if (!priv->internal_win_id) {
|
||||
g_debug ("failed to create gl window: %d\n", priv->internal_win_id);
|
||||
|
@ -200,6 +196,38 @@ gst_gl_window_error_quark (void)
|
|||
return g_quark_from_static_string ("gst-gl-window-error");
|
||||
}
|
||||
|
||||
gulong
|
||||
gst_gl_window_get_internal_gl_context (GstGLWindow *window)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
return (gulong) priv->gl_context;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
callback_activate_gl_context (GstGLWindowPrivate *priv)
|
||||
{
|
||||
/*if (!wglMakeCurrent (priv->device, priv->gl_context))
|
||||
g_debug ("failed to activate opengl context %lud\n", GetLastError ());*/
|
||||
}
|
||||
|
||||
void
|
||||
callback_inactivate_gl_context (GstGLWindowPrivate *priv)
|
||||
{
|
||||
/*if (!wglMakeCurrent (NULL, NULL))
|
||||
g_debug ("failed to inactivate opengl context %lud\n", GetLastError ());*/
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_window_activate_gl_context (GstGLWindow *window, gboolean activate)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
if (activate)
|
||||
gst_gl_window_send_message (window, callback_activate_gl_context, priv);
|
||||
else
|
||||
gst_gl_window_send_message (window, callback_inactivate_gl_context, priv);
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id)
|
||||
{
|
||||
|
@ -292,18 +320,28 @@ gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
|
|||
}
|
||||
|
||||
void
|
||||
gst_gl_window_draw_unlocked (GstGLWindow * window)
|
||||
gst_gl_window_draw_unlocked (GstGLWindow * window, gint width, gint height)
|
||||
{
|
||||
gst_gl_window_draw (window);
|
||||
gst_gl_window_draw (window, width, height);
|
||||
}
|
||||
|
||||
/* Thread safe */
|
||||
void
|
||||
gst_gl_window_draw (GstGLWindow * window)
|
||||
gst_gl_window_draw (GstGLWindow * window, gint width, gint height)
|
||||
{
|
||||
GstGLWindowPrivate *priv = window->priv;
|
||||
|
||||
if (!priv->visible) {
|
||||
HWND parent_id = GetProp (priv->internal_win_id, "gl_window_parent_id");
|
||||
/* if no parent the real size has to be set now because this has not been done
|
||||
* when at window creation */
|
||||
if (!parent_id) {
|
||||
RECT rect;
|
||||
GetClientRect (priv->internal_win_id, &rect);
|
||||
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
|
||||
height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
|
||||
MoveWindow (priv->internal_win_id, rect.left, rect.top, width, height, FALSE);
|
||||
}
|
||||
ShowWindowAsync (priv->internal_win_id, SW_SHOW);
|
||||
priv->visible = TRUE;
|
||||
}
|
||||
|
|
|
@ -394,8 +394,7 @@ gst_gl_colorscale_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
|||
colorscale->display = gst_gl_display_new ();
|
||||
|
||||
//init unvisible opengl context
|
||||
gst_gl_display_create_context (colorscale->display,
|
||||
colorscale->output_video_width, colorscale->output_video_height, 0);
|
||||
gst_gl_display_create_context (colorscale->display, 0);
|
||||
|
||||
//blocking call, init colorspace conversion if needed
|
||||
gst_gl_display_init_upload (colorscale->display,
|
||||
|
|
|
@ -118,7 +118,7 @@ static const gchar *cube_v_src =
|
|||
" -sin(zrot), cos(zrot), 0.0, 0.0, \n"
|
||||
" 0.0, 0.0, 1.0, 0.0, \n"
|
||||
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||
" gl_Position = matZ * matY * matX * u_matrix * a_position; \n"
|
||||
" gl_Position = u_matrix * matZ * matY * matX * a_position; \n"
|
||||
" v_texCoord = a_texCoord; \n"
|
||||
"} \n";
|
||||
|
||||
|
|
|
@ -376,8 +376,12 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
|
|||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
if (!glimage_sink->display)
|
||||
if (!glimage_sink->display) {
|
||||
glimage_sink->display = gst_gl_display_new ();
|
||||
|
||||
/* init opengl context */
|
||||
gst_gl_display_create_context (glimage_sink->display, 0);
|
||||
}
|
||||
break;
|
||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||
break;
|
||||
|
@ -470,10 +474,6 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|||
is_gl = FALSE;
|
||||
ok = gst_video_format_parse_caps (caps, &format, &width, &height);
|
||||
|
||||
/* init opengl context */
|
||||
gst_gl_display_create_context (glimage_sink->display,
|
||||
width, height, 0);
|
||||
|
||||
/* init colorspace conversion if needed */
|
||||
gst_gl_display_init_upload (glimage_sink->display, format,
|
||||
width, height, width, height);
|
||||
|
|
349
gst/gl/gstglmosaic.c
Normal file
349
gst/gl/gstglmosaic.c
Normal file
|
@ -0,0 +1,349 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstglmosaic.h"
|
||||
|
||||
#define GST_CAT_DEFAULT gst_gl_mosaic_debug
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||
|
||||
static const GstElementDetails element_details =
|
||||
GST_ELEMENT_DETAILS ("OpenGL mosaic",
|
||||
"Filter/Effect",
|
||||
"OpenGL mosaic",
|
||||
"Julien Isorce <julien.isorce@gmail.com>");
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
};
|
||||
|
||||
#define DEBUG_INIT(bla) \
|
||||
GST_DEBUG_CATEGORY_INIT (gst_gl_mosaic_debug, "glmosaic", 0, "glmosaic element");
|
||||
|
||||
GST_BOILERPLATE_FULL (GstGLMosaic, gst_gl_mosaic, GstGLMixer,
|
||||
GST_TYPE_GL_MIXER, DEBUG_INIT);
|
||||
|
||||
static void gst_gl_mosaic_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_gl_mosaic_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static void gst_gl_mosaic_reset (GstGLMixer * mixer);
|
||||
static gboolean gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps *outcaps);
|
||||
|
||||
static gboolean gst_gl_mosaic_proc (GstGLMixer * mixer,
|
||||
GArray *buffers, GstBuffer * outbuf);
|
||||
static void gst_gl_mosaic_callback (gpointer stuff);
|
||||
|
||||
//vertex source
|
||||
static const gchar *mosaic_v_src =
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"uniform mat4 u_matrix; \n"
|
||||
"uniform float xrot_degree, yrot_degree, zrot_degree; \n"
|
||||
"attribute vec4 a_position; \n"
|
||||
"attribute vec2 a_texCoord; \n"
|
||||
"varying vec2 v_texCoord; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" float PI = 3.14159265; \n"
|
||||
" float xrot = xrot_degree*2.0*PI/360.0; \n"
|
||||
" float yrot = yrot_degree*2.0*PI/360.0; \n"
|
||||
" float zrot = zrot_degree*2.0*PI/360.0; \n"
|
||||
" mat4 matX = mat4 ( \n"
|
||||
" 1.0, 0.0, 0.0, 0.0, \n"
|
||||
" 0.0, cos(xrot), sin(xrot), 0.0, \n"
|
||||
" 0.0, -sin(xrot), cos(xrot), 0.0, \n"
|
||||
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||
" mat4 matY = mat4 ( \n"
|
||||
" cos(yrot), 0.0, -sin(yrot), 0.0, \n"
|
||||
" 0.0, 1.0, 0.0, 0.0, \n"
|
||||
" sin(yrot), 0.0, cos(yrot), 0.0, \n"
|
||||
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||
" mat4 matZ = mat4 ( \n"
|
||||
" cos(zrot), sin(zrot), 0.0, 0.0, \n"
|
||||
" -sin(zrot), cos(zrot), 0.0, 0.0, \n"
|
||||
" 0.0, 0.0, 1.0, 0.0, \n"
|
||||
" 0.0, 0.0, 0.0, 1.0 ); \n"
|
||||
" gl_Position = u_matrix * matZ * matY * matX * a_position; \n"
|
||||
" v_texCoord = a_texCoord; \n"
|
||||
"} \n";
|
||||
|
||||
//fragment source
|
||||
static const gchar *mosaic_f_src =
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"uniform sampler2DRect s_texture; \n"
|
||||
"varying vec2 v_texCoord; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
//" gl_FragColor = vec4( 1.0, 0.5, 1.0, 1.0 );\n"
|
||||
" gl_FragColor = texture2DRect( s_texture, v_texCoord );\n"
|
||||
"} \n";
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_base_init (gpointer klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gst_element_class_set_details (element_class, &element_details);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_class_init (GstGLMosaicClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gobject_class->set_property = gst_gl_mosaic_set_property;
|
||||
gobject_class->get_property = gst_gl_mosaic_get_property;
|
||||
|
||||
GST_GL_MIXER_CLASS (klass)->set_caps = gst_gl_mosaic_init_shader;
|
||||
GST_GL_MIXER_CLASS (klass)->reset = gst_gl_mosaic_reset;
|
||||
GST_GL_MIXER_CLASS (klass)->process_buffers = gst_gl_mosaic_proc;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_init (GstGLMosaic * mosaic, GstGLMosaicClass * klass)
|
||||
{
|
||||
mosaic->shader = NULL;
|
||||
mosaic->input_gl_buffers = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
//GstGLMosaic *mixer = GST_GL_MOSAIC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
//GstGLMosaic* mixer = GST_GL_MOSAIC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_mosaic_reset (GstGLMixer * mixer)
|
||||
{
|
||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);
|
||||
|
||||
mosaic->input_gl_buffers = NULL;
|
||||
|
||||
//blocking call, wait the opengl thread has destroyed the shader
|
||||
gst_gl_display_del_shader (mixer->display, mosaic->shader);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
|
||||
{
|
||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);
|
||||
|
||||
//blocking call, wait the opengl thread has compiled the shader
|
||||
gst_gl_display_gen_shader (mixer->display, mosaic_v_src, mosaic_f_src,
|
||||
&mosaic->shader);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_mosaic_proc (GstGLMixer *mix,
|
||||
GArray *buffers, GstBuffer *outbuf)
|
||||
{
|
||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
|
||||
GstGLBuffer *gl_out_buffer = GST_GL_BUFFER (outbuf);
|
||||
|
||||
mosaic->input_gl_buffers = buffers;
|
||||
|
||||
//blocking call, use a FBO
|
||||
gst_gl_display_use_fbo_v2 (mix->display, mix->width, mix->height,
|
||||
mix->fbo, mix->depthbuffer, gl_out_buffer->texture,
|
||||
gst_gl_mosaic_callback, (gpointer) mosaic);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//opengl scene, params: input texture (not the output mixer->texture)
|
||||
static void
|
||||
gst_gl_mosaic_callback (gpointer stuff)
|
||||
{
|
||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff);
|
||||
|
||||
GstGLBuffer *gl_in_buffer = g_array_index (mosaic->input_gl_buffers, GstGLBuffer*, 0);
|
||||
GLuint texture = gl_in_buffer->texture;
|
||||
GLfloat width = (GLfloat) gl_in_buffer->width;
|
||||
GLfloat height = (GLfloat) gl_in_buffer->height;
|
||||
|
||||
static GLfloat xrot = 0;
|
||||
static GLfloat yrot = 0;
|
||||
static GLfloat zrot = 0;
|
||||
|
||||
const GLfloat v_vertices[] = {
|
||||
|
||||
//front face
|
||||
1.0f, 1.0f, -1.0f,
|
||||
width, 0.0f,
|
||||
1.0f, -1.0f, -1.0f,
|
||||
width, height,
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
0.0f, height,
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
0.0f, 0.0f,
|
||||
//back face
|
||||
1.0f, 1.0f, 1.0f,
|
||||
width, 0.0f,
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
0.0f, height,
|
||||
1.0f, -1.0f, 1.0f,
|
||||
width, height,
|
||||
//right face
|
||||
1.0f, 1.0f, 1.0f,
|
||||
width, 0.0f,
|
||||
1.0f, -1.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
1.0f, -1.0f, -1.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f, -1.0f,
|
||||
width, height,
|
||||
//left face
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
width, 0.0f,
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
width, height,
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
0.0f, height,
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
//top face
|
||||
1.0f, -1.0f, 1.0f,
|
||||
width, 0.0f,
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
0.0f, height,
|
||||
1.0f, -1.0f, -1.0f,
|
||||
width, height,
|
||||
//bottom face
|
||||
1.0f, 1.0f, 1.0f,
|
||||
width, 0.0f,
|
||||
1.0f, 1.0f, -1.0f,
|
||||
width, height,
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
0.0f, height,
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
0.0f, 0.0f
|
||||
};
|
||||
|
||||
GLushort indices[] = {
|
||||
0, 1, 2,
|
||||
0, 2, 3,
|
||||
4, 5, 6,
|
||||
4, 6, 7,
|
||||
8, 9, 10,
|
||||
8, 10, 11,
|
||||
12, 13, 14,
|
||||
12, 14, 15,
|
||||
16, 17, 18,
|
||||
16, 18, 19,
|
||||
20, 21, 22,
|
||||
20, 22, 23
|
||||
};
|
||||
|
||||
GLint attr_position_loc = 0;
|
||||
GLint attr_texture_loc = 0;
|
||||
|
||||
const GLfloat matrix[] = {
|
||||
0.5f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
glUseProgramObjectARB (0);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
glDisable (GL_TEXTURE_RECTANGLE_ARB);
|
||||
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
|
||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
gst_gl_shader_use (mosaic->shader);
|
||||
|
||||
attr_position_loc =
|
||||
gst_gl_shader_get_attribute_location (mosaic->shader, "a_position");
|
||||
attr_texture_loc =
|
||||
gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");
|
||||
|
||||
//Load the vertex position
|
||||
glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT,
|
||||
GL_FALSE, 5 * sizeof (GLfloat), v_vertices);
|
||||
|
||||
//Load the texture coordinate
|
||||
glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT,
|
||||
GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]);
|
||||
|
||||
glEnableVertexAttribArrayARB (attr_position_loc);
|
||||
glEnableVertexAttribArrayARB (attr_texture_loc);
|
||||
|
||||
if (glGetError () != GL_NO_ERROR)
|
||||
g_print ("ERROR\n");
|
||||
|
||||
glActiveTextureARB (GL_TEXTURE0_ARB);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||
gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0);
|
||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot);
|
||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot);
|
||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot);
|
||||
gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1, GL_FALSE, matrix);
|
||||
|
||||
if (glGetError () != GL_NO_ERROR)
|
||||
g_print ("ERROR\n");
|
||||
|
||||
glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);
|
||||
|
||||
glDisableVertexAttribArrayARB (attr_position_loc);
|
||||
glDisableVertexAttribArrayARB (attr_texture_loc);
|
||||
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
|
||||
/*xrot += 3.0f;
|
||||
yrot += 2.0f;
|
||||
zrot += 4.0f;*/
|
||||
}
|
55
gst/gl/gstglmosaic.h
Normal file
55
gst/gl/gstglmosaic.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GST_GL_MOSAIC_H_
|
||||
#define _GST_GL_MOSAIC_H_
|
||||
|
||||
#include "gstglmixer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_GL_MOSAIC (gst_gl_mosaic_get_type())
|
||||
#define GST_GL_MOSAIC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_MOSAIC,GstGLMosaic))
|
||||
#define GST_IS_GL_MOSAIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_MOSAIC))
|
||||
#define GST_GL_MOSAIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_GL_MOSAIC,GstGLMosaicClass))
|
||||
#define GST_IS_GL_MOSAIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_GL_MOSAIC))
|
||||
#define GST_GL_MOSAIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GL_MOSAIC,GstGLMosaicClass))
|
||||
|
||||
typedef struct _GstGLMosaic GstGLMosaic;
|
||||
typedef struct _GstGLMosaicClass GstGLMosaicClass;
|
||||
|
||||
struct _GstGLMosaic
|
||||
{
|
||||
GstGLMixer mixer;
|
||||
|
||||
GstGLShader *shader;
|
||||
GArray *input_gl_buffers;
|
||||
};
|
||||
|
||||
struct _GstGLMosaicClass
|
||||
{
|
||||
GstGLMixerClass mixer_class;
|
||||
};
|
||||
|
||||
GType gst_gl_mosaic_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _GST_GLFILTERCUBE_H_ */
|
|
@ -387,9 +387,6 @@ gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
|
|||
gltestsrc->width, gltestsrc->height,
|
||||
gltestsrc->rate_numerator, gltestsrc->rate_denominator);
|
||||
|
||||
gst_gl_display_create_context (gltestsrc->display,
|
||||
gltestsrc->width, gltestsrc->height, 0);
|
||||
|
||||
gst_gl_display_gen_fbo (gltestsrc->display, gltestsrc->width,
|
||||
gltestsrc->height, &gltestsrc->fbo, &gltestsrc->depthbuffer);
|
||||
}
|
||||
|
@ -631,9 +628,11 @@ gst_gl_test_src_start (GstBaseSrc * basesrc)
|
|||
if (G_VALUE_HOLDS_POINTER (id_value))
|
||||
/* at least one gl element is before in our gl chain */
|
||||
src->display = g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
|
||||
else
|
||||
else {
|
||||
/* this gl filter is a sink in terms of the gl chain */
|
||||
src->display = gst_gl_display_new ();
|
||||
gst_gl_display_create_context (src->display, 0);
|
||||
}
|
||||
}
|
||||
|
||||
gst_query_unref (query);
|
||||
|
|
|
@ -283,11 +283,13 @@ gst_gl_upload_start (GstBaseTransform * bt)
|
|||
if (isPerformed) {
|
||||
const GValue *id_value = gst_structure_get_value (structure, "gstgldisplay");
|
||||
if (G_VALUE_HOLDS_POINTER (id_value))
|
||||
/* at least one gl element is before in our gl chain */
|
||||
/* at least one gl element is after in our gl chain */
|
||||
upload->display = g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
|
||||
else
|
||||
else {
|
||||
/* this gl filter is a sink in terms of the gl chain */
|
||||
upload->display = gst_gl_display_new ();
|
||||
gst_gl_display_create_context (upload->display, 0);
|
||||
}
|
||||
}
|
||||
|
||||
gst_query_unref (query);
|
||||
|
@ -493,10 +495,6 @@ gst_gl_upload_set_caps (GstBaseTransform * bt, GstCaps * incaps,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
//init unvisible opengl context
|
||||
gst_gl_display_create_context (upload->display,
|
||||
upload->gl_width, upload->gl_height, upload->external_gl_context);
|
||||
|
||||
//init colorspace conversion if needed
|
||||
gst_gl_display_init_upload (upload->display, upload->video_format,
|
||||
upload->gl_width, upload->gl_height,
|
||||
|
|
|
@ -60,6 +60,7 @@ GType gst_gl_filter_cube_get_type (void);
|
|||
#include "gstgldeinterlace.h"
|
||||
#include "gstgleffects.h"
|
||||
#include "gstglbumper.h"
|
||||
#include "gstglmosaic.h"
|
||||
|
||||
GType gst_gl_effects_get_type (void);
|
||||
GType gst_gl_deinterlace_get_type (void);
|
||||
|
@ -71,6 +72,7 @@ GType gst_gl_filter_glass_get_type (void);
|
|||
GType gst_gl_overlay_get_type (void);
|
||||
GType gst_gl_differencematte_get_type (void);
|
||||
GType gst_gl_bumper_get_type (void);
|
||||
GType gst_gl_mosaic_get_type (void);
|
||||
#endif
|
||||
|
||||
#define GST_CAT_DEFAULT gst_gl_gstgl_debug
|
||||
|
@ -160,6 +162,10 @@ plugin_init (GstPlugin * plugin)
|
|||
GST_RANK_NONE, GST_TYPE_GL_COLORSCALE)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!gst_element_register (plugin, "glmosaic",
|
||||
GST_RANK_NONE, GST_TYPE_GL_MOSAIC)) {
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in a new issue