[310/906] Global reindent

Indent parameters:
INDENT_PARAMETERS="--braces-on-if-line \
        --case-brace-indentation0 \
        --case-indentation2 \
        --braces-after-struct-decl-line \
        --line-length80 \
        --no-tabs \
        --cuddle-else \
        --dont-line-up-parentheses \
        --honour-newlines \
        --continuation-indentation4 \
        --tab-size8 \
        --indent-level2"
This commit is contained in:
David Schleef 2009-02-10 22:39:14 -08:00 committed by Matthew Waters
parent 3fbd8bbd24
commit d015d5862d
42 changed files with 5376 additions and 5424 deletions

View file

@ -25,40 +25,40 @@
#include "gstglbuffer.h"
static GObjectClass* gst_gl_buffer_parent_class;
static GObjectClass *gst_gl_buffer_parent_class;
static void
gst_gl_buffer_finalize (GstGLBuffer* buffer)
gst_gl_buffer_finalize (GstGLBuffer * buffer)
{
//blocking call, put the texture in the pool
gst_gl_display_del_texture (buffer->display, buffer->texture,
//blocking call, put the texture in the pool
gst_gl_display_del_texture (buffer->display, buffer->texture,
buffer->width, buffer->height);
g_object_unref (buffer->display);
g_object_unref (buffer->display);
GST_MINI_OBJECT_CLASS (gst_gl_buffer_parent_class)->
finalize (GST_MINI_OBJECT (buffer));
GST_MINI_OBJECT_CLASS (gst_gl_buffer_parent_class)->finalize (GST_MINI_OBJECT
(buffer));
}
static void
gst_gl_buffer_init (GstGLBuffer* buffer, gpointer g_class)
gst_gl_buffer_init (GstGLBuffer * buffer, gpointer g_class)
{
buffer->display = NULL;
buffer->display = NULL;
buffer->width = 0;
buffer->height = 0;
buffer->texture = 0;
buffer->width = 0;
buffer->height = 0;
buffer->texture = 0;
}
static void
gst_gl_buffer_class_init (gpointer g_class, gpointer class_data)
{
GstMiniObjectClass* mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
gst_gl_buffer_parent_class = g_type_class_peek_parent (g_class);
gst_gl_buffer_parent_class = g_type_class_peek_parent (g_class);
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_gl_buffer_finalize;
mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_gl_buffer_finalize;
}
@ -87,47 +87,48 @@ gst_gl_buffer_get_type (void)
}
GstGLBuffer*
gst_gl_buffer_new (GstGLDisplay* display,
gint gl_width, gint gl_height)
GstGLBuffer *
gst_gl_buffer_new (GstGLDisplay * display, gint gl_width, gint gl_height)
{
GstGLBuffer* gl_buffer = (GstGLBuffer *) gst_mini_object_new (GST_TYPE_GL_BUFFER);
GstGLBuffer *gl_buffer =
(GstGLBuffer *) gst_mini_object_new (GST_TYPE_GL_BUFFER);
gl_buffer->display = g_object_ref (display);
gl_buffer->width = gl_width;
gl_buffer->height = gl_height;
gl_buffer->display = g_object_ref (display);
gl_buffer->width = gl_width;
gl_buffer->height = gl_height;
//it does not depends on the video format because gl buffer has always one texture.
//the one attached to the upload FBO
GST_BUFFER_SIZE (gl_buffer) = gst_gl_buffer_get_size (gl_width, gl_height);
//it does not depends on the video format because gl buffer has always one texture.
//the one attached to the upload FBO
GST_BUFFER_SIZE (gl_buffer) = gst_gl_buffer_get_size (gl_width, gl_height);
//blocking call, generate a texture using the pool
gst_gl_display_gen_texture (gl_buffer->display, &gl_buffer->texture, gl_width, gl_height) ;
//blocking call, generate a texture using the pool
gst_gl_display_gen_texture (gl_buffer->display, &gl_buffer->texture, gl_width,
gl_height);
return gl_buffer;
return gl_buffer;
}
gint
gst_gl_buffer_get_size (gint width, gint height)
{
//this is not strictly true, but it's used for compatibility with
//queue and BaseTransform
return width * height * 4;
//this is not strictly true, but it's used for compatibility with
//queue and BaseTransform
return width * height * 4;
}
gboolean
gst_gl_buffer_parse_caps (GstCaps* caps, gint* width, gint* height)
gst_gl_buffer_parse_caps (GstCaps * caps, gint * width, gint * height)
{
GstStructure* structure = gst_caps_get_structure (caps, 0);
gboolean ret = gst_structure_has_name (structure, "video/x-raw-gl");
if (!ret)
return ret;
ret = gst_structure_get_int (structure, "width", width);
ret &= gst_structure_get_int (structure, "height", height);
GstStructure *structure = gst_caps_get_structure (caps, 0);
gboolean ret = gst_structure_has_name (structure, "video/x-raw-gl");
if (!ret)
return ret;
ret = gst_structure_get_int (structure, "width", width);
ret &= gst_structure_get_int (structure, "height", height);
return ret;
}

File diff suppressed because it is too large Load diff

View file

@ -31,48 +31,48 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static GstStaticPadTemplate gst_gl_filter_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
);
static GstStaticPadTemplate gst_gl_filter_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_GL_VIDEO_CAPS)
);
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_debug, "glfilter", 0, "glfilter element");
GST_BOILERPLATE_FULL (GstGLFilter, gst_gl_filter, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
static void gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static GstCaps* gst_gl_filter_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static GstCaps *gst_gl_filter_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps);
static void gst_gl_filter_reset (GstGLFilter * filter);
static gboolean gst_gl_filter_start (GstBaseTransform * bt);
static gboolean gst_gl_filter_stop (GstBaseTransform * bt);
static gboolean gst_gl_filter_get_unit_size (GstBaseTransform * trans,
GstCaps * caps, guint * size);
GstCaps * caps, guint * size);
static GstFlowReturn gst_gl_filter_transform (GstBaseTransform * bt,
GstBuffer * inbuf, GstBuffer * outbuf);
GstBuffer * inbuf, GstBuffer * outbuf);
static GstFlowReturn gst_gl_filter_prepare_output_buffer (GstBaseTransform *
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
static gboolean gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps);
GstCaps * outcaps);
static gboolean gst_gl_filter_do_transform (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
/* GstGLDisplayThreadFunc */
static void gst_gl_filter_start_gl (GstGLDisplay *display, gpointer data);
static void gst_gl_filter_stop_gl (GstGLDisplay *display, gpointer data);
static void gst_gl_filter_start_gl (GstGLDisplay * display, gpointer data);
static void gst_gl_filter_stop_gl (GstGLDisplay * display, gpointer data);
static void
@ -81,9 +81,9 @@ gst_gl_filter_base_init (gpointer klass)
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
gst_static_pad_template_get (&gst_gl_filter_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
gst_static_pad_template_get (&gst_gl_filter_sink_pad_template));
}
static void
@ -96,14 +96,14 @@ gst_gl_filter_class_init (GstGLFilterClass * klass)
gobject_class->get_property = gst_gl_filter_get_property;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_filter_transform_caps;
gst_gl_filter_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_filter_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_filter_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_filter_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_filter_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_filter_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
gst_gl_filter_prepare_output_buffer;
gst_gl_filter_prepare_output_buffer;
klass->set_caps = NULL;
klass->filter = NULL;
@ -128,48 +128,45 @@ gst_gl_filter_init (GstGLFilter * filter, GstGLFilterClass * klass)
static void
gst_gl_filter_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
const GValue * value, GParamSpec * pspec)
{
//GstGLFilter *filter = GST_GL_FILTER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
GValue * value, GParamSpec * pspec)
{
//GstGLFilter *filter = GST_GL_FILTER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_reset (GstGLFilter* filter)
gst_gl_filter_reset (GstGLFilter * filter)
{
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
if (filter->display)
{
if (filter->display) {
if (filter_class->onReset)
filter_class->onReset (filter);
if (filter_class->display_reset_cb != NULL) {
gst_gl_display_thread_add (filter->display, gst_gl_filter_stop_gl, filter);
gst_gl_display_thread_add (filter->display, gst_gl_filter_stop_gl,
filter);
}
//blocking call, delete the FBO
gst_gl_display_del_fbo (filter->display, filter->fbo,
filter->depthbuffer);
gst_gl_display_del_fbo (filter->display, filter->fbo, filter->depthbuffer);
g_object_unref (filter->display);
filter->display = NULL;
}
@ -180,19 +177,19 @@ gst_gl_filter_reset (GstGLFilter* filter)
}
static gboolean
gst_gl_filter_start (GstBaseTransform* bt)
gst_gl_filter_start (GstBaseTransform * bt)
{
GstGLFilter *filter = GST_GL_FILTER (bt);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
if (filter_class->onStart)
filter_class->onStart (filter);
return TRUE;
}
static gboolean
gst_gl_filter_stop (GstBaseTransform* bt)
gst_gl_filter_stop (GstBaseTransform * bt)
{
GstGLFilter *filter = GST_GL_FILTER (bt);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
@ -206,7 +203,7 @@ gst_gl_filter_stop (GstBaseTransform* bt)
}
static void
gst_gl_filter_start_gl (GstGLDisplay *display, gpointer data)
gst_gl_filter_start_gl (GstGLDisplay * display, gpointer data)
{
GstGLFilter *filter = GST_GL_FILTER (data);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
@ -215,7 +212,7 @@ gst_gl_filter_start_gl (GstGLDisplay *display, gpointer data)
}
static void
gst_gl_filter_stop_gl (GstGLDisplay *display, gpointer data)
gst_gl_filter_stop_gl (GstGLDisplay * display, gpointer data)
{
GstGLFilter *filter = GST_GL_FILTER (data);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
@ -223,30 +220,28 @@ gst_gl_filter_stop_gl (GstGLDisplay *display, gpointer data)
filter_class->display_reset_cb (filter);
}
static GstCaps*
gst_gl_filter_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps)
static GstCaps *
gst_gl_filter_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps)
{
//GstGLFilter* filter = GST_GL_FILTER (bt);
GstStructure* structure = gst_caps_get_structure (caps, 0);
GstCaps* ret = gst_caps_copy (caps);
const GValue* par = NULL;
GstStructure *structure = gst_caps_get_structure (caps, 0);
GstCaps *ret = gst_caps_copy (caps);
const GValue *par = NULL;
structure = gst_structure_copy (gst_caps_get_structure (ret, 0));
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_caps_merge_structure (ret, gst_structure_copy (structure));
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio")))
{
if ((par = gst_structure_get_value (structure, "pixel-aspect-ratio"))) {
gst_structure_set (structure,
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
gst_caps_merge_structure (ret, structure);
}
else
} else
gst_structure_free (structure);
GST_DEBUG_OBJECT (bt, "returning caps: %" GST_PTR_FORMAT, ret);
@ -256,8 +251,8 @@ gst_gl_filter_transform_caps (GstBaseTransform* bt,
static gboolean
gst_gl_filter_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size)
gst_gl_filter_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{
gboolean ret = FALSE;
gint width = 0;
@ -271,27 +266,27 @@ gst_gl_filter_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
}
static GstFlowReturn
gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
GstBuffer* inbuf, gint size, GstCaps* caps, GstBuffer** buf)
gst_gl_filter_prepare_output_buffer (GstBaseTransform * trans,
GstBuffer * inbuf, gint size, GstCaps * caps, GstBuffer ** buf)
{
GstGLFilter* filter = NULL;
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer* gl_outbuf = NULL;
GstGLFilter *filter = NULL;
GstGLBuffer *gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer *gl_outbuf = NULL;
filter = GST_GL_FILTER (trans);
if (filter->display == NULL)
{
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
if (filter->display == NULL) {
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
filter->display = g_object_ref (gl_inbuf->display);
//blocking call, generate a FBO
gst_gl_display_gen_fbo (filter->display, filter->width, filter->height,
&filter->fbo, &filter->depthbuffer);
&filter->fbo, &filter->depthbuffer);
if (filter_class->display_init_cb != NULL) {
gst_gl_display_thread_add (filter->display, gst_gl_filter_start_gl, filter);
gst_gl_display_thread_add (filter->display, gst_gl_filter_start_gl,
filter);
}
if (filter_class->onInitFBO)
@ -299,7 +294,7 @@ gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
}
gl_outbuf = gst_gl_buffer_new (filter->display,
filter->width, filter->height);
filter->width, filter->height);
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);
@ -311,20 +306,19 @@ gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
}
static gboolean
gst_gl_filter_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps)
{
GstGLFilter* filter = GST_GL_FILTER (bt);
GstGLFilter *filter = GST_GL_FILTER (bt);
gboolean ret = FALSE;
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
ret = gst_gl_buffer_parse_caps (outcaps, &filter->width, &filter->height);
if (filter_class->set_caps)
filter_class->set_caps (filter, incaps, outcaps);
if (!ret)
{
if (!ret) {
GST_DEBUG ("bad caps");
return FALSE;
}
@ -335,12 +329,12 @@ gst_gl_filter_set_caps (GstBaseTransform* bt, GstCaps* incaps,
}
static GstFlowReturn
gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
GstBuffer* outbuf)
gst_gl_filter_transform (GstBaseTransform * bt, GstBuffer * inbuf,
GstBuffer * outbuf)
{
GstGLFilter* filter;
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
GstGLFilter *filter;
GstGLBuffer *gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLBuffer *gl_outbuf = GST_GL_BUFFER (outbuf);
filter = GST_GL_FILTER (bt);
@ -350,10 +344,10 @@ gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
}
static gboolean
gst_gl_filter_do_transform (GstGLFilter* filter,
GstGLBuffer* inbuf, GstGLBuffer* outbuf)
gst_gl_filter_do_transform (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf)
{
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter);
filter_class->filter (filter, inbuf, outbuf);
@ -363,15 +357,13 @@ gst_gl_filter_do_transform (GstGLFilter* filter,
/* convenience functions to simplify filter development */
void
gst_gl_filter_render_to_target (GstGLFilter *filter,
GLuint input, GLuint target,
GLCB func, gpointer data)
gst_gl_filter_render_to_target (GstGLFilter * filter,
GLuint input, GLuint target, GLCB func, gpointer data)
{
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, target,
func,
filter->width, filter->height, input,
0, filter->width, 0, filter->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D,
data);
filter->fbo, filter->depthbuffer, target,
func,
filter->width, filter->height, input,
0, filter->width, 0, filter->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D, data);
}

View file

@ -132,8 +132,8 @@ gst_gl_shader_get_property (GObject * object,
}
static void
gst_gl_shader_log_handler (const gchar *domain, GLogLevelFlags flags,
const gchar *message, gpointer user_data)
gst_gl_shader_log_handler (const gchar * domain, GLogLevelFlags flags,
const gchar * message, gpointer user_data)
{
if (_gst_gl_shader_debug) {
g_log_default_handler (domain, flags, message, user_data);
@ -249,7 +249,7 @@ gst_gl_shader_init (GstGLShader * self)
_gst_gl_shader_debug = TRUE;
g_log_set_handler ("GstGLShader", G_LOG_LEVEL_DEBUG,
gst_gl_shader_log_handler, NULL);
gst_gl_shader_log_handler, NULL);
}
GstGLShader *
@ -511,7 +511,7 @@ gst_gl_shader_set_uniform_1i (GstGLShader * shader, const gchar * name,
}
GLint
gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar *name)
gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar * name)
{
GstGLShaderPrivate *priv;

View file

@ -32,9 +32,11 @@
#define WM_GST_GL_WINDOW_CUSTOM (WM_APP+1)
#define WM_GST_GL_WINDOW_QUIT (WM_APP+2)
void gst_gl_window_set_pixel_format (GstGLWindow *window);
LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT FAR PASCAL sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void gst_gl_window_set_pixel_format (GstGLWindow * window);
LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
LRESULT FAR PASCAL sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
#define GST_GL_WINDOW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW, GstGLWindowPrivate))
@ -79,8 +81,8 @@ gst_gl_window_finalize (GObject * object)
}
static void
gst_gl_window_log_handler (const gchar *domain, GLogLevelFlags flags,
const gchar *message, gpointer user_data)
gst_gl_window_log_handler (const gchar * domain, GLogLevelFlags flags,
const gchar * message, gpointer user_data)
{
if (_gst_gl_window_debug) {
g_log_default_handler (domain, flags, message, user_data);
@ -106,9 +108,8 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
atom = GetClassInfo (hinstance, "GSTGL", &wc);
if (atom == 0)
{
ZeroMemory (&wc, sizeof(WNDCLASS));
if (atom == 0) {
ZeroMemory (&wc, sizeof (WNDCLASS));
wc.lpfnWndProc = window_proc;
wc.cbClsExtra = 0;
@ -124,12 +125,12 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
atom = RegisterClass (&wc);
if (atom == 0)
g_error ("Failed to register window class %x\r\n", GetLastError());
g_error ("Failed to register window class %x\r\n", GetLastError ());
}
}
static void
gst_gl_window_init (GstGLWindow *window)
gst_gl_window_init (GstGLWindow * window)
{
window->priv = GST_GL_WINDOW_GET_PRIVATE (window);
@ -137,7 +138,7 @@ gst_gl_window_init (GstGLWindow *window)
_gst_gl_window_debug = TRUE;
g_log_set_handler ("GstGLWindow", G_LOG_LEVEL_DEBUG,
gst_gl_window_log_handler, NULL);
gst_gl_window_log_handler, NULL);
}
/* Must be called in the gl thread */
@ -146,7 +147,7 @@ gst_gl_window_new (gint width, gint height)
{
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
GstGLWindowPrivate *priv = window->priv;
GstGLWindowClass* klass = GST_GL_WINDOW_GET_CLASS (window);
GstGLWindowClass *klass = GST_GL_WINDOW_GET_CLASS (window);
HINSTANCE hinstance = GetModuleHandle (NULL);
@ -169,22 +170,16 @@ gst_gl_window_new (gint width, gint height)
priv->visible = FALSE;
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
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
);
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);
if (!priv->internal_win_id)
{
if (!priv->internal_win_id) {
g_debug ("failed to create gl window: %d\n", priv->internal_win_id);
return NULL;
}
@ -206,36 +201,41 @@ gst_gl_window_error_quark (void)
}
void
gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
gst_gl_window_set_external_window_id (GstGLWindow * window, guint64 id)
{
GstGLWindowPrivate *priv = window->priv;
WNDPROC window_parent_proc = (WNDPROC) (guint64) GetWindowLongPtr((HWND)id, GWL_WNDPROC);
WNDPROC window_parent_proc =
(WNDPROC) (guint64) GetWindowLongPtr ((HWND) id, GWL_WNDPROC);
RECT rect;
SetProp (priv->internal_win_id, "gl_window_parent_id", (HWND)id);
SetProp ((HWND)id, "gl_window_id", priv->internal_win_id);
SetProp ((HWND)id, "gl_window_parent_proc", (WNDPROC) window_parent_proc);
SetWindowLongPtr ((HWND)id, GWL_WNDPROC, (DWORD) (guint64) sub_class_proc);
SetProp (priv->internal_win_id, "gl_window_parent_id", (HWND) id);
SetProp ((HWND) id, "gl_window_id", priv->internal_win_id);
SetProp ((HWND) id, "gl_window_parent_proc", (WNDPROC) window_parent_proc);
SetWindowLongPtr ((HWND) id, GWL_WNDPROC, (DWORD) (guint64) sub_class_proc);
SetWindowLongPtr (priv->internal_win_id, GWL_STYLE, WS_CHILD | WS_MAXIMIZE);
SetParent (priv->internal_win_id, (HWND)id);
SetParent (priv->internal_win_id, (HWND) id);
//take changes into account: SWP_FRAMECHANGED
GetClientRect ((HWND)id, &rect);
SetWindowPos (priv->internal_win_id, HWND_TOP, rect.left, rect.top, rect.right, rect.bottom,
SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
MoveWindow (priv->internal_win_id, rect.left, rect.top, rect.right, rect.bottom, FALSE);
GetClientRect ((HWND) id, &rect);
SetWindowPos (priv->internal_win_id, HWND_TOP, rect.left, rect.top,
rect.right, rect.bottom,
SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_FRAMECHANGED | SWP_NOACTIVATE);
MoveWindow (priv->internal_win_id, rect.left, rect.top, rect.right,
rect.bottom, FALSE);
}
void
gst_gl_window_set_external_gl_context (GstGLWindow *window, guint64 context)
gst_gl_window_set_external_gl_context (GstGLWindow * window, guint64 context)
{
g_warning ("gst_gl_window_set_external_gl_context: not implemented\n");
}
/* Must be called in the gl thread */
void
gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_set_draw_callback (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -245,7 +245,8 @@ gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gp
/* Must be called in the gl thread */
void
gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback , gpointer data)
gst_gl_window_set_resize_callback (GstGLWindow * window,
GstGLWindowCB2 callback, gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -255,7 +256,8 @@ gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback
/* Must be called in the gl thread */
void
gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -264,29 +266,28 @@ gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, g
}
void
gst_gl_window_draw_unlocked (GstGLWindow *window)
gst_gl_window_draw_unlocked (GstGLWindow * window)
{
gst_gl_window_draw (window);
}
/* Thread safe */
void
gst_gl_window_draw (GstGLWindow *window)
gst_gl_window_draw (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
if (!priv->visible)
{
if (!priv->visible) {
ShowWindowAsync (priv->internal_win_id, SW_SHOW);
priv->visible = TRUE;
}
RedrawWindow (priv->internal_win_id, NULL, NULL,
RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE);
RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE);
}
void
gst_gl_window_run_loop (GstGLWindow *window)
gst_gl_window_run_loop (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
gboolean running = TRUE;
@ -295,18 +296,14 @@ gst_gl_window_run_loop (GstGLWindow *window)
g_debug ("begin loop\n");
while (running && (bRet = GetMessage (&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
g_error ("Failed to get message %x\r\n", GetLastError());
running = FALSE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
while (running && (bRet = GetMessage (&msg, NULL, 0, 0)) != 0) {
if (bRet == -1) {
g_error ("Failed to get message %x\r\n", GetLastError ());
running = FALSE;
} else {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
g_debug ("end loop\n");
@ -314,12 +311,13 @@ gst_gl_window_run_loop (GstGLWindow *window)
/* Thread safe */
void
gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_quit_loop (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
LRESULT res = PostMessage(priv->internal_win_id, WM_GST_GL_WINDOW_QUIT, (WPARAM) data, (LPARAM) callback);
LRESULT res = PostMessage (priv->internal_win_id, WM_GST_GL_WINDOW_QUIT,
(WPARAM) data, (LPARAM) callback);
g_assert (SUCCEEDED (res));
g_debug ("end loop requested\n");
}
@ -327,12 +325,13 @@ gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer d
/* Thread safe */
void
gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
LRESULT res = SendMessage (priv->internal_win_id, WM_GST_GL_WINDOW_CUSTOM, (WPARAM) data, (LPARAM) callback);
LRESULT res = SendMessage (priv->internal_win_id, WM_GST_GL_WINDOW_CUSTOM,
(WPARAM) data, (LPARAM) callback);
g_assert (SUCCEEDED (res));
}
}
@ -340,56 +339,58 @@ gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointe
/* PRIVATE */
void
gst_gl_window_set_pixel_format (GstGLWindow *window)
gst_gl_window_set_pixel_format (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
PIXELFORMATDESCRIPTOR pfd;
gint pixelformat = 0;
gboolean res = FALSE;
GstGLWindowPrivate *priv = window->priv;
PIXELFORMATDESCRIPTOR pfd;
gint pixelformat = 0;
gboolean res = FALSE;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cRedBits = 0;
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAccumBits = 0;
pfd.cAccumRedBits = 0;
pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = 32;
pfd.cStencilBits = 8;
pfd.cAuxBuffers = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.bReserved = 0;
pfd.dwLayerMask = 0;
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cRedBits = 0;
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAccumBits = 0;
pfd.cAccumRedBits = 0;
pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = 32;
pfd.cStencilBits = 8;
pfd.cAuxBuffers = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.bReserved = 0;
pfd.dwLayerMask = 0;
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
pfd.cColorBits = (BYTE) GetDeviceCaps (priv->device, BITSPIXEL);
pfd.cColorBits = (BYTE) GetDeviceCaps (priv->device, BITSPIXEL);
pixelformat = ChoosePixelFormat (priv->device, &pfd );
pixelformat = ChoosePixelFormat (priv->device, &pfd);
g_assert (pixelformat);
g_assert (pixelformat);
res = SetPixelFormat (priv->device, pixelformat, &pfd);
res = SetPixelFormat (priv->device, pixelformat, &pfd);
g_assert (res);
g_assert (res);
}
LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CREATE) {
GstGLWindow *window = (GstGLWindow *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
GstGLWindow *window =
(GstGLWindow *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
g_debug ("WM_CREATE\n");
@ -403,20 +404,21 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
if (priv->gl_context)
g_debug ("gl context created: %d\n", priv->gl_context);
else
g_debug ("failed to create glcontext %d, %x\r\n", hWnd, GetLastError());
g_debug ("failed to create glcontext %d, %x\r\n", hWnd,
GetLastError ());
g_assert (priv->gl_context);
ReleaseDC (hWnd, priv->device);
if (!wglMakeCurrent (priv->device, priv->gl_context))
g_debug ("failed to make opengl context current %d, %x\r\n", hWnd, GetLastError());
g_debug ("failed to make opengl context current %d, %x\r\n", hWnd,
GetLastError ());
}
SetProp (hWnd, "gl_window", window);
return 0;
}
else if (GetProp(hWnd, "gl_window")) {
} else if (GetProp (hWnd, "gl_window")) {
GstGLWindow *window = GetProp(hWnd, "gl_window");
GstGLWindow *window = GetProp (hWnd, "gl_window");
GstGLWindowPrivate *priv = NULL;
g_assert (window);
@ -427,21 +429,20 @@ LRESULT CALLBACK 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 (priv->gl_context == wglGetCurrentContext ());
switch ( uMsg ) {
switch (uMsg) {
case WM_SIZE:
{
if (priv->resize_cb)
priv->resize_cb (priv->resize_data, LOWORD(lParam), HIWORD(lParam));
priv->resize_cb (priv->resize_data, LOWORD (lParam), HIWORD (lParam));
break;
}
case WM_PAINT:
{
if (priv->draw_cb)
{
if (priv->draw_cb) {
PAINTSTRUCT ps;
BeginPaint (hWnd, &ps);
priv->draw_cb (priv->draw_data);
@ -456,14 +457,14 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
ShowWindowAsync (priv->internal_win_id, SW_HIDE);
if (priv->close_cb)
priv->close_cb (priv->close_data);
priv->close_cb (priv->close_data);
priv->draw_cb = NULL;
priv->draw_data = NULL;
priv->resize_cb = NULL;
priv->resize_data = NULL;
priv->close_cb = NULL;
priv->close_data = NULL;
priv->draw_cb = NULL;
priv->draw_data = NULL;
priv->resize_cb = NULL;
priv->resize_data = NULL;
priv->close_cb = NULL;
priv->close_data = NULL;
break;
}
@ -477,13 +478,13 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
destroy_cb ((gpointer) wParam);
parent_id = GetProp (hWnd, "gl_window_parent_id");
if (parent_id)
{
if (parent_id) {
WNDPROC parent_proc = GetProp (parent_id, "gl_window_parent_proc");
g_assert (parent_proc);
SetWindowLongPtr (parent_id, GWL_WNDPROC, (LONG) (guint64) parent_proc);
SetWindowLongPtr (parent_id, GWL_WNDPROC,
(LONG) (guint64) parent_proc);
SetParent (hWnd, NULL);
RemoveProp (parent_id, "gl_window_parent_proc");
@ -494,19 +495,19 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
RemoveProp (hWnd, "gl_window");
if (!wglMakeCurrent (NULL, NULL))
g_debug ("failed to make current %d, %x\r\n", hWnd, GetLastError());
g_debug ("failed to make current %d, %x\r\n", hWnd, GetLastError ());
if (priv->gl_context)
{
if (priv->gl_context) {
if (!wglDeleteContext (priv->gl_context))
g_debug ("failed to destroy context %d, %x\r\n", priv->gl_context, GetLastError());
g_debug ("failed to destroy context %d, %x\r\n", priv->gl_context,
GetLastError ());
}
if (priv->internal_win_id)
{
if (priv->internal_win_id) {
g_debug ("BEFORE\n");
if (!DestroyWindow(priv->internal_win_id))
g_debug ("failed to destroy window %d, %x\r\n", hWnd, GetLastError());
if (!DestroyWindow (priv->internal_win_id))
g_debug ("failed to destroy window %d, %x\r\n", hWnd,
GetLastError ());
g_debug ("AFTER\n");
}
@ -524,8 +525,7 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case WM_GST_GL_WINDOW_CUSTOM:
{
if (!priv->is_closed)
{
if (!priv->is_closed) {
GstGLWindowCB custom_cb = (GstGLWindowCB) lParam;
custom_cb ((gpointer) wParam);
}
@ -536,25 +536,23 @@ LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return TRUE;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
return 0;
}
else
return DefWindowProc( hWnd, uMsg, wParam, lParam );
} else
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
LRESULT FAR PASCAL sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT FAR PASCAL
sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WNDPROC window_parent_proc = GetProp (hWnd, "gl_window_parent_proc");
if (uMsg == WM_SIZE)
{
if (uMsg == WM_SIZE) {
HWND gl_window_id = GetProp (hWnd, "gl_window_id");
MoveWindow (gl_window_id, 0, 0, LOWORD(lParam), HIWORD(lParam), FALSE);
MoveWindow (gl_window_id, 0, 0, LOWORD (lParam), HIWORD (lParam), FALSE);
}
return CallWindowProc (window_parent_proc, hWnd, uMsg, wParam, lParam);
}

View file

@ -119,14 +119,14 @@ gst_gl_window_finalize (GObject * object)
XSync (priv->device, FALSE);
while(XPending (priv->device))
while (XPending (priv->device))
XNextEvent (priv->device, &event);
XSetCloseDownMode (priv->device, DestroyAll);
/*XAddToSaveSet (display, w)
Display *display;
Window w;*/
Display *display;
Window w; */
//FIXME: it seems it causes destroy all created windows, even by other display connection:
//This is case in: gst-launch-0.10 videotestsrc ! tee name=t t. ! queue ! glimagesink t. ! queue ! glimagesink
@ -142,16 +142,14 @@ gst_gl_window_finalize (GObject * object)
g_debug ("display sender closed\n");
if (priv->cond_send_message)
{
if (priv->cond_send_message) {
g_cond_free (priv->cond_send_message);
priv->cond_send_message = NULL;
}
g_mutex_unlock (priv->x_lock);
if (priv->x_lock)
{
if (priv->x_lock) {
g_mutex_free (priv->x_lock);
priv->x_lock = NULL;
}
@ -206,8 +204,8 @@ gst_gl_window_get_property (GObject * object, guint prop_id,
}
static void
gst_gl_window_log_handler (const gchar *domain, GLogLevelFlags flags,
const gchar *message, gpointer user_data)
gst_gl_window_log_handler (const gchar * domain, GLogLevelFlags flags,
const gchar * message, gpointer user_data)
{
if (_gst_gl_window_debug) {
g_log_default_handler (domain, flags, message, user_data);
@ -231,7 +229,7 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
}
static void
gst_gl_window_init (GstGLWindow *window)
gst_gl_window_init (GstGLWindow * window)
{
window->priv = GST_GL_WINDOW_GET_PRIVATE (window);
@ -239,7 +237,7 @@ gst_gl_window_init (GstGLWindow *window)
_gst_gl_window_debug = TRUE;
g_log_set_handler ("GstGLWindow", G_LOG_LEVEL_DEBUG,
gst_gl_window_log_handler, NULL);
gst_gl_window_log_handler, NULL);
}
/* Must be called in the gl thread */
@ -270,7 +268,7 @@ gst_gl_window_new (gint width, gint height)
static gint x = 0;
static gint y = 0;
setlocale(LC_NUMERIC, "C");
setlocale (LC_NUMERIC, "C");
priv->x_lock = g_mutex_new ();
priv->cond_send_message = g_cond_new ();
@ -314,8 +312,7 @@ gst_gl_window_new (gint width, gint height)
priv->visual_info = glXChooseVisual (priv->device, priv->screen_num, attrib);
if (!priv->visual_info)
{
if (!priv->visual_info) {
g_warning ("glx visual is null (bad attributes)\n");
return NULL;
}
@ -326,7 +323,8 @@ gst_gl_window_new (gint width, gint height)
if (priv->visual_info->class == TrueColor)
g_debug ("visual is using TrueColor\n");
g_debug ("visual ID: %d\n", (gint)XVisualIDFromVisual(priv->visual_info->visual));
g_debug ("visual ID: %d\n",
(gint) XVisualIDFromVisual (priv->visual_info->visual));
g_debug ("visual info screen: %d\n", priv->visual_info->screen);
g_debug ("visual info visualid: %d\n", (gint) priv->visual_info->visualid);
g_debug ("visual info depth: %d\n", priv->visual_info->depth);
@ -336,20 +334,23 @@ gst_gl_window_new (gint width, gint height)
g_debug ("visual info blue_mask: %ld\n", priv->visual_info->blue_mask);
g_debug ("visual info bits_per_rgb: %d\n", priv->visual_info->bits_per_rgb);
win_attr.event_mask = StructureNotifyMask | ExposureMask | VisibilityChangeMask;
win_attr.event_mask =
StructureNotifyMask | ExposureMask | VisibilityChangeMask;
win_attr.do_not_propagate_mask = NoEventMask;
win_attr.background_pixmap = None;
win_attr.background_pixel = 0;
win_attr.border_pixel = 0;
win_attr.colormap = XCreateColormap(priv->device, priv->root, priv->visual_info->visual, AllocNone);
win_attr.colormap =
XCreateColormap (priv->device, priv->root, priv->visual_info->visual,
AllocNone);
mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
priv->internal_win_id = XCreateWindow (priv->device, priv->root, x, y,
width, height, 0, priv->visual_info->depth, InputOutput,
priv->visual_info->visual, mask, &win_attr);
width, height, 0, priv->visual_info->depth, InputOutput,
priv->visual_info->visual, mask, &win_attr);
x += 20;
y += 20;
@ -358,7 +359,8 @@ gst_gl_window_new (gint width, gint height)
XSetWindowBackgroundPixmap (priv->device, priv->internal_win_id, None);
g_debug ("gl window id: %" G_GUINT64_FORMAT "\n", (guint64) priv->internal_win_id);
g_debug ("gl window id: %" G_GUINT64_FORMAT "\n",
(guint64) priv->internal_win_id);
g_debug ("gl window props: x:%d y:%d w:%d h:%d\n", x, y, width, height);
@ -376,21 +378,22 @@ gst_gl_window_new (gint width, gint height)
XSetWMProtocols (priv->device, priv->internal_win_id, wm_atoms, 2);
priv->gl_context = glXCreateContext (priv->device, priv->visual_info, NULL, TRUE);
priv->gl_context =
glXCreateContext (priv->device, priv->visual_info, NULL, TRUE);
g_debug ("gl context id: %ld\n", (gulong) priv->gl_context);
if (!glXIsDirect(priv->device, priv->gl_context))
if (!glXIsDirect (priv->device, priv->gl_context))
g_debug ("direct rendering failed\n");
wm_hints.flags = StateHint;
wm_hints.initial_state = NormalState;
wm_hints.input = False;
XStringListToTextProperty ((char**)&title, 1, &text_property);
XStringListToTextProperty ((char **) &title, 1, &text_property);
XSetWMProperties (priv->device, priv->internal_win_id, &text_property, &text_property, 0, 0,
NULL, &wm_hints, NULL);
XSetWMProperties (priv->device, priv->internal_win_id, &text_property,
&text_property, 0, 0, NULL, &wm_hints, NULL);
XFree (text_property.value);
@ -417,10 +420,9 @@ gst_gl_window_error_quark (void)
/* Not called by the gl thread */
void
gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
gst_gl_window_set_external_window_id (GstGLWindow * window, guint64 id)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
XWindowAttributes attr;
@ -432,9 +434,11 @@ gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
XGetWindowAttributes (priv->disp_send, priv->parent, &attr);
XResizeWindow (priv->disp_send, priv->internal_win_id, attr.width, attr.height);
XResizeWindow (priv->disp_send, priv->internal_win_id, attr.width,
attr.height);
XReparentWindow (priv->disp_send, priv->internal_win_id, priv->parent, attr.x, attr.y);
XReparentWindow (priv->disp_send, priv->internal_win_id, priv->parent,
attr.x, attr.y);
XSync (priv->disp_send, FALSE);
@ -443,13 +447,14 @@ gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
}
void
gst_gl_window_set_external_gl_context (GstGLWindow *window, guint64 context)
gst_gl_window_set_external_gl_context (GstGLWindow * window, guint64 context)
{
g_warning ("gst_gl_window_set_external_gl_context: not implemented\n");
}
void
gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_set_draw_callback (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -462,7 +467,8 @@ gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gp
}
void
gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback , gpointer data)
gst_gl_window_set_resize_callback (GstGLWindow * window,
GstGLWindowCB2 callback, gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -475,7 +481,8 @@ gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback
}
void
gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
@ -489,12 +496,11 @@ gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, g
/* Called in the gl thread */
void
gst_gl_window_draw_unlocked (GstGLWindow *window)
gst_gl_window_draw_unlocked (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
if (priv->running && priv->allow_extra_expose_events)
{
if (priv->running && priv->allow_extra_expose_events) {
XEvent event;
XWindowAttributes attr;
@ -510,44 +516,42 @@ gst_gl_window_draw_unlocked (GstGLWindow *window)
event.xexpose.height = attr.height;
event.xexpose.count = 0;
XSendEvent (priv->device, priv->internal_win_id, FALSE, ExposureMask, &event);
XSendEvent (priv->device, priv->internal_win_id, FALSE, ExposureMask,
&event);
XSync (priv->disp_send, FALSE);
}
}
/* Not called by the gl thread */
void
gst_gl_window_draw (GstGLWindow *window)
gst_gl_window_draw (GstGLWindow * window)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
g_mutex_lock (priv->x_lock);
if (priv->running)
{
if (priv->running) {
XEvent event;
XWindowAttributes attr;
if (!priv->visible)
{
if (!priv->visible) {
XMapWindow (priv->disp_send, priv->internal_win_id);
priv->visible = TRUE;
}
XGetWindowAttributes (priv->disp_send, priv->internal_win_id, &attr);
if (priv->parent)
{
if (priv->parent) {
XWindowAttributes attr_parent;
XGetWindowAttributes (priv->disp_send, priv->parent, &attr_parent);
if (attr.x != attr_parent.x || attr.y != attr_parent.y ||
attr.width != attr_parent.width || attr.height != attr_parent.height)
{
XMoveResizeWindow (priv->disp_send, priv->internal_win_id, attr_parent.x, attr_parent.y,
attr_parent.width, attr_parent.height);
attr.width != attr_parent.width
|| attr.height != attr_parent.height) {
XMoveResizeWindow (priv->disp_send, priv->internal_win_id,
attr_parent.x, attr_parent.y, attr_parent.width,
attr_parent.height);
XSync (priv->disp_send, FALSE);
attr.x = attr_parent.x;
@ -556,8 +560,8 @@ gst_gl_window_draw (GstGLWindow *window)
attr.width = attr_parent.width;
attr.height = attr_parent.height;
g_debug ("parent resize: %d, %d, %d, %d\n", attr_parent.x, attr_parent.y,
attr_parent.width, attr_parent.height);
g_debug ("parent resize: %d, %d, %d, %d\n", attr_parent.x,
attr_parent.y, attr_parent.width, attr_parent.height);
}
}
@ -571,7 +575,8 @@ gst_gl_window_draw (GstGLWindow *window)
event.xexpose.height = attr.height;
event.xexpose.count = 0;
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, ExposureMask, &event);
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, ExposureMask,
&event);
XSync (priv->disp_send, FALSE);
}
@ -581,7 +586,7 @@ gst_gl_window_draw (GstGLWindow *window)
/* Called in the gl thread */
void
gst_gl_window_run_loop (GstGLWindow *window)
gst_gl_window_run_loop (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
@ -589,23 +594,21 @@ gst_gl_window_run_loop (GstGLWindow *window)
g_mutex_lock (priv->x_lock);
while (priv->running)
{
while (priv->running) {
XEvent event;
XEvent pending_event;
g_mutex_unlock (priv->x_lock);
/* XSendEvent (which are called in other threads) are done from another display structure */
XNextEvent(priv->device, &event);
XNextEvent (priv->device, &event);
g_mutex_lock (priv->x_lock);
// use in generic/cube and other related uses
priv->allow_extra_expose_events = XPending (priv->device) <= 2;
switch (event.type)
{
switch (event.type) {
case ClientMessage:
{
@ -647,9 +650,10 @@ gst_gl_window_run_loop (GstGLWindow *window)
}
/* User clicked on the cross */
else if (wm_delete != None && (Atom) event.xclient.data.l[0] == wm_delete)
{
g_debug ("Close %" G_GUINT64_FORMAT "\n", (guint64) priv->internal_win_id);
else if (wm_delete != None
&& (Atom) event.xclient.data.l[0] == wm_delete) {
g_debug ("Close %" G_GUINT64_FORMAT "\n",
(guint64) priv->internal_win_id);
if (priv->close_cb)
priv->close_cb (priv->close_data);
@ -679,7 +683,8 @@ gst_gl_window_run_loop (GstGLWindow *window)
gpointer destroy_data = (gpointer) event.xclient.data.l[1];
#endif
g_debug ("Quit loop message %" G_GUINT64_FORMAT "\n", (guint64) priv->internal_win_id);
g_debug ("Quit loop message %" G_GUINT64_FORMAT "\n",
(guint64) priv->internal_win_id);
/* exit loop */
priv->running = FALSE;
@ -716,9 +721,8 @@ gst_gl_window_run_loop (GstGLWindow *window)
destroy_cb (destroy_data);
}
else
g_debug("client message not reconized \n");
} else
g_debug ("client message not reconized \n");
break;
}
@ -726,7 +730,8 @@ gst_gl_window_run_loop (GstGLWindow *window)
case ConfigureNotify:
{
if (priv->resize_cb)
priv->resize_cb (priv->resize_data, event.xconfigure.width, event.xconfigure.height);
priv->resize_cb (priv->resize_data, event.xconfigure.width,
event.xconfigure.height);
break;
}
@ -735,18 +740,16 @@ gst_gl_window_run_loop (GstGLWindow *window)
break;
case Expose:
if (priv->draw_cb)
{
if (priv->draw_cb) {
priv->draw_cb (priv->draw_data);
glFlush();
glFlush ();
glXSwapBuffers (priv->device, priv->internal_win_id);
}
break;
case VisibilityNotify:
{
switch (event.xvisibility.state)
{
switch (event.xvisibility.state) {
case VisibilityUnobscured:
if (priv->draw_cb)
priv->draw_cb (priv->draw_data);
@ -761,7 +764,8 @@ gst_gl_window_run_loop (GstGLWindow *window)
break;
default:
g_debug("unknown xvisibility event: %d\n", event.xvisibility.state);
g_debug ("unknown xvisibility event: %d\n",
event.xvisibility.state);
break;
}
break;
@ -771,9 +775,9 @@ gst_gl_window_run_loop (GstGLWindow *window)
g_debug ("unknow\n");
break;
}// switch
} // switch
}// while running
} // while running
g_mutex_unlock (priv->x_lock);
@ -782,23 +786,23 @@ gst_gl_window_run_loop (GstGLWindow *window)
/* Not called by the gl thread */
void
gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_quit_loop (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
g_mutex_lock (priv->x_lock);
if (priv->running)
{
if (priv->running) {
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.send_event = TRUE;
event.xclient.display = priv->disp_send;
event.xclient.window = priv->internal_win_id;
event.xclient.message_type = XInternAtom (priv->disp_send, "WM_QUIT_LOOP", True);;
event.xclient.message_type =
XInternAtom (priv->disp_send, "WM_QUIT_LOOP", True);;
event.xclient.format = 32;
#if SIZEOF_VOID_P == 8
event.xclient.data.l[0] = (((long) callback) >> 32) & 0xffffffff;
@ -810,7 +814,8 @@ gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer d
event.xclient.data.l[1] = (long) data;
#endif
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask, &event);
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask,
&event);
XSync (priv->disp_send, FALSE);
}
@ -820,23 +825,23 @@ gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer d
/* Not called by the gl thread */
void
gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
gpointer data)
{
if (window)
{
if (window) {
GstGLWindowPrivate *priv = window->priv;
g_mutex_lock (priv->x_lock);
if (priv->running)
{
if (priv->running) {
XEvent event;
event.xclient.type = ClientMessage;
event.xclient.send_event = TRUE;
event.xclient.display = priv->disp_send;
event.xclient.window = priv->internal_win_id;
event.xclient.message_type = XInternAtom (priv->disp_send, "WM_GL_WINDOW", True);
event.xclient.message_type =
XInternAtom (priv->disp_send, "WM_GL_WINDOW", True);
event.xclient.format = 32;
#if SIZEOF_VOID_P == 8
event.xclient.data.l[0] = (((long) callback) >> 32) & 0xffffffff;
@ -848,7 +853,8 @@ gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointe
event.xclient.data.l[1] = (long) data;
#endif
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask, &event);
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask,
&event);
XSync (priv->disp_send, FALSE);
/* block until opengl calls have been executed in the gl thread */

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_bulge_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_bulge_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "bulge0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "bulge0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, bulge_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
bulge_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_bulge (GstGLEffects *effects) {
gst_gl_effects_bulge (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_bulge_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_bulge_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_fisheye_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_fisheye_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "fisheye0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "fisheye0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, fisheye_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
fisheye_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_fisheye (GstGLEffects *effects) {
gst_gl_effects_fisheye (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_fisheye_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_fisheye_callback, effects);
}

View file

@ -20,61 +20,62 @@
#include <gstgleffects.h>
static gfloat gauss_kernel[9] = { 0.060493f, 0.075284f, 0.088016f,
0.096667f, 0.099736f, 0.096667f,
0.088016f, 0.075284f, 0.060493f };
static gfloat gauss_kernel[9] = { 0.060493f, 0.075284f, 0.088016f,
0.096667f, 0.099736f, 0.096667f,
0.088016f, 0.075284f, 0.060493f
};
static void
gst_gl_effects_glow_step_one (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_glow_step_one (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "glow0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "glow0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, luma_threshold_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
luma_threshold_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_effects_draw_texture (effects, texture);
}
static void
gst_gl_effects_glow_step_two (gint width, gint height, guint texture, gpointer stuff)
gst_gl_effects_glow_step_two (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLEffects* effects = GST_GL_EFFECTS (stuff);
GstGLEffects *effects = GST_GL_EFFECTS (stuff);
GstGLShader *shader;
/* hard coded kernel, it could be easily generated at runtime with a
* property to change standard deviation */
shader = g_hash_table_lookup (effects->shaderstable, "glow1");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "glow1", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, hconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
hconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -96,21 +97,21 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture, gpointer s
}
void
gst_gl_effects_glow_step_three (gint width, gint height, guint texture, gpointer stuff)
gst_gl_effects_glow_step_three (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLEffects* effects = GST_GL_EFFECTS (stuff);
GstGLEffects *effects = GST_GL_EFFECTS (stuff);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "glow2");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "glow2", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, vconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
vconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -132,21 +133,21 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture, gpointer
}
void
gst_gl_effects_glow_step_four (gint width, gint height, guint texture, gpointer stuff)
gst_gl_effects_glow_step_four (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLEffects* effects = GST_GL_EFFECTS (stuff);
GstGLEffects *effects = GST_GL_EFFECTS (stuff);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "glow3");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "glow3", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, sum_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
sum_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -156,35 +157,36 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture, gpointer
glActiveTexture (GL_TEXTURE2);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, effects->intexture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1f (shader, "alpha", 1.0);
gst_gl_shader_set_uniform_1i (shader, "base", 2);
glActiveTexture (GL_TEXTURE1);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1f (shader, "beta", (gfloat) 1/3.5f);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1f (shader, "beta", (gfloat) 1 / 3.5f);
gst_gl_shader_set_uniform_1i (shader, "blend", 1);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_glow (GstGLEffects *effects) {
gst_gl_effects_glow (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
/* threshold */
gst_gl_filter_render_to_target (filter, effects->intexture, effects->midtexture[0],
gst_gl_effects_glow_step_one, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->midtexture[0], gst_gl_effects_glow_step_one, effects);
/* blur */
gst_gl_filter_render_to_target (filter, effects->midtexture[0], effects->midtexture[1],
gst_gl_effects_glow_step_two, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[1], effects->midtexture[2],
gst_gl_effects_glow_step_three, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[0],
effects->midtexture[1], gst_gl_effects_glow_step_two, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[1],
effects->midtexture[2], gst_gl_effects_glow_step_three, effects);
/* add blurred luma to intexture */
gst_gl_filter_render_to_target (filter, effects->midtexture[2], effects->outtexture,
gst_gl_effects_glow_step_four, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[2],
effects->outtexture, gst_gl_effects_glow_step_four, effects);
}

View file

@ -21,9 +21,10 @@
#include <gstgleffects.h>
static void
gst_gl_effects_identity_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_identity_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -32,9 +33,10 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture, gpoint
}
void
gst_gl_effects_identity (GstGLEffects *effects) {
gst_gl_effects_identity (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_identity_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_identity_callback, effects);
}

View file

@ -21,24 +21,22 @@
#include <gstgleffects.h>
#include <gstgleffectlumatocurve.h>
void gst_gl_effects_luma_to_curve (GstGLEffects *effects,
GstGLEffectsCurve curve,
gint curve_index,
gint width, gint height,
GLuint texture)
void
gst_gl_effects_luma_to_curve (GstGLEffects * effects,
GstGLEffectsCurve curve,
gint curve_index, gint width, gint height, GLuint texture)
{
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "lumamap0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "lumamap0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, luma_to_curve_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
luma_to_curve_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -47,20 +45,18 @@ void gst_gl_effects_luma_to_curve (GstGLEffects *effects,
if (effects->curve[curve_index] == 0) {
/* this parameters are needed to have a right, predictable, mapping */
glGenTextures(1, &effects->curve[curve_index]);
glEnable(GL_TEXTURE_1D);
glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenTextures (1, &effects->curve[curve_index]);
glEnable (GL_TEXTURE_1D);
glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage1D(GL_TEXTURE_1D, 0, curve.bytes_per_pixel,
curve.width, 0,
GL_RGB, GL_UNSIGNED_BYTE,
curve.pixel_data);
glDisable(GL_TEXTURE_1D);
glTexImage1D (GL_TEXTURE_1D, 0, curve.bytes_per_pixel,
curve.width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve.pixel_data);
glDisable (GL_TEXTURE_1D);
}
glActiveTexture (GL_TEXTURE2);
@ -78,55 +74,63 @@ void gst_gl_effects_luma_to_curve (GstGLEffects *effects,
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
glDisable (GL_TEXTURE_1D);
gst_gl_effects_draw_texture (effects, texture);
}
static void gst_gl_effects_heat_callback (gint width, gint height, guint texture, gpointer data)
static void
gst_gl_effects_heat_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, heat_curve, GST_GL_EFFECTS_CURVE_HEAT,
width, height, texture);
GstGLEffects *effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, heat_curve, GST_GL_EFFECTS_CURVE_HEAT,
width, height, texture);
}
void
gst_gl_effects_heat (GstGLEffects *effects) {
gst_gl_effects_heat (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_heat_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_heat_callback, effects);
}
static void gst_gl_effects_sepia_callback (gint width, gint height, guint texture, gpointer data)
static void
gst_gl_effects_sepia_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, sepia_curve, GST_GL_EFFECTS_CURVE_SEPIA,
width, height, texture);
GstGLEffects *effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, sepia_curve,
GST_GL_EFFECTS_CURVE_SEPIA, width, height, texture);
}
void
gst_gl_effects_sepia (GstGLEffects *effects) {
gst_gl_effects_sepia (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_sepia_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_sepia_callback, effects);
}
static void gst_gl_effects_luma_xpro_callback (gint width, gint height, guint texture, gpointer data)
static void
gst_gl_effects_luma_xpro_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, luma_xpro_curve, GST_GL_EFFECTS_CURVE_LUMA_XPRO,
width, height, texture);
GstGLEffects *effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, luma_xpro_curve,
GST_GL_EFFECTS_CURVE_LUMA_XPRO, width, height, texture);
}
void
gst_gl_effects_luma_xpro (GstGLEffects *effects) {
gst_gl_effects_luma_xpro (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_luma_xpro_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_luma_xpro_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_mirror_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "mirror0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "mirror0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, mirror_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
mirror_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_mirror (GstGLEffects *effects) {
gst_gl_effects_mirror (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_mirror_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_mirror_callback, effects);
}

View file

@ -21,24 +21,22 @@
#include <gstgleffects.h>
#include <gstgleffectscurves.h>
static void gst_gl_effects_rgb_to_curve (GstGLEffects *effects,
GstGLEffectsCurve curve,
gint curve_index,
gint width, gint height,
GLuint texture)
static void
gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
GstGLEffectsCurve curve,
gint curve_index, gint width, gint height, GLuint texture)
{
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "rgbmap0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "rgbmap0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, rgb_to_curve_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
rgb_to_curve_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -47,20 +45,18 @@ static void gst_gl_effects_rgb_to_curve (GstGLEffects *effects,
if (effects->curve[curve_index] == 0) {
/* this parameters are needed to have a right, predictable, mapping */
glGenTextures(1, &effects->curve[curve_index]);
glEnable(GL_TEXTURE_1D);
glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenTextures (1, &effects->curve[curve_index]);
glEnable (GL_TEXTURE_1D);
glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage1D(GL_TEXTURE_1D, 0, curve.bytes_per_pixel,
curve.width, 0,
GL_RGB, GL_UNSIGNED_BYTE,
curve.pixel_data);
glDisable(GL_TEXTURE_1D);
glTexImage1D (GL_TEXTURE_1D, 0, curve.bytes_per_pixel,
curve.width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve.pixel_data);
glDisable (GL_TEXTURE_1D);
}
glActiveTexture (GL_TEXTURE0);
@ -78,22 +74,25 @@ static void gst_gl_effects_rgb_to_curve (GstGLEffects *effects,
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
glDisable (GL_TEXTURE_1D);
gst_gl_effects_draw_texture (effects, texture);
}
static void gst_gl_effects_xpro_callback (gint width, gint height, guint texture, gpointer data)
static void
gst_gl_effects_xpro_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
gst_gl_effects_rgb_to_curve (effects, xpro_curve, GST_GL_EFFECTS_CURVE_XPRO,
width, height, texture);
GstGLEffects *effects = GST_GL_EFFECTS (data);
gst_gl_effects_rgb_to_curve (effects, xpro_curve, GST_GL_EFFECTS_CURVE_XPRO,
width, height, texture);
}
void
gst_gl_effects_xpro (GstGLEffects *effects) {
gst_gl_effects_xpro (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_xpro_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_xpro_callback, effects);
}

View file

@ -21,41 +21,42 @@
#include <gstgleffects.h>
static void
gst_gl_effects_sin_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_sin_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "sin0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "sin0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, sin_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
sin_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_sin (GstGLEffects *effects) {
gst_gl_effects_sin (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_sin_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_sin_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_square_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_square_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "square0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "square0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, square_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
square_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_square (GstGLEffects *effects) {
gst_gl_effects_square (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_square_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_square_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_squeeze_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "squeeze0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "squeeze0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, squeeze_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
squeeze_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_squeeze (GstGLEffects *effects) {
gst_gl_effects_squeeze (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_squeeze_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_squeeze_callback, effects);
}

View file

@ -27,391 +27,350 @@
/* Mirror effect */
const gchar *mirror_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" normcoord.x *= sign (normcoord.x);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color * gl_Color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" normcoord.x *= sign (normcoord.x);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color * gl_Color;" "}";
/* Squeeze effect */
const gchar *squeeze_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0; "
" float r = length (normcoord);"
" r = pow(r, 0.40)*1.3;"
" normcoord = normcoord / r;"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color * gl_Color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0; "
" float r = length (normcoord);"
" r = pow(r, 0.40)*1.3;"
" normcoord = normcoord / r;"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color * gl_Color;" "}";
/* Stretch Effect */
const gchar *stretch_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= 2.0 - smoothstep(0.0, 0.7, r);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color * gl_Color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= 2.0 - smoothstep(0.0, 0.7, r);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color * gl_Color;" "}";
/* Light Tunnel effect */
const gchar *tunnel_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
/* little trick with normalized coords to obtain a circle */
" normcoord = texturecoord / tex_size.x - tex_size / tex_size.x;"
" float r = length(normcoord);"
" float phi = atan(normcoord.y, normcoord.x);"
" r = clamp (r, 0.0, 0.5);" /* is there a way to do this without polars? */
" normcoord.x = r * cos(phi);"
" normcoord.y = r * sin(phi); "
" texturecoord = (normcoord + tex_size/tex_size.x) * tex_size.x;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;" " vec2 normcoord;"
/* little trick with normalized coords to obtain a circle */
" normcoord = texturecoord / tex_size.x - tex_size / tex_size.x;" " float r = length(normcoord);" " float phi = atan(normcoord.y, normcoord.x);" " r = clamp (r, 0.0, 0.5);" /* is there a way to do this without polars? */
" normcoord.x = r * cos(phi);"
" normcoord.y = r * sin(phi); "
" texturecoord = (normcoord + tex_size/tex_size.x) * tex_size.x;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;" "}";
/* FishEye effect */
const gchar *fisheye_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= r/sqrt(2.0);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= r/sqrt(2.0);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color;" "}";
/* Twirl effect */
const gchar *twirl_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" float phi = atan (normcoord.y, normcoord.x);"
" phi += (1.0 - smoothstep (-0.6, 0.6, r)) * 4.8;"
" normcoord.x = r * cos(phi);"
" normcoord.y = r * sin(phi);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" float phi = atan (normcoord.y, normcoord.x);"
" phi += (1.0 - smoothstep (-0.6, 0.6, r)) * 4.8;"
" normcoord.x = r * cos(phi);"
" normcoord.y = r * sin(phi);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;" "}";
/* Bulge effect */
const gchar *bulge_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= smoothstep (-0.1, 0.5, r);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= smoothstep (-0.1, 0.5, r);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color;" "}";
/* Square Effect */
const gchar *square_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width;"
"uniform float height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= 1.0 + smoothstep(0.25, 0.5, abs(normcoord));"
" normcoord /= 2.0; /* zoom amount */"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color * gl_Color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width;"
"uniform float height;"
"void main () {"
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
" float r = length (normcoord);"
" normcoord *= 1.0 + smoothstep(0.25, 0.5, abs(normcoord));"
" normcoord /= 2.0; /* zoom amount */"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord);"
" gl_FragColor = color * gl_Color;" "}";
const gchar *luma_threshold_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"void main () {"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 color = texture2DRect(tex, texturecoord);"
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));" /* BT.709 (from orange book) */
" gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
"}";
const gchar *luma_threshold_fragment_source = "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect tex;" "void main () {" " vec2 texturecoord = gl_TexCoord[0].st;" " int i;" " vec4 color = texture2DRect(tex, texturecoord);" " float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));" /* BT.709 (from orange book) */
" gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
"}";
const gchar *sobel_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float hkern[9];"
"uniform float vkern[9];"
"uniform bool invert;"
"void main () {"
" vec2 offset[9] = vec2[9] ( vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" float luma;"
" float gx = 0.0;"
" float gy = 0.0 ;"
" for (i = 0; i < 9; i++) { "
" if(hkern[i] != 0.0 || vkern[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, texturecoord + vec2(offset[i])); "
" luma = dot(neighbor, vec4(0.2125, 0.7154, 0.0721, neighbor.a));"
" gx += luma * hkern[i]; "
" gy += luma * vkern[i]; "
" }"
" }"
" float g = sqrt(gx*gx + gy*gy);"
" if (invert) g = 1.0 - g;"
" gl_FragColor = vec4(vec3(g), 1.0);"
"}";
const gchar *sobel_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float hkern[9];"
"uniform float vkern[9];"
"uniform bool invert;"
"void main () {"
" vec2 offset[9] = vec2[9] ( vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" float luma;"
" float gx = 0.0;"
" float gy = 0.0 ;"
" for (i = 0; i < 9; i++) { "
" if(hkern[i] != 0.0 || vkern[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, texturecoord + vec2(offset[i])); "
" luma = dot(neighbor, vec4(0.2125, 0.7154, 0.0721, neighbor.a));"
" gx += luma * hkern[i]; "
" gy += luma * vkern[i]; "
" }"
" }"
" float g = sqrt(gx*gx + gy*gy);"
" if (invert) g = 1.0 - g;" " gl_FragColor = vec4(vec3(g), 1.0);" "}";
/* horizontal convolution */
const gchar *hconv9_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;" "uniform float kernel[9];" "void main () {"
/* "float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);" */
/* don't use array constructor so we don't have to depend on #version 120 */
" float offset[9];"
" offset[0] = -4.0;"
" offset[1] = -3.0;"
" offset[2] = -2.0;"
" offset[3] = -1.0;"
" offset[4] = 0.0;"
" offset[5] = 1.0;"
" offset[6] = 2.0;"
" offset[7] = 3.0;"
" offset[8] = 4.0;"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s+offset[i], texturecoord.t)); "
" sum += neighbor * kernel[i]/norm_const; "
" }"
" }"
" gl_FragColor = sum + norm_offset;"
"}";
" float offset[9];"
" offset[0] = -4.0;"
" offset[1] = -3.0;"
" offset[2] = -2.0;"
" offset[3] = -1.0;"
" offset[4] = 0.0;"
" offset[5] = 1.0;"
" offset[6] = 2.0;"
" offset[7] = 3.0;"
" offset[8] = 4.0;"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s+offset[i], texturecoord.t)); "
" sum += neighbor * kernel[i]/norm_const; "
" }" " }" " gl_FragColor = sum + norm_offset;" "}";
/* vertical convolution */
const gchar *vconv9_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;" "uniform float kernel[9];" "void main () {"
/* "float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);" */
/* don't use array constructor so we don't have to depend on #version 120 */
" float offset[9];"
" offset[0] = -4.0;"
" offset[1] = -3.0;"
" offset[2] = -2.0;"
" offset[3] = -1.0;"
" offset[4] = 0.0;"
" offset[5] = 1.0;"
" offset[6] = 2.0;"
" offset[7] = 3.0;"
" offset[8] = 4.0;"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s, texturecoord.t+offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }"
" }"
" gl_FragColor = sum + norm_offset;"
"}";
" float offset[9];"
" offset[0] = -4.0;"
" offset[1] = -3.0;"
" offset[2] = -2.0;"
" offset[3] = -1.0;"
" offset[4] = 0.0;"
" offset[5] = 1.0;"
" offset[6] = 2.0;"
" offset[7] = 3.0;"
" offset[8] = 4.0;"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s, texturecoord.t+offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }" " }" " gl_FragColor = sum + norm_offset;" "}";
/* TODO: support several blend modes */
const gchar *sum_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform float alpha;"
"uniform float beta;"
"void main () {"
" vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
" vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
" gl_FragColor = alpha * basecolor + beta * blendcolor;"
"}";
const gchar *sum_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform float alpha;"
"uniform float beta;"
"void main () {"
" vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
" vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
" gl_FragColor = alpha * basecolor + beta * blendcolor;" "}";
const gchar *multiply_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform float alpha;"
"void main () {"
" vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
" vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
" gl_FragColor = (1 - alpha) * basecolor + alpha * basecolor * blendcolor;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform float alpha;"
"void main () {"
" vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
" vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
" gl_FragColor = (1 - alpha) * basecolor + alpha * basecolor * blendcolor;"
"}";
/* lut operations, map luma to tex1d, see orange book (chapter 19) */
const gchar *luma_to_curve_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform sampler1D curve;"
"void main () {"
" vec2 texturecoord = gl_TexCoord[0].st;"
" vec4 color = texture2DRect (tex, texturecoord);"
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
" color = texture1D(curve, luma);"
" gl_FragColor = color;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform sampler1D curve;"
"void main () {"
" vec2 texturecoord = gl_TexCoord[0].st;"
" vec4 color = texture2DRect (tex, texturecoord);"
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
" color = texture1D(curve, luma);" " gl_FragColor = color;" "}";
/* lut operations, map rgb to tex1d, see orange book (chapter 19) */
const gchar *rgb_to_curve_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform sampler1D curve;"
"void main () {"
" vec2 texturecoord = gl_TexCoord[0].st;"
" vec4 color = texture2DRect (tex, texturecoord);"
" vec4 outcolor;"
" outcolor.r = texture1D(curve, color.r).r;"
" outcolor.g = texture1D(curve, color.g).g;"
" outcolor.b = texture1D(curve, color.b).b;"
" outcolor.a = color.a;"
" gl_FragColor = outcolor;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform sampler1D curve;"
"void main () {"
" vec2 texturecoord = gl_TexCoord[0].st;"
" vec4 color = texture2DRect (tex, texturecoord);"
" vec4 outcolor;"
" outcolor.r = texture1D(curve, color.r).r;"
" outcolor.g = texture1D(curve, color.g).g;"
" outcolor.b = texture1D(curve, color.b).b;"
" outcolor.a = color.a;" " gl_FragColor = outcolor;" "}";
const gchar *sin_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"vec3 rgb2hsl (vec3 v) "
"{"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;" "vec3 rgb2hsl (vec3 v) " "{"
/* TODO: check this algorythm */
" float MIN, MAX;"
" float r, g, b;"
" float h, l, s;"
" float delta;"
" h = 0.0; l = 0.0; s = 0.0;"
" r = v.r; g = v.g; b = v.b;"
" MIN = min (r, min (g, b));"
" MAX = max (r, max (g, b));"
" delta = MAX - MIN;"
" l = (MAX + MIN) / 2.0;"
" if ((MAX - MIN) < 0.0001) { h = 0.0; s = 0.0; }"
" else {"
" if (l <= 0.5) s = (MAX - MIN) / (MAX + MIN);"
" else s = (MAX - MIN) / (2.0 - MAX - MIN);"
" if (r == MAX) h = (g - b) / delta;"
" else if (g == MAX) h = 2.0 + (b - r) / delta;"
" else h = 4.0 + (r - g) / delta;"
" h *= 60.0;"
" if (h < 0.0) h += 360.0;"
" }"
" return vec3 (h, l, s);"
"}"
"void main () {"
" vec3 HSL, RGB;"
" vec4 color = texture2DRect (tex, vec2(gl_TexCoord[0].st));"
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
" HSL = rgb2hsl (color.rgb);"
" float MIN, MAX;"
" float r, g, b;"
" float h, l, s;"
" float delta;"
" h = 0.0; l = 0.0; s = 0.0;"
" r = v.r; g = v.g; b = v.b;"
" MIN = min (r, min (g, b));"
" MAX = max (r, max (g, b));"
" delta = MAX - MIN;"
" l = (MAX + MIN) / 2.0;"
" if ((MAX - MIN) < 0.0001) { h = 0.0; s = 0.0; }"
" else {"
" if (l <= 0.5) s = (MAX - MIN) / (MAX + MIN);"
" else s = (MAX - MIN) / (2.0 - MAX - MIN);"
" if (r == MAX) h = (g - b) / delta;"
" else if (g == MAX) h = 2.0 + (b - r) / delta;"
" else h = 4.0 + (r - g) / delta;"
" h *= 60.0;"
" if (h < 0.0) h += 360.0;"
" }"
" return vec3 (h, l, s);"
"}"
"void main () {"
" vec3 HSL, RGB;"
" vec4 color = texture2DRect (tex, vec2(gl_TexCoord[0].st));"
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
" HSL = rgb2hsl (color.rgb);"
/* move hls discontinuity away from the desired red zone so we can use
* smoothstep.. to try: convert degrees in radiants, divide by 2 and
* smoothstep cosine */
" HSL.x += 180.0;"
" if ((HSL.x) > 360.0) HSL.x -= 360.0;"
" HSL.x += 180.0;" " if ((HSL.x) > 360.0) HSL.x -= 360.0;"
/* damn, it is extremely hard to get rid of human face reds! */
/* picked hue is slightly shifted towards violet to prevent this but
* still fails.. maybe hsl is not well suited for this */
" float a = smoothstep (110.0, 150.0, HSL.x);"
" float b = smoothstep (170.0, 210.0, HSL.x);"
" float alpha = a - b;"
" gl_FragColor = color * alpha + luma * (1.0 - alpha);"
"}";
" float a = smoothstep (110.0, 150.0, HSL.x);"
" float b = smoothstep (170.0, 210.0, HSL.x);"
" float alpha = a - b;"
" gl_FragColor = color * alpha + luma * (1.0 - alpha);" "}";
const gchar *interpolate_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"void main () {"
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
"vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
"vec4 white = vec4(1.0);"
"gl_FragColor = blendcolor + (1.0 - blendcolor.a) * basecolor;"
"}";
const gchar *interpolate_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"void main () {"
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
"vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
"vec4 white = vec4(1.0);"
"gl_FragColor = blendcolor + (1.0 - blendcolor.a) * basecolor;" "}";
const gchar *texture_interp_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform sampler2DRect alpha;"
"void main () {"
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
"vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
"vec4 alphacolor = texture2DRect (alpha, gl_TexCoord[0].st);"
const gchar *texture_interp_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect base;"
"uniform sampler2DRect blend;"
"uniform sampler2DRect alpha;"
"void main () {"
"vec4 basecolor = texture2DRect (base, gl_TexCoord[0].st);"
"vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);"
"vec4 alphacolor = texture2DRect (alpha, gl_TexCoord[0].st);"
// "gl_FragColor = alphacolor;"
"gl_FragColor = (alphacolor * blendcolor) + (1.0 - alphacolor) * basecolor;"
"}";
"gl_FragColor = (alphacolor * blendcolor) + (1.0 - alphacolor) * basecolor;"
"}";
const gchar *difference_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect saved;"
"uniform sampler2DRect current;"
"void main () {"
"vec4 savedcolor = texture2DRect (saved, gl_TexCoord[0].st);"
"vec4 currentcolor = texture2DRect (current, gl_TexCoord[0].st);"
"gl_FragColor = vec4 (step (0.12, length (savedcolor - currentcolor)));"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect saved;"
"uniform sampler2DRect current;"
"void main () {"
"vec4 savedcolor = texture2DRect (saved, gl_TexCoord[0].st);"
"vec4 currentcolor = texture2DRect (current, gl_TexCoord[0].st);"
"gl_FragColor = vec4 (step (0.12, length (savedcolor - currentcolor)));"
"}";

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_stretch_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_stretch_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "stretch0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "stretch0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, stretch_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
stretch_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_stretch (GstGLEffects *effects) {
gst_gl_effects_stretch (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_stretch_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_stretch_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_tunnel_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_tunnel_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "tunnel0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "tunnel0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, tunnel_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
tunnel_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_tunnel (GstGLEffects *effects) {
gst_gl_effects_tunnel (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_tunnel_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_tunnel_callback, effects);
}

View file

@ -21,44 +21,45 @@
#include <gstgleffects.h>
static void
gst_gl_effects_twirl_callback (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_twirl_callback (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "twirl0");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "twirl0", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, twirl_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
twirl_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_shader_use (shader);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_effects_draw_texture (effects, texture);
}
void
gst_gl_effects_twirl (GstGLEffects *effects) {
gst_gl_effects_twirl (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture,
gst_gl_effects_twirl_callback, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->outtexture, gst_gl_effects_twirl_callback, effects);
}

View file

@ -24,34 +24,38 @@
/* Gaussian Kernel: std = 1.200000, size = 9x1 */
static gfloat gauss_kernel[9] = { 0.001285f, 0.014607f, 0.082898f,
0.234927f, 0.332452f, 0.234927f,
0.082898f, 0.014607f, 0.001285f };
0.234927f, 0.332452f, 0.234927f,
0.082898f, 0.014607f, 0.001285f
};
/* Normalization Constant = 0.999885 */
static void gst_gl_effects_xray_step_one (gint width, gint height, guint texture, gpointer data)
static void
gst_gl_effects_xray_step_one (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, xray_curve, GST_GL_EFFECTS_CURVE_XRAY,
width, height, texture);
GstGLEffects *effects = GST_GL_EFFECTS (data);
gst_gl_effects_luma_to_curve (effects, xray_curve, GST_GL_EFFECTS_CURVE_XRAY,
width, height, texture);
}
static void
gst_gl_effects_xray_step_two (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_xray_step_two (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "xray1");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "xray1", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, hconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
hconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -73,21 +77,21 @@ gst_gl_effects_xray_step_two (gint width, gint height, guint texture, gpointer d
}
static void
gst_gl_effects_xray_step_three (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_xray_step_three (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "xray2");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "xray2", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, vconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
vconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -109,33 +113,33 @@ gst_gl_effects_xray_step_three (gint width, gint height, guint texture, gpointer
}
static void
gst_gl_effects_xray_step_four (gint width, gint height, guint texture, gpointer data)
gst_gl_effects_xray_step_four (gint width, gint height, guint texture,
gpointer data)
{
GstGLEffects* effects = GST_GL_EFFECTS (data);
GstGLEffects *effects = GST_GL_EFFECTS (data);
GstGLShader *shader;
gfloat hkern[9] = {
gfloat hkern[9] = {
1.0, 0.0, -1.0,
2.0, 0.0, -2.0,
1.0, 0.0, -1.0
};
gfloat vkern[9] = {
1.0, 2.0, 1.0,
0.0, 0.0, 0.0,
1.0, 2.0, 1.0,
0.0, 0.0, 0.0,
-1.0, -2.0, -1.0
};
shader = g_hash_table_lookup (effects->shaderstable, "xray3");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "xray3", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, sobel_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
sobel_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -158,21 +162,21 @@ gst_gl_effects_xray_step_four (gint width, gint height, guint texture, gpointer
}
void
gst_gl_effects_xray_step_five (gint width, gint height, guint texture, gpointer stuff)
gst_gl_effects_xray_step_five (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLEffects* effects = GST_GL_EFFECTS (stuff);
GstGLEffects *effects = GST_GL_EFFECTS (stuff);
GstGLShader *shader;
shader = g_hash_table_lookup (effects->shaderstable, "xray4");
if (!shader) {
shader = gst_gl_shader_new ();
g_hash_table_insert (effects->shaderstable, "xray4", shader);
}
g_return_if_fail (
gst_gl_shader_compile_and_check (shader, multiply_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (shader,
multiply_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -182,37 +186,39 @@ gst_gl_effects_xray_step_five (gint width, gint height, guint texture, gpointer
glActiveTexture (GL_TEXTURE2);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, effects->midtexture[2]);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (shader, "base", 2);
glActiveTexture (GL_TEXTURE1);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1f (shader, "alpha", (gfloat) 0.28f);
gst_gl_shader_set_uniform_1i (shader, "blend", 1);
gst_gl_effects_draw_texture (effects, texture);
}
void gst_gl_effects_xray (GstGLEffects *effects) {
void
gst_gl_effects_xray (GstGLEffects * effects)
{
GstGLFilter *filter = GST_GL_FILTER (effects);
/* map luma to xray curve */
gst_gl_filter_render_to_target (filter, effects->intexture, effects->midtexture[0],
gst_gl_effects_xray_step_one, effects);
gst_gl_filter_render_to_target (filter, effects->intexture,
effects->midtexture[0], gst_gl_effects_xray_step_one, effects);
/* horizontal blur */
gst_gl_filter_render_to_target (filter, effects->midtexture[0], effects->midtexture[1],
gst_gl_effects_xray_step_two, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[0],
effects->midtexture[1], gst_gl_effects_xray_step_two, effects);
/* vertical blur */
gst_gl_filter_render_to_target (filter, effects->midtexture[1], effects->midtexture[2],
gst_gl_effects_xray_step_three, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[1],
effects->midtexture[2], gst_gl_effects_xray_step_three, effects);
/* detect edges with Sobel */
gst_gl_filter_render_to_target (filter, effects->midtexture[2], effects->midtexture[3],
gst_gl_effects_xray_step_four, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[2],
effects->midtexture[3], gst_gl_effects_xray_step_four, effects);
/* multiply edges with the blurred image */
gst_gl_filter_render_to_target (filter, effects->midtexture[3], effects->outtexture,
gst_gl_effects_xray_step_five, effects);
gst_gl_filter_render_to_target (filter, effects->midtexture[3],
effects->outtexture, gst_gl_effects_xray_step_five, effects);
}

View file

@ -101,7 +101,8 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
vts_colors[i].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0 * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1.0f) * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1.0f) * (2.0f / 7.0f),
-1.0f + 2.0f * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1.0f) * (2.0f / 7.0f), -1.0f, 0);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f, 0);
glEnd ();
@ -120,8 +121,10 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
vts_colors[k].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (3.0f / 4.0f),
0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f),
0);
glVertex3f (-1.0f + i * (2.0f / 7.0f), -1.0f + 2.0f * (2.0f / 3.0f), 0);
glEnd ();
}
@ -142,7 +145,8 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
glBegin (GL_QUADS);
glVertex3f (-1.0f + i * (2.0f / 6.0f), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 6.0f), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 6.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + (i + 1) * (2.0f / 6.0f), -1.0f + 2.0f * (3.0f / 4.0f),
0);
glVertex3f (-1.0f + i * (2.0f / 6.0f), -1.0f + 2.0f * (3.0f / 4.0f), 0);
glEnd ();
}
@ -162,11 +166,12 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstGLBuffer * buffer, int w, int h)
vts_colors[k].B * (1 / 255.0f), 1.0f);
glBegin (GL_QUADS);
glVertex3f (-1.0f + 2.0f * (0.5f + i * (1.0f / 12.0f)), -1.0 + 2.0f * 1, 0);
glVertex3f (-1.0f + 2.0f * (0.5f + (i + 1) * (1.0f / 12.0f)), -1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + 2.0f * (0.5f + (i + 1) * (1.0f / 12.0f)),
-1.0f + 2.0f * 1, 0);
glVertex3f (-1.0f + 2.0f * (0.5f + (i + 1) * (1.0f / 12.0f)),
-1.0f + 2.0f * (3.0f / 4.0f), 0);
glVertex3f (-1.0f + 2.0f * (0.5f + i * (1.0f / 12.0f)), -1.0f + 2.0f * (3.0f / 4.0f),
0);
glVertex3f (-1.0f + 2.0f * (0.5f + i * (1.0f / 12.0f)),
-1.0f + 2.0f * (3.0f / 4.0f), 0);
glEnd ();
}

View file

@ -44,7 +44,7 @@
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL bumper filter",
GST_ELEMENT_DETAILS ("OpenGL bumper filter",
"Filter/Effect",
"Bump mapping filter",
"Cyril Comparon <cyril.comparon@gmail.com>, Julien Isorce <julien.isorce@gmail.com>");
@ -59,98 +59,98 @@ enum
GST_DEBUG_CATEGORY_INIT (gst_gl_bumper_debug, "glbumper", 0, "glbumper element");
GST_BOILERPLATE_FULL (GstGLBumper, gst_gl_bumper, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_bumper_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
const GValue * value, GParamSpec * pspec);
static void gst_gl_bumper_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static void gst_gl_bumper_reset (GstGLFilter* filter);
static void gst_gl_bumper_init_shader (GstGLFilter* filter);
static void gst_gl_bumper_reset (GstGLFilter * filter);
static void gst_gl_bumper_init_shader (GstGLFilter * filter);
static gboolean gst_gl_bumper_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_bumper_callback (gint width, gint height, guint texture, gpointer stuff);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_bumper_callback (gint width, gint height, guint texture,
gpointer stuff);
//vertex source
static const gchar *bumper_v_src =
"attribute vec3 aTangent;\n"
"\n"
"varying vec3 vNormal;\n"
"varying vec3 vTangent;\n"
"varying vec3 vVertexToLight0;\n"
"varying vec3 vVertexToLight1;\n"
"\n"
"void main()\n"
"{\n"
" // transform the vertex\n"
" gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n"
"\n"
" // transform the normal and the tangent to scene coords\n"
" vNormal = normalize(gl_NormalMatrix * gl_Normal);\n"
" vTangent = normalize(gl_NormalMatrix * aTangent);\n"
"\n"
" // transforming the vertex position to modelview-space\n"
" //const vec4 vertexInSceneCoords = gl_ModelViewMatrix * gl_Vertex;\n"
"\n"
" // calculate the vector from the vertex position to the light position\n"
" vVertexToLight0 = normalize(gl_LightSource[0].position).xyz;\n"
" vVertexToLight1 = normalize(gl_LightSource[1].position).xyz;\n"
"\n"
" // transit vertex color\n"
" gl_FrontColor = gl_BackColor = gl_Color;\n"
"\n"
" // use the two first sets of texture coordinates in the fragment shader\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_TexCoord[1] = gl_MultiTexCoord1;\n"
"}\n";
"attribute vec3 aTangent;\n"
"\n"
"varying vec3 vNormal;\n"
"varying vec3 vTangent;\n"
"varying vec3 vVertexToLight0;\n"
"varying vec3 vVertexToLight1;\n"
"\n"
"void main()\n"
"{\n"
" // transform the vertex\n"
" gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n"
"\n"
" // transform the normal and the tangent to scene coords\n"
" vNormal = normalize(gl_NormalMatrix * gl_Normal);\n"
" vTangent = normalize(gl_NormalMatrix * aTangent);\n"
"\n"
" // transforming the vertex position to modelview-space\n"
" //const vec4 vertexInSceneCoords = gl_ModelViewMatrix * gl_Vertex;\n"
"\n"
" // calculate the vector from the vertex position to the light position\n"
" vVertexToLight0 = normalize(gl_LightSource[0].position).xyz;\n"
" vVertexToLight1 = normalize(gl_LightSource[1].position).xyz;\n"
"\n"
" // transit vertex color\n"
" gl_FrontColor = gl_BackColor = gl_Color;\n"
"\n"
" // use the two first sets of texture coordinates in the fragment shader\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" gl_TexCoord[1] = gl_MultiTexCoord1;\n" "}\n";
//fragment source
static const gchar *bumper_f_src =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect texture0;\n"
"uniform sampler2DRect texture1;\n"
"\n"
"varying vec3 vNormal;\n"
"varying vec3 vTangent;\n"
"varying vec3 vVertexToLight0;\n"
"varying vec3 vVertexToLight1;\n"
"\n"
"void main()\n"
"{\n"
" // get the color of the textures\n"
" vec4 textureColor = texture2DRect(texture0, gl_TexCoord[0].st);\n"
" vec3 normalmapItem = texture2DRect(texture1, gl_TexCoord[1].st).xyz * 2.0 - 1.0;\n"
"\n"
" // calculate matrix that transform from tangent space to normalmap space (contrary of intuition)\n"
" vec3 binormal = cross(vNormal, vTangent);\n"
" mat3 tangentSpace2normalmapSpaceMat = mat3(vTangent, binormal, vNormal);\n"
"\n"
" // disturb the normal\n"
" vec3 disturbedNormal = tangentSpace2normalmapSpaceMat * normalmapItem;\n"
"\n"
" // calculate the diffuse term and clamping it to [0;1]\n"
" float diffuseTerm0 = clamp(dot(disturbedNormal, vVertexToLight0), 0.0, 1.0);\n"
" float diffuseTerm1 = clamp(dot(disturbedNormal, vVertexToLight1), 0.0, 1.0);\n"
"\n"
" vec3 irradiance = (diffuseTerm0 * gl_LightSource[0].diffuse.rgb + diffuseTerm1 * gl_LightSource[1].diffuse.rgb);\n"
"\n"
" // calculate the final color\n"
" gl_FragColor = vec4(irradiance * textureColor.rgb, textureColor.w);\n"
"}\n";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect texture0;\n"
"uniform sampler2DRect texture1;\n"
"\n"
"varying vec3 vNormal;\n"
"varying vec3 vTangent;\n"
"varying vec3 vVertexToLight0;\n"
"varying vec3 vVertexToLight1;\n"
"\n"
"void main()\n"
"{\n"
" // get the color of the textures\n"
" vec4 textureColor = texture2DRect(texture0, gl_TexCoord[0].st);\n"
" vec3 normalmapItem = texture2DRect(texture1, gl_TexCoord[1].st).xyz * 2.0 - 1.0;\n"
"\n"
" // calculate matrix that transform from tangent space to normalmap space (contrary of intuition)\n"
" vec3 binormal = cross(vNormal, vTangent);\n"
" mat3 tangentSpace2normalmapSpaceMat = mat3(vTangent, binormal, vNormal);\n"
"\n"
" // disturb the normal\n"
" vec3 disturbedNormal = tangentSpace2normalmapSpaceMat * normalmapItem;\n"
"\n"
" // calculate the diffuse term and clamping it to [0;1]\n"
" float diffuseTerm0 = clamp(dot(disturbedNormal, vVertexToLight0), 0.0, 1.0);\n"
" float diffuseTerm1 = clamp(dot(disturbedNormal, vVertexToLight1), 0.0, 1.0);\n"
"\n"
" vec3 irradiance = (diffuseTerm0 * gl_LightSource[0].diffuse.rgb + diffuseTerm1 * gl_LightSource[1].diffuse.rgb);\n"
"\n"
" // calculate the final color\n"
" gl_FragColor = vec4(irradiance * textureColor.rgb, textureColor.w);\n"
"}\n";
#define LOAD_ERROR(msg) { GST_WARNING ("unable to load %s: %s", bumper->location, msg); display->isAlive = FALSE; return; }
//png reading error handler
static void
user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
static void
user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
{
g_warning("%s\n", warning_msg);
g_warning ("%s\n", warning_msg);
}
//Called in the gl thread
static void
gst_gl_bumper_init_resources (GstGLFilter *filter)
gst_gl_bumper_init_resources (GstGLFilter * filter)
{
GstGLBumper *bumper = GST_GL_BUMPER (filter);
GstGLDisplay *display = filter->display;
@ -173,80 +173,76 @@ gst_gl_bumper_init_resources (GstGLFilter *filter)
/* BEGIN load png image file */
if ((fp = fopen(bumper->location, "rb")) == NULL)
if ((fp = fopen (bumper->location, "rb")) == NULL)
LOAD_ERROR ("file not found");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
fclose(fp);
if (png_ptr == NULL) {
fclose (fp);
LOAD_ERROR ("failed to initialize the png_struct");
}
png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("failed to initialize the memory for image information");
}
png_init_io(png_ptr, fp);
png_init_io (png_ptr, fp);
png_set_sig_bytes(png_ptr, sig_read);
png_set_sig_bytes (png_ptr, sig_read);
png_read_info(png_ptr, info_ptr);
png_read_info (png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
if (color_type != PNG_COLOR_TYPE_RGB)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
if (color_type != PNG_COLOR_TYPE_RGB) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("color type is not rgb");
}
raw_data = (guchar*) malloc ( sizeof(guchar) * width * height * 3 );
raw_data = (guchar *) malloc (sizeof (guchar) * width * height * 3);
rows = (guchar**)malloc(sizeof(guchar*) * height);
rows = (guchar **) malloc (sizeof (guchar *) * height);
for (y = 0; y < height; ++y)
rows[y] = (guchar*) (raw_data + y * width * 3);
for (y = 0; y < height; ++y)
rows[y] = (guchar *) (raw_data + y * width * 3);
png_read_image(png_ptr, rows);
png_read_image (png_ptr, rows);
free(rows);
free (rows);
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
fclose(fp);
png_read_end (png_ptr, info_ptr);
png_destroy_read_struct (&png_ptr, &info_ptr, png_infopp_NULL);
fclose (fp);
/* END load png image file */
bumper->bumpmap_width = width;
bumper->bumpmap_height = height;
glGenTextures (1, &bumper->bumpmap);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, bumper->bumpmap);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, bumper->bumpmap);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
bumper->bumpmap_width, bumper->bumpmap_height, 0,
GL_RGB, GL_UNSIGNED_BYTE, raw_data);
bumper->bumpmap_width, bumper->bumpmap_height, 0,
GL_RGB, GL_UNSIGNED_BYTE, raw_data);
free (raw_data);
}
//Called in the gl thread
static void
gst_gl_bumper_reset_resources (GstGLFilter *filter)
gst_gl_bumper_reset_resources (GstGLFilter * filter)
{
GstGLBumper *bumper = GST_GL_BUMPER (filter);
if (bumper->bumpmap)
{
if (bumper->bumpmap) {
glDeleteTextures (1, &bumper->bumpmap);
bumper->bumpmap = 0;
}
@ -261,9 +257,9 @@ gst_gl_bumper_base_init (gpointer klass)
}
static void
gst_gl_bumper_class_init (GstGLBumperClass* klass)
gst_gl_bumper_class_init (GstGLBumperClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_bumper_set_property;
@ -276,90 +272,87 @@ gst_gl_bumper_class_init (GstGLBumperClass* klass)
GST_GL_FILTER_CLASS (klass)->onReset = gst_gl_bumper_reset;
g_object_class_install_property (gobject_class,
PROP_LOCATION, g_param_spec_string ("location",
"Normal map location",
"Normal map location",
NULL, G_PARAM_READWRITE));
PROP_LOCATION, g_param_spec_string ("location",
"Normal map location",
"Normal map location", NULL, G_PARAM_READWRITE));
}
static void
gst_gl_bumper_init (GstGLBumper* bumper,
GstGLBumperClass* klass)
gst_gl_bumper_init (GstGLBumper * bumper, GstGLBumperClass * klass)
{
bumper->shader = NULL;
bumper->bumpmap = 0;
bumper->bumpmap_width = 0;
bumper->bumpmap_height = 0;
bumper->location = NULL;
bumper->shader = NULL;
bumper->bumpmap = 0;
bumper->bumpmap_width = 0;
bumper->bumpmap_height = 0;
bumper->location = NULL;
}
static void
gst_gl_bumper_reset (GstGLFilter* filter)
gst_gl_bumper_reset (GstGLFilter * filter)
{
GstGLBumper* bumper_filter = GST_GL_BUMPER(filter);
GstGLBumper *bumper_filter = GST_GL_BUMPER (filter);
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, bumper_filter->shader);
}
static void
gst_gl_bumper_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_bumper_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLBumper *bumper = GST_GL_BUMPER (object);
switch (prop_id)
{
case PROP_LOCATION:
if (bumper->location != NULL)
g_free (bumper->location);
bumper->location = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
case PROP_LOCATION:
if (bumper->location != NULL)
g_free (bumper->location);
bumper->location = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_bumper_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_bumper_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstGLBumper *bumper = GST_GL_BUMPER (object);
switch (prop_id)
{
case PROP_LOCATION:
g_value_set_string (value, bumper->location);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
case PROP_LOCATION:
g_value_set_string (value, bumper->location);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_bumper_init_shader (GstGLFilter* filter)
gst_gl_bumper_init_shader (GstGLFilter * filter)
{
GstGLBumper *bumper = GST_GL_BUMPER (filter);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, bumper_v_src, bumper_f_src, &bumper->shader);
gst_gl_display_gen_shader (filter->display, bumper_v_src, bumper_f_src,
&bumper->shader);
}
static gboolean
gst_gl_bumper_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_bumper_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
gpointer bumper_filter = GST_GL_BUMPER (filter);
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_bumper_callback,
inbuf->width, inbuf->height, inbuf->texture,
//bumper_filter->fovy, bumper_filter->aspect, bumper_filter->znear, bumper_filter->zfar,
45, (gdouble)filter->width/(gdouble)filter->height, 0.1, 50,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, bumper_filter);
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_bumper_callback,
inbuf->width, inbuf->height, inbuf->texture,
//bumper_filter->fovy, bumper_filter->aspect, bumper_filter->znear, bumper_filter->zfar,
45, (gdouble) filter->width / (gdouble) filter->height, 0.1, 50,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, bumper_filter);
return TRUE;
}
@ -368,48 +361,47 @@ gst_gl_bumper_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
static void
gst_gl_bumper_callback (gint width, gint height, guint texture, gpointer stuff)
{
static GLfloat xrot = 0;
static GLfloat yrot = 0;
static GLfloat zrot = 0;
GstGLBumper* bumper = GST_GL_BUMPER (stuff);
static GLfloat xrot = 0;
static GLfloat yrot = 0;
static GLfloat zrot = 0;
GstGLBumper *bumper = GST_GL_BUMPER (stuff);
GLint locTangent = 0;
//choose the lights
GLfloat light_direction0[] = { 1.0, 0.0, -1.0, 0.0 }; // light goes along -x
GLfloat light_direction1[] = { -1.0, 0.0, -1.0, 0.0 }; // light goes along x
GLfloat light_direction1[] = { -1.0, 0.0, -1.0, 0.0 }; // light goes along x
GLfloat light_diffuse0[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_diffuse1[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
//eye point
glMatrixMode(GL_PROJECTION);
gluLookAt(0.0, 0.0, -6.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glMatrixMode (GL_PROJECTION);
gluLookAt (0.0, 0.0, -6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode (GL_MODELVIEW);
//scene conf
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel (GL_SMOOTH);
//set the lights
glLightfv(GL_LIGHT0, GL_POSITION, light_direction0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
glLightfv(GL_LIGHT1, GL_POSITION, light_direction1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glLightfv (GL_LIGHT0, GL_POSITION, light_direction0);
glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
glLightfv (GL_LIGHT1, GL_POSITION, light_direction1);
glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse);
glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable (GL_COLOR_MATERIAL);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_LIGHT1);
//configure shader
gst_gl_shader_use (bumper->shader);
locTangent = gst_gl_shader_get_attribute_location (bumper->shader, "aTangent");
locTangent =
gst_gl_shader_get_attribute_location (bumper->shader, "aTangent");
//set the normal map
glActiveTextureARB (GL_TEXTURE1_ARB);
@ -423,117 +415,123 @@ gst_gl_bumper_callback (gint width, gint height, guint texture, gpointer stuff)
//glTranslatef(2.0f, 2.0f, 5.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);
glRotatef (xrot, 1.0f, 0.0f, 0.0f);
glRotatef (yrot, 0.0f, 1.0f, 0.0f);
glRotatef (zrot, 0.0f, 0.0f, 1.0f);
//Cube
glBegin(GL_QUADS);
glBegin (GL_QUADS);
// front face
glNormal3d(0.0, 0.0, -1.0);
glVertexAttrib3dARB(locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d( 1.0, 1.0, -1.0); // B
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d( 1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d(-1.0, -1.0, -1.0); // D
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d(-1.0, 1.0, -1.0); // C
// front face
glNormal3d (0.0, 0.0, -1.0);
glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (1.0, 1.0, -1.0); // B
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (-1.0, -1.0, -1.0); // D
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (-1.0, 1.0, -1.0); // C
// right face
glNormal3d(-1.0, 0.0, 0.0);
glVertexAttrib3dARB(locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d(-1.0, 1.0, -1.0); // C
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d(-1.0, -1.0, -1.0); // D
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d(-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d(-1.0, 1.0, 1.0); // G
// right face
glNormal3d (-1.0, 0.0, 0.0);
glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (-1.0, 1.0, -1.0); // C
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (-1.0, -1.0, -1.0); // D
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (-1.0, 1.0, 1.0); // G
// back face
glNormal3d(0.0, 0.0, 1.0);
glVertexAttrib3dARB(locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d(-1.0, 1.0, 1.0); // G
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d(-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d( 1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d( 1.0, 1.0, 1.0); // F
// back face
glNormal3d (0.0, 0.0, 1.0);
glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (-1.0, 1.0, 1.0); // G
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (1.0, 1.0, 1.0); // F
// left face
glNormal3d(1.0, 0.0, 0.0);
glVertexAttrib3dARB(locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d( 1.0, 1.0, 1.0); // F
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d( 1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d( 1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d( 1.0, 1.0, -1.0); // B
// left face
glNormal3d (1.0, 0.0, 0.0);
glVertexAttrib3dARB (locTangent, 0.0, 1.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (1.0, 1.0, 1.0); // F
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (1.0, 1.0, -1.0); // B
// top face
glNormal3d(0.0, 1.0, 0.0);
glVertexAttrib3dARB(locTangent, 0.0, 0.0, 1.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d( 1.0, 1.0, 1.0); // F
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d( 1.0, 1.0, -1.0); // B
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d(-1.0, 1.0, -1.0); // C
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d(-1.0, 1.0, 1.0); // G
// top face
glNormal3d (0.0, 1.0, 0.0);
glVertexAttrib3dARB (locTangent, 0.0, 0.0, 1.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (1.0, 1.0, 1.0); // F
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (1.0, 1.0, -1.0); // B
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (-1.0, 1.0, -1.0); // C
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (-1.0, 1.0, 1.0); // G
// bottom face
glNormal3d(0.0, -1.0, 0.0);
glVertexAttrib3dARB(locTangent, 0.0, 0.0, -1.0);
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d( 1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d( 1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, bumper->bumpmap_height);
glVertex3d(-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB(GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB(GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d(-1.0, -1.0, -1.0); // D
glEnd();
// bottom face
glNormal3d (0.0, -1.0, 0.0);
glVertexAttrib3dARB (locTangent, 0.0, 0.0, -1.0);
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3d (1.0, -1.0, -1.0); // A
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, 0.0, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, 0.0, bumper->bumpmap_height);
glVertex3d (1.0, -1.0, 1.0); // E
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, height);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width,
bumper->bumpmap_height);
glVertex3d (-1.0, -1.0, 1.0); // H
glMultiTexCoord2dARB (GL_TEXTURE0_ARB, width, 0.0);
glMultiTexCoord2dARB (GL_TEXTURE1_ARB, bumper->bumpmap_width, 0.0);
glVertex3d (-1.0, -1.0, -1.0); // D
glEnd ();
glUseProgram(0);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glUseProgram (0);
glDisable (GL_LIGHT0);
glDisable (GL_LIGHT1);
glDisable (GL_LIGHTING);
glDisable (GL_COLOR_MATERIAL);
xrot+=1.0f;
yrot+=0.9f;
zrot+=1.1f;
xrot += 1.0f;
yrot += 0.9f;
zrot += 1.1f;
}

View file

@ -51,17 +51,17 @@
#define GST_CAT_DEFAULT gst_gl_colorscale_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL color scale",
"Filter/Effect",
"Colorspace converter and video scaler",
"Julien Isorce <julien.isorce@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL color scale",
"Filter/Effect",
"Colorspace converter and video scaler",
"Julien Isorce <julien.isorce@gmail.com>");
/* Source pad definition */
static GstStaticPadTemplate gst_gl_colorscale_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";"
@ -86,7 +86,7 @@ static GstStaticPadTemplate gst_gl_colorscale_sink_pad_template =
/* Properties */
enum
{
PROP_0
PROP_0
};
#define DEBUG_INIT(bla) \
@ -95,398 +95,379 @@ enum
GST_BOILERPLATE_FULL (GstGLColorscale, gst_gl_colorscale, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
static void gst_gl_colorscale_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
static void gst_gl_colorscale_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec);
static void gst_gl_colorscale_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_colorscale_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_colorscale_reset (GstGLColorscale* colorscale);
static gboolean gst_gl_colorscale_set_caps (GstBaseTransform* bt,
GstCaps* incaps, GstCaps* outcaps);
static GstCaps *gst_gl_colorscale_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static void gst_gl_colorscale_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps);
static gboolean gst_gl_colorscale_start (GstBaseTransform* bt);
static gboolean gst_gl_colorscale_stop (GstBaseTransform* bt);
static GstFlowReturn gst_gl_colorscale_transform (GstBaseTransform* trans,
GstBuffer* inbuf, GstBuffer * outbuf);
static gboolean gst_gl_colorscale_get_unit_size (GstBaseTransform* trans,
GstCaps* caps, guint* size);
static void gst_gl_colorscale_reset (GstGLColorscale * colorscale);
static gboolean gst_gl_colorscale_set_caps (GstBaseTransform * bt,
GstCaps * incaps, GstCaps * outcaps);
static GstCaps *gst_gl_colorscale_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps);
static void gst_gl_colorscale_fixate_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
static gboolean gst_gl_colorscale_start (GstBaseTransform * bt);
static gboolean gst_gl_colorscale_stop (GstBaseTransform * bt);
static GstFlowReturn gst_gl_colorscale_transform (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_colorscale_get_unit_size (GstBaseTransform * trans,
GstCaps * caps, guint * size);
static void
gst_gl_colorscale_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_colorscale_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_colorscale_sink_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_colorscale_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_colorscale_sink_pad_template));
}
static void
gst_gl_colorscale_class_init (GstGLColorscaleClass* klass)
gst_gl_colorscale_class_init (GstGLColorscaleClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_colorscale_set_property;
gobject_class->get_property = gst_gl_colorscale_get_property;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_colorscale_set_property;
gobject_class->get_property = gst_gl_colorscale_get_property;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_colorscale_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_colorscale_fixate_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_colorscale_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_colorscale_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_colorscale_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_colorscale_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_colorscale_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_colorscale_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_colorscale_fixate_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_colorscale_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_colorscale_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_colorscale_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_colorscale_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
gst_gl_colorscale_get_unit_size;
}
static void
gst_gl_colorscale_init (GstGLColorscale* colorscale, GstGLColorscaleClass* klass)
gst_gl_colorscale_init (GstGLColorscale * colorscale,
GstGLColorscaleClass * klass)
{
gst_gl_colorscale_reset (colorscale);
gst_gl_colorscale_reset (colorscale);
}
static void
gst_gl_colorscale_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_colorscale_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (object);
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_colorscale_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_colorscale_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLColorscale *colorscale = GST_GL_COLORSCALE (object);
//GstGLColorscale *colorscale = GST_GL_COLORSCALE (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_colorscale_reset (GstGLColorscale* colorscale)
gst_gl_colorscale_reset (GstGLColorscale * colorscale)
{
if (colorscale->display)
{
g_object_unref (colorscale->display);
colorscale->display = NULL;
}
if (colorscale->display) {
g_object_unref (colorscale->display);
colorscale->display = NULL;
}
}
static gboolean
gst_gl_colorscale_start (GstBaseTransform* bt)
gst_gl_colorscale_start (GstBaseTransform * bt)
{
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
return TRUE;
return TRUE;
}
static gboolean
gst_gl_colorscale_stop (GstBaseTransform* bt)
gst_gl_colorscale_stop (GstBaseTransform * bt)
{
GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
GstGLColorscale *colorscale = GST_GL_COLORSCALE (bt);
gst_gl_colorscale_reset (colorscale);
gst_gl_colorscale_reset (colorscale);
return TRUE;
return TRUE;
}
static GstCaps*
gst_gl_colorscale_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps)
static GstCaps *
gst_gl_colorscale_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps)
{
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
GstStructure* structure = gst_caps_get_structure (caps, 0);
GstCaps* newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
GstCaps* newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
const GValue* framerate_value = NULL;
const GValue* par_value = NULL;
//GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
GstStructure *structure = gst_caps_get_structure (caps, 0);
GstCaps *newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
GstCaps *newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
const GValue *framerate_value = NULL;
const GValue *par_value = NULL;
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
gst_caps_append(newcaps, newothercaps);
gst_caps_append (newcaps, newothercaps);
structure = gst_structure_copy (gst_caps_get_structure (newcaps, 0));
structure = gst_structure_copy (gst_caps_get_structure (newcaps, 0));
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_structure_set_value (structure, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (structure, "pixel-aspect-ratio", par_value);
else
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_structure_set_value (structure, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (structure, "pixel-aspect-ratio", par_value);
else
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_caps_merge_structure (newcaps, gst_structure_copy (structure));
gst_caps_merge_structure (newcaps, gst_structure_copy (structure));
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
return newcaps;
return newcaps;
}
/* from gst-plugins-base "videoscale" code */
static void
gst_gl_colorscale_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps)
gst_gl_colorscale_fixate_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
{
GstStructure *ins, *outs;
GstStructure *ins, *outs;
const GValue *from_par, *to_par;
const GValue *from_par, *to_par;
g_return_if_fail (gst_caps_is_fixed (caps));
g_return_if_fail (gst_caps_is_fixed (caps));
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
ins = gst_caps_get_structure (caps, 0);
outs = gst_caps_get_structure (othercaps, 0);
ins = gst_caps_get_structure (caps, 0);
outs = gst_caps_get_structure (othercaps, 0);
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
//we have both PAR but they might not be fixated
if (from_par && to_par)
{
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
//we have both PAR but they might not be fixated
if (from_par && to_par) {
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
gint count = 0, w = 0, h = 0;
gint count = 0, w = 0, h = 0;
guint num, den;
guint num, den;
//from_par should be fixed
g_return_if_fail (gst_value_is_fixed (from_par));
//from_par should be fixed
g_return_if_fail (gst_value_is_fixed (from_par));
from_par_n = gst_value_get_fraction_numerator (from_par);
from_par_d = gst_value_get_fraction_denominator (from_par);
from_par_n = gst_value_get_fraction_numerator (from_par);
from_par_d = gst_value_get_fraction_denominator (from_par);
//fixate the out PAR
if (!gst_value_is_fixed (to_par))
{
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", from_par_n,
from_par_d);
gst_structure_fixate_field_nearest_fraction (outs, "pixel-aspect-ratio",
from_par_n, from_par_d);
}
to_par_n = gst_value_get_fraction_numerator (to_par);
to_par_d = gst_value_get_fraction_denominator (to_par);
//f both width and height are already fixed, we can't do anything
//about it anymore
if (gst_structure_get_int (outs, "width", &w))
++count;
if (gst_structure_get_int (outs, "height", &h))
++count;
if (count == 2)
{
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
w, h);
return;
}
gst_structure_get_int (ins, "width", &from_w);
gst_structure_get_int (ins, "height", &from_h);
if (!gst_video_calculate_display_ratio (&num, &den, from_w, from_h,
from_par_n, from_par_d, to_par_n, to_par_d))
{
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
("Error calculating the output scaled size - integer overflow"));
return;
}
GST_DEBUG_OBJECT (base,
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
GST_DEBUG_OBJECT (base, "resulting output should respect ratio of %d/%d",
num, den);
//now find a width x height that respects this display ratio.
//prefer those that have one of w/h the same as the incoming video
//using wd / hd = num / den
//if one of the output width or height is fixed, we work from there
if (h)
{
GST_DEBUG_OBJECT (base, "height is fixed,scaling width");
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (w)
{
GST_DEBUG_OBJECT (base, "width is fixed, scaling height");
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
//none of width or height is fixed, figure out both of them based only on
//the input width and height
//check hd / den is an integer scale factor, and scale wd with the PAR
if (from_h % den == 0)
{
GST_DEBUG_OBJECT (base, "keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (from_w % num == 0)
{
GST_DEBUG_OBJECT (base, "keeping video width");
w = from_w;
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
}
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
//now fixate
gst_structure_fixate_field_nearest_int (outs, "width", w);
gst_structure_fixate_field_nearest_int (outs, "height", h);
}
else
{
gint width, height;
if (gst_structure_get_int (ins, "width", &width))
{
if (gst_structure_has_field (outs, "width"))
gst_structure_fixate_field_nearest_int (outs, "width", width);
}
if (gst_structure_get_int (ins, "height", &height)) {
if (gst_structure_has_field (outs, "height")) {
gst_structure_fixate_field_nearest_int (outs, "height", height);
}
}
//fixate the out PAR
if (!gst_value_is_fixed (to_par)) {
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", from_par_n,
from_par_d);
gst_structure_fixate_field_nearest_fraction (outs, "pixel-aspect-ratio",
from_par_n, from_par_d);
}
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
to_par_n = gst_value_get_fraction_numerator (to_par);
to_par_d = gst_value_get_fraction_denominator (to_par);
//f both width and height are already fixed, we can't do anything
//about it anymore
if (gst_structure_get_int (outs, "width", &w))
++count;
if (gst_structure_get_int (outs, "height", &h))
++count;
if (count == 2) {
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
w, h);
return;
}
gst_structure_get_int (ins, "width", &from_w);
gst_structure_get_int (ins, "height", &from_h);
if (!gst_video_calculate_display_ratio (&num, &den, from_w, from_h,
from_par_n, from_par_d, to_par_n, to_par_d)) {
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
("Error calculating the output scaled size - integer overflow"));
return;
}
GST_DEBUG_OBJECT (base,
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
GST_DEBUG_OBJECT (base, "resulting output should respect ratio of %d/%d",
num, den);
//now find a width x height that respects this display ratio.
//prefer those that have one of w/h the same as the incoming video
//using wd / hd = num / den
//if one of the output width or height is fixed, we work from there
if (h) {
GST_DEBUG_OBJECT (base, "height is fixed,scaling width");
w = (guint) gst_util_uint64_scale_int (h, num, den);
} else if (w) {
GST_DEBUG_OBJECT (base, "width is fixed, scaling height");
h = (guint) gst_util_uint64_scale_int (w, den, num);
} else {
//none of width or height is fixed, figure out both of them based only on
//the input width and height
//check hd / den is an integer scale factor, and scale wd with the PAR
if (from_h % den == 0) {
GST_DEBUG_OBJECT (base, "keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
} else if (from_w % num == 0) {
GST_DEBUG_OBJECT (base, "keeping video width");
w = from_w;
h = (guint) gst_util_uint64_scale_int (w, den, num);
} else {
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
}
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
//now fixate
gst_structure_fixate_field_nearest_int (outs, "width", w);
gst_structure_fixate_field_nearest_int (outs, "height", h);
} else {
gint width, height;
if (gst_structure_get_int (ins, "width", &width)) {
if (gst_structure_has_field (outs, "width"))
gst_structure_fixate_field_nearest_int (outs, "width", width);
}
if (gst_structure_get_int (ins, "height", &height)) {
if (gst_structure_has_field (outs, "height")) {
gst_structure_fixate_field_nearest_int (outs, "height", height);
}
}
}
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
}
static gboolean
gst_gl_colorscale_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_colorscale_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps)
{
GstGLColorscale* colorscale = GST_GL_COLORSCALE (bt);
gboolean ret = FALSE;
GstGLColorscale *colorscale = GST_GL_COLORSCALE (bt);
gboolean ret = FALSE;
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
ret = gst_video_format_parse_caps (outcaps, &colorscale->output_video_format,
&colorscale->output_video_width, &colorscale->output_video_height);
ret = gst_video_format_parse_caps (outcaps, &colorscale->output_video_format,
&colorscale->output_video_width, &colorscale->output_video_height);
ret |= gst_video_format_parse_caps (incaps, &colorscale->input_video_format,
&colorscale->input_video_width, &colorscale->input_video_height);
ret |= gst_video_format_parse_caps (incaps, &colorscale->input_video_format,
&colorscale->input_video_width, &colorscale->input_video_height);
if (!ret)
{
GST_DEBUG ("bad caps");
return FALSE;
}
if (!ret) {
GST_DEBUG ("bad caps");
return FALSE;
}
colorscale->display = gst_gl_display_new ();
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);
//init unvisible opengl context
gst_gl_display_create_context (colorscale->display,
colorscale->output_video_width, colorscale->output_video_height);
//blocking call, init colorspace conversion if needed
gst_gl_display_init_upload (colorscale->display, colorscale->input_video_format,
colorscale->output_video_width, colorscale->output_video_height,
colorscale->input_video_width, colorscale->input_video_height);
//blocking call, init colorspace conversion if needed
gst_gl_display_init_upload (colorscale->display,
colorscale->input_video_format, colorscale->output_video_width,
colorscale->output_video_height, colorscale->input_video_width,
colorscale->input_video_height);
//blocking call, init colorspace conversion if needed
gst_gl_display_init_download (colorscale->display, colorscale->output_video_format,
colorscale->output_video_width, colorscale->output_video_height);
//blocking call, init colorspace conversion if needed
gst_gl_display_init_download (colorscale->display,
colorscale->output_video_format, colorscale->output_video_width,
colorscale->output_video_height);
return ret;
return ret;
}
static gboolean
gst_gl_colorscale_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size)
gst_gl_colorscale_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{
gboolean ret;
GstStructure *structure;
gint width;
gint height;
gboolean ret;
GstStructure *structure;
gint width;
gint height;
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl"))
{
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
}
else
{
GstVideoFormat video_format;
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl")) {
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
} else {
GstVideoFormat video_format;
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
return TRUE;
return TRUE;
}
static GstFlowReturn
gst_gl_colorscale_transform (GstBaseTransform* trans, GstBuffer* inbuf,
GstBuffer* outbuf)
gst_gl_colorscale_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer * outbuf)
{
GstGLColorscale* colorscale = GST_GL_COLORSCALE (trans);
gboolean isAlive = TRUE;
GstGLColorscale *colorscale = GST_GL_COLORSCALE (trans);
gboolean isAlive = TRUE;
//blocking call
GstGLBuffer* gl_temp_buffer = gst_gl_buffer_new (colorscale->display,
colorscale->output_video_width, colorscale->output_video_height);
//blocking call
GstGLBuffer *gl_temp_buffer = gst_gl_buffer_new (colorscale->display,
colorscale->output_video_width, colorscale->output_video_height);
GST_DEBUG ("input size %p size %d",
GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
GST_DEBUG ("input size %p size %d",
GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
//blocking call
isAlive = gst_gl_display_do_upload (colorscale->display, gl_temp_buffer->texture,
colorscale->input_video_width, colorscale->input_video_height,
GST_BUFFER_DATA (inbuf));
//blocking call
isAlive =
gst_gl_display_do_upload (colorscale->display, gl_temp_buffer->texture,
colorscale->input_video_width, colorscale->input_video_height,
GST_BUFFER_DATA (inbuf));
GST_DEBUG ("output size %p size %d",
GST_DEBUG ("output size %p size %d",
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
//blocking call
isAlive &= gst_gl_display_do_download(colorscale->display, gl_temp_buffer->texture,
gl_temp_buffer->width, gl_temp_buffer->height,
GST_BUFFER_DATA (outbuf));
//blocking call
isAlive &=
gst_gl_display_do_download (colorscale->display, gl_temp_buffer->texture,
gl_temp_buffer->width, gl_temp_buffer->height, GST_BUFFER_DATA (outbuf));
gst_buffer_unref (gl_temp_buffer);
gst_buffer_unref (gl_temp_buffer);
if (isAlive)
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
if (isAlive)
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
}

View file

@ -52,7 +52,7 @@ struct _GstGLDifferenceMatte
GstGLFilter filter;
GstGLShader *shader[4];
gchar *location;
gboolean bg_has_changed;
@ -78,26 +78,26 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GST_DEBUG_CATEGORY_INIT (gst_gl_differencematte_debug, "gldifferencematte", 0, "gldifferencematte element");
GST_BOILERPLATE_FULL (GstGLDifferenceMatte, gst_gl_differencematte, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_differencematte_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_differencematte_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_differencematte_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_gl_differencematte_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_gl_differencematte_init_resources (GstGLFilter* filter);
static void gst_gl_differencematte_reset_resources (GstGLFilter* filter);
static void gst_gl_differencematte_init_resources (GstGLFilter * filter);
static void gst_gl_differencematte_reset_resources (GstGLFilter * filter);
static gboolean gst_gl_differencematte_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static gboolean gst_gl_differencematte_loader (GstGLFilter* filter);
static gboolean gst_gl_differencematte_loader (GstGLFilter * filter);
static const GstElementDetails element_details = GST_ELEMENT_DETAILS (
"Gstreamer OpenGL DifferenceMatte",
"Filter/Effect",
"Saves a background frame and replace it with a pixbuf",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("Gstreamer OpenGL DifferenceMatte",
"Filter/Effect",
"Saves a background frame and replace it with a pixbuf",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
enum
{
@ -108,53 +108,49 @@ enum
/* init resources that need a gl context */
static void
gst_gl_differencematte_init_gl_resources (GstGLFilter *filter)
gst_gl_differencematte_init_gl_resources (GstGLFilter * filter)
{
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
gint i;
for (i=0; i<4; i++) {
for (i = 0; i < 4; i++) {
glGenTextures (1, &differencematte->midtexture[i]);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, differencematte->midtexture[i]);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->midtexture[i]);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
differencematte->shader[i] = gst_gl_shader_new ();
}
g_return_if_fail (
gst_gl_shader_compile_and_check (differencematte->shader[0],
difference_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (
gst_gl_shader_compile_and_check (differencematte->shader[1],
hconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (
gst_gl_shader_compile_and_check (differencematte->shader[2],
vconv9_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (
gst_gl_shader_compile_and_check (differencematte->shader[3],
texture_interp_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (differencematte->shader[0],
difference_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (differencematte->shader[1],
hconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (differencematte->shader[2],
vconv9_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
g_return_if_fail (gst_gl_shader_compile_and_check (differencematte->shader[3],
texture_interp_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE));
}
/* free resources that need a gl context */
static void
gst_gl_differencematte_reset_gl_resources (GstGLFilter *filter)
gst_gl_differencematte_reset_gl_resources (GstGLFilter * filter)
{
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
gint i;
glDeleteTextures (1, &differencematte->savedbgtexture);
glDeleteTextures (1, &differencematte->newbgtexture);
for (i=0; i<4; i++) {
for (i = 0; i < 4; i++) {
g_object_unref (differencematte->shader[i]);
differencematte->shader[i] = NULL;
glDeleteTextures (1, &differencematte->midtexture[i]);
@ -184,21 +180,23 @@ gst_gl_differencematte_class_init (GstGLDifferenceMatteClass * klass)
gobject_class->get_property = gst_gl_differencematte_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_differencematte_filter;
GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_differencematte_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_differencematte_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_init_cb =
gst_gl_differencematte_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
gst_gl_differencematte_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_differencematte_init_resources;
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_differencematte_reset_resources;
g_object_class_install_property (gobject_class,
PROP_LOCATION,
g_param_spec_string ("location",
"Background image location",
"Background image location",
NULL, G_PARAM_READWRITE));
PROP_LOCATION,
g_param_spec_string ("location",
"Background image location",
"Background image location", NULL, G_PARAM_READWRITE));
}
void
gst_gl_differencematte_draw_texture (GstGLDifferenceMatte * differencematte, GLuint tex)
gst_gl_differencematte_draw_texture (GstGLDifferenceMatte * differencematte,
GLuint tex)
{
GstGLFilter *filter = GST_GL_FILTER (differencematte);
@ -210,19 +208,19 @@ gst_gl_differencematte_draw_texture (GstGLDifferenceMatte * differencematte, GLu
glTexCoord2f (0.0, 0.0);
glVertex2f (-1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, 0.0);
glTexCoord2f ((gfloat) filter->width, 0.0);
glVertex2f (1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, (gfloat)filter->height);
glTexCoord2f ((gfloat) filter->width, (gfloat) filter->height);
glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, (gfloat)filter->height);
glTexCoord2f (0.0, (gfloat) filter->height);
glVertex2f (-1.0, 1.0);
glEnd ();
}
static void
gst_gl_differencematte_init (GstGLDifferenceMatte * differencematte,
GstGLDifferenceMatteClass * klass)
gst_gl_differencematte_init (GstGLDifferenceMatte * differencematte,
GstGLDifferenceMatteClass * klass)
{
differencematte->shader[0] = NULL;
differencematte->shader[1] = NULL;
@ -236,7 +234,7 @@ gst_gl_differencematte_init (GstGLDifferenceMatte * differencematte,
}
static void
gst_gl_differencematte_reset_resources (GstGLFilter* filter)
gst_gl_differencematte_reset_resources (GstGLFilter * filter)
{
// GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE(filter);
}
@ -245,17 +243,18 @@ static void
gst_gl_differencematte_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (object);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (object);
switch (prop_id) {
case PROP_LOCATION:
if (differencematte->location != NULL) g_free (differencematte->location);
differencematte->bg_has_changed = TRUE;
differencematte->location = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_LOCATION:
if (differencematte->location != NULL)
g_free (differencematte->location);
differencematte->bg_has_changed = TRUE;
differencematte->location = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@ -266,61 +265,68 @@ gst_gl_differencematte_get_property (GObject * object, guint prop_id,
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (object);
switch (prop_id) {
case PROP_LOCATION:
g_value_set_string (value, differencematte->location);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_LOCATION:
g_value_set_string (value, differencematte->location);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_differencematte_init_resources (GstGLFilter* filter)
gst_gl_differencematte_init_resources (GstGLFilter * filter)
{
// GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
}
static void
gst_gl_differencematte_save_texture (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_save_texture (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_differencematte_draw_texture (differencematte, texture);
}
static void init_pixbuf_texture (GstGLDisplay *display, gpointer data)
static void
init_pixbuf_texture (GstGLDisplay * display, gpointer data)
{
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (data);
GstGLFilter *filter = GST_GL_FILTER (data);
glDeleteTextures (1, &differencematte->newbgtexture);
glGenTextures (1, &differencematte->newbgtexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->newbgtexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
filter->width, filter->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, differencematte->pixbuf);
filter->width, filter->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, differencematte->pixbuf);
if (differencematte->savedbgtexture == 0) {
glGenTextures (1, &differencematte->savedbgtexture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, differencematte->savedbgtexture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, differencematte->savedbgtexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
}
}
static void
gst_gl_differencematte_diff (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_diff (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -329,8 +335,8 @@ gst_gl_differencematte_diff (gint width, gint height, guint texture, gpointer st
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (differencematte->shader[0], "current", 0);
glActiveTexture (GL_TEXTURE1);
@ -344,15 +350,16 @@ gst_gl_differencematte_diff (gint width, gint height, guint texture, gpointer st
}
static void
gst_gl_differencematte_hblur (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_hblur (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
gfloat gauss_kernel[9] = {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
gfloat gauss_kernel[9] = {
0.026995f, 0.064759f, 0.120985f,
0.176033f, 0.199471f, 0.176033f,
0.120985f, 0.064759f, 0.026995f
};
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -361,27 +368,31 @@ gst_gl_differencematte_hblur (gint width, gint height, guint texture, gpointer s
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (differencematte->shader[1], "tex", 0);
gst_gl_shader_set_uniform_1fv (differencematte->shader[1], "kernel", 9, gauss_kernel);
gst_gl_shader_set_uniform_1f (differencematte->shader[1], "norm_const", 0.977016f);
gst_gl_shader_set_uniform_1f (differencematte->shader[1], "norm_offset", 0.0f);
gst_gl_shader_set_uniform_1fv (differencematte->shader[1], "kernel", 9,
gauss_kernel);
gst_gl_shader_set_uniform_1f (differencematte->shader[1], "norm_const",
0.977016f);
gst_gl_shader_set_uniform_1f (differencematte->shader[1], "norm_offset",
0.0f);
gst_gl_differencematte_draw_texture (differencematte, texture);
}
static void
gst_gl_differencematte_vblur (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_vblur (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
gfloat gauss_kernel[9] = {
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
gfloat gauss_kernel[9] = {
0.026995f, 0.064759f, 0.120985f,
0.176033f, 0.199471f, 0.176033f,
0.120985f, 0.064759f, 0.026995f
};
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -390,22 +401,26 @@ gst_gl_differencematte_vblur (gint width, gint height, guint texture, gpointer s
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (differencematte->shader[2], "tex", 0);
gst_gl_shader_set_uniform_1fv (differencematte->shader[2], "kernel", 9, gauss_kernel);
gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_const", 0.977016f);
gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_offset", 0.0f);
gst_gl_shader_set_uniform_1fv (differencematte->shader[2], "kernel", 9,
gauss_kernel);
gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_const",
0.977016f);
gst_gl_shader_set_uniform_1f (differencematte->shader[2], "norm_offset",
0.0f);
gst_gl_differencematte_draw_texture (differencematte, texture);
}
static void
gst_gl_differencematte_interp (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_interp (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -414,8 +429,8 @@ gst_gl_differencematte_interp (gint width, gint height, guint texture, gpointer
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (differencematte->shader[3], "blend", 0);
glActiveTexture (GL_TEXTURE1);
@ -436,10 +451,11 @@ gst_gl_differencematte_interp (gint width, gint height, guint texture, gpointer
}
static void
gst_gl_differencematte_identity (gint width, gint height, guint texture, gpointer stuff)
gst_gl_differencematte_identity (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE (stuff);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -447,10 +463,10 @@ gst_gl_differencematte_identity (gint width, gint height, guint texture, gpointe
}
static gboolean
gst_gl_differencematte_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_differencematte_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE(filter);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
differencematte->intexture = inbuf->texture;
@ -460,14 +476,14 @@ gst_gl_differencematte_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
differencematte->pixbuf = NULL;
/* if loader failed then display is turned off */
gst_gl_display_thread_add (filter->display, init_pixbuf_texture, differencematte);
gst_gl_display_thread_add (filter->display, init_pixbuf_texture,
differencematte);
/* save current frame, needed to calculate difference between
* this frame and next ones */
gst_gl_filter_render_to_target (filter, inbuf->texture,
differencematte->savedbgtexture,
gst_gl_differencematte_save_texture,
differencematte);
gst_gl_filter_render_to_target (filter, inbuf->texture,
differencematte->savedbgtexture,
gst_gl_differencematte_save_texture, differencematte);
if (differencematte->pixbuf) {
free (differencematte->pixbuf);
@ -479,43 +495,41 @@ gst_gl_differencematte_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
if (differencematte->savedbgtexture != 0) {
gst_gl_filter_render_to_target (filter,
inbuf->texture,
differencematte->midtexture[0],
gst_gl_differencematte_diff, differencematte);
gst_gl_filter_render_to_target (filter,
differencematte->midtexture[0],
differencematte->midtexture[1],
gst_gl_differencematte_hblur, differencematte);
gst_gl_filter_render_to_target (filter,
differencematte->midtexture[1],
differencematte->midtexture[2],
gst_gl_differencematte_vblur, differencematte);
gst_gl_filter_render_to_target (filter,
inbuf->texture,
outbuf->texture,
gst_gl_differencematte_interp, differencematte);
inbuf->texture,
differencematte->midtexture[0],
gst_gl_differencematte_diff, differencematte);
gst_gl_filter_render_to_target (filter,
differencematte->midtexture[0],
differencematte->midtexture[1],
gst_gl_differencematte_hblur, differencematte);
gst_gl_filter_render_to_target (filter,
differencematte->midtexture[1],
differencematte->midtexture[2],
gst_gl_differencematte_vblur, differencematte);
gst_gl_filter_render_to_target (filter,
inbuf->texture,
outbuf->texture, gst_gl_differencematte_interp, differencematte);
} else {
gst_gl_filter_render_to_target (filter,
inbuf->texture,
outbuf->texture,
gst_gl_differencematte_identity, differencematte);
gst_gl_filter_render_to_target (filter,
inbuf->texture,
outbuf->texture, gst_gl_differencematte_identity, differencematte);
}
return TRUE;
}
static void
user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
static void
user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
{
g_warning("%s\n", warning_msg);
g_warning ("%s\n", warning_msg);
}
#define LOAD_ERROR(msg) { GST_WARNING ("unable to load %s: %s", differencematte->location, msg); return FALSE; }
static gboolean
gst_gl_differencematte_loader (GstGLFilter* filter)
gst_gl_differencematte_loader (GstGLFilter * filter)
{
GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE(filter);
GstGLDifferenceMatte *differencematte = GST_GL_DIFFERENCEMATTE (filter);
png_structp png_ptr;
png_infop info_ptr;
@ -532,60 +546,58 @@ gst_gl_differencematte_loader (GstGLFilter* filter)
if (!filter->display)
return TRUE;
if ((fp = fopen(differencematte->location, "rb")) == NULL)
if ((fp = fopen (differencematte->location, "rb")) == NULL)
LOAD_ERROR ("file not found");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
fclose(fp);
if (png_ptr == NULL) {
fclose (fp);
LOAD_ERROR ("failed to initialize the png_struct");
}
png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("failed to initialize the memory for image information");
}
png_init_io(png_ptr, fp);
png_init_io (png_ptr, fp);
png_set_sig_bytes(png_ptr, sig_read);
png_set_sig_bytes (png_ptr, sig_read);
png_read_info(png_ptr, info_ptr);
png_read_info (png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("color type is not rgb");
}
filter->width = width;
filter->height = height;
differencematte->pixbuf = (guchar*) malloc ( sizeof(guchar) * width * height * 4 );
differencematte->pixbuf =
(guchar *) malloc (sizeof (guchar) * width * height * 4);
rows = (guchar**)malloc(sizeof(guchar*) * height);
rows = (guchar **) malloc (sizeof (guchar *) * height);
for (y = 0; y < height; ++y)
rows[y] = (guchar*) (differencematte->pixbuf + y * width * 4);
for (y = 0; y < height; ++y)
rows[y] = (guchar *) (differencematte->pixbuf + y * width * 4);
png_read_image(png_ptr, rows);
png_read_image (png_ptr, rows);
free(rows);
free (rows);
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
fclose(fp);
png_read_end (png_ptr, info_ptr);
png_destroy_read_struct (&png_ptr, &info_ptr, png_infopp_NULL);
fclose (fp);
return TRUE;
}

View file

@ -66,20 +66,19 @@
#include "gstgldownload.h"
#define GST_CAT_DEFAULT gst_gl_download_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL video maker",
"Filter/Effect",
"A from GL to video flow filter",
"Julien Isorce <julien.isorce@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL video maker",
"Filter/Effect",
"A from GL to video flow filter",
"Julien Isorce <julien.isorce@gmail.com>");
static GstStaticPadTemplate gst_gl_download_src_pad_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";"
@ -96,7 +95,7 @@ GST_STATIC_PAD_TEMPLATE ("sink",
enum
{
PROP_0
PROP_0
};
#define DEBUG_INIT(bla) \
@ -105,255 +104,246 @@ enum
GST_BOILERPLATE_FULL (GstGLDownload, gst_gl_download, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
static void gst_gl_download_set_property (GObject* object, guint prop_id,
static void gst_gl_download_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_download_get_property (GObject* object, guint prop_id,
static void gst_gl_download_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_download_reset (GstGLDownload* download);
static gboolean gst_gl_download_set_caps (GstBaseTransform* bt,
GstCaps* incaps, GstCaps* outcaps);
static GstCaps* gst_gl_download_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static gboolean gst_gl_download_start (GstBaseTransform* bt);
static gboolean gst_gl_download_stop (GstBaseTransform* bt);
static GstFlowReturn gst_gl_download_transform (GstBaseTransform* trans,
GstBuffer* inbuf, GstBuffer* outbuf);
static gboolean gst_gl_download_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size);
static void gst_gl_download_reset (GstGLDownload * download);
static gboolean gst_gl_download_set_caps (GstBaseTransform * bt,
GstCaps * incaps, GstCaps * outcaps);
static GstCaps *gst_gl_download_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps);
static gboolean gst_gl_download_start (GstBaseTransform * bt);
static gboolean gst_gl_download_stop (GstBaseTransform * bt);
static GstFlowReturn gst_gl_download_transform (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_download_get_unit_size (GstBaseTransform * trans,
GstCaps * caps, guint * size);
static void
gst_gl_download_base_init (gpointer klass)
{
GstElementClass* element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_download_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_download_sink_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_download_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_download_sink_pad_template));
}
static void
gst_gl_download_class_init (GstGLDownloadClass* klass)
gst_gl_download_class_init (GstGLDownloadClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_download_set_property;
gobject_class->get_property = gst_gl_download_get_property;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_download_set_property;
gobject_class->get_property = gst_gl_download_get_property;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_download_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_download_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_download_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_download_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_download_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
gst_gl_download_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_download_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_download_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_download_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_download_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_download_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size =
gst_gl_download_get_unit_size;
}
static void
gst_gl_download_init (GstGLDownload* download, GstGLDownloadClass* klass)
gst_gl_download_init (GstGLDownload * download, GstGLDownloadClass * klass)
{
gst_gl_download_reset (download);
gst_gl_download_reset (download);
}
static void
gst_gl_download_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_download_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLDownload *download = GST_GL_DOWNLOAD (object);
//GstGLDownload *download = GST_GL_DOWNLOAD (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_download_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_download_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLDownload *download = GST_GL_DOWNLOAD (object);
//GstGLDownload *download = GST_GL_DOWNLOAD (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_download_reset (GstGLDownload* download)
gst_gl_download_reset (GstGLDownload * download)
{
if (download->display)
{
g_object_unref (download->display);
download->display = NULL;
}
if (download->display) {
g_object_unref (download->display);
download->display = NULL;
}
}
static gboolean
gst_gl_download_start (GstBaseTransform* bt)
gst_gl_download_start (GstBaseTransform * bt)
{
//GstGLDownload* download = GST_GL_DOWNLOAD (bt);
//GstGLDownload* download = GST_GL_DOWNLOAD (bt);
return TRUE;
return TRUE;
}
static gboolean
gst_gl_download_stop (GstBaseTransform* bt)
gst_gl_download_stop (GstBaseTransform * bt)
{
GstGLDownload* download = GST_GL_DOWNLOAD (bt);
GstGLDownload *download = GST_GL_DOWNLOAD (bt);
gst_gl_download_reset (download);
gst_gl_download_reset (download);
return TRUE;
return TRUE;
}
static GstCaps*
static GstCaps *
gst_gl_download_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps* caps)
GstPadDirection direction, GstCaps * caps)
{
GstGLDownload* download;
GstStructure* structure;
GstCaps *newcaps, *newothercaps;
GstStructure* newstruct;
const GValue* width_value;
const GValue* height_value;
const GValue* framerate_value;
const GValue* par_value;
GstGLDownload *download;
GstStructure *structure;
GstCaps *newcaps, *newothercaps;
GstStructure *newstruct;
const GValue *width_value;
const GValue *height_value;
const GValue *framerate_value;
const GValue *par_value;
download = GST_GL_DOWNLOAD (bt);
download = GST_GL_DOWNLOAD (bt);
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
structure = gst_caps_get_structure (caps, 0);
structure = gst_caps_get_structure (caps, 0);
width_value = gst_structure_get_value (structure, "width");
height_value = gst_structure_get_value (structure, "height");
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
width_value = gst_structure_get_value (structure, "width");
height_value = gst_structure_get_value (structure, "height");
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
if (direction == GST_PAD_SINK)
{
newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
newstruct = gst_caps_get_structure (newothercaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
gst_structure_set_value (newstruct, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
else
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
gst_caps_append(newcaps, newothercaps);
}
else newcaps = gst_caps_new_simple ("video/x-raw-gl", NULL);
newstruct = gst_caps_get_structure (newcaps, 0);
if (direction == GST_PAD_SINK) {
newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
newstruct = gst_caps_get_structure (newothercaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
gst_structure_set_value (newstruct, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
else
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
gst_caps_append (newcaps, newothercaps);
} else
newcaps = gst_caps_new_simple ("video/x-raw-gl", NULL);
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
newstruct = gst_caps_get_structure (newcaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
gst_structure_set_value (newstruct, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
else
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
return newcaps;
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
return newcaps;
}
static gboolean
gst_gl_download_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_download_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps)
{
GstGLDownload* download;
gboolean ret;
GstGLDownload *download;
gboolean ret;
download = GST_GL_DOWNLOAD (bt);
download = GST_GL_DOWNLOAD (bt);
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
ret = gst_video_format_parse_caps (outcaps, &download->video_format,
&download->width, &download->height);
ret = gst_video_format_parse_caps (outcaps, &download->video_format,
&download->width, &download->height);
if (!ret)
{
GST_ERROR ("bad caps");
return FALSE;
}
if (!ret) {
GST_ERROR ("bad caps");
return FALSE;
}
return ret;
return ret;
}
static gboolean
gst_gl_download_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size)
gst_gl_download_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{
gboolean ret;
GstStructure *structure;
gint width;
gint height;
gboolean ret;
GstStructure *structure;
gint width;
gint height;
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl"))
{
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
}
else
{
GstVideoFormat video_format;
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl")) {
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
} else {
GstVideoFormat video_format;
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
return ret;
return ret;
}
static GstFlowReturn
gst_gl_download_transform (GstBaseTransform* trans, GstBuffer* inbuf,
GstBuffer* outbuf)
gst_gl_download_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer * outbuf)
{
GstGLDownload* download = GST_GL_DOWNLOAD (trans);
GstGLBuffer* gl_inbuf = GST_GL_BUFFER (inbuf);
GstGLDownload *download = GST_GL_DOWNLOAD (trans);
GstGLBuffer *gl_inbuf = GST_GL_BUFFER (inbuf);
if (download->display == NULL)
{
download->display = g_object_ref (gl_inbuf->display);
if (download->display == NULL) {
download->display = g_object_ref (gl_inbuf->display);
//blocking call, init color space conversion if needed
gst_gl_display_init_download (download->display, download->video_format,
download->width, download->height);
}
else
g_assert (download->display == gl_inbuf->display);
//blocking call, init color space conversion if needed
gst_gl_display_init_download (download->display, download->video_format,
download->width, download->height);
} else
g_assert (download->display == gl_inbuf->display);
GST_DEBUG ("making video %p size %d",
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
GST_DEBUG ("making video %p size %d",
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
//blocking call
if (gst_gl_display_do_download(download->display, gl_inbuf->texture,
gl_inbuf->width, gl_inbuf->height, GST_BUFFER_DATA (outbuf)))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
//blocking call
if (gst_gl_display_do_download (download->display, gl_inbuf->texture,
gl_inbuf->width, gl_inbuf->height, GST_BUFFER_DATA (outbuf)))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
}

View file

@ -48,31 +48,33 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GST_DEBUG_CATEGORY_INIT (gst_gl_effects_debug, "gleffects", 0, "gleffects element");
GST_BOILERPLATE_FULL (GstGLEffects, gst_gl_effects, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_effects_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
const GValue * value, GParamSpec * pspec);
static void gst_gl_effects_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static void gst_gl_effects_init_resources (GstGLFilter* filter);
static void gst_gl_effects_reset_resources (GstGLFilter* filter);
static void gst_gl_effects_init_resources (GstGLFilter * filter);
static void gst_gl_effects_reset_resources (GstGLFilter * filter);
static void gst_gl_effects_on_init_gl_context (GstGLFilter* filter);
static void gst_gl_effects_on_init_gl_context (GstGLFilter * filter);
static void gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data);
static void gst_gl_effects_ghash_func_clean (gpointer key, gpointer value,
gpointer data);
static gboolean gst_gl_effects_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static const GstElementDetails element_details = GST_ELEMENT_DETAILS (
"Gstreamer OpenGL Effects",
"Filter/Effect",
"GL Shading Language effects",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("Gstreamer OpenGL Effects",
"Filter/Effect",
"GL Shading Language effects",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
/* dont' forget to edit the following when a new effect is added */
typedef enum {
typedef enum
{
GST_GL_EFFECT_IDENTITY,
GST_GL_EFFECT_MIRROR,
GST_GL_EFFECT_SQUEEZE,
@ -97,122 +99,127 @@ static GType
gst_gl_effects_effect_get_type (void)
{
static GType gl_effects_effect_type = 0;
static const GEnumValue effect_types [] = {
{ GST_GL_EFFECT_IDENTITY, "Do nothing Effect", "identity" },
{ GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror" },
{ GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze" },
{ GST_GL_EFFECT_STRETCH, "Stretch Effect", "stretch" },
{ GST_GL_EFFECT_FISHEYE, "FishEye Effect", "fisheye" },
{ GST_GL_EFFECT_TWIRL, "Twirl Effect", "twirl" },
{ GST_GL_EFFECT_BULGE, "Bulge Effect", "bulge" },
{ GST_GL_EFFECT_TUNNEL, "Light Tunnel Effect", "tunnel" },
{ GST_GL_EFFECT_SQUARE, "Square Effect", "square" },
{ GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat" },
{ GST_GL_EFFECT_SEPIA, "Sepia Toning Effect", "sepia" },
{ GST_GL_EFFECT_XPRO, "Cross Processing Effect", "xpro" },
{ GST_GL_EFFECT_LUMA_XPRO, "Luma Cross Processing Effect", "lumaxpro" },
{ GST_GL_EFFECT_XRAY, "Glowing negative effect", "xray" },
{ GST_GL_EFFECT_SIN, "All Grey but Red Effect", "sin" },
{ GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow" },
{ 0, NULL, NULL }
static const GEnumValue effect_types[] = {
{GST_GL_EFFECT_IDENTITY, "Do nothing Effect", "identity"},
{GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror"},
{GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze"},
{GST_GL_EFFECT_STRETCH, "Stretch Effect", "stretch"},
{GST_GL_EFFECT_FISHEYE, "FishEye Effect", "fisheye"},
{GST_GL_EFFECT_TWIRL, "Twirl Effect", "twirl"},
{GST_GL_EFFECT_BULGE, "Bulge Effect", "bulge"},
{GST_GL_EFFECT_TUNNEL, "Light Tunnel Effect", "tunnel"},
{GST_GL_EFFECT_SQUARE, "Square Effect", "square"},
{GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat"},
{GST_GL_EFFECT_SEPIA, "Sepia Toning Effect", "sepia"},
{GST_GL_EFFECT_XPRO, "Cross Processing Effect", "xpro"},
{GST_GL_EFFECT_LUMA_XPRO, "Luma Cross Processing Effect", "lumaxpro"},
{GST_GL_EFFECT_XRAY, "Glowing negative effect", "xray"},
{GST_GL_EFFECT_SIN, "All Grey but Red Effect", "sin"},
{GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow"},
{0, NULL, NULL}
};
if (!gl_effects_effect_type) {
gl_effects_effect_type =
g_enum_register_static ("GstGLEffectsEffect", effect_types);
g_enum_register_static ("GstGLEffectsEffect", effect_types);
}
return gl_effects_effect_type;
}
static void
gst_gl_effects_set_effect (GstGLEffects *effects, gint effect_type) {
gst_gl_effects_set_effect (GstGLEffects * effects, gint effect_type)
{
switch (effect_type) {
case GST_GL_EFFECT_IDENTITY:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_identity;
break;
case GST_GL_EFFECT_MIRROR:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_mirror;
break;
case GST_GL_EFFECT_SQUEEZE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_squeeze;
break;
case GST_GL_EFFECT_STRETCH:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_stretch;
break;
case GST_GL_EFFECT_TUNNEL:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_tunnel;
break;
case GST_GL_EFFECT_FISHEYE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_fisheye;
break;
case GST_GL_EFFECT_TWIRL:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_twirl;
break;
case GST_GL_EFFECT_BULGE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_bulge;
break;
case GST_GL_EFFECT_SQUARE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_square;
break;
case GST_GL_EFFECT_HEAT:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_heat;
break;
case GST_GL_EFFECT_SEPIA:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sepia;
break;
case GST_GL_EFFECT_XPRO:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xpro;
break;
case GST_GL_EFFECT_LUMA_XPRO:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_luma_xpro;
break;
case GST_GL_EFFECT_XRAY:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xray;
break;
case GST_GL_EFFECT_SIN:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sin;
break;
case GST_GL_EFFECT_GLOW:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow;
break;
default:
g_assert_not_reached ();
case GST_GL_EFFECT_IDENTITY:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_identity;
break;
case GST_GL_EFFECT_MIRROR:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_mirror;
break;
case GST_GL_EFFECT_SQUEEZE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_squeeze;
break;
case GST_GL_EFFECT_STRETCH:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_stretch;
break;
case GST_GL_EFFECT_TUNNEL:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_tunnel;
break;
case GST_GL_EFFECT_FISHEYE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_fisheye;
break;
case GST_GL_EFFECT_TWIRL:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_twirl;
break;
case GST_GL_EFFECT_BULGE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_bulge;
break;
case GST_GL_EFFECT_SQUARE:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_square;
break;
case GST_GL_EFFECT_HEAT:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_heat;
break;
case GST_GL_EFFECT_SEPIA:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sepia;
break;
case GST_GL_EFFECT_XPRO:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xpro;
break;
case GST_GL_EFFECT_LUMA_XPRO:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_luma_xpro;
break;
case GST_GL_EFFECT_XRAY:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xray;
break;
case GST_GL_EFFECT_SIN:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sin;
break;
case GST_GL_EFFECT_GLOW:
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow;
break;
default:
g_assert_not_reached ();
}
effects->current_effect = effect_type;
}
/* init resources that need a gl context */
static void
gst_gl_effects_init_gl_resources (GstGLFilter *filter)
gst_gl_effects_init_gl_resources (GstGLFilter * filter)
{
GstGLEffects *effects = GST_GL_EFFECTS (filter);
gint i;
for (i=0; i<NEEDED_TEXTURES; i++) {
for (i = 0; i < NEEDED_TEXTURES; i++) {
glGenTextures (1, &effects->midtexture[i]);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, effects->midtexture[i]);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, effects->midtexture[i]);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
}
}
/* free resources that need a gl context */
static void
gst_gl_effects_reset_gl_resources (GstGLFilter *filter)
gst_gl_effects_reset_gl_resources (GstGLFilter * filter)
{
GstGLEffects *effects = GST_GL_EFFECTS (filter);
gint i;
for (i=0; i<10; i++) {
for (i = 0; i < 10; i++) {
glDeleteTextures (1, &effects->midtexture[i]);
effects->midtexture[i] = 0;
}
for (i=0; i<GST_GL_EFFECTS_N_CURVES; i++) {
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
glDeleteTextures (1, &effects->curve[i]);
effects->curve[i] = 0;
}
@ -236,29 +243,27 @@ gst_gl_effects_class_init (GstGLEffectsClass * klass)
gobject_class->get_property = gst_gl_effects_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_effects_filter;
GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_effects_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_effects_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_init_cb =
gst_gl_effects_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
gst_gl_effects_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_effects_init_resources;
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_effects_reset_resources;
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_effects_on_init_gl_context;
g_object_class_install_property (
gobject_class,
PROP_EFFECT,
g_param_spec_enum ("effect",
"Effect",
"Select which effect apply to GL video texture",
GST_TYPE_GL_EFFECTS_EFFECT,
GST_GL_EFFECT_IDENTITY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
gobject_class,
PROP_HSWAP,
g_param_spec_boolean ("hswap",
"Horizontal Swap",
"Switch video texture left to right, useful with webcams",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_EFFECT,
g_param_spec_enum ("effect",
"Effect",
"Select which effect apply to GL video texture",
GST_TYPE_GL_EFFECTS_EFFECT,
GST_GL_EFFECT_IDENTITY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_HSWAP,
g_param_spec_boolean ("hswap",
"Horizontal Swap",
"Switch video texture left to right, useful with webcams",
FALSE, G_PARAM_READWRITE));
}
void
@ -274,18 +279,18 @@ gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex)
glTexCoord2f (0.0, 0.0);
glVertex2f (-1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, 0.0);
glTexCoord2f ((gfloat) filter->width, 0.0);
glVertex2f (1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, (gfloat)filter->height);
glTexCoord2f ((gfloat) filter->width, (gfloat) filter->height);
glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, (gfloat)filter->height);
glTexCoord2f (0.0, (gfloat) filter->height);
glVertex2f (-1.0, 1.0);
glEnd ();
}
static void
set_horizontal_swap (GstGLDisplay *display, gpointer data)
set_horizontal_swap (GstGLDisplay * display, gpointer data)
{
// GstGLEffects *effects = GST_GL_EFFECTS (data);
@ -310,8 +315,8 @@ gst_gl_effects_init (GstGLEffects * effects, GstGLEffectsClass * klass)
static void
gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data)
{
GstGLShader* shader = (GstGLShader*) value;
GstGLFilter* filter = (GstGLFilter*) data;
GstGLShader *shader = (GstGLShader *) value;
GstGLFilter *filter = (GstGLFilter *) data;
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, shader);
@ -320,15 +325,15 @@ gst_gl_effects_ghash_func_clean (gpointer key, gpointer value, gpointer data)
}
static void
gst_gl_effects_reset_resources (GstGLFilter* filter)
gst_gl_effects_reset_resources (GstGLFilter * filter)
{
GstGLEffects* effects = GST_GL_EFFECTS(filter);
GstGLEffects *effects = GST_GL_EFFECTS (filter);
// g_message ("reset resources");
//release shaders in the gl thread
g_hash_table_foreach (effects->shaderstable, gst_gl_effects_ghash_func_clean,
filter);
filter);
//clean the htable without calling values destructors
//because shaders have been released in the glthread
@ -344,15 +349,15 @@ gst_gl_effects_set_property (GObject * object, guint prop_id,
GstGLEffects *effects = GST_GL_EFFECTS (object);
switch (prop_id) {
case PROP_EFFECT:
gst_gl_effects_set_effect (effects, g_value_get_enum (value));
break;
case PROP_HSWAP:
effects->horizontal_swap = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_EFFECT:
gst_gl_effects_set_effect (effects, g_value_get_enum (value));
break;
case PROP_HSWAP:
effects->horizontal_swap = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@ -363,38 +368,37 @@ gst_gl_effects_get_property (GObject * object, guint prop_id,
GstGLEffects *effects = GST_GL_EFFECTS (object);
switch (prop_id) {
case PROP_EFFECT:
g_value_set_enum (value, effects->current_effect);
break;
case PROP_HSWAP:
g_value_set_boolean (value, effects->horizontal_swap);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_EFFECT:
g_value_set_enum (value, effects->current_effect);
break;
case PROP_HSWAP:
g_value_set_boolean (value, effects->horizontal_swap);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_effects_init_resources (GstGLFilter* filter)
gst_gl_effects_init_resources (GstGLFilter * filter)
{
GstGLEffects *effects = GST_GL_EFFECTS (filter);
gint i;
// g_message ("init resources");
// g_message ("init hashtable");
effects->shaderstable = g_hash_table_new (g_str_hash,
g_str_equal);
effects->shaderstable = g_hash_table_new (g_str_hash, g_str_equal);
// g_message ("zero textures and curves");
for (i=0; i<NEEDED_TEXTURES; i++) {
for (i = 0; i < NEEDED_TEXTURES; i++) {
effects->midtexture[i] = 0;
}
for (i=0; i<GST_GL_EFFECTS_N_CURVES; i++) {
for (i = 0; i < GST_GL_EFFECTS_N_CURVES; i++) {
effects->curve[i] = 0;
}
}
static void
gst_gl_effects_on_init_gl_context (GstGLFilter* filter)
gst_gl_effects_on_init_gl_context (GstGLFilter * filter)
{
//check that your hardware supports shader
//if not the pipeline correctly shut down
@ -402,10 +406,10 @@ gst_gl_effects_on_init_gl_context (GstGLFilter* filter)
}
static gboolean
gst_gl_effects_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_effects_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLEffects* effects = GST_GL_EFFECTS(filter);
GstGLEffects *effects = GST_GL_EFFECTS (filter);
effects->intexture = inbuf->texture;
effects->outtexture = outbuf->texture;

View file

@ -45,17 +45,17 @@
#define GST_CAT_DEFAULT gst_gl_filter_app_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL application filter",
"Filter/Effect",
"Use client callbacks to define the scene",
"Julien Isorce <julien.isorce@gmail.com>");
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL application filter",
"Filter/Effect",
"Use client callbacks to define the scene",
"Julien Isorce <julien.isorce@gmail.com>");
enum
{
PROP_0,
PROP_CLIENT_RESHAPE_CALLBACK,
PROP_CLIENT_DRAW_CALLBACK
PROP_0,
PROP_CLIENT_RESHAPE_CALLBACK,
PROP_CLIENT_DRAW_CALLBACK
};
#define DEBUG_INIT(bla) \
@ -64,16 +64,17 @@ enum
GST_BOILERPLATE_FULL (GstGLFilterApp, gst_gl_filter_app, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filter_app_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
static void gst_gl_filter_app_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec * pspec);
static void gst_gl_filter_app_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_app_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_gl_filter_app_set_caps (GstGLFilter* filter,
GstCaps* incaps, GstCaps* outcaps);
static gboolean gst_gl_filter_app_filter (GstGLFilter* filter,
GstGLBuffer* inbuf, GstGLBuffer* outbuf);
static void gst_gl_filter_app_callback (gint width, gint height, guint texture, gpointer stuff);
static gboolean gst_gl_filter_app_set_caps (GstGLFilter * filter,
GstCaps * incaps, GstCaps * outcaps);
static gboolean gst_gl_filter_app_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filter_app_callback (gint width, gint height, guint texture,
gpointer stuff);
static void
@ -85,136 +86,135 @@ gst_gl_filter_app_base_init (gpointer klass)
}
static void
gst_gl_filter_app_class_init (GstGLFilterAppClass* klass)
gst_gl_filter_app_class_init (GstGLFilterAppClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_app_set_property;
gobject_class->get_property = gst_gl_filter_app_get_property;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_app_set_property;
gobject_class->get_property = gst_gl_filter_app_get_property;
GST_GL_FILTER_CLASS (klass)->set_caps = gst_gl_filter_app_set_caps;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_app_filter;
GST_GL_FILTER_CLASS (klass)->set_caps = gst_gl_filter_app_set_caps;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_app_filter;
g_object_class_install_property (gobject_class, PROP_CLIENT_RESHAPE_CALLBACK,
g_param_spec_pointer ("client_reshape_callback", "Client reshape callback",
"Define a custom reshape callback in a client code",
g_object_class_install_property (gobject_class, PROP_CLIENT_RESHAPE_CALLBACK,
g_param_spec_pointer ("client_reshape_callback",
"Client reshape callback",
"Define a custom reshape callback in a client code",
G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_CLIENT_DRAW_CALLBACK,
g_object_class_install_property (gobject_class, PROP_CLIENT_DRAW_CALLBACK,
g_param_spec_pointer ("client_draw_callback", "Client draw callback",
"Define a custom draw callback in a client code",
G_PARAM_WRITABLE));
"Define a custom draw callback in a client code", G_PARAM_WRITABLE));
}
static void
gst_gl_filter_app_init (GstGLFilterApp* filter,
GstGLFilterAppClass* klass)
gst_gl_filter_app_init (GstGLFilterApp * filter, GstGLFilterAppClass * klass)
{
filter->clientReshapeCallback = NULL;
filter->clientDrawCallback = NULL;
filter->clientReshapeCallback = NULL;
filter->clientDrawCallback = NULL;
}
static void
gst_gl_filter_app_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_filter_app_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLFilterApp* filter = GST_GL_FILTER_APP (object);
GstGLFilterApp *filter = GST_GL_FILTER_APP (object);
switch (prop_id) {
case PROP_CLIENT_RESHAPE_CALLBACK:
{
filter->clientReshapeCallback = g_value_get_pointer (value);
break;
}
case PROP_CLIENT_DRAW_CALLBACK:
{
filter->clientDrawCallback = g_value_get_pointer (value);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_app_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
{
//GstGLFilterApp* filter = GST_GL_FILTER_APP (object);
switch (prop_id)
switch (prop_id) {
case PROP_CLIENT_RESHAPE_CALLBACK:
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
filter->clientReshapeCallback = g_value_get_pointer (value);
break;
}
case PROP_CLIENT_DRAW_CALLBACK:
{
filter->clientDrawCallback = g_value_get_pointer (value);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_app_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLFilterApp* filter = GST_GL_FILTER_APP (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_gl_filter_app_set_caps (GstGLFilter* filter, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_filter_app_set_caps (GstGLFilter * filter, GstCaps * incaps,
GstCaps * outcaps)
{
//GstGLFilterApp* app_filter = GST_GL_FILTER_APP(filter);
//GstGLFilterApp* app_filter = GST_GL_FILTER_APP(filter);
return TRUE;
return TRUE;
}
static gboolean
gst_gl_filter_app_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filter_app_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLFilterApp* app_filter = GST_GL_FILTER_APP(filter);
GstGLFilterApp *app_filter = GST_GL_FILTER_APP (filter);
if (app_filter->clientDrawCallback)
{
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, app_filter->clientDrawCallback,
inbuf->width, inbuf->height, inbuf->texture,
45, (gfloat)filter->width / (gfloat)filter->height, 0.1, 100,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, NULL);
}
//default
else
{
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_filter_app_callback,
inbuf->width, inbuf->height, inbuf->texture,
0, filter->width, 0, filter->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D, NULL);
}
if (app_filter->clientDrawCallback) {
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture,
app_filter->clientDrawCallback, inbuf->width, inbuf->height,
inbuf->texture, 45, (gfloat) filter->width / (gfloat) filter->height,
0.1, 100, GST_GL_DISPLAY_PROJECTION_PERSPECIVE, NULL);
}
//default
else {
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture,
gst_gl_filter_app_callback, inbuf->width, inbuf->height, inbuf->texture,
0, filter->width, 0, filter->height, GST_GL_DISPLAY_PROJECTION_ORTHO2D,
NULL);
}
return TRUE;
return TRUE;
}
//opengl scene, params: input texture (not the output filter->texture)
static void
gst_gl_filter_app_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filter_app_callback (gint width, gint height, guint texture,
gpointer stuff)
{
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin (GL_QUADS);
glTexCoord2i (0, 0);
glVertex2f (-1.0f, -1.0f);
glTexCoord2i (width, 0);
glVertex2f (1.0f, -1.0f);
glTexCoord2i (width, height);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, height);
glVertex2f (-1.0f, 1.0f);
glEnd ();
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glBegin (GL_QUADS);
glTexCoord2i (0, 0);
glVertex2f (-1.0f, -1.0f);
glTexCoord2i (width, 0);
glVertex2f (1.0f, -1.0f);
glTexCoord2i (width, height);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, height);
glVertex2f (-1.0f, 1.0f);
glEnd ();
}

View file

@ -66,45 +66,39 @@ GType gst_gl_glfilterblur_get_type (void);
/* horizontal convolution */
static const gchar *hconv9_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s+offset[i], texturecoord.t)); "
" sum += neighbor * kernel[i]/norm_const; "
" }"
" }"
" gl_FragColor = sum + norm_offset;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s+offset[i], texturecoord.t)); "
" sum += neighbor * kernel[i]/norm_const; "
" }" " }" " gl_FragColor = sum + norm_offset;" "}";
/* vertical convolution */
static const gchar *vconv9_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s, texturecoord.t+offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }"
" }"
" gl_FragColor = sum + norm_offset;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" float offset[9] = float[9] (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0);"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, vec2(texturecoord.s, texturecoord.t+offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }" " }" " gl_FragColor = sum + norm_offset;" "}";
#define GST_CAT_DEFAULT gst_gl_filterblur_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -119,39 +113,44 @@ GST_ELEMENT_DETAILS ("Gstreamer OpenGL Blur",
GST_DEBUG_CATEGORY_INIT (gst_gl_filterblur_debug, "glfilterblur", 0, "glfilterblur element");
GST_BOILERPLATE_FULL (GstGLFilterBlur, gst_gl_filterblur, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filterblur_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filterblur_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_filter_filterblur_reset (GstGLFilter* filter);
static void gst_gl_filterblur_draw_texture (GstGLFilterBlur * filterblur, GLuint tex);
static void gst_gl_filter_filterblur_reset (GstGLFilter * filter);
static void gst_gl_filterblur_draw_texture (GstGLFilterBlur * filterblur,
GLuint tex);
static void gst_gl_filterblur_init_shader (GstGLFilter* filter);
static void gst_gl_filterblur_init_shader (GstGLFilter * filter);
static gboolean gst_gl_filterblur_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filterblur_hcallback (gint width, gint height, guint texture, gpointer stuff);
static void gst_gl_filterblur_vcallback (gint width, gint height, guint texture, gpointer stuff);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filterblur_hcallback (gint width, gint height, guint texture,
gpointer stuff);
static void gst_gl_filterblur_vcallback (gint width, gint height, guint texture,
gpointer stuff);
static void
gst_gl_filterblur_init_resources (GstGLFilter *filter)
gst_gl_filterblur_init_resources (GstGLFilter * filter)
{
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (filter);
glGenTextures (1, &filterblur->midtexture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, filterblur->midtexture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, filterblur->midtexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
}
static void
gst_gl_filterblur_reset_resources (GstGLFilter *filter)
gst_gl_filterblur_reset_resources (GstGLFilter * filter)
{
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (filter);
@ -176,14 +175,17 @@ gst_gl_filterblur_class_init (GstGLFilterBlurClass * klass)
gobject_class->get_property = gst_gl_filterblur_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filterblur_filter;
GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_filterblur_init_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_filterblur_reset_resources;
GST_GL_FILTER_CLASS (klass)->display_init_cb =
gst_gl_filterblur_init_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
gst_gl_filterblur_reset_resources;
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_filterblur_init_shader;
GST_GL_FILTER_CLASS (klass)->onReset = gst_gl_filter_filterblur_reset;
}
static void
gst_gl_filterblur_init (GstGLFilterBlur * filterblur, GstGLFilterBlurClass * klass)
gst_gl_filterblur_init (GstGLFilterBlur * filterblur,
GstGLFilterBlurClass * klass)
{
filterblur->shader0 = NULL;
filterblur->shader1 = NULL;
@ -191,9 +193,9 @@ gst_gl_filterblur_init (GstGLFilterBlur * filterblur, GstGLFilterBlurClass * kla
}
static void
gst_gl_filter_filterblur_reset (GstGLFilter* filter)
gst_gl_filter_filterblur_reset (GstGLFilter * filter)
{
GstGLFilterBlur* filterblur = GST_GL_FILTERBLUR(filter);
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (filter);
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, filterblur->shader0);
@ -229,15 +231,17 @@ gst_gl_filterblur_get_property (GObject * object, guint prop_id,
}
static void
gst_gl_filterblur_init_shader (GstGLFilter* filter)
gst_gl_filterblur_init_shader (GstGLFilter * filter)
{
GstGLFilterBlur* blur_filter = GST_GL_FILTERBLUR (filter);
GstGLFilterBlur *blur_filter = GST_GL_FILTERBLUR (filter);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, 0, hconv9_fragment_source, &blur_filter->shader0);
gst_gl_display_gen_shader (filter->display, 0, hconv9_fragment_source,
&blur_filter->shader0);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, 0, vconv9_fragment_source, &blur_filter->shader1);
gst_gl_display_gen_shader (filter->display, 0, vconv9_fragment_source,
&blur_filter->shader1);
}
static void
@ -253,18 +257,18 @@ gst_gl_filterblur_draw_texture (GstGLFilterBlur * filterblur, GLuint tex)
glTexCoord2f (0.0, 0.0);
glVertex2f (-1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, 0.0);
glTexCoord2f ((gfloat) filter->width, 0.0);
glVertex2f (1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, (gfloat)filter->height);
glTexCoord2f ((gfloat) filter->width, (gfloat) filter->height);
glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, (gfloat)filter->height);
glTexCoord2f (0.0, (gfloat) filter->height);
glVertex2f (-1.0, 1.0);
glEnd ();
}
static void
change_view (GstGLDisplay *display, gpointer data)
change_view (GstGLDisplay * display, gpointer data)
{
// GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (data);
@ -280,33 +284,35 @@ change_view (GstGLDisplay *display, gpointer data)
}
static gboolean
gst_gl_filterblur_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filterblur_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLFilterBlur* filterblur = GST_GL_FILTERBLUR(filter);
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (filter);
gst_gl_filter_render_to_target (filter, inbuf->texture, filterblur->midtexture,
gst_gl_filterblur_hcallback, filterblur);
gst_gl_filter_render_to_target (filter, inbuf->texture,
filterblur->midtexture, gst_gl_filterblur_hcallback, filterblur);
gst_gl_display_thread_add (filter->display, change_view, filterblur);
gst_gl_filter_render_to_target (filter, filterblur->midtexture, outbuf->texture,
gst_gl_filterblur_vcallback, filterblur);
gst_gl_filter_render_to_target (filter, filterblur->midtexture,
outbuf->texture, gst_gl_filterblur_vcallback, filterblur);
return TRUE;
}
static void
gst_gl_filterblur_hcallback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filterblur_hcallback (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLFilterBlur* filterblur = GST_GL_FILTERBLUR (stuff);
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (stuff);
/* hard coded kernel, it could be easily generated at runtime with a
* property to change standard deviation */
gfloat gauss_kernel[9] = {
0.026995f, 0.064759f, 0.120985f,
0.176033f, 0.199471f, 0.176033f,
0.120985f, 0.064759f, 0.026995f };
0.120985f, 0.064759f, 0.026995f
};
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -320,7 +326,8 @@ gst_gl_filterblur_hcallback (gint width, gint height, guint texture, gpointer st
gst_gl_shader_set_uniform_1i (filterblur->shader0, "tex", 1);
gst_gl_shader_set_uniform_1fv (filterblur->shader0, "kernel", 9, gauss_kernel);
gst_gl_shader_set_uniform_1fv (filterblur->shader0, "kernel", 9,
gauss_kernel);
gst_gl_shader_set_uniform_1f (filterblur->shader0, "norm_const", 0.977016f);
gst_gl_shader_set_uniform_1f (filterblur->shader0, "norm_offset", 0.0f);
@ -329,16 +336,18 @@ gst_gl_filterblur_hcallback (gint width, gint height, guint texture, gpointer st
static void
gst_gl_filterblur_vcallback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filterblur_vcallback (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLFilterBlur* filterblur = GST_GL_FILTERBLUR (stuff);
GstGLFilterBlur *filterblur = GST_GL_FILTERBLUR (stuff);
/* hard coded kernel, it could be easily generated at runtime with a
* property to change standard deviation */
gfloat gauss_kernel[9] = {
0.026995f, 0.064759f, 0.120985f,
0.176033f, 0.199471f, 0.176033f,
0.120985f, 0.064759f, 0.026995f };
0.120985f, 0.064759f, 0.026995f
};
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -352,7 +361,8 @@ gst_gl_filterblur_vcallback (gint width, gint height, guint texture, gpointer st
gst_gl_shader_set_uniform_1i (filterblur->shader1, "tex", 1);
gst_gl_shader_set_uniform_1fv (filterblur->shader1, "kernel", 9, gauss_kernel);
gst_gl_shader_set_uniform_1fv (filterblur->shader1, "kernel", 9,
gauss_kernel);
gst_gl_shader_set_uniform_1f (filterblur->shader1, "norm_const", 0.977016f);
gst_gl_shader_set_uniform_1f (filterblur->shader1, "norm_offset", 0.0f);

View file

@ -49,22 +49,22 @@
#define GST_CAT_DEFAULT gst_gl_filter_cube_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL cube filter",
"Filter/Effect",
"Map input texture on the 6 cube faces",
"Julien Isorce <julien.isorce@gmail.com>");
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL cube filter",
"Filter/Effect",
"Map input texture on the 6 cube faces",
"Julien Isorce <julien.isorce@gmail.com>");
enum
{
PROP_0,
PROP_RED,
PROP_GREEN,
PROP_BLUE,
PROP_FOVY,
PROP_ASPECT,
PROP_ZNEAR,
PROP_ZFAR
PROP_0,
PROP_RED,
PROP_GREEN,
PROP_BLUE,
PROP_FOVY,
PROP_ASPECT,
PROP_ZNEAR,
PROP_ZFAR
};
#define DEBUG_INIT(bla) \
@ -73,223 +73,249 @@ enum
GST_BOILERPLATE_FULL (GstGLFilterCube, gst_gl_filter_cube, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filter_cube_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec * pspec);
static void gst_gl_filter_cube_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec);
static void gst_gl_filter_cube_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_cube_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_gl_filter_cube_set_caps (GstGLFilter* filter,
GstCaps* incaps, GstCaps* outcaps);
static gboolean gst_gl_filter_cube_filter (GstGLFilter* filter,
GstGLBuffer* inbuf, GstGLBuffer* outbuf);
static void gst_gl_filter_cube_callback (gint width, gint height, guint texture, gpointer stuff);
static gboolean gst_gl_filter_cube_set_caps (GstGLFilter * filter,
GstCaps * incaps, GstCaps * outcaps);
static gboolean gst_gl_filter_cube_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filter_cube_callback (gint width, gint height, guint texture,
gpointer stuff);
static void
gst_gl_filter_cube_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_set_details (element_class, &element_details);
}
static void
gst_gl_filter_cube_class_init (GstGLFilterCubeClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_cube_set_property;
gobject_class->get_property = gst_gl_filter_cube_get_property;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_cube_set_property;
gobject_class->get_property = gst_gl_filter_cube_get_property;
GST_GL_FILTER_CLASS (klass)->set_caps = gst_gl_filter_cube_set_caps;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_cube_filter;
GST_GL_FILTER_CLASS (klass)->set_caps = gst_gl_filter_cube_set_caps;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_cube_filter;
g_object_class_install_property (gobject_class, PROP_RED,
g_param_spec_float ("red", "Red", "Background red color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_RED,
g_param_spec_float ("red", "Red", "Background red color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_GREEN,
g_param_spec_float ("green", "Green", "Background reen color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_GREEN,
g_param_spec_float ("green", "Green", "Background reen color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_BLUE,
g_param_spec_float ("blue", "Blue", "Background blue color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_BLUE,
g_param_spec_float ("blue", "Blue", "Background blue color",
0.0f, 1.0f, 0.0f, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_FOVY,
g_param_spec_double ("fovy", "Fovy", "Field of view angle in degrees",
0.0, 180.0, 45.0, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_FOVY,
g_param_spec_double ("fovy", "Fovy", "Field of view angle in degrees",
0.0, 180.0, 45.0, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ASPECT,
g_param_spec_double ("aspect", "Aspect", "Field of view in the x direction",
0.0, 100, 0.0, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ASPECT,
g_param_spec_double ("aspect", "Aspect",
"Field of view in the x direction", 0.0, 100, 0.0, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ZNEAR,
g_param_spec_double ("znear", "Znear",
"Specifies the distance from the viewer to the near clipping plane",
0.0, 100.0, 0.1, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ZNEAR,
g_param_spec_double ("znear", "Znear",
"Specifies the distance from the viewer to the near clipping plane",
0.0, 100.0, 0.1, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ZFAR,
g_param_spec_double ("zfar", "Zfar",
"Specifies the distance from the viewer to the far clipping plane",
0.0, 1000.0, 100.0, G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_ZFAR,
g_param_spec_double ("zfar", "Zfar",
"Specifies the distance from the viewer to the far clipping plane",
0.0, 1000.0, 100.0, G_PARAM_WRITABLE));
}
static void
gst_gl_filter_cube_init (GstGLFilterCube* filter,
GstGLFilterCubeClass* klass)
gst_gl_filter_cube_init (GstGLFilterCube * filter, GstGLFilterCubeClass * klass)
{
filter->fovy = 45;
filter->aspect = 0;
filter->znear = 0.1;
filter->zfar = 100;
filter->fovy = 45;
filter->aspect = 0;
filter->znear = 0.1;
filter->zfar = 100;
}
static void
gst_gl_filter_cube_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_filter_cube_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLFilterCube* filter = GST_GL_FILTER_CUBE (object);
GstGLFilterCube *filter = GST_GL_FILTER_CUBE (object);
switch (prop_id)
{
case PROP_RED:
filter->red = g_value_get_float (value);
break;
case PROP_GREEN:
filter->green = g_value_get_float (value);
break;
case PROP_BLUE:
filter->blue = g_value_get_float (value);
break;
case PROP_FOVY:
filter->fovy = g_value_get_double (value);
break;
case PROP_ASPECT:
filter->aspect = g_value_get_double (value);
break;
case PROP_ZNEAR:
filter->znear = g_value_get_double (value);
break;
case PROP_ZFAR:
filter->zfar = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
case PROP_RED:
filter->red = g_value_get_float (value);
break;
case PROP_GREEN:
filter->green = g_value_get_float (value);
break;
case PROP_BLUE:
filter->blue = g_value_get_float (value);
break;
case PROP_FOVY:
filter->fovy = g_value_get_double (value);
break;
case PROP_ASPECT:
filter->aspect = g_value_get_double (value);
break;
case PROP_ZNEAR:
filter->znear = g_value_get_double (value);
break;
case PROP_ZFAR:
filter->zfar = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_cube_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_filter_cube_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLFilterCube* filter = GST_GL_FILTER_CUBE (object);
//GstGLFilterCube* filter = GST_GL_FILTER_CUBE (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_gl_filter_cube_set_caps (GstGLFilter* filter, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_filter_cube_set_caps (GstGLFilter * filter, GstCaps * incaps,
GstCaps * outcaps)
{
GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE (filter);
GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
if (cube_filter->aspect == 0)
cube_filter->aspect = (gdouble)filter->width / (gdouble)filter->height;
if (cube_filter->aspect == 0)
cube_filter->aspect = (gdouble) filter->width / (gdouble) filter->height;
return TRUE;
return TRUE;
}
static gboolean
gst_gl_filter_cube_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filter_cube_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE (filter);
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_filter_cube_callback,
inbuf->width, inbuf->height, inbuf->texture,
cube_filter->fovy, cube_filter->aspect, cube_filter->znear, cube_filter->zfar,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, (gpointer)cube_filter);
GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (filter);
return TRUE;
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture,
gst_gl_filter_cube_callback, inbuf->width, inbuf->height, inbuf->texture,
cube_filter->fovy, cube_filter->aspect, cube_filter->znear,
cube_filter->zfar, GST_GL_DISPLAY_PROJECTION_PERSPECIVE,
(gpointer) cube_filter);
return TRUE;
}
//opengl scene, params: input texture (not the output filter->texture)
static void
gst_gl_filter_cube_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filter_cube_callback (gint width, gint height, guint texture,
gpointer stuff)
{
static GLfloat xrot = 0;
static GLfloat yrot = 0;
static GLfloat zrot = 0;
static GLfloat xrot = 0;
static GLfloat yrot = 0;
static GLfloat zrot = 0;
GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE (stuff);
GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff);
glEnable(GL_DEPTH_TEST);
glEnable (GL_DEPTH_TEST);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glClearColor (cube_filter->red, cube_filter->green, cube_filter->blue, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);
glTranslatef (0.0f, 0.0f, -5.0f);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f((gfloat)width, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
// Bottom Face
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f((gfloat)width,(gfloat)height); glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f((gfloat)width, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// Left Face
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, (gfloat)height); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
glRotatef (xrot, 1.0f, 0.0f, 0.0f);
glRotatef (yrot, 0.0f, 1.0f, 0.0f);
glRotatef (zrot, 0.0f, 0.0f, 1.0f);
xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;
glBegin (GL_QUADS);
// Front Face
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (-1.0f, -1.0f, 1.0f);
glTexCoord2f (0.0f, 0.0f);
glVertex3f (1.0f, -1.0f, 1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (1.0f, 1.0f, 1.0f);
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (-1.0f, 1.0f, 1.0f);
// Back Face
glTexCoord2f (0.0f, 0.0f);
glVertex3f (-1.0f, -1.0f, -1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (-1.0f, 1.0f, -1.0f);
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (1.0f, 1.0f, -1.0f);
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (1.0f, -1.0f, -1.0f);
// Top Face
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (-1.0f, 1.0f, -1.0f);
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (-1.0f, 1.0f, 1.0f);
glTexCoord2f (0.0f, 0.0f);
glVertex3f (1.0f, 1.0f, 1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (1.0f, 1.0f, -1.0f);
// Bottom Face
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (-1.0f, -1.0f, -1.0f);
glTexCoord2f (0.0f, 0.0f);
glVertex3f (1.0f, -1.0f, -1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (1.0f, -1.0f, 1.0f);
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (-1.0f, -1.0f, 1.0f);
// Right face
glTexCoord2f (0.0f, 0.0f);
glVertex3f (1.0f, -1.0f, -1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (1.0f, 1.0f, -1.0f);
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (1.0f, 1.0f, 1.0f);
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (1.0f, -1.0f, 1.0f);
// Left Face
glTexCoord2f ((gfloat) width, 0.0f);
glVertex3f (-1.0f, -1.0f, -1.0f);
glTexCoord2f (0.0f, 0.0f);
glVertex3f (-1.0f, -1.0f, 1.0f);
glTexCoord2f (0.0f, (gfloat) height);
glVertex3f (-1.0f, 1.0f, 1.0f);
glTexCoord2f ((gfloat) width, (gfloat) height);
glVertex3f (-1.0f, 1.0f, -1.0f);
glEnd ();
glDisable(GL_DEPTH_TEST);
xrot += 0.3f;
yrot += 0.2f;
zrot += 0.4f;
glDisable (GL_DEPTH_TEST);
}

View file

@ -47,10 +47,10 @@
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL glass filter",
"Filter/Effect",
"Glass Filter",
"Julien Isorce <julien.isorce@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL glass filter",
"Filter/Effect",
"Glass Filter",
"Julien Isorce <julien.isorce@gmail.com>");
enum
{
@ -61,52 +61,49 @@ enum
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_glass_debug, "glfilterglass", 0, "glfilterglass element");
GST_BOILERPLATE_FULL (GstGLFilterGlass, gst_gl_filter_glass, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filter_glass_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_glass_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static void gst_gl_filter_glass_reset (GstGLFilter* filter);
static void gst_gl_filter_glass_init_shader (GstGLFilter* filter);
static void gst_gl_filter_glass_reset (GstGLFilter * filter);
static void gst_gl_filter_glass_init_shader (GstGLFilter * filter);
static gboolean gst_gl_filter_glass_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filter_glass_draw_background_gradient ();
static void gst_gl_filter_glass_draw_video_plane (GstGLFilter* filter,
gint width, gint height, guint texture, gfloat center_x, gfloat center_y,
gfloat start_alpha, gfloat stop_alpha, gboolean reversed);
static void gst_gl_filter_glass_draw_video_plane (GstGLFilter * filter,
gint width, gint height, guint texture, gfloat center_x, gfloat center_y,
gfloat start_alpha, gfloat stop_alpha, gboolean reversed);
static void gst_gl_filter_glass_callback (gint width, gint height, guint texture, gpointer stuff);
static void gst_gl_filter_glass_callback (gint width, gint height,
guint texture, gpointer stuff);
static const gchar *glass_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" float p = 0.0525;"
" float L1 = p*width;"
" float L2 = width - L1;"
" float L3 = height - L1;"
" float w = 1.0;"
" float r = L1;"
" if (gl_TexCoord[0].x < L1 && gl_TexCoord[0].y < L1)"
" r = sqrt( (gl_TexCoord[0].x - L1) * (gl_TexCoord[0].x - L1) + (gl_TexCoord[0].y - L1) * (gl_TexCoord[0].y - L1) );"
" else if (gl_TexCoord[0].x > L2 && gl_TexCoord[0].y < L1)"
" r = sqrt( (gl_TexCoord[0].x - L2) * (gl_TexCoord[0].x - L2) + (gl_TexCoord[0].y - L1) * (gl_TexCoord[0].y - L1) );"
" else if (gl_TexCoord[0].x > L2 && gl_TexCoord[0].y > L3)"
" r = sqrt( (gl_TexCoord[0].x - L2) * (gl_TexCoord[0].x - L2) + (gl_TexCoord[0].y - L3) * (gl_TexCoord[0].y - L3) );"
" else if (gl_TexCoord[0].x < L1 && gl_TexCoord[0].y > L3)"
" r = sqrt( (gl_TexCoord[0].x - L1) * (gl_TexCoord[0].x - L1) + (gl_TexCoord[0].y - L3) * (gl_TexCoord[0].y - L3) );"
" if (r > L1)"
" w = 0.0;"
" vec4 color = texture2DRect (tex, gl_TexCoord[0].st);"
" gl_FragColor = vec4(color.rgb, gl_Color.a * w);"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float width, height;"
"void main () {"
" float p = 0.0525;"
" float L1 = p*width;"
" float L2 = width - L1;"
" float L3 = height - L1;"
" float w = 1.0;"
" float r = L1;"
" if (gl_TexCoord[0].x < L1 && gl_TexCoord[0].y < L1)"
" r = sqrt( (gl_TexCoord[0].x - L1) * (gl_TexCoord[0].x - L1) + (gl_TexCoord[0].y - L1) * (gl_TexCoord[0].y - L1) );"
" else if (gl_TexCoord[0].x > L2 && gl_TexCoord[0].y < L1)"
" r = sqrt( (gl_TexCoord[0].x - L2) * (gl_TexCoord[0].x - L2) + (gl_TexCoord[0].y - L1) * (gl_TexCoord[0].y - L1) );"
" else if (gl_TexCoord[0].x > L2 && gl_TexCoord[0].y > L3)"
" r = sqrt( (gl_TexCoord[0].x - L2) * (gl_TexCoord[0].x - L2) + (gl_TexCoord[0].y - L3) * (gl_TexCoord[0].y - L3) );"
" else if (gl_TexCoord[0].x < L1 && gl_TexCoord[0].y > L3)"
" r = sqrt( (gl_TexCoord[0].x - L1) * (gl_TexCoord[0].x - L1) + (gl_TexCoord[0].y - L3) * (gl_TexCoord[0].y - L3) );"
" if (r > L1)"
" w = 0.0;"
" vec4 color = texture2DRect (tex, gl_TexCoord[0].st);"
" gl_FragColor = vec4(color.rgb, gl_Color.a * w);" "}";
static void
gst_gl_filter_glass_base_init (gpointer klass)
@ -117,9 +114,9 @@ gst_gl_filter_glass_base_init (gpointer klass)
}
static void
gst_gl_filter_glass_class_init (GstGLFilterGlassClass* klass)
gst_gl_filter_glass_class_init (GstGLFilterGlassClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_glass_set_property;
@ -131,72 +128,71 @@ gst_gl_filter_glass_class_init (GstGLFilterGlassClass* klass)
}
static void
gst_gl_filter_glass_init (GstGLFilterGlass* filter,
GstGLFilterGlassClass* klass)
gst_gl_filter_glass_init (GstGLFilterGlass * filter,
GstGLFilterGlassClass * klass)
{
filter->shader = NULL;
filter->timestamp = 0;
filter->shader = NULL;
filter->timestamp = 0;
}
static void
gst_gl_filter_glass_reset (GstGLFilter* filter)
gst_gl_filter_glass_reset (GstGLFilter * filter)
{
GstGLFilterGlass* glass_filter = GST_GL_FILTER_GLASS(filter);
GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter);
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, glass_filter->shader);
}
static void
gst_gl_filter_glass_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_filter_glass_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLFilterGlass *filter = GST_GL_FILTER_GLASS (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_glass_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_filter_glass_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLFilterGlass *filter = GST_GL_FILTER_GLASS (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_glass_init_shader (GstGLFilter* filter)
gst_gl_filter_glass_init_shader (GstGLFilter * filter)
{
GstGLFilterGlass* glass_filter = GST_GL_FILTER_GLASS (filter);
GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, 0, glass_fragment_source, &glass_filter->shader);
gst_gl_display_gen_shader (filter->display, 0, glass_fragment_source,
&glass_filter->shader);
}
static gboolean
gst_gl_filter_glass_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filter_glass_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
gpointer glass_filter = GST_GL_FILTER_GLASS (filter);
GST_GL_FILTER_GLASS(glass_filter)->timestamp = GST_BUFFER_TIMESTAMP (inbuf);
GST_GL_FILTER_GLASS (glass_filter)->timestamp = GST_BUFFER_TIMESTAMP (inbuf);
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_filter_glass_callback,
inbuf->width, inbuf->height, inbuf->texture,
80, (gdouble)filter->width/(gdouble)filter->height, 1.0, 5000.0,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, (gpointer)glass_filter);
filter->fbo, filter->depthbuffer, outbuf->texture,
gst_gl_filter_glass_callback, inbuf->width, inbuf->height, inbuf->texture,
80, (gdouble) filter->width / (gdouble) filter->height, 1.0, 5000.0,
GST_GL_DISPLAY_PROJECTION_PERSPECIVE, (gpointer) glass_filter);
return TRUE;
}
@ -204,60 +200,59 @@ gst_gl_filter_glass_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
static gint64
get_time (void)
{
static GTimeVal val;
g_get_current_time (&val);
static GTimeVal val;
g_get_current_time (&val);
return (val.tv_sec * G_USEC_PER_SEC) + val.tv_usec;
return (val.tv_sec * G_USEC_PER_SEC) + val.tv_usec;
}
static void
gst_gl_filter_glass_draw_background_gradient ()
{
glMatrixMode (GL_PROJECTION);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
glOrtho (-100, 100, -100, 100, -1000.0, 1000.0);
glPushMatrix ();
glLoadIdentity ();
glOrtho (-100, 100, -100, 100, -1000.0, 1000.0);
glBegin (GL_QUADS);
glBegin (GL_QUADS);
glColor4f (0.0f, 0.0f, 0.0f, 1.0f);
glVertex2f (-100.0f, -100.0f);
glVertex2f (100.0f, -100.0f);
glColor4f (0.0f, 0.0f, 0.0f, 1.0f);
glVertex2f (-100.0f, -100.0f);
glVertex2f (100.0f, -100.0f);
glColor4f (0.0f, 0.0f, 0.2f, 1.0f);
glVertex2f (100.0f, 80.0f);
glVertex2f (-100.0f, 80.0f);
glColor4f (0.0f, 0.0f, 0.2f, 1.0f);
glVertex2f (100.0f, 80.0f);
glVertex2f (-100.0f, 80.0f);
glVertex2f (100.0f, 80.0f);
glVertex2f (-100.0f, 80.0f);
glVertex2f (100.0f, 80.0f);
glVertex2f (-100.0f, 80.0f);
glVertex2f (-100.0f, 100.0f);
glVertex2f (100.0f, 100.0f);
glVertex2f (-100.0f, 100.0f);
glVertex2f (100.0f, 100.0f);
glEnd ();
glPopMatrix ();
glEnd ();
glPopMatrix ();
glMatrixMode (GL_MODELVIEW);
glMatrixMode (GL_MODELVIEW);
}
static void
gst_gl_filter_glass_draw_video_plane (GstGLFilter* filter,
gint width, gint height, guint texture,
gfloat center_x, gfloat center_y,
gfloat start_alpha, gfloat stop_alpha,
gboolean reversed)
gst_gl_filter_glass_draw_video_plane (GstGLFilter * filter,
gint width, gint height, guint texture,
gfloat center_x, gfloat center_y,
gfloat start_alpha, gfloat stop_alpha, gboolean reversed)
{
GstGLFilterGlass* glass_filter = GST_GL_FILTER_GLASS (filter);
GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (filter);
gfloat topy;
gfloat bottomy;
if (reversed) {
topy = center_y - 1.0f;
bottomy = center_y + 1.0f;
topy = center_y - 1.0f;
bottomy = center_y + 1.0f;
} else {
topy = center_y + 1.0f;
bottomy = center_y - 1.0f;
topy = center_y + 1.0f;
bottomy = center_y - 1.0f;
}
gst_gl_shader_use (glass_filter->shader);
@ -267,22 +262,23 @@ gst_gl_filter_glass_draw_video_plane (GstGLFilter* filter,
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
gst_gl_shader_set_uniform_1i (glass_filter->shader, "tex", 0);
gst_gl_shader_set_uniform_1f (glass_filter->shader, "width", (gfloat)width);
gst_gl_shader_set_uniform_1f (glass_filter->shader, "height", (gfloat)height);
gst_gl_shader_set_uniform_1i (glass_filter->shader, "tex", 0);
gst_gl_shader_set_uniform_1f (glass_filter->shader, "width", (gfloat) width);
gst_gl_shader_set_uniform_1f (glass_filter->shader, "height",
(gfloat) height);
glBegin (GL_QUADS);
glColor4f (1.0f, 1.0f, 1.0f, start_alpha);
glTexCoord2i (0, height);
glVertex2f (center_x - 1.6f, topy);
glTexCoord2i (width, height);
glVertex2f (center_x + 1.6f, topy);
glColor4f (1.0f, 1.0f, 1.0f, start_alpha);
glTexCoord2i (0, height);
glVertex2f (center_x - 1.6f, topy);
glTexCoord2i (width, height);
glVertex2f (center_x + 1.6f, topy);
glColor4f (1.0, 1.0, 1.0, stop_alpha);
glTexCoord2i (width, 0);
glVertex2f (center_x + 1.6f, bottomy);
glTexCoord2i (0, 0);
glVertex2f (center_x - 1.6f, bottomy);
glColor4f (1.0, 1.0, 1.0, stop_alpha);
glTexCoord2i (width, 0);
glVertex2f (center_x + 1.6f, bottomy);
glTexCoord2i (0, 0);
glVertex2f (center_x - 1.6f, bottomy);
glEnd ();
gst_gl_shader_use (0);
@ -290,35 +286,35 @@ gst_gl_filter_glass_draw_video_plane (GstGLFilter* filter,
//opengl scene, params: input texture (not the output filter->texture)
static void
gst_gl_filter_glass_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filter_glass_callback (gint width, gint height, guint texture,
gpointer stuff)
{
static gint64 start_time = 0;
GstGLFilter* filter = GST_GL_FILTER (stuff);
GstGLFilterGlass* glass_filter = GST_GL_FILTER_GLASS (stuff);
GstGLFilter *filter = GST_GL_FILTER (stuff);
GstGLFilterGlass *glass_filter = GST_GL_FILTER_GLASS (stuff);
if (start_time == 0)
start_time = get_time ();
else
{
gint64 time_left = (glass_filter->timestamp / 1000) - (get_time () - start_time);
else {
gint64 time_left =
(glass_filter->timestamp / 1000) - (get_time () - start_time);
time_left -= 1000000 / 25;
if (time_left > 2000)
{
GST_LOG ("escape");
return;
if (time_left > 2000) {
GST_LOG ("escape");
return;
}
}
glTranslatef(0.0f, 2.0f, -3.0f);
glTranslatef (0.0f, 2.0f, -3.0f);
gst_gl_filter_glass_draw_background_gradient ();
//Rotation
if (start_time != 0) {
gint64 time_passed = get_time () - start_time;
glRotated (sin (time_passed / 1200000.0) * 45.0, 0.0, 1.0, 0.0);
gint64 time_passed = get_time () - start_time;
glRotated (sin (time_passed / 1200000.0) * 45.0, 0.0, 1.0, 0.0);
}
glEnable (GL_BLEND);
@ -326,11 +322,11 @@ gst_gl_filter_glass_callback (gint width, gint height, guint texture, gpointer s
//Reflection
gst_gl_filter_glass_draw_video_plane (filter, width, height, texture,
0.0f, 0.0f, 0.3f, 0.0f, TRUE);
0.0f, 0.0f, 0.3f, 0.0f, TRUE);
//Main video
gst_gl_filter_glass_draw_video_plane (filter, width, height, texture,
0.0f, -2.0f, 1.0f, 1.0f, FALSE);
0.0f, -2.0f, 1.0f, 1.0f, FALSE);
glDisable (GL_TEXTURE_RECTANGLE_ARB);
glDisable (GL_BLEND);

View file

@ -42,10 +42,10 @@
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL laplacian filter",
"Filter/Effect",
"Laplacian Convolution Demo Filter",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL laplacian filter",
"Filter/Effect",
"Laplacian Convolution Demo Filter",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
enum
{
@ -55,42 +55,40 @@ enum
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_laplacian_debug, "glfilterlaplacian", 0, "glfilterlaplacian element");
GST_BOILERPLATE_FULL (GstGLFilterLaplacian, gst_gl_filter_laplacian, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_BOILERPLATE_FULL (GstGLFilterLaplacian, gst_gl_filter_laplacian,
GstGLFilter, GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filter_laplacian_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_laplacian_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_filter_laplacian_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_gl_filter_laplacian_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_gl_filter_laplacian_reset (GstGLFilter* filter);
static void gst_gl_filter_laplacian_init_shader (GstGLFilter* filter);
static void gst_gl_filter_laplacian_reset (GstGLFilter * filter);
static void gst_gl_filter_laplacian_init_shader (GstGLFilter * filter);
static gboolean gst_gl_filter_laplacian_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filter_laplacian_callback (gint width, gint height, guint texture, gpointer stuff);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filter_laplacian_callback (gint width, gint height,
guint texture, gpointer stuff);
static const gchar *convolution_fragment_source =
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" vec2 offset[9] = vec2[9] ("
" vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, texturecoord + vec2(offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }"
" }"
" gl_FragColor = sum + norm_offset;"
"}";
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect tex;"
"uniform float norm_const;"
"uniform float norm_offset;"
"uniform float kernel[9];"
"void main () {"
" vec2 offset[9] = vec2[9] ("
" vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );"
" vec2 texturecoord = gl_TexCoord[0].st;"
" int i;"
" vec4 sum = vec4 (0.0);"
" for (i = 0; i < 9; i++) { "
" if (kernel[i] != 0.0) {"
" vec4 neighbor = texture2DRect(tex, texturecoord + vec2(offset[i])); "
" sum += neighbor * kernel[i]/norm_const; "
" }" " }" " gl_FragColor = sum + norm_offset;" "}";
static void
gst_gl_filter_laplacian_base_init (gpointer klass)
@ -101,9 +99,9 @@ gst_gl_filter_laplacian_base_init (gpointer klass)
}
static void
gst_gl_filter_laplacian_class_init (GstGLFilterLaplacianClass* klass)
gst_gl_filter_laplacian_class_init (GstGLFilterLaplacianClass * klass)
{
GObjectClass* gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_filter_laplacian_set_property;
@ -115,83 +113,84 @@ gst_gl_filter_laplacian_class_init (GstGLFilterLaplacianClass* klass)
}
static void
gst_gl_filter_laplacian_init (GstGLFilterLaplacian* filter,
GstGLFilterLaplacianClass* klass)
gst_gl_filter_laplacian_init (GstGLFilterLaplacian * filter,
GstGLFilterLaplacianClass * klass)
{
filter->shader = NULL;
filter->shader = NULL;
}
static void
gst_gl_filter_laplacian_reset (GstGLFilter* filter)
gst_gl_filter_laplacian_reset (GstGLFilter * filter)
{
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN(filter);
GstGLFilterLaplacian *laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, laplacian_filter->shader);
}
static void
gst_gl_filter_laplacian_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_filter_laplacian_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLFilterLaplacian *filter = GST_GL_FILTER_LAPLACIAN (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_laplacian_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_filter_laplacian_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLFilterLaplacian *filter = GST_GL_FILTER_LAPLACIAN (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filter_laplacian_init_shader (GstGLFilter* filter)
gst_gl_filter_laplacian_init_shader (GstGLFilter * filter)
{
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
GstGLFilterLaplacian *laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, 0, convolution_fragment_source, &laplacian_filter->shader);
gst_gl_display_gen_shader (filter->display, 0, convolution_fragment_source,
&laplacian_filter->shader);
}
static gboolean
gst_gl_filter_laplacian_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filter_laplacian_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
gpointer laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
//blocking call, use a FBO
gst_gl_display_use_fbo (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_filter_laplacian_callback,
inbuf->width, inbuf->height, inbuf->texture,
0, filter->width, 0, filter->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D, laplacian_filter);
filter->fbo, filter->depthbuffer, outbuf->texture,
gst_gl_filter_laplacian_callback, inbuf->width, inbuf->height,
inbuf->texture, 0, filter->width, 0, filter->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D, laplacian_filter);
return TRUE;
}
//opengl scene, params: input texture (not the output filter->texture)
static void
gst_gl_filter_laplacian_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filter_laplacian_callback (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (stuff);
GstGLFilterLaplacian *laplacian_filter = GST_GL_FILTER_LAPLACIAN (stuff);
gfloat kernel[9] = { 0.0, -1.0, 0.0,
-1.0, 4.0, -1.0,
0.0, -1.0, 0.0 };
gfloat kernel[9] = { 0.0, -1.0, 0.0,
-1.0, 4.0, -1.0,
0.0, -1.0, 0.0
};
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@ -202,10 +201,10 @@ gst_gl_filter_laplacian_callback (gint width, gint height, guint texture, gpoint
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
gst_gl_shader_set_uniform_1i (laplacian_filter->shader, "tex", 0);
gst_gl_shader_set_uniform_1i (laplacian_filter->shader, "tex", 0);
gst_gl_shader_set_uniform_1fv (laplacian_filter->shader, "kernel", 9, kernel);
gst_gl_shader_set_uniform_1f (laplacian_filter->shader, "norm_const", 1.0);
gst_gl_shader_set_uniform_1f (laplacian_filter->shader, "norm_offset", 0.0); //set to 0.5 to preserve overall greylevel
gst_gl_shader_set_uniform_1f (laplacian_filter->shader, "norm_const", 1.0);
gst_gl_shader_set_uniform_1f (laplacian_filter->shader, "norm_offset", 0.0); //set to 0.5 to preserve overall greylevel
glBegin (GL_QUADS);

View file

@ -85,37 +85,41 @@ GST_ELEMENT_DETAILS ("Gstreamer OpenGL Sobel",
GST_DEBUG_CATEGORY_INIT (gst_gl_filtersobel_debug, "glfiltersobel", 0, "glfiltersobel element");
GST_BOILERPLATE_FULL (GstGLFilterSobel, gst_gl_filtersobel, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_filter_filtersobel_reset (GstGLFilter* filter);
static void gst_gl_filtersobel_draw_texture (GstGLFilterSobel * filtersobel, GLuint tex);
static void gst_gl_filter_filtersobel_reset (GstGLFilter * filter);
static void gst_gl_filtersobel_draw_texture (GstGLFilterSobel * filtersobel,
GLuint tex);
static void gst_gl_filtersobel_init_shader (GstGLFilter* filter);
static void gst_gl_filtersobel_init_shader (GstGLFilter * filter);
static gboolean gst_gl_filtersobel_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filtersobel_callback (gint width, gint height, guint texture, gpointer stuff);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static void gst_gl_filtersobel_callback (gint width, gint height, guint texture,
gpointer stuff);
static void
gst_gl_filtersobel_init_resources (GstGLFilter *filter)
gst_gl_filtersobel_init_resources (GstGLFilter * filter)
{
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
glGenTextures (1, &filtersobel->midtexture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, filtersobel->midtexture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, filtersobel->midtexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
filter->width, filter->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
}
static void
gst_gl_filtersobel_reset_resources (GstGLFilter *filter)
gst_gl_filtersobel_reset_resources (GstGLFilter * filter)
{
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
@ -140,23 +144,24 @@ gst_gl_filtersobel_class_init (GstGLFilterSobelClass * klass)
gobject_class->get_property = gst_gl_filtersobel_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filtersobel_filter;
GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_filtersobel_init_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_filtersobel_reset_resources;
GST_GL_FILTER_CLASS (klass)->display_init_cb =
gst_gl_filtersobel_init_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
gst_gl_filtersobel_reset_resources;
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_filtersobel_init_shader;
GST_GL_FILTER_CLASS (klass)->onReset = gst_gl_filter_filtersobel_reset;
g_object_class_install_property (
gobject_class,
PROP_INVERT,
g_param_spec_boolean ("invert",
"Invert the colors",
"Invert colors to get dark edges on bright background",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_INVERT,
g_param_spec_boolean ("invert",
"Invert the colors",
"Invert colors to get dark edges on bright background",
FALSE, G_PARAM_READWRITE));
}
static void
gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel, GstGLFilterSobelClass * klass)
gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel,
GstGLFilterSobelClass * klass)
{
filtersobel->shader0 = NULL;
filtersobel->midtexture = 0;
@ -164,9 +169,9 @@ gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel, GstGLFilterSobelClass *
}
static void
gst_gl_filter_filtersobel_reset (GstGLFilter* filter)
gst_gl_filter_filtersobel_reset (GstGLFilter * filter)
{
GstGLFilterSobel* filtersobel = GST_GL_FILTERSOBEL(filter);
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
//blocking call, wait the opengl thread has destroyed the shader
gst_gl_display_del_shader (filter->display, filtersobel->shader0);
@ -179,12 +184,12 @@ gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
switch (prop_id) {
case PROP_INVERT:
filtersobel->invert = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_INVERT:
filtersobel->invert = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@ -195,22 +200,23 @@ gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
switch (prop_id) {
case PROP_INVERT:
g_value_set_boolean (value, filtersobel->invert);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_INVERT:
g_value_set_boolean (value, filtersobel->invert);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_filtersobel_init_shader (GstGLFilter* filter)
gst_gl_filtersobel_init_shader (GstGLFilter * filter)
{
GstGLFilterSobel* filtersobel = GST_GL_FILTERSOBEL (filter);
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
//blocking call, wait the opengl thread has compiled the shader
gst_gl_display_gen_shader (filter->display, 0, sobel_fragment_source, &filtersobel->shader0);
gst_gl_display_gen_shader (filter->display, 0, sobel_fragment_source,
&filtersobel->shader0);
}
static void
@ -226,11 +232,11 @@ gst_gl_filtersobel_draw_texture (GstGLFilterSobel * filtersobel, GLuint tex)
glTexCoord2f (0.0, 0.0);
glVertex2f (-1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, 0.0);
glTexCoord2f ((gfloat) filter->width, 0.0);
glVertex2f (1.0, -1.0);
glTexCoord2f ((gfloat)filter->width, (gfloat)filter->height);
glTexCoord2f ((gfloat) filter->width, (gfloat) filter->height);
glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, (gfloat)filter->height);
glTexCoord2f (0.0, (gfloat) filter->height);
glVertex2f (-1.0, 1.0);
glEnd ();
@ -253,33 +259,34 @@ change_view (GstGLDisplay *display, gpointer data)
}*/
static gboolean
gst_gl_filtersobel_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_filtersobel_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLFilterSobel* filtersobel = GST_GL_FILTERSOBEL(filter);
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
// gst_gl_display_thread_add (filter->display, change_view, filtersobel);
gst_gl_filter_render_to_target (filter, inbuf->texture, outbuf->texture,
gst_gl_filtersobel_callback, filtersobel);
gst_gl_filtersobel_callback, filtersobel);
return TRUE;
}
static void
gst_gl_filtersobel_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_filtersobel_callback (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLFilterSobel* filtersobel = GST_GL_FILTERSOBEL (stuff);
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (stuff);
gfloat hkern[9] = {
gfloat hkern[9] = {
1.0, 0.0, -1.0,
2.0, 0.0, -2.0,
1.0, 0.0, -1.0
};
gfloat vkern[9] = {
1.0, 2.0, 1.0,
0.0, 0.0, 0.0,
1.0, 2.0, 1.0,
0.0, 0.0, 0.0,
-1.0, -2.0, -1.0
};
@ -298,7 +305,8 @@ gst_gl_filtersobel_callback (gint width, gint height, guint texture, gpointer st
gst_gl_shader_set_uniform_1fv (filtersobel->shader0, "hkern", 9, hkern);
gst_gl_shader_set_uniform_1fv (filtersobel->shader0, "vkern", 9, vkern);
gst_gl_shader_set_uniform_1i (filtersobel->shader0, "invert", filtersobel->invert);
gst_gl_shader_set_uniform_1i (filtersobel->shader0, "invert",
filtersobel->invert);
gst_gl_filtersobel_draw_texture (filtersobel, texture);
}

View file

@ -119,10 +119,10 @@ static void gst_glimage_sink_implements_init (GstImplementsInterfaceClass *
klass);
static const GstElementDetails gst_glimage_sink_details =
GST_ELEMENT_DETAILS ("OpenGL video sink",
"Sink/Video",
"A videosink based on OpenGL",
"Julien Isorce <julien.isorce@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL video sink",
"Sink/Video",
"A videosink based on OpenGL",
"Julien Isorce <julien.isorce@gmail.com>");
static GstStaticPadTemplate gst_glimage_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
@ -139,10 +139,10 @@ static GstStaticPadTemplate gst_glimage_sink_template =
enum
{
ARG_0,
ARG_DISPLAY,
PROP_CLIENT_RESHAPE_CALLBACK,
PROP_CLIENT_DRAW_CALLBACK
ARG_0,
ARG_DISPLAY,
PROP_CLIENT_RESHAPE_CALLBACK,
PROP_CLIENT_DRAW_CALLBACK
};
GST_BOILERPLATE_FULL (GstGLImageSink, gst_glimage_sink, GstVideoSink,
@ -158,7 +158,7 @@ gst_glimage_sink_init_interfaces (GType type)
NULL
};
static const GInterfaceInfo xoverlay_info = {
static const GInterfaceInfo xoverlay_info = {
(GInterfaceInitFunc) gst_glimage_sink_xoverlay_init,
NULL,
NULL,
@ -170,7 +170,7 @@ gst_glimage_sink_init_interfaces (GType type)
g_type_add_interface_static (type, GST_TYPE_X_OVERLAY, &xoverlay_info);
GST_DEBUG_CATEGORY_INIT (gst_debug_glimage_sink, "glimagesink", 0,
"OpenGL Video Sink");
"OpenGL Video Sink");
}
static void
@ -185,127 +185,125 @@ gst_glimage_sink_base_init (gpointer g_class)
}
static void
gst_glimage_sink_class_init (GstGLImageSinkClass* klass)
gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class;
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass;
gobject_class->set_property = gst_glimage_sink_set_property;
gobject_class->get_property = gst_glimage_sink_get_property;
gobject_class->set_property = gst_glimage_sink_set_property;
gobject_class->get_property = gst_glimage_sink_get_property;
g_object_class_install_property (gobject_class, ARG_DISPLAY,
g_object_class_install_property (gobject_class, ARG_DISPLAY,
g_param_spec_string ("display", "Display", "Display name",
NULL, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_CLIENT_RESHAPE_CALLBACK,
g_param_spec_pointer ("client_reshape_callback", "Client reshape callback",
g_object_class_install_property (gobject_class, PROP_CLIENT_RESHAPE_CALLBACK,
g_param_spec_pointer ("client_reshape_callback",
"Client reshape callback",
"Define a custom reshape callback in a client code",
G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class, PROP_CLIENT_DRAW_CALLBACK,
g_object_class_install_property (gobject_class, PROP_CLIENT_DRAW_CALLBACK,
g_param_spec_pointer ("client_draw_callback", "Client draw callback",
"Define a custom draw callback in a client code",
G_PARAM_WRITABLE));
"Define a custom draw callback in a client code", G_PARAM_WRITABLE));
gobject_class->finalize = gst_glimage_sink_finalize;
gobject_class->finalize = gst_glimage_sink_finalize;
gstelement_class->change_state = gst_glimage_sink_change_state;
gstelement_class->change_state = gst_glimage_sink_change_state;
gstbasesink_class->set_caps = gst_glimage_sink_set_caps;
gstbasesink_class->get_times = gst_glimage_sink_get_times;
gstbasesink_class->preroll = gst_glimage_sink_render;
gstbasesink_class->render = gst_glimage_sink_render;
gstbasesink_class->start = gst_glimage_sink_start;
gstbasesink_class->stop = gst_glimage_sink_stop;
gstbasesink_class->set_caps = gst_glimage_sink_set_caps;
gstbasesink_class->get_times = gst_glimage_sink_get_times;
gstbasesink_class->preroll = gst_glimage_sink_render;
gstbasesink_class->render = gst_glimage_sink_render;
gstbasesink_class->start = gst_glimage_sink_start;
gstbasesink_class->stop = gst_glimage_sink_stop;
}
static void
gst_glimage_sink_init (GstGLImageSink* glimage_sink,
GstGLImageSinkClass* glimage_sink_class)
gst_glimage_sink_init (GstGLImageSink * glimage_sink,
GstGLImageSinkClass * glimage_sink_class)
{
glimage_sink->display_name = NULL;
glimage_sink->window_id = 0;
glimage_sink->display = NULL;
glimage_sink->stored_buffer = NULL;
glimage_sink->clientReshapeCallback = NULL;
glimage_sink->clientDrawCallback = NULL;
glimage_sink->display_name = NULL;
glimage_sink->window_id = 0;
glimage_sink->display = NULL;
glimage_sink->stored_buffer = NULL;
glimage_sink->clientReshapeCallback = NULL;
glimage_sink->clientDrawCallback = NULL;
}
static void
gst_glimage_sink_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_glimage_sink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLImageSink *glimage_sink;
GstGLImageSink *glimage_sink;
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
glimage_sink = GST_GLIMAGE_SINK (object);
glimage_sink = GST_GLIMAGE_SINK (object);
switch (prop_id)
switch (prop_id) {
case ARG_DISPLAY:
{
case ARG_DISPLAY:
{
g_free (glimage_sink->display_name);
glimage_sink->display_name = g_strdup (g_value_get_string (value));
break;
}
case PROP_CLIENT_RESHAPE_CALLBACK:
{
glimage_sink->clientReshapeCallback = g_value_get_pointer (value);
break;
}
case PROP_CLIENT_DRAW_CALLBACK:
{
glimage_sink->clientDrawCallback = g_value_get_pointer (value);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_free (glimage_sink->display_name);
glimage_sink->display_name = g_strdup (g_value_get_string (value));
break;
}
}
static void
gst_glimage_sink_finalize (GObject* object)
{
GstGLImageSink* glimage_sink;
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
glimage_sink = GST_GLIMAGE_SINK (object);
if (glimage_sink->caps)
gst_caps_unref (glimage_sink->caps);
g_free (glimage_sink->display_name);
GST_DEBUG ("finalized");
}
static void
gst_glimage_sink_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
{
GstGLImageSink *glimage_sink;
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
glimage_sink = GST_GLIMAGE_SINK (object);
switch (prop_id)
case PROP_CLIENT_RESHAPE_CALLBACK:
{
case ARG_DISPLAY:
g_value_set_string (value, glimage_sink->display_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
glimage_sink->clientReshapeCallback = g_value_get_pointer (value);
break;
}
case PROP_CLIENT_DRAW_CALLBACK:
{
glimage_sink->clientDrawCallback = g_value_get_pointer (value);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_glimage_sink_finalize (GObject * object)
{
GstGLImageSink *glimage_sink;
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
glimage_sink = GST_GLIMAGE_SINK (object);
if (glimage_sink->caps)
gst_caps_unref (glimage_sink->caps);
g_free (glimage_sink->display_name);
GST_DEBUG ("finalized");
}
static void
gst_glimage_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstGLImageSink *glimage_sink;
g_return_if_fail (GST_IS_GLIMAGE_SINK (object));
glimage_sink = GST_GLIMAGE_SINK (object);
switch (prop_id) {
case ARG_DISPLAY:
g_value_set_string (value, glimage_sink->display_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*
@ -313,49 +311,47 @@ gst_glimage_sink_get_property (GObject* object, guint prop_id,
*/
static GstStateChangeReturn
gst_glimage_sink_change_state (GstElement* element, GstStateChange transition)
gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
{
GstGLImageSink* glimage_sink;
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstGLImageSink *glimage_sink;
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GST_DEBUG ("change state");
GST_DEBUG ("change state");
glimage_sink = GST_GLIMAGE_SINK (element);
glimage_sink = GST_GLIMAGE_SINK (element);
switch (transition)
{
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition)
{
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_glimage_sink_stop (GST_BASE_SINK (glimage_sink));
glimage_sink->fps_n = 0;
glimage_sink->fps_d = 1;
GST_VIDEO_SINK_WIDTH (glimage_sink) = 0;
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 0;
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
break;
}
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_glimage_sink_stop (GST_BASE_SINK (glimage_sink));
glimage_sink->fps_n = 0;
glimage_sink->fps_d = 1;
GST_VIDEO_SINK_WIDTH (glimage_sink) = 0;
GST_VIDEO_SINK_HEIGHT (glimage_sink) = 0;
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
break;
}
return ret;
}
/*
@ -363,248 +359,239 @@ gst_glimage_sink_change_state (GstElement* element, GstStateChange transition)
*/
static gboolean
gst_glimage_sink_start (GstBaseSink* bsink)
gst_glimage_sink_start (GstBaseSink * bsink)
{
//GstGLImageSink* glimage_sink = GST_GLIMAGE_SINK (bsink);
//GstGLImageSink* glimage_sink = GST_GLIMAGE_SINK (bsink);
GST_DEBUG ("start");
GST_DEBUG ("start");
return TRUE;
return TRUE;
}
static gboolean
gst_glimage_sink_stop (GstBaseSink* bsink)
gst_glimage_sink_stop (GstBaseSink * bsink)
{
GstGLImageSink* glimage_sink;
GstGLImageSink *glimage_sink;
GST_DEBUG ("stop");
GST_DEBUG ("stop");
glimage_sink = GST_GLIMAGE_SINK (bsink);
glimage_sink = GST_GLIMAGE_SINK (bsink);
if (glimage_sink->stored_buffer)
{
gst_buffer_unref (glimage_sink->stored_buffer);
glimage_sink->stored_buffer = NULL;
}
if (glimage_sink->display)
{
g_object_unref (glimage_sink->display);
glimage_sink->display = NULL;
}
if (glimage_sink->stored_buffer) {
gst_buffer_unref (glimage_sink->stored_buffer);
glimage_sink->stored_buffer = NULL;
}
if (glimage_sink->display) {
g_object_unref (glimage_sink->display);
glimage_sink->display = NULL;
}
return TRUE;
return TRUE;
}
static void
gst_glimage_sink_get_times (GstBaseSink* bsink, GstBuffer* buf,
GstClockTime* start, GstClockTime* end)
gst_glimage_sink_get_times (GstBaseSink * bsink, GstBuffer * buf,
GstClockTime * start, GstClockTime * end)
{
GstGLImageSink* glimagesink;
GstGLImageSink *glimagesink;
glimagesink = GST_GLIMAGE_SINK (bsink);
glimagesink = GST_GLIMAGE_SINK (bsink);
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf))
{
*start = GST_BUFFER_TIMESTAMP (buf);
if (GST_BUFFER_DURATION_IS_VALID (buf))
*end = *start + GST_BUFFER_DURATION (buf);
else
{
if (glimagesink->fps_n > 0) {
*end = *start +
gst_util_uint64_scale_int (GST_SECOND, glimagesink->fps_d,
glimagesink->fps_n);
}
}
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
*start = GST_BUFFER_TIMESTAMP (buf);
if (GST_BUFFER_DURATION_IS_VALID (buf))
*end = *start + GST_BUFFER_DURATION (buf);
else {
if (glimagesink->fps_n > 0) {
*end = *start +
gst_util_uint64_scale_int (GST_SECOND, glimagesink->fps_d,
glimagesink->fps_n);
}
}
}
}
static gboolean
gst_glimage_sink_set_caps (GstBaseSink* bsink, GstCaps* caps)
gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
{
GstGLImageSink* glimage_sink;
gint width;
gint height;
gboolean ok;
gint fps_n, fps_d;
gint par_n, par_d;
GstVideoFormat format;
GstStructure *structure;
gboolean is_gl;
GstGLImageSink *glimage_sink;
gint width;
gint height;
gboolean ok;
gint fps_n, fps_d;
gint par_n, par_d;
GstVideoFormat format;
GstStructure *structure;
gboolean is_gl;
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
glimage_sink = GST_GLIMAGE_SINK (bsink);
glimage_sink = GST_GLIMAGE_SINK (bsink);
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl")) {
is_gl = TRUE;
format = GST_VIDEO_FORMAT_UNKNOWN;
ok = gst_structure_get_int (structure, "width", &width);
ok &= gst_structure_get_int (structure, "height", &height);
} else {
is_gl = FALSE;
ok = gst_video_format_parse_caps (caps, &format, &width, &height);
}
ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d);
ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d);
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl")) {
is_gl = TRUE;
format = GST_VIDEO_FORMAT_UNKNOWN;
ok = gst_structure_get_int (structure, "width", &width);
ok &= gst_structure_get_int (structure, "height", &height);
} else {
is_gl = FALSE;
ok = gst_video_format_parse_caps (caps, &format, &width, &height);
}
ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d);
ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d);
if (!ok)
return FALSE;
if (!ok)
return FALSE;
GST_VIDEO_SINK_WIDTH (glimage_sink) = width;
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
glimage_sink->is_gl = is_gl;
glimage_sink->format = format;
glimage_sink->width = width;
glimage_sink->height = height;
glimage_sink->fps_n = fps_n;
glimage_sink->fps_d = fps_d;
glimage_sink->par_n = par_n;
glimage_sink->par_d = par_d;
GST_VIDEO_SINK_WIDTH (glimage_sink) = width;
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
glimage_sink->is_gl = is_gl;
glimage_sink->format = format;
glimage_sink->width = width;
glimage_sink->height = height;
glimage_sink->fps_n = fps_n;
glimage_sink->fps_d = fps_d;
glimage_sink->par_n = par_n;
glimage_sink->par_d = par_d;
if (!glimage_sink->window_id)
gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink));
if (!glimage_sink->window_id)
gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink));
return TRUE;
return TRUE;
}
static GstFlowReturn
gst_glimage_sink_render (GstBaseSink* bsink, GstBuffer* buf)
gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
{
GstGLImageSink* glimage_sink = NULL;
GstGLBuffer* gl_buffer = NULL;
GstGLImageSink *glimage_sink = NULL;
GstGLBuffer *gl_buffer = NULL;
glimage_sink = GST_GLIMAGE_SINK (bsink);
glimage_sink = GST_GLIMAGE_SINK (bsink);
GST_INFO ("buffer size: %d", GST_BUFFER_SIZE (buf));
GST_INFO ("buffer size: %d", GST_BUFFER_SIZE (buf));
//is gl
if (glimage_sink->is_gl)
{
//increment gl buffer ref before storage
gl_buffer = GST_GL_BUFFER (gst_buffer_ref (buf));
//is gl
if (glimage_sink->is_gl) {
//increment gl buffer ref before storage
gl_buffer = GST_GL_BUFFER (gst_buffer_ref (buf));
//if glimagesink has not the display yet
if (glimage_sink->display == NULL)
{
glimage_sink->display = g_object_ref (gl_buffer->display);
//if glimagesink has not the display yet
if (glimage_sink->display == NULL) {
glimage_sink->display = g_object_ref (gl_buffer->display);
if (glimage_sink->window_id)
gst_gl_display_set_window_id (glimage_sink->display, glimage_sink->window_id);
if (glimage_sink->window_id)
gst_gl_display_set_window_id (glimage_sink->display,
glimage_sink->window_id);
gst_gl_display_set_client_reshape_callback (glimage_sink->display,
glimage_sink->clientReshapeCallback);
gst_gl_display_set_client_reshape_callback (glimage_sink->display,
glimage_sink->clientReshapeCallback);
gst_gl_display_set_client_draw_callback (glimage_sink->display,
glimage_sink->clientDrawCallback);
}
gst_gl_display_set_client_draw_callback (glimage_sink->display,
glimage_sink->clientDrawCallback);
}
//is not gl
else
{
//if glimagesink has not the display yet
if (glimage_sink->display == NULL)
{
//create a display
glimage_sink->display = gst_gl_display_new ();
}
//is not gl
else {
//if glimagesink has not the display yet
if (glimage_sink->display == NULL) {
//create a display
glimage_sink->display = gst_gl_display_new ();
//init opengl context
gst_gl_display_create_context (glimage_sink->display,
glimage_sink->width, glimage_sink->height);
//init opengl context
gst_gl_display_create_context (glimage_sink->display,
glimage_sink->width, glimage_sink->height);
if (glimage_sink->window_id)
gst_gl_display_set_window_id (glimage_sink->display, glimage_sink->window_id);
if (glimage_sink->window_id)
gst_gl_display_set_window_id (glimage_sink->display,
glimage_sink->window_id);
//init colorspace conversion if needed
gst_gl_display_init_upload (glimage_sink->display, glimage_sink->format,
glimage_sink->width, glimage_sink->height,
glimage_sink->width, glimage_sink->height);
//init colorspace conversion if needed
gst_gl_display_init_upload (glimage_sink->display, glimage_sink->format,
glimage_sink->width, glimage_sink->height,
glimage_sink->width, glimage_sink->height);
gst_gl_display_set_client_reshape_callback (glimage_sink->display,
glimage_sink->clientReshapeCallback);
gst_gl_display_set_client_reshape_callback (glimage_sink->display,
glimage_sink->clientReshapeCallback);
gst_gl_display_set_client_draw_callback (glimage_sink->display,
glimage_sink->clientDrawCallback);
}
//blocking call
gl_buffer = gst_gl_buffer_new (glimage_sink->display,
glimage_sink->width, glimage_sink->height);
//blocking call
gst_gl_display_do_upload(glimage_sink->display, gl_buffer->texture,
glimage_sink->width, glimage_sink->height, GST_BUFFER_DATA (buf));
//gl_buffer is created in this block, so the gl buffer is already referenced
gst_gl_display_set_client_draw_callback (glimage_sink->display,
glimage_sink->clientDrawCallback);
}
//blocking call
gl_buffer = gst_gl_buffer_new (glimage_sink->display,
glimage_sink->width, glimage_sink->height);
//the buffer is cleared when an other comes in
if (glimage_sink->stored_buffer)
{
gst_buffer_unref (glimage_sink->stored_buffer);
glimage_sink->stored_buffer = NULL;
}
//blocking call
gst_gl_display_do_upload (glimage_sink->display, gl_buffer->texture,
glimage_sink->width, glimage_sink->height, GST_BUFFER_DATA (buf));
//store current buffer
glimage_sink->stored_buffer = gl_buffer;
//gl_buffer is created in this block, so the gl buffer is already referenced
}
//redisplay opengl scene
if (gl_buffer->texture &&
gst_gl_display_redisplay (glimage_sink->display,
gl_buffer->texture, gl_buffer->width, gl_buffer->height))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
//the buffer is cleared when an other comes in
if (glimage_sink->stored_buffer) {
gst_buffer_unref (glimage_sink->stored_buffer);
glimage_sink->stored_buffer = NULL;
}
//store current buffer
glimage_sink->stored_buffer = gl_buffer;
//redisplay opengl scene
if (gl_buffer->texture &&
gst_gl_display_redisplay (glimage_sink->display,
gl_buffer->texture, gl_buffer->width, gl_buffer->height))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
}
static void
gst_glimage_sink_xoverlay_init (GstXOverlayClass* iface)
gst_glimage_sink_xoverlay_init (GstXOverlayClass * iface)
{
iface->set_xwindow_id = gst_glimage_sink_set_xwindow_id;
iface->expose = gst_glimage_sink_expose;
iface->set_xwindow_id = gst_glimage_sink_set_xwindow_id;
iface->expose = gst_glimage_sink_expose;
}
static void
gst_glimage_sink_set_xwindow_id (GstXOverlay* overlay, gulong window_id)
gst_glimage_sink_set_xwindow_id (GstXOverlay * overlay, gulong window_id)
{
GstGLImageSink* glimage_sink = GST_GLIMAGE_SINK (overlay);
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
g_return_if_fail (GST_IS_GLIMAGE_SINK (overlay));
g_return_if_fail (GST_IS_GLIMAGE_SINK (overlay));
GST_DEBUG ("set_xwindow_id %ld", window_id);
GST_DEBUG ("set_xwindow_id %ld", window_id);
if (glimage_sink->window_id == window_id)
return;
if (glimage_sink->window_id == window_id)
return;
if (window_id)
glimage_sink->window_id = window_id;
if (window_id)
glimage_sink->window_id = window_id;
}
static void
gst_glimage_sink_expose (GstXOverlay* overlay)
gst_glimage_sink_expose (GstXOverlay * overlay)
{
GstGLImageSink* glimage_sink = GST_GLIMAGE_SINK (overlay);
GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
//redisplay opengl scene
if (glimage_sink->display && glimage_sink->window_id)
gst_gl_display_redisplay (glimage_sink->display, 0, 0, 0);
//redisplay opengl scene
if (glimage_sink->display && glimage_sink->window_id)
gst_gl_display_redisplay (glimage_sink->display, 0, 0, 0);
}
static gboolean
gst_glimage_sink_interface_supported (GstImplementsInterface* iface,
gst_glimage_sink_interface_supported (GstImplementsInterface * iface,
GType type)
{
return TRUE;
return TRUE;
}
static void
gst_glimage_sink_implements_init (GstImplementsInterfaceClass* klass)
gst_glimage_sink_implements_init (GstImplementsInterfaceClass * klass)
{
klass->supported = gst_glimage_sink_interface_supported;
klass->supported = gst_glimage_sink_interface_supported;
}

View file

@ -76,26 +76,26 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
GST_DEBUG_CATEGORY_INIT (gst_gl_overlay_debug, "gloverlay", 0, "gloverlay element");
GST_BOILERPLATE_FULL (GstGLOverlay, gst_gl_overlay, GstGLFilter,
GST_TYPE_GL_FILTER, DEBUG_INIT);
GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_overlay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
const GValue * value, GParamSpec * pspec);
static void gst_gl_overlay_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
GValue * value, GParamSpec * pspec);
static void gst_gl_overlay_init_resources (GstGLFilter* filter);
static void gst_gl_overlay_reset_resources (GstGLFilter* filter);
static void gst_gl_overlay_init_resources (GstGLFilter * filter);
static void gst_gl_overlay_reset_resources (GstGLFilter * filter);
static gboolean gst_gl_overlay_filter (GstGLFilter * filter,
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
GstGLBuffer * inbuf, GstGLBuffer * outbuf);
static gboolean gst_gl_overlay_loader (GstGLFilter* filter);
static gboolean gst_gl_overlay_loader (GstGLFilter * filter);
static const GstElementDetails element_details = GST_ELEMENT_DETAILS (
"Gstreamer OpenGL Overlay",
"Filter/Effect",
"Overlay GL video texture with a PNG image",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("Gstreamer OpenGL Overlay",
"Filter/Effect",
"Overlay GL video texture with a PNG image",
"Filippo Argiolas <filippo.argiolas@gmail.com>");
enum
{
@ -112,17 +112,17 @@ enum
/* init resources that need a gl context */
static void
gst_gl_overlay_init_gl_resources (GstGLFilter *filter)
gst_gl_overlay_init_gl_resources (GstGLFilter * filter)
{
// GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
}
/* free resources that need a gl context */
static void
gst_gl_overlay_reset_gl_resources (GstGLFilter *filter)
gst_gl_overlay_reset_gl_resources (GstGLFilter * filter)
{
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
glDeleteTextures (1, &overlay->pbuftexture);
}
@ -144,25 +144,26 @@ gst_gl_overlay_class_init (GstGLOverlayClass * klass)
gobject_class->get_property = gst_gl_overlay_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_overlay_filter;
GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_overlay_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_overlay_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_init_cb =
gst_gl_overlay_init_gl_resources;
GST_GL_FILTER_CLASS (klass)->display_reset_cb =
gst_gl_overlay_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_overlay_init_resources;
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_overlay_reset_resources;
g_object_class_install_property (gobject_class,
PROP_LOCATION,
g_param_spec_string ("location",
"Location of the image",
"Location of the image",
NULL, G_PARAM_READWRITE));
PROP_LOCATION,
g_param_spec_string ("location",
"Location of the image",
"Location of the image", NULL, G_PARAM_READWRITE));
/*
g_object_class_install_property (gobject_class,
PROP_STRETCH,
g_param_spec_boolean ("stretch",
"Stretch the image to texture size",
"Stretch the image to fit video texture size",
TRUE, G_PARAM_READWRITE));
*/
g_object_class_install_property (gobject_class,
PROP_STRETCH,
g_param_spec_boolean ("stretch",
"Stretch the image to texture size",
"Stretch the image to fit video texture size",
TRUE, G_PARAM_READWRITE));
*/
}
void
@ -190,15 +191,16 @@ gst_gl_overlay_draw_texture (GstGLOverlay * overlay, GLuint tex)
glEnd ();
if (overlay->pbuftexture == 0) return;
if (overlay->pbuftexture == 0)
return;
// if (overlay->stretch) {
width = (gfloat) overlay->width;
height = (gfloat) overlay->height;
width = (gfloat) overlay->width;
height = (gfloat) overlay->height;
// }
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
@ -221,8 +223,7 @@ gst_gl_overlay_draw_texture (GstGLOverlay * overlay, GLuint tex)
}
static void
gst_gl_overlay_init (GstGLOverlay * overlay,
GstGLOverlayClass * klass)
gst_gl_overlay_init (GstGLOverlay * overlay, GstGLOverlayClass * klass)
{
overlay->location = NULL;
overlay->pixbuf = NULL;
@ -235,7 +236,7 @@ gst_gl_overlay_init (GstGLOverlay * overlay,
}
static void
gst_gl_overlay_reset_resources (GstGLFilter* filter)
gst_gl_overlay_reset_resources (GstGLFilter * filter)
{
// GstGLOverlay* overlay = GST_GL_OVERLAY(filter);
}
@ -244,21 +245,22 @@ static void
gst_gl_overlay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLOverlay *overlay = GST_GL_OVERLAY (object);
GstGLOverlay *overlay = GST_GL_OVERLAY (object);
switch (prop_id) {
case PROP_LOCATION:
if (overlay->location != NULL) g_free (overlay->location);
overlay->pbuf_has_changed = TRUE;
overlay->location = g_value_dup_string (value);
break;
case PROP_LOCATION:
if (overlay->location != NULL)
g_free (overlay->location);
overlay->pbuf_has_changed = TRUE;
overlay->location = g_value_dup_string (value);
break;
/* case PROP_STRETCH:
overlay->stretch = g_value_get_boolean (value);
break;
*/
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@ -269,21 +271,21 @@ gst_gl_overlay_get_property (GObject * object, guint prop_id,
GstGLOverlay *overlay = GST_GL_OVERLAY (object);
switch (prop_id) {
case PROP_LOCATION:
g_value_set_string (value, overlay->location);
break;
case PROP_LOCATION:
g_value_set_string (value, overlay->location);
break;
/* case PROP_STRETCH:
g_value_set_boolean (value, overlay->stretch);
break;
*/
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_overlay_init_resources (GstGLFilter* filter)
gst_gl_overlay_init_resources (GstGLFilter * filter)
{
// GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
}
@ -291,42 +293,42 @@ gst_gl_overlay_init_resources (GstGLFilter* filter)
static void
gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
{
GstGLOverlay* overlay = GST_GL_OVERLAY (stuff);
GstGLOverlay *overlay = GST_GL_OVERLAY (stuff);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_overlay_draw_texture (overlay, texture);
}
static void init_pixbuf_texture (GstGLDisplay *display, gpointer data)
static void
init_pixbuf_texture (GstGLDisplay * display, gpointer data)
{
GstGLOverlay *overlay = GST_GL_OVERLAY (data);
if (overlay->pixbuf) {
glDeleteTextures (1, &overlay->pbuftexture);
glGenTextures (1, &overlay->pbuftexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, overlay->pbuftexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
(gint)overlay->width, (gint)overlay->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, overlay->pixbuf);
}
else
(gint) overlay->width, (gint) overlay->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, overlay->pixbuf);
} else
display->isAlive = FALSE;
}
static gboolean
gst_gl_overlay_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
GstGLBuffer* outbuf)
gst_gl_overlay_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
GstGLBuffer * outbuf)
{
GstGLOverlay* overlay = GST_GL_OVERLAY(filter);
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
if (overlay->pbuf_has_changed && (overlay->location != NULL)) {
if (!gst_gl_overlay_loader (filter))
overlay->pixbuf = NULL;
/* if loader failed then display is turned off */
gst_gl_display_thread_add (filter->display, init_pixbuf_texture, overlay);
@ -337,25 +339,25 @@ gst_gl_overlay_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
overlay->pbuf_has_changed = FALSE;
}
gst_gl_filter_render_to_target (filter, inbuf->texture, outbuf->texture,
gst_gl_overlay_callback, overlay);
gst_gl_overlay_callback, overlay);
return TRUE;
}
static void
user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
static void
user_warning_fn (png_structp png_ptr, png_const_charp warning_msg)
{
g_warning("%s\n", warning_msg);
g_warning ("%s\n", warning_msg);
}
#define LOAD_ERROR(msg) { GST_WARNING ("unable to load %s: %s", overlay->location, msg); return FALSE; }
static gboolean
gst_gl_overlay_loader (GstGLFilter* filter)
gst_gl_overlay_loader (GstGLFilter * filter)
{
GstGLOverlay* overlay = GST_GL_OVERLAY(filter);
GstGLOverlay *overlay = GST_GL_OVERLAY (filter);
png_structp png_ptr;
png_infop info_ptr;
@ -372,60 +374,57 @@ gst_gl_overlay_loader (GstGLFilter* filter)
if (!filter->display)
return TRUE;
if ((fp = fopen(overlay->location, "rb")) == NULL)
if ((fp = fopen (overlay->location, "rb")) == NULL)
LOAD_ERROR ("file not found");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
fclose(fp);
if (png_ptr == NULL) {
fclose (fp);
LOAD_ERROR ("failed to initialize the png_struct");
}
png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("failed to initialize the memory for image information");
}
png_init_io(png_ptr, fp);
png_init_io (png_ptr, fp);
png_set_sig_bytes(png_ptr, sig_read);
png_set_sig_bytes (png_ptr, sig_read);
png_read_info(png_ptr, info_ptr);
png_read_info (png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, int_p_NULL, int_p_NULL);
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("color type is not rgb");
}
overlay->width = width;
overlay->height = height;
overlay->pixbuf = (guchar*) malloc ( sizeof(guchar) * width * height * 4 );
overlay->pixbuf = (guchar *) malloc (sizeof (guchar) * width * height * 4);
rows = (guchar**)malloc(sizeof(guchar*) * height);
rows = (guchar **) malloc (sizeof (guchar *) * height);
for (y = 0; y < height; ++y)
rows[y] = (guchar*) (overlay->pixbuf + y * width * 4);
for (y = 0; y < height; ++y)
rows[y] = (guchar *) (overlay->pixbuf + y * width * 4);
png_read_image(png_ptr, rows);
png_read_image (png_ptr, rows);
free(rows);
free (rows);
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
fclose(fp);
png_read_end (png_ptr, info_ptr);
png_destroy_read_struct (&png_ptr, &info_ptr, png_infopp_NULL);
fclose (fp);
return TRUE;
}

View file

@ -60,548 +60,516 @@ GST_ELEMENT_DETAILS ("Video test source",
enum
{
PROP_0,
PROP_PATTERN,
PROP_TIMESTAMP_OFFSET,
PROP_IS_LIVE
PROP_0,
PROP_PATTERN,
PROP_TIMESTAMP_OFFSET,
PROP_IS_LIVE
/* FILL ME */
};
GST_BOILERPLATE (GstGLTestSrc, gst_gl_test_src, GstPushSrc, GST_TYPE_PUSH_SRC);
static void gst_gl_test_src_set_pattern (GstGLTestSrc* gltestsrc,
static void gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc,
int pattern_type);
static void gst_gl_test_src_set_property (GObject* object, guint prop_id,
static void gst_gl_test_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_test_src_get_property (GObject* object, guint prop_id,
static void gst_gl_test_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_gl_test_src_setcaps (GstBaseSrc* bsrc, GstCaps* caps);
static void gst_gl_test_src_src_fixate (GstPad* pad, GstCaps* caps);
static gboolean gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
static void gst_gl_test_src_src_fixate (GstPad * pad, GstCaps * caps);
static gboolean gst_gl_test_src_is_seekable (GstBaseSrc* psrc);
static gboolean gst_gl_test_src_do_seek (GstBaseSrc* bsrc,
static gboolean gst_gl_test_src_is_seekable (GstBaseSrc * psrc);
static gboolean gst_gl_test_src_do_seek (GstBaseSrc * bsrc,
GstSegment * segment);
static gboolean gst_gl_test_src_query (GstBaseSrc* bsrc, GstQuery * query);
static gboolean gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
static void gst_gl_test_src_get_times (GstBaseSrc* basesrc,
GstBuffer * buffer, GstClockTime* start, GstClockTime* end);
static GstFlowReturn gst_gl_test_src_create (GstPushSrc* psrc,
GstBuffer** buffer);
static gboolean gst_gl_test_src_start (GstBaseSrc* basesrc);
static gboolean gst_gl_test_src_stop (GstBaseSrc* basesrc);
static void gst_gl_test_src_get_times (GstBaseSrc * basesrc,
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
static GstFlowReturn gst_gl_test_src_create (GstPushSrc * psrc,
GstBuffer ** buffer);
static gboolean gst_gl_test_src_start (GstBaseSrc * basesrc);
static gboolean gst_gl_test_src_stop (GstBaseSrc * basesrc);
static void gst_gl_test_src_callback (gint width, gint height, guint texture, gpointer stuff);
static void gst_gl_test_src_callback (gint width, gint height, guint texture,
gpointer stuff);
#define GST_TYPE_GL_TEST_SRC_PATTERN (gst_gl_test_src_pattern_get_type ())
static GType
gst_gl_test_src_pattern_get_type (void)
{
static GType gl_test_src_pattern_type = 0;
static const GEnumValue pattern_types[] = {
{GST_GL_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
{GST_GL_TEST_SRC_SNOW, "Random (television snow)", "snow"},
{GST_GL_TEST_SRC_BLACK, "100% Black", "black"},
{GST_GL_TEST_SRC_WHITE, "100% White", "white"},
{GST_GL_TEST_SRC_RED, "Red", "red"},
{GST_GL_TEST_SRC_GREEN, "Green", "green"},
{GST_GL_TEST_SRC_BLUE, "Blue", "blue"},
{GST_GL_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
{GST_GL_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
{GST_GL_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
{GST_GL_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
{GST_GL_TEST_SRC_CIRCULAR, "Circular", "circular"},
{GST_GL_TEST_SRC_BLINK, "Blink", "blink"},
{0, NULL, NULL}
};
static GType gl_test_src_pattern_type = 0;
static const GEnumValue pattern_types[] = {
{GST_GL_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
{GST_GL_TEST_SRC_SNOW, "Random (television snow)", "snow"},
{GST_GL_TEST_SRC_BLACK, "100% Black", "black"},
{GST_GL_TEST_SRC_WHITE, "100% White", "white"},
{GST_GL_TEST_SRC_RED, "Red", "red"},
{GST_GL_TEST_SRC_GREEN, "Green", "green"},
{GST_GL_TEST_SRC_BLUE, "Blue", "blue"},
{GST_GL_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
{GST_GL_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
{GST_GL_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
{GST_GL_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
{GST_GL_TEST_SRC_CIRCULAR, "Circular", "circular"},
{GST_GL_TEST_SRC_BLINK, "Blink", "blink"},
{0, NULL, NULL}
};
if (!gl_test_src_pattern_type)
{
gl_test_src_pattern_type =
g_enum_register_static ("GstGLTestSrcPattern", pattern_types);
}
return gl_test_src_pattern_type;
if (!gl_test_src_pattern_type) {
gl_test_src_pattern_type =
g_enum_register_static ("GstGLTestSrcPattern", pattern_types);
}
return gl_test_src_pattern_type;
}
static void
gst_gl_test_src_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details (element_class, &gl_test_src_details);
gst_element_class_set_details (element_class, &gl_test_src_details);
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
gst_caps_from_string (GST_GL_VIDEO_CAPS)));
gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
gst_caps_from_string (GST_GL_VIDEO_CAPS)));
}
static void
gst_gl_test_src_class_init (GstGLTestSrcClass* klass)
gst_gl_test_src_class_init (GstGLTestSrcClass * klass)
{
GObjectClass *gobject_class;
GstBaseSrcClass *gstbasesrc_class;
GstPushSrcClass *gstpushsrc_class;
GObjectClass *gobject_class;
GstBaseSrcClass *gstbasesrc_class;
GstPushSrcClass *gstpushsrc_class;
GST_DEBUG_CATEGORY_INIT (gl_test_src_debug, "gltestsrc", 0,
"Video Test Source");
GST_DEBUG_CATEGORY_INIT (gl_test_src_debug, "gltestsrc", 0,
"Video Test Source");
gobject_class = (GObjectClass *) klass;
gstbasesrc_class = (GstBaseSrcClass *) klass;
gstpushsrc_class = (GstPushSrcClass *) klass;
gobject_class = (GObjectClass *) klass;
gstbasesrc_class = (GstBaseSrcClass *) klass;
gstpushsrc_class = (GstPushSrcClass *) klass;
gobject_class->set_property = gst_gl_test_src_set_property;
gobject_class->get_property = gst_gl_test_src_get_property;
gobject_class->set_property = gst_gl_test_src_set_property;
gobject_class->get_property = gst_gl_test_src_get_property;
g_object_class_install_property (gobject_class, PROP_PATTERN,
g_param_spec_enum ("pattern", "Pattern",
"Type of test pattern to generate", GST_TYPE_GL_TEST_SRC_PATTERN,
GST_GL_TEST_SRC_SMPTE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TIMESTAMP_OFFSET, g_param_spec_int64 ("timestamp-offset",
"Timestamp offset",
"An offset added to timestamps set on buffers (in ns)", G_MININT64,
G_MAXINT64, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_IS_LIVE,
g_param_spec_boolean ("is-live", "Is Live",
"Whether to act as a live source", FALSE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_PATTERN,
g_param_spec_enum ("pattern", "Pattern",
"Type of test pattern to generate", GST_TYPE_GL_TEST_SRC_PATTERN,
GST_GL_TEST_SRC_SMPTE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TIMESTAMP_OFFSET, g_param_spec_int64 ("timestamp-offset",
"Timestamp offset",
"An offset added to timestamps set on buffers (in ns)", G_MININT64,
G_MAXINT64, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_IS_LIVE,
g_param_spec_boolean ("is-live", "Is Live",
"Whether to act as a live source", FALSE, G_PARAM_READWRITE));
gstbasesrc_class->set_caps = gst_gl_test_src_setcaps;
gstbasesrc_class->is_seekable = gst_gl_test_src_is_seekable;
gstbasesrc_class->do_seek = gst_gl_test_src_do_seek;
gstbasesrc_class->query = gst_gl_test_src_query;
gstbasesrc_class->get_times = gst_gl_test_src_get_times;
gstbasesrc_class->start = gst_gl_test_src_start;
gstbasesrc_class->stop = gst_gl_test_src_stop;
gstbasesrc_class->set_caps = gst_gl_test_src_setcaps;
gstbasesrc_class->is_seekable = gst_gl_test_src_is_seekable;
gstbasesrc_class->do_seek = gst_gl_test_src_do_seek;
gstbasesrc_class->query = gst_gl_test_src_query;
gstbasesrc_class->get_times = gst_gl_test_src_get_times;
gstbasesrc_class->start = gst_gl_test_src_start;
gstbasesrc_class->stop = gst_gl_test_src_stop;
gstpushsrc_class->create = gst_gl_test_src_create;
gstpushsrc_class->create = gst_gl_test_src_create;
}
static void
gst_gl_test_src_init (GstGLTestSrc* src, GstGLTestSrcClass* g_class)
gst_gl_test_src_init (GstGLTestSrc * src, GstGLTestSrcClass * g_class)
{
GstPad *pad = GST_BASE_SRC_PAD (src);
GstPad *pad = GST_BASE_SRC_PAD (src);
gst_pad_set_fixatecaps_function (pad, gst_gl_test_src_src_fixate);
gst_pad_set_fixatecaps_function (pad, gst_gl_test_src_src_fixate);
gst_gl_test_src_set_pattern (src, GST_GL_TEST_SRC_SMPTE);
gst_gl_test_src_set_pattern (src, GST_GL_TEST_SRC_SMPTE);
src->timestamp_offset = 0;
src->timestamp_offset = 0;
/* we operate in time */
gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
/* we operate in time */
gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
}
static void
gst_gl_test_src_src_fixate (GstPad* pad, GstCaps* caps)
gst_gl_test_src_src_fixate (GstPad * pad, GstCaps * caps)
{
GstStructure *structure;
GstStructure *structure;
GST_DEBUG ("fixate");
GST_DEBUG ("fixate");
structure = gst_caps_get_structure (caps, 0);
structure = gst_caps_get_structure (caps, 0);
gst_structure_fixate_field_nearest_int (structure, "width", 320);
gst_structure_fixate_field_nearest_int (structure, "height", 240);
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
gst_structure_fixate_field_nearest_int (structure, "width", 320);
gst_structure_fixate_field_nearest_int (structure, "height", 240);
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
}
static void
gst_gl_test_src_set_pattern (GstGLTestSrc* gltestsrc, gint pattern_type)
gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
{
gltestsrc->pattern_type = pattern_type;
gltestsrc->pattern_type = pattern_type;
GST_DEBUG_OBJECT (gltestsrc, "setting pattern to %d", pattern_type);
GST_DEBUG_OBJECT (gltestsrc, "setting pattern to %d", pattern_type);
switch (pattern_type) {
case GST_GL_TEST_SRC_SMPTE:
gltestsrc->make_image = gst_gl_test_src_smpte;
break;
case GST_GL_TEST_SRC_SNOW:
gltestsrc->make_image = gst_gl_test_src_snow;
break;
case GST_GL_TEST_SRC_BLACK:
gltestsrc->make_image = gst_gl_test_src_black;
break;
case GST_GL_TEST_SRC_WHITE:
gltestsrc->make_image = gst_gl_test_src_white;
break;
case GST_GL_TEST_SRC_RED:
gltestsrc->make_image = gst_gl_test_src_red;
break;
case GST_GL_TEST_SRC_GREEN:
gltestsrc->make_image = gst_gl_test_src_green;
break;
case GST_GL_TEST_SRC_BLUE:
gltestsrc->make_image = gst_gl_test_src_blue;
break;
case GST_GL_TEST_SRC_CHECKERS1:
gltestsrc->make_image = gst_gl_test_src_checkers1;
break;
case GST_GL_TEST_SRC_CHECKERS2:
gltestsrc->make_image = gst_gl_test_src_checkers2;
break;
case GST_GL_TEST_SRC_CHECKERS4:
gltestsrc->make_image = gst_gl_test_src_checkers4;
break;
case GST_GL_TEST_SRC_CHECKERS8:
gltestsrc->make_image = gst_gl_test_src_checkers8;
break;
case GST_GL_TEST_SRC_CIRCULAR:
gltestsrc->make_image = gst_gl_test_src_circular;
break;
case GST_GL_TEST_SRC_BLINK:
gltestsrc->make_image = gst_gl_test_src_black;
break;
default:
g_assert_not_reached ();
}
switch (pattern_type) {
case GST_GL_TEST_SRC_SMPTE:
gltestsrc->make_image = gst_gl_test_src_smpte;
break;
case GST_GL_TEST_SRC_SNOW:
gltestsrc->make_image = gst_gl_test_src_snow;
break;
case GST_GL_TEST_SRC_BLACK:
gltestsrc->make_image = gst_gl_test_src_black;
break;
case GST_GL_TEST_SRC_WHITE:
gltestsrc->make_image = gst_gl_test_src_white;
break;
case GST_GL_TEST_SRC_RED:
gltestsrc->make_image = gst_gl_test_src_red;
break;
case GST_GL_TEST_SRC_GREEN:
gltestsrc->make_image = gst_gl_test_src_green;
break;
case GST_GL_TEST_SRC_BLUE:
gltestsrc->make_image = gst_gl_test_src_blue;
break;
case GST_GL_TEST_SRC_CHECKERS1:
gltestsrc->make_image = gst_gl_test_src_checkers1;
break;
case GST_GL_TEST_SRC_CHECKERS2:
gltestsrc->make_image = gst_gl_test_src_checkers2;
break;
case GST_GL_TEST_SRC_CHECKERS4:
gltestsrc->make_image = gst_gl_test_src_checkers4;
break;
case GST_GL_TEST_SRC_CHECKERS8:
gltestsrc->make_image = gst_gl_test_src_checkers8;
break;
case GST_GL_TEST_SRC_CIRCULAR:
gltestsrc->make_image = gst_gl_test_src_circular;
break;
case GST_GL_TEST_SRC_BLINK:
gltestsrc->make_image = gst_gl_test_src_black;
break;
default:
g_assert_not_reached ();
}
}
static void
gst_gl_test_src_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_test_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstGLTestSrc* src = GST_GL_TEST_SRC (object);
GstGLTestSrc *src = GST_GL_TEST_SRC (object);
switch (prop_id)
{
case PROP_PATTERN:
gst_gl_test_src_set_pattern (src, g_value_get_enum (value));
break;
case PROP_TIMESTAMP_OFFSET:
src->timestamp_offset = g_value_get_int64 (value);
break;
case PROP_IS_LIVE:
gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
break;
default:
break;
}
switch (prop_id) {
case PROP_PATTERN:
gst_gl_test_src_set_pattern (src, g_value_get_enum (value));
break;
case PROP_TIMESTAMP_OFFSET:
src->timestamp_offset = g_value_get_int64 (value);
break;
case PROP_IS_LIVE:
gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
break;
default:
break;
}
}
static void
gst_gl_test_src_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_test_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstGLTestSrc* src = GST_GL_TEST_SRC (object);
GstGLTestSrc *src = GST_GL_TEST_SRC (object);
switch (prop_id) {
case PROP_PATTERN:
g_value_set_enum (value, src->pattern_type);
break;
case PROP_TIMESTAMP_OFFSET:
g_value_set_int64 (value, src->timestamp_offset);
break;
case PROP_IS_LIVE:
g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
case PROP_PATTERN:
g_value_set_enum (value, src->pattern_type);
break;
case PROP_TIMESTAMP_OFFSET:
g_value_set_int64 (value, src->timestamp_offset);
break;
case PROP_IS_LIVE:
g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_gl_test_src_parse_caps (const GstCaps* caps,
gint* width, gint* height, gint* rate_numerator, gint* rate_denominator)
gst_gl_test_src_parse_caps (const GstCaps * caps,
gint * width, gint * height, gint * rate_numerator, gint * rate_denominator)
{
const GstStructure *structure;
GstPadLinkReturn ret;
const GValue *framerate;
const GstStructure *structure;
GstPadLinkReturn ret;
const GValue *framerate;
GST_DEBUG ("parsing caps");
GST_DEBUG ("parsing caps");
if (gst_caps_get_size (caps) < 1)
return FALSE;
if (gst_caps_get_size (caps) < 1)
return FALSE;
structure = gst_caps_get_structure (caps, 0);
structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "width", width);
ret &= gst_structure_get_int (structure, "height", height);
framerate = gst_structure_get_value (structure, "framerate");
ret = gst_structure_get_int (structure, "width", width);
ret &= gst_structure_get_int (structure, "height", height);
framerate = gst_structure_get_value (structure, "framerate");
if (framerate)
{
*rate_numerator = gst_value_get_fraction_numerator (framerate);
*rate_denominator = gst_value_get_fraction_denominator (framerate);
}
else
goto no_framerate;
if (framerate) {
*rate_numerator = gst_value_get_fraction_numerator (framerate);
*rate_denominator = gst_value_get_fraction_denominator (framerate);
} else
goto no_framerate;
return ret;
return ret;
/* ERRORS */
no_framerate:
{
GST_DEBUG ("gltestsrc no framerate given");
return FALSE;
}
/* ERRORS */
no_framerate:
{
GST_DEBUG ("gltestsrc no framerate given");
return FALSE;
}
}
static gboolean
gst_gl_test_src_setcaps (GstBaseSrc* bsrc, GstCaps* caps)
gst_gl_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
{
gboolean res;
gint width, height, rate_denominator, rate_numerator;
GstGLTestSrc* gltestsrc;
gboolean res;
gint width, height, rate_denominator, rate_numerator;
GstGLTestSrc *gltestsrc;
gltestsrc = GST_GL_TEST_SRC (bsrc);
gltestsrc = GST_GL_TEST_SRC (bsrc);
GST_DEBUG ("setcaps");
GST_DEBUG ("setcaps");
res = gst_gl_test_src_parse_caps (caps, &width, &height,
&rate_numerator, &rate_denominator);
if (res)
{
/* looks ok here */
gltestsrc->width = width;
gltestsrc->height = height;
gltestsrc->rate_numerator = rate_numerator;
gltestsrc->rate_denominator = rate_denominator;
gltestsrc->negotiated = TRUE;
res = gst_gl_test_src_parse_caps (caps, &width, &height,
&rate_numerator, &rate_denominator);
if (res) {
/* looks ok here */
gltestsrc->width = width;
gltestsrc->height = height;
gltestsrc->rate_numerator = rate_numerator;
gltestsrc->rate_denominator = rate_denominator;
gltestsrc->negotiated = TRUE;
GST_DEBUG_OBJECT (gltestsrc, "size %dx%d, %d/%d fps",
gltestsrc->width, gltestsrc->height,
gltestsrc->rate_numerator, gltestsrc->rate_denominator);
GST_DEBUG_OBJECT (gltestsrc, "size %dx%d, %d/%d fps",
gltestsrc->width, gltestsrc->height,
gltestsrc->rate_numerator, gltestsrc->rate_denominator);
gltestsrc->display = gst_gl_display_new ();
gltestsrc->display = gst_gl_display_new ();
gst_gl_display_create_context (gltestsrc->display,
gltestsrc->width, gltestsrc->height);
gst_gl_display_create_context (gltestsrc->display,
gltestsrc->width, gltestsrc->height);
gst_gl_display_gen_fbo (gltestsrc->display, gltestsrc->width, gltestsrc->height,
&gltestsrc->fbo, &gltestsrc->depthbuffer);
}
return res;
gst_gl_display_gen_fbo (gltestsrc->display, gltestsrc->width,
gltestsrc->height, &gltestsrc->fbo, &gltestsrc->depthbuffer);
}
return res;
}
static gboolean
gst_gl_test_src_query (GstBaseSrc* bsrc, GstQuery* query)
gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
{
gboolean res;
GstGLTestSrc *src;
gboolean res;
GstGLTestSrc *src;
src = GST_GL_TEST_SRC (bsrc);
src = GST_GL_TEST_SRC (bsrc);
switch (GST_QUERY_TYPE (query))
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONVERT:
{
case GST_QUERY_CONVERT:
{
GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val;
GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val;
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
if (src_fmt == dest_fmt)
{
dest_val = src_val;
goto done;
}
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
if (src_fmt == dest_fmt) {
dest_val = src_val;
goto done;
}
switch (src_fmt)
{
case GST_FORMAT_DEFAULT:
switch (dest_fmt)
{
case GST_FORMAT_TIME:
/* frames to time */
if (src->rate_numerator)
{
dest_val = gst_util_uint64_scale (src_val,
src->rate_denominator * GST_SECOND, src->rate_numerator);
}
else
dest_val = 0;
break;
default:
goto error;
}
break;
case GST_FORMAT_TIME:
switch (dest_fmt)
{
case GST_FORMAT_DEFAULT:
/* time to frames */
if (src->rate_numerator)
{
dest_val = gst_util_uint64_scale (src_val,
src->rate_numerator, src->rate_denominator * GST_SECOND);
}
else
dest_val = 0;
break;
default:
goto error;
}
break;
default:
goto error;
}
done:
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
res = TRUE;
switch (src_fmt) {
case GST_FORMAT_DEFAULT:
switch (dest_fmt) {
case GST_FORMAT_TIME:
/* frames to time */
if (src->rate_numerator) {
dest_val = gst_util_uint64_scale (src_val,
src->rate_denominator * GST_SECOND, src->rate_numerator);
} else
dest_val = 0;
break;
default:
goto error;
}
break;
case GST_FORMAT_TIME:
switch (dest_fmt) {
case GST_FORMAT_DEFAULT:
/* time to frames */
if (src->rate_numerator) {
dest_val = gst_util_uint64_scale (src_val,
src->rate_numerator, src->rate_denominator * GST_SECOND);
} else
dest_val = 0;
break;
default:
goto error;
}
break;
}
default:
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
goto error;
}
done:
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
res = TRUE;
break;
}
return res;
default:
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
}
return res;
/* ERROR */
error:
{
GST_DEBUG_OBJECT (src, "query failed");
return FALSE;
}
/* ERROR */
error:
{
GST_DEBUG_OBJECT (src, "query failed");
return FALSE;
}
}
static void
gst_gl_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
GstClockTime * start, GstClockTime * end)
{
/* for live sources, sync on the timestamp of the buffer */
if (gst_base_src_is_live (basesrc))
{
GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
/* for live sources, sync on the timestamp of the buffer */
if (gst_base_src_is_live (basesrc)) {
GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
if (GST_CLOCK_TIME_IS_VALID (timestamp))
{
/* get duration to calculate end time */
GstClockTime duration = GST_BUFFER_DURATION (buffer);
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
/* get duration to calculate end time */
GstClockTime duration = GST_BUFFER_DURATION (buffer);
if (GST_CLOCK_TIME_IS_VALID (duration))
*end = timestamp + duration;
*start = timestamp;
}
}
else
{
*start = -1;
*end = -1;
if (GST_CLOCK_TIME_IS_VALID (duration))
*end = timestamp + duration;
*start = timestamp;
}
} else {
*start = -1;
*end = -1;
}
}
static gboolean
gst_gl_test_src_do_seek (GstBaseSrc* bsrc, GstSegment* segment)
gst_gl_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
{
GstClockTime time;
GstGLTestSrc* src;
GstClockTime time;
GstGLTestSrc *src;
src = GST_GL_TEST_SRC (bsrc);
src = GST_GL_TEST_SRC (bsrc);
segment->time = segment->start;
time = segment->last_stop;
segment->time = segment->start;
time = segment->last_stop;
/* now move to the time indicated */
if (src->rate_numerator)
{
src->n_frames = gst_util_uint64_scale (time,
/* now move to the time indicated */
if (src->rate_numerator) {
src->n_frames = gst_util_uint64_scale (time,
src->rate_numerator, src->rate_denominator * GST_SECOND);
}
else
src->n_frames = 0;
} else
src->n_frames = 0;
if (src->rate_numerator)
{
src->running_time = gst_util_uint64_scale (src->n_frames,
if (src->rate_numerator) {
src->running_time = gst_util_uint64_scale (src->n_frames,
src->rate_denominator * GST_SECOND, src->rate_numerator);
}
else
{
/* FIXME : Not sure what to set here */
src->running_time = 0;
}
} else {
/* FIXME : Not sure what to set here */
src->running_time = 0;
}
g_assert (src->running_time <= time);
g_assert (src->running_time <= time);
return TRUE;
return TRUE;
}
static gboolean
gst_gl_test_src_is_seekable (GstBaseSrc* psrc)
gst_gl_test_src_is_seekable (GstBaseSrc * psrc)
{
/* we're seekable... */
return TRUE;
/* we're seekable... */
return TRUE;
}
static GstFlowReturn
gst_gl_test_src_create (GstPushSrc* psrc, GstBuffer** buffer)
gst_gl_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
{
GstGLTestSrc* src;
GstGLBuffer* outbuf;
GstGLTestSrc *src;
GstGLBuffer *outbuf;
//GstFlowReturn res;
GstClockTime next_time;
//GstFlowReturn res;
GstClockTime next_time;
src = GST_GL_TEST_SRC (psrc);
src = GST_GL_TEST_SRC (psrc);
if (G_UNLIKELY (!src->negotiated))
goto not_negotiated;
if (G_UNLIKELY (!src->negotiated))
goto not_negotiated;
/* 0 framerate and we are at the second frame, eos */
if (G_UNLIKELY (src->rate_numerator == 0 && src->n_frames == 1))
goto eos;
/* 0 framerate and we are at the second frame, eos */
if (G_UNLIKELY (src->rate_numerator == 0 && src->n_frames == 1))
goto eos;
GST_LOG_OBJECT (src, "creating buffer %dx%d image for frame %d",
src->width, src->height, (gint) src->n_frames);
GST_LOG_OBJECT (src, "creating buffer %dx%d image for frame %d",
src->width, src->height, (gint) src->n_frames);
outbuf = gst_gl_buffer_new (src->display,
src->width, src->height);
outbuf = gst_gl_buffer_new (src->display, src->width, src->height);
if (!outbuf->texture)
{
gst_buffer_unref (outbuf);
goto eos;
}
if (!outbuf->texture) {
gst_buffer_unref (outbuf);
goto eos;
}
gst_buffer_set_caps (GST_BUFFER (outbuf),
GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
gst_buffer_set_caps (GST_BUFFER (outbuf),
GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
if (src->pattern_type == GST_GL_TEST_SRC_BLINK)
{
if (src->n_frames & 0x1)
src->make_image = gst_gl_test_src_white;
else
src->make_image = gst_gl_test_src_black;
}
if (src->pattern_type == GST_GL_TEST_SRC_BLINK) {
if (src->n_frames & 0x1)
src->make_image = gst_gl_test_src_white;
else
src->make_image = gst_gl_test_src_black;
}
src->buffer = outbuf;
//blocking call, generate a FBO
if(!gst_gl_display_use_fbo (src->display, src->width, src->height,
src->fbo, src->depthbuffer, outbuf->texture,
gst_gl_test_src_callback,
0, 0, 0, //no input texture
0, src->width, 0, src->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D,
(gpointer)src))
{
gst_buffer_unref (outbuf);
goto eos;
}
src->buffer = outbuf;
GST_BUFFER_TIMESTAMP (GST_BUFFER (outbuf)) =
src->timestamp_offset + src->running_time;
GST_BUFFER_OFFSET (GST_BUFFER (outbuf)) = src->n_frames;
src->n_frames++;
GST_BUFFER_OFFSET_END (GST_BUFFER (outbuf)) = src->n_frames;
if (src->rate_numerator)
{
next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
src->rate_denominator, src->rate_numerator);
GST_BUFFER_DURATION (GST_BUFFER (outbuf)) = next_time - src->running_time;
}
else {
next_time = src->timestamp_offset;
/* NONE means forever */
GST_BUFFER_DURATION (GST_BUFFER (outbuf)) = GST_CLOCK_TIME_NONE;
}
//blocking call, generate a FBO
if (!gst_gl_display_use_fbo (src->display, src->width, src->height, src->fbo, src->depthbuffer, outbuf->texture, gst_gl_test_src_callback, 0, 0, 0, //no input texture
0, src->width, 0, src->height,
GST_GL_DISPLAY_PROJECTION_ORTHO2D, (gpointer) src)) {
gst_buffer_unref (outbuf);
goto eos;
}
src->running_time = next_time;
GST_BUFFER_TIMESTAMP (GST_BUFFER (outbuf)) =
src->timestamp_offset + src->running_time;
GST_BUFFER_OFFSET (GST_BUFFER (outbuf)) = src->n_frames;
src->n_frames++;
GST_BUFFER_OFFSET_END (GST_BUFFER (outbuf)) = src->n_frames;
if (src->rate_numerator) {
next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
src->rate_denominator, src->rate_numerator);
GST_BUFFER_DURATION (GST_BUFFER (outbuf)) = next_time - src->running_time;
} else {
next_time = src->timestamp_offset;
/* NONE means forever */
GST_BUFFER_DURATION (GST_BUFFER (outbuf)) = GST_CLOCK_TIME_NONE;
}
*buffer = GST_BUFFER (outbuf);
src->running_time = next_time;
return GST_FLOW_OK;
*buffer = GST_BUFFER (outbuf);
return GST_FLOW_OK;
not_negotiated:
{
@ -625,39 +593,38 @@ no_buffer:
}
static gboolean
gst_gl_test_src_start (GstBaseSrc* basesrc)
gst_gl_test_src_start (GstBaseSrc * basesrc)
{
GstGLTestSrc* src = GST_GL_TEST_SRC (basesrc);
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
src->running_time = 0;
src->n_frames = 0;
src->negotiated = FALSE;
src->running_time = 0;
src->n_frames = 0;
src->negotiated = FALSE;
return TRUE;
return TRUE;
}
static gboolean
gst_gl_test_src_stop (GstBaseSrc* basesrc)
gst_gl_test_src_stop (GstBaseSrc * basesrc)
{
GstGLTestSrc* src = GST_GL_TEST_SRC (basesrc);
GstGLTestSrc *src = GST_GL_TEST_SRC (basesrc);
if (src->display)
{
//blocking call, delete the FBO
gst_gl_display_del_fbo (src->display, src->fbo,
src->depthbuffer);
g_object_unref (src->display);
src->display = NULL;
}
if (src->display) {
//blocking call, delete the FBO
gst_gl_display_del_fbo (src->display, src->fbo, src->depthbuffer);
g_object_unref (src->display);
src->display = NULL;
}
return TRUE;
return TRUE;
}
//opengl scene
static void
gst_gl_test_src_callback (gint width, gint height, guint texture, gpointer stuff)
gst_gl_test_src_callback (gint width, gint height, guint texture,
gpointer stuff)
{
GstGLTestSrc* src = GST_GL_TEST_SRC (stuff);
GstGLTestSrc *src = GST_GL_TEST_SRC (stuff);
src->make_image (src, src->buffer, src->width, src->height);
src->make_image (src, src->buffer, src->width, src->height);
}

View file

@ -75,10 +75,10 @@
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
static const GstElementDetails element_details =
GST_ELEMENT_DETAILS ("OpenGL upload",
"Filter/Effect",
"A from video to GL flow filter",
"Julien Isorce <julien.isorce@gmail.com>");
GST_ELEMENT_DETAILS ("OpenGL upload",
"Filter/Effect",
"A from video to GL flow filter",
"Julien Isorce <julien.isorce@gmail.com>");
/* Source pad definition */
static GstStaticPadTemplate gst_gl_upload_src_pad_template =
@ -93,8 +93,7 @@ static GstStaticPadTemplate gst_gl_upload_sink_pad_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (
GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx ";"
GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA ";"
@ -105,7 +104,7 @@ static GstStaticPadTemplate gst_gl_upload_sink_pad_template =
/* Properties */
enum
{
PROP_0
PROP_0
};
#define DEBUG_INIT(bla) \
@ -114,411 +113,384 @@ enum
GST_BOILERPLATE_FULL (GstGLUpload, gst_gl_upload, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
static void gst_gl_upload_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
static void gst_gl_upload_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec);
static void gst_gl_upload_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_gl_upload_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gl_upload_reset (GstGLUpload* upload);
static gboolean gst_gl_upload_set_caps (GstBaseTransform* bt,
GstCaps* incaps, GstCaps* outcaps);
static GstCaps *gst_gl_upload_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static void gst_gl_upload_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps);
static gboolean gst_gl_upload_start (GstBaseTransform* bt);
static gboolean gst_gl_upload_stop (GstBaseTransform* bt);
static GstFlowReturn gst_gl_upload_prepare_output_buffer (GstBaseTransform* trans,
GstBuffer* input, gint size, GstCaps* caps, GstBuffer** buf);
static GstFlowReturn gst_gl_upload_transform (GstBaseTransform* trans,
GstBuffer* inbuf, GstBuffer * outbuf);
static gboolean gst_gl_upload_get_unit_size (GstBaseTransform* trans,
GstCaps* caps, guint* size);
static void gst_gl_upload_reset (GstGLUpload * upload);
static gboolean gst_gl_upload_set_caps (GstBaseTransform * bt,
GstCaps * incaps, GstCaps * outcaps);
static GstCaps *gst_gl_upload_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps);
static void gst_gl_upload_fixate_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
static gboolean gst_gl_upload_start (GstBaseTransform * bt);
static gboolean gst_gl_upload_stop (GstBaseTransform * bt);
static GstFlowReturn gst_gl_upload_prepare_output_buffer (GstBaseTransform *
trans, GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf);
static GstFlowReturn gst_gl_upload_transform (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_gl_upload_get_unit_size (GstBaseTransform * trans,
GstCaps * caps, guint * size);
static void
gst_gl_upload_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_set_details (element_class, &element_details);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_upload_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_upload_sink_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_upload_src_pad_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_gl_upload_sink_pad_template));
}
static void
gst_gl_upload_class_init (GstGLUploadClass * klass)
{
GObjectClass *gobject_class;
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_upload_set_property;
gobject_class->get_property = gst_gl_upload_get_property;
gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_gl_upload_set_property;
gobject_class->get_property = gst_gl_upload_get_property;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_upload_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_upload_fixate_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_upload_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_upload_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_upload_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_upload_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_upload_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
gst_gl_upload_prepare_output_buffer;
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_upload_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_upload_fixate_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_upload_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_upload_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_upload_stop;
GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_upload_set_caps;
GST_BASE_TRANSFORM_CLASS (klass)->get_unit_size = gst_gl_upload_get_unit_size;
GST_BASE_TRANSFORM_CLASS (klass)->prepare_output_buffer =
gst_gl_upload_prepare_output_buffer;
}
static void
gst_gl_upload_init (GstGLUpload* upload, GstGLUploadClass * klass)
gst_gl_upload_init (GstGLUpload * upload, GstGLUploadClass * klass)
{
gst_gl_upload_reset (upload);
gst_gl_upload_reset (upload);
}
static void
gst_gl_upload_set_property (GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec)
gst_gl_upload_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
//GstGLUpload* upload = GST_GL_UPLOAD (object);
//GstGLUpload* upload = GST_GL_UPLOAD (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_upload_get_property (GObject* object, guint prop_id,
GValue* value, GParamSpec* pspec)
gst_gl_upload_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
//GstGLUpload *upload = GST_GL_UPLOAD (object);
//GstGLUpload *upload = GST_GL_UPLOAD (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_gl_upload_reset (GstGLUpload* upload)
gst_gl_upload_reset (GstGLUpload * upload)
{
if (upload->display)
{
g_object_unref (upload->display);
upload->display = NULL;
}
if (upload->display) {
g_object_unref (upload->display);
upload->display = NULL;
}
}
static gboolean
gst_gl_upload_start (GstBaseTransform* bt)
gst_gl_upload_start (GstBaseTransform * bt)
{
//GstGLUpload* upload = GST_GL_UPLOAD (bt);
//GstGLUpload* upload = GST_GL_UPLOAD (bt);
return TRUE;
return TRUE;
}
static gboolean
gst_gl_upload_stop (GstBaseTransform* bt)
gst_gl_upload_stop (GstBaseTransform * bt)
{
GstGLUpload* upload = GST_GL_UPLOAD (bt);
GstGLUpload *upload = GST_GL_UPLOAD (bt);
gst_gl_upload_reset (upload);
gst_gl_upload_reset (upload);
return TRUE;
return TRUE;
}
static GstCaps*
gst_gl_upload_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps)
static GstCaps *
gst_gl_upload_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps)
{
//GstGLUpload* upload = GST_GL_UPLOAD (bt);
GstStructure* structure = gst_caps_get_structure (caps, 0);
GstCaps* newcaps = NULL;
const GValue* framerate_value = NULL;
const GValue* par_value = NULL;
//GstGLUpload* upload = GST_GL_UPLOAD (bt);
GstStructure *structure = gst_caps_get_structure (caps, 0);
GstCaps *newcaps = NULL;
const GValue *framerate_value = NULL;
const GValue *par_value = NULL;
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
if (direction == GST_PAD_SRC)
{
GstCaps* newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
if (direction == GST_PAD_SRC) {
GstCaps *newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
gst_caps_append(newcaps, newothercaps);
}
else
gst_caps_append (newcaps, newothercaps);
} else
newcaps = gst_caps_new_simple ("video/x-raw-gl", NULL);
structure = gst_caps_get_structure (newcaps, 0);
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_structure_set_value (structure, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (structure, "pixel-aspect-ratio", par_value);
else
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_structure_set_value (structure, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (structure, "pixel-aspect-ratio", par_value);
else
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_caps_merge_structure (newcaps, gst_structure_copy (structure));
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
GST_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
return newcaps;
return newcaps;
}
/* from gst-plugins-base "videoscale" code */
static void
gst_gl_upload_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps)
gst_gl_upload_fixate_caps (GstBaseTransform * base, GstPadDirection direction,
GstCaps * caps, GstCaps * othercaps)
{
GstStructure *ins, *outs;
GstStructure *ins, *outs;
const GValue *from_par, *to_par;
const GValue *from_par, *to_par;
g_return_if_fail (gst_caps_is_fixed (caps));
g_return_if_fail (gst_caps_is_fixed (caps));
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
ins = gst_caps_get_structure (caps, 0);
outs = gst_caps_get_structure (othercaps, 0);
ins = gst_caps_get_structure (caps, 0);
outs = gst_caps_get_structure (othercaps, 0);
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
//we have both PAR but they might not be fixated
if (from_par && to_par)
{
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
//we have both PAR but they might not be fixated
if (from_par && to_par) {
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
gint count = 0, w = 0, h = 0;
gint count = 0, w = 0, h = 0;
guint num, den;
guint num, den;
//from_par should be fixed
g_return_if_fail (gst_value_is_fixed (from_par));
//from_par should be fixed
g_return_if_fail (gst_value_is_fixed (from_par));
from_par_n = gst_value_get_fraction_numerator (from_par);
from_par_d = gst_value_get_fraction_denominator (from_par);
from_par_n = gst_value_get_fraction_numerator (from_par);
from_par_d = gst_value_get_fraction_denominator (from_par);
//fixate the out PAR
if (!gst_value_is_fixed (to_par))
{
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", from_par_n,
from_par_d);
gst_structure_fixate_field_nearest_fraction (outs, "pixel-aspect-ratio",
from_par_n, from_par_d);
}
to_par_n = gst_value_get_fraction_numerator (to_par);
to_par_d = gst_value_get_fraction_denominator (to_par);
//f both width and height are already fixed, we can't do anything
//about it anymore
if (gst_structure_get_int (outs, "width", &w))
++count;
if (gst_structure_get_int (outs, "height", &h))
++count;
if (count == 2)
{
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
w, h);
return;
}
gst_structure_get_int (ins, "width", &from_w);
gst_structure_get_int (ins, "height", &from_h);
if (!gst_video_calculate_display_ratio (&num, &den, from_w, from_h,
from_par_n, from_par_d, to_par_n, to_par_d))
{
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
("Error calculating the output scaled size - integer overflow"));
return;
}
GST_DEBUG_OBJECT (base,
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
GST_DEBUG_OBJECT (base, "resulting output should respect ratio of %d/%d",
num, den);
//now find a width x height that respects this display ratio.
//prefer those that have one of w/h the same as the incoming video
//using wd / hd = num / den
//if one of the output width or height is fixed, we work from there
if (h)
{
GST_DEBUG_OBJECT (base, "height is fixed,scaling width");
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (w)
{
GST_DEBUG_OBJECT (base, "width is fixed, scaling height");
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
//none of width or height is fixed, figure out both of them based only on
//the input width and height
//check hd / den is an integer scale factor, and scale wd with the PAR
if (from_h % den == 0)
{
GST_DEBUG_OBJECT (base, "keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (from_w % num == 0)
{
GST_DEBUG_OBJECT (base, "keeping video width");
w = from_w;
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
}
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
//now fixate
gst_structure_fixate_field_nearest_int (outs, "width", w);
gst_structure_fixate_field_nearest_int (outs, "height", h);
}
else
{
gint width, height;
if (gst_structure_get_int (ins, "width", &width))
{
if (gst_structure_has_field (outs, "width"))
gst_structure_fixate_field_nearest_int (outs, "width", width);
}
if (gst_structure_get_int (ins, "height", &height)) {
if (gst_structure_has_field (outs, "height")) {
gst_structure_fixate_field_nearest_int (outs, "height", height);
}
}
//fixate the out PAR
if (!gst_value_is_fixed (to_par)) {
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", from_par_n,
from_par_d);
gst_structure_fixate_field_nearest_fraction (outs, "pixel-aspect-ratio",
from_par_n, from_par_d);
}
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
to_par_n = gst_value_get_fraction_numerator (to_par);
to_par_d = gst_value_get_fraction_denominator (to_par);
//f both width and height are already fixed, we can't do anything
//about it anymore
if (gst_structure_get_int (outs, "width", &w))
++count;
if (gst_structure_get_int (outs, "height", &h))
++count;
if (count == 2) {
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
w, h);
return;
}
gst_structure_get_int (ins, "width", &from_w);
gst_structure_get_int (ins, "height", &from_h);
if (!gst_video_calculate_display_ratio (&num, &den, from_w, from_h,
from_par_n, from_par_d, to_par_n, to_par_d)) {
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
("Error calculating the output scaled size - integer overflow"));
return;
}
GST_DEBUG_OBJECT (base,
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
GST_DEBUG_OBJECT (base, "resulting output should respect ratio of %d/%d",
num, den);
//now find a width x height that respects this display ratio.
//prefer those that have one of w/h the same as the incoming video
//using wd / hd = num / den
//if one of the output width or height is fixed, we work from there
if (h) {
GST_DEBUG_OBJECT (base, "height is fixed,scaling width");
w = (guint) gst_util_uint64_scale_int (h, num, den);
} else if (w) {
GST_DEBUG_OBJECT (base, "width is fixed, scaling height");
h = (guint) gst_util_uint64_scale_int (w, den, num);
} else {
//none of width or height is fixed, figure out both of them based only on
//the input width and height
//check hd / den is an integer scale factor, and scale wd with the PAR
if (from_h % den == 0) {
GST_DEBUG_OBJECT (base, "keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
} else if (from_w % num == 0) {
GST_DEBUG_OBJECT (base, "keeping video width");
w = from_w;
h = (guint) gst_util_uint64_scale_int (w, den, num);
} else {
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
}
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
//now fixate
gst_structure_fixate_field_nearest_int (outs, "width", w);
gst_structure_fixate_field_nearest_int (outs, "height", h);
} else {
gint width, height;
if (gst_structure_get_int (ins, "width", &width)) {
if (gst_structure_has_field (outs, "width"))
gst_structure_fixate_field_nearest_int (outs, "width", width);
}
if (gst_structure_get_int (ins, "height", &height)) {
if (gst_structure_has_field (outs, "height")) {
gst_structure_fixate_field_nearest_int (outs, "height", height);
}
}
}
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
}
static gboolean
gst_gl_upload_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
gst_gl_upload_set_caps (GstBaseTransform * bt, GstCaps * incaps,
GstCaps * outcaps)
{
GstGLUpload* upload = GST_GL_UPLOAD (bt);
gboolean ret = FALSE;
GstGLUpload *upload = GST_GL_UPLOAD (bt);
gboolean ret = FALSE;
GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
ret = gst_video_format_parse_caps (outcaps, &video_format,
&upload->gl_width, &upload->gl_height);
ret |= gst_video_format_parse_caps (incaps, &upload->video_format,
&upload->video_width, &upload->video_height);
if (!ret) {
GST_DEBUG ("caps connot be parsed");
return FALSE;
}
//we have video and gl size, we can now init OpenGL stuffs
upload->display = gst_gl_display_new ();
//init unvisible opengl context
gst_gl_display_create_context (upload->display,
upload->gl_width, upload->gl_height);
//init colorspace conversion if needed
gst_gl_display_init_upload (upload->display, upload->video_format,
upload->gl_width, upload->gl_height,
upload->video_width, upload->video_height);
return ret;
}
static gboolean
gst_gl_upload_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
guint * size)
{
gboolean ret = FALSE;
GstStructure *structure = NULL;
gint width = 0;
gint height = 0;
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl")) {
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
} else {
GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
ret = gst_video_format_parse_caps (outcaps, &video_format,
&upload->gl_width, &upload->gl_height);
ret |= gst_video_format_parse_caps (incaps, &upload->video_format,
&upload->video_width, &upload->video_height);
if (!ret)
{
GST_DEBUG ("caps connot be parsed");
return FALSE;
}
//we have video and gl size, we can now init OpenGL stuffs
upload->display = gst_gl_display_new ();
//init unvisible opengl context
gst_gl_display_create_context (upload->display,
upload->gl_width, upload->gl_height);
//init colorspace conversion if needed
gst_gl_display_init_upload (upload->display, upload->video_format,
upload->gl_width, upload->gl_height,
upload->video_width, upload->video_height);
return ret;
}
static gboolean
gst_gl_upload_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
guint* size)
{
gboolean ret = FALSE;
GstStructure* structure = NULL;
gint width = 0;
gint height = 0;
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw-gl"))
{
ret = gst_gl_buffer_parse_caps (caps, &width, &height);
if (ret)
*size = gst_gl_buffer_get_size (width, height);
}
else
{
GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
ret = gst_video_format_parse_caps (caps, &video_format, &width, &height);
if (ret)
*size = gst_video_format_get_size (video_format, width, height);
}
return TRUE;
return TRUE;
}
static GstFlowReturn
gst_gl_upload_prepare_output_buffer (GstBaseTransform* trans,
GstBuffer* input, gint size, GstCaps* caps, GstBuffer** buf)
gst_gl_upload_prepare_output_buffer (GstBaseTransform * trans,
GstBuffer * input, gint size, GstCaps * caps, GstBuffer ** buf)
{
GstGLUpload* upload = GST_GL_UPLOAD (trans);
GstGLUpload *upload = GST_GL_UPLOAD (trans);
//blocking call, request a texture and attach it to the upload FBO
GstGLBuffer* gl_outbuf = gst_gl_buffer_new (upload->display,
upload->gl_width, upload->gl_height);
//blocking call, request a texture and attach it to the upload FBO
GstGLBuffer *gl_outbuf = gst_gl_buffer_new (upload->display,
upload->gl_width, upload->gl_height);
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);
if (gl_outbuf->texture)
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
if (gl_outbuf->texture)
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
}
static GstFlowReturn
gst_gl_upload_transform (GstBaseTransform* trans, GstBuffer* inbuf,
GstBuffer* outbuf)
gst_gl_upload_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer * outbuf)
{
GstGLUpload* upload = GST_GL_UPLOAD (trans);
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
GstGLUpload *upload = GST_GL_UPLOAD (trans);
GstGLBuffer *gl_outbuf = GST_GL_BUFFER (outbuf);
GST_DEBUG ("Upload %p size %d",
GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
GST_DEBUG ("Upload %p size %d",
GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf));
//blocking call.
//Depending on the colorspace, video is upload into several textures.
//However, there is only one output texture. The one attached
//to the upload FBO.
if (gst_gl_display_do_upload (upload->display, gl_outbuf->texture,
upload->video_width, upload->video_height, GST_BUFFER_DATA (inbuf)))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
//blocking call.
//Depending on the colorspace, video is upload into several textures.
//However, there is only one output texture. The one attached
//to the upload FBO.
if (gst_gl_display_do_upload (upload->display, gl_outbuf->texture,
upload->video_width, upload->video_height, GST_BUFFER_DATA (inbuf)))
return GST_FLOW_OK;
else
return GST_FLOW_UNEXPECTED;
}

View file

@ -91,30 +91,30 @@ plugin_init (GstPlugin * plugin)
return FALSE;
}
if (!gst_element_register (plugin, "gloverlay",
GST_RANK_NONE, gst_gl_overlay_get_type())) {
GST_RANK_NONE, gst_gl_overlay_get_type ())) {
return FALSE;
}
if (!gst_element_register (plugin, "gldifferencematte",
GST_RANK_NONE, gst_gl_differencematte_get_type())) {
GST_RANK_NONE, gst_gl_differencematte_get_type ())) {
return FALSE;
}
if (!gst_element_register (plugin, "glbumper",
GST_RANK_NONE, gst_gl_bumper_get_type())) {
GST_RANK_NONE, gst_gl_bumper_get_type ())) {
return FALSE;
}
if (!gst_element_register (plugin, "gleffects",
GST_RANK_NONE, gst_gl_effects_get_type())) {
GST_RANK_NONE, gst_gl_effects_get_type ())) {
return FALSE;
}
if (!gst_element_register (plugin, "glfilterblur",
GST_RANK_NONE, gst_gl_filterblur_get_type())) {
GST_RANK_NONE, gst_gl_filterblur_get_type ())) {
return FALSE;
}
if (!gst_element_register (plugin, "glfiltersobel",
GST_RANK_NONE, gst_gl_filtersobel_get_type())) {
GST_RANK_NONE, gst_gl_filtersobel_get_type ())) {
return FALSE;
}

View file

@ -31,7 +31,8 @@
#define W 320
#define H 240
struct GstGLClutterActor_ {
struct GstGLClutterActor_
{
Window win;
Window root;
ClutterActor *texture;
@ -41,44 +42,45 @@ struct GstGLClutterActor_ {
typedef struct GstGLClutterActor_ GstGLClutterActor;
static gboolean
create_actor (GstGLClutterActor *actor) {
create_actor (GstGLClutterActor * actor)
{
ClutterKnot knot[2];
ClutterTimeline *timeline;
ClutterEffectTemplate *effect_template;
actor->texture = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
"window", actor->win,
"automatic-updates", TRUE, NULL);
clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage), actor->texture);
clutter_actor_set_scale (actor->texture, 0.2 , 0.2);
actor->texture = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
"window", actor->win, "automatic-updates", TRUE, NULL);
clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage),
actor->texture);
clutter_actor_set_scale (actor->texture, 0.2, 0.2);
clutter_actor_set_opacity (actor->texture, 0);
clutter_actor_show (actor->texture);
clutter_actor_show (actor->texture);
timeline =
clutter_timeline_new (120 /* frames */ , 50 /* frames per second. */ );
clutter_timeline_set_loop (timeline, TRUE);
clutter_timeline_start (timeline);
timeline = clutter_timeline_new(120 /* frames */, 50 /* frames per second. */);
clutter_timeline_set_loop(timeline, TRUE);
clutter_timeline_start(timeline);
/* Instead of our custom callback,
* we could use a standard callback. For instance, CLUTTER_ALPHA_SINE_INC.
*/
effect_template =
clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC);
effect_template =
clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC);
knot[0].x = -10;
knot[0].y = -10;
knot[1].x= 160;
knot[1].y= 120;
knot[1].x = 160;
knot[1].y = 120;
// Move the actor along the path:
clutter_effect_path (effect_template, actor->texture, knot,
sizeof(knot) / sizeof(ClutterKnot), NULL, NULL);
clutter_effect_path (effect_template, actor->texture, knot,
sizeof (knot) / sizeof (ClutterKnot), NULL, NULL);
clutter_effect_scale (effect_template, actor->texture, 1.0, 1.0, NULL, NULL);
clutter_effect_rotate (effect_template, actor->texture,
CLUTTER_Z_AXIS, 360.0, W/2.0, H/2.0, 0.0,
CLUTTER_ROTATE_CW, NULL, NULL);
clutter_effect_rotate (effect_template, actor->texture,
CLUTTER_X_AXIS, 360.0, 0.0, W/4.0, 0.0,
CLUTTER_ROTATE_CW, NULL, NULL);
clutter_effect_rotate (effect_template, actor->texture,
CLUTTER_Z_AXIS, 360.0, W / 2.0, H / 2.0, 0.0,
CLUTTER_ROTATE_CW, NULL, NULL);
clutter_effect_rotate (effect_template, actor->texture,
CLUTTER_X_AXIS, 360.0, 0.0, W / 4.0, 0.0, CLUTTER_ROTATE_CW, NULL, NULL);
// Also change the actor's opacity while moving it along the path:
// (You would probably want to use a different ClutterEffectTemplate,
@ -88,7 +90,7 @@ create_actor (GstGLClutterActor *actor) {
g_object_unref (effect_template);
g_object_unref (timeline);
return FALSE;
return FALSE;
}
static GstBusSyncReply
@ -98,15 +100,16 @@ create_window (GstBus * bus, GstMessage * message, gpointer data)
// ignore anything but 'prepare-xwindow-id' element messages
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
return GST_BUS_PASS;
g_debug ("CREATING WINDOW");
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), actor->win);
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
actor->win);
clutter_threads_add_idle ((GSourceFunc) create_actor, actor);
gst_message_unref (message);
return GST_BUS_DROP;
}
@ -114,8 +117,8 @@ create_window (GstBus * bus, GstMessage * message, gpointer data)
int
main (int argc, char *argv[])
{
GstPipeline *pipeline;
GstBus *bus;
GstPipeline *pipeline;
GstBus *bus;
ClutterActor *stage;
GstGLClutterActor *actor;
Display *disp;
@ -125,10 +128,10 @@ main (int argc, char *argv[])
gst_init (&argc, &argv);
disp = clutter_x11_get_default_display ();
if(!clutter_x11_has_composite_extension ()) {
if (!clutter_x11_has_composite_extension ()) {
g_error ("XComposite extension missing");
}
stage = clutter_stage_get_default ();
// clutter_actor_set_size (CLUTTER_ACTOR (stage), W*3+2, H);
@ -142,8 +145,10 @@ main (int argc, char *argv[])
XMapRaised (disp, actor->win);
XSync (disp, FALSE);
pipeline = GST_PIPELINE (gst_parse_launch ("videotestsrc ! video/x-raw-rgb, width=320, height=240, framerate=(fraction)30/1 ! "
"glupload ! gleffects effect=twirl ! glimagesink", NULL));
pipeline =
GST_PIPELINE (gst_parse_launch
("videotestsrc ! video/x-raw-rgb, width=320, height=240, framerate=(fraction)30/1 ! "
"glupload ! gleffects effect=twirl ! glimagesink", NULL));
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
@ -153,10 +158,10 @@ main (int argc, char *argv[])
clutter_actor_show_all (stage);
clutter_main();
clutter_main ();
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
g_object_unref (pipeline);
return 0;
}

View file

@ -32,7 +32,8 @@
#define W 160
#define H 120
struct GstGLClutterActor_ {
struct GstGLClutterActor_
{
Window win;
Window root;
ClutterActor *texture;
@ -42,24 +43,25 @@ struct GstGLClutterActor_ {
typedef struct GstGLClutterActor_ GstGLClutterActor;
static gboolean
create_actor (GstGLClutterActor *actor) {
create_actor (GstGLClutterActor * actor)
{
static gint xpos = 0;
static gint ypos = 0;
Display *disp;
actor->texture = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
"window", actor->win,
"automatic-updates", TRUE, NULL);
clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage), actor->texture);
"window", actor->win, "automatic-updates", TRUE, NULL);
clutter_container_add_actor (CLUTTER_CONTAINER (actor->stage),
actor->texture);
clutter_actor_set_position (actor->texture, xpos, ypos);
disp = clutter_x11_get_default_display ();
XMoveResizeWindow (disp, actor->win, xpos, ypos, W, H);
if (xpos > (COLS-1)*W) {
if (xpos > (COLS - 1) * W) {
xpos = 0;
ypos += H+1;
ypos += H + 1;
} else
xpos += W+1;
xpos += W + 1;
clutter_actor_show (actor->texture);
return FALSE;
@ -79,14 +81,14 @@ create_window (GstBus * bus, GstMessage * message, gpointer data)
return GST_BUS_PASS;
if (!mutex)
mutex = g_mutex_new ();
mutex = g_mutex_new ();
g_mutex_lock (mutex);
if (count < N_ACTORS) {
g_message ("adding actor %d", count);
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
actor[count]->win);
actor[count]->win);
clutter_threads_add_idle ((GSourceFunc) create_actor, actor[count]);
count++;
}
@ -99,7 +101,7 @@ create_window (GstBus * bus, GstMessage * message, gpointer data)
#if 0
void
apply_fx (GstElement *element, const gchar *fx)
apply_fx (GstElement * element, const gchar * fx)
{
GEnumClass *p_class;
@ -120,12 +122,13 @@ apply_fx (GstElement *element, const gchar *fx)
int
main (int argc, char *argv[])
{
GstPipeline *pipeline;
GstBus *bus;
GstPipeline *pipeline;
GstBus *bus;
GstElement *srcbin;
GstElement *tee;
GstElement *queue[N_ACTORS], *upload[N_ACTORS], *effect[N_ACTORS], *sink[N_ACTORS];
GstElement *queue[N_ACTORS], *upload[N_ACTORS], *effect[N_ACTORS],
*sink[N_ACTORS];
ClutterActor *stage;
GstGLClutterActor *actor[N_ACTORS];
@ -139,18 +142,17 @@ main (int argc, char *argv[])
gst_init (&argc, &argv);
disp = clutter_x11_get_default_display ();
if(!clutter_x11_has_composite_extension ()) {
if (!clutter_x11_has_composite_extension ()) {
g_error ("XComposite extension missing");
}
stage = clutter_stage_get_default ();
clutter_actor_set_size (CLUTTER_ACTOR (stage),
W*COLS + (COLS-1),
H*ROWS + (ROWS-1));
W * COLS + (COLS - 1), H * ROWS + (ROWS - 1));
stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
for (i=0; i<N_ACTORS; i++) {
for (i = 0; i < N_ACTORS; i++) {
actor[i] = g_new0 (GstGLClutterActor, 1);
actor[i]->stage = stage;
actor[i]->win = XCreateSimpleWindow (disp, stage_win, 0, 0, W, H, 0, 0, 0);
@ -166,38 +168,41 @@ main (int argc, char *argv[])
"identity", W, H);
*/
desc = g_strdup_printf ("videotestsrc ! "
"video/x-raw-rgb, width=%d, height=%d !"
"identity", W, H);
"video/x-raw-rgb, width=%d, height=%d !" "identity", W, H);
pipeline = GST_PIPELINE (gst_pipeline_new (NULL));
srcbin = gst_parse_bin_from_description (desc, TRUE, NULL);
if (!srcbin) g_error ("Source bin creation failed");
if (!srcbin)
g_error ("Source bin creation failed");
tee = gst_element_factory_make ("tee", NULL);
gst_bin_add_many (GST_BIN (pipeline), srcbin, tee, NULL);
for (i=0; i<N_ACTORS; i++) {
for (i = 0; i < N_ACTORS; i++) {
queue[i] = gst_element_factory_make ("queue", NULL);
upload[i] = gst_element_factory_make ("glupload", NULL);
effect[i] = gst_element_factory_make ("gleffects", NULL);
sink[i] = gst_element_factory_make ("glimagesink", NULL);
gst_bin_add_many (GST_BIN (pipeline),
queue[i], upload[i], effect[i], sink[i], NULL);
queue[i], upload[i], effect[i], sink[i], NULL);
}
gst_element_link_many (srcbin, tee, NULL);
for (i=0; i<N_ACTORS; i++) {
ok |= gst_element_link_many (tee, queue[i], upload[i], effect[i], sink[i], NULL);
for (i = 0; i < N_ACTORS; i++) {
ok |=
gst_element_link_many (tee, queue[i], upload[i], effect[i], sink[i],
NULL);
}
if (!ok)
g_error ("Failed to link one or more elements");
for (i=0; i<N_ACTORS; i++) {
g_message ("setting effect %d on %s", i+1, gst_element_get_name (effect[i]));
g_object_set (G_OBJECT (effect[i]), "effect", i+1, NULL);
for (i = 0; i < N_ACTORS; i++) {
g_message ("setting effect %d on %s", i + 1,
gst_element_get_name (effect[i]));
g_object_set (G_OBJECT (effect[i]), "effect", i + 1, NULL);
}
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
@ -208,7 +213,7 @@ main (int argc, char *argv[])
clutter_actor_show_all (stage);
clutter_main();
clutter_main ();
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
g_object_unref (pipeline);

View file

@ -17,10 +17,11 @@ static gboolean
expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
{
GstXOverlay *overlay =
GST_X_OVERLAY (gst_bin_get_by_interface (GST_BIN (data),
GST_TYPE_X_OVERLAY));
GST_X_OVERLAY (gst_bin_get_by_interface (GST_BIN (data),
GST_TYPE_X_OVERLAY));
#ifdef WIN32
gst_x_overlay_set_xwindow_id (overlay, (gulong)GDK_WINDOW_HWND(widget->window));
gst_x_overlay_set_xwindow_id (overlay,
(gulong) GDK_WINDOW_HWND (widget->window));
#else
gst_x_overlay_set_xwindow_id (overlay, GDK_WINDOW_XWINDOW (widget->window));
#endif
@ -29,7 +30,7 @@ expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
}
static void
destroy_cb (GtkWidget *widget, GdkEvent *event, GstElement *pipeline)
destroy_cb (GtkWidget * widget, GdkEvent * event, GstElement * pipeline)
{
g_message ("destroy callback");
@ -111,9 +112,10 @@ main (gint argc, gchar * argv[])
GOptionContext *context;
GOptionEntry options[] = {
{ "source-bin", 's', 0, G_OPTION_ARG_STRING_ARRAY, &source_desc_array,
"Use a custom source bin description (gst-launch style)", NULL },
{ NULL }
{"source-bin", 's', 0, G_OPTION_ARG_STRING_ARRAY, &source_desc_array,
"Use a custom source bin description (gst-launch style)", NULL}
,
{NULL}
};
g_thread_init (NULL);
@ -127,20 +129,23 @@ main (gint argc, gchar * argv[])
return -1;
}
g_option_context_free (context);
if (source_desc_array != NULL) {
source_desc = g_strjoinv (" ", source_desc_array);
g_strfreev (source_desc_array);
}
if (source_desc == NULL) {
source_desc = g_strdup ("videotestsrc ! video/x-raw-rgb, width=352, height=288 ! identity");
source_desc =
g_strdup
("videotestsrc ! video/x-raw-rgb, width=352, height=288 ! identity");
}
sourcebin = gst_parse_bin_from_description (g_strdup (source_desc), TRUE, &error);
sourcebin =
gst_parse_bin_from_description (g_strdup (source_desc), TRUE, &error);
g_free (source_desc);
if (error) {
g_print ("Error while parsing source bin description: %s\n",
GST_STR_NULL (error->message));
g_print ("Error while parsing source bin description: %s\n",
GST_STR_NULL (error->message));
return -1;
}
@ -163,9 +168,9 @@ main (gint argc, gchar * argv[])
}
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (destroy_cb), pipeline);
G_CALLBACK (destroy_cb), pipeline);
g_signal_connect (G_OBJECT (window), "destroy-event",
G_CALLBACK (destroy_cb), pipeline);
G_CALLBACK (destroy_cb), pipeline);
screen = gtk_drawing_area_new ();

View file

@ -23,38 +23,38 @@ struct _SourceData
};
typedef struct _SourceData SourceData;
static GstBusSyncReply
create_window (GstBus *bus, GstMessage *message, GtkWidget *widget)
static GstBusSyncReply
create_window (GstBus * bus, GstMessage * message, GtkWidget * widget)
{
// ignore anything but 'prepare-xwindow-id' element messages
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
// ignore anything but 'prepare-xwindow-id' element messages
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
return GST_BUS_PASS;
if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
return GST_BUS_PASS;
#ifdef WIN32
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
(gulong)GDK_WINDOW_HWND(widget->window));
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
(gulong) GDK_WINDOW_HWND (widget->window));
#else
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
GDK_WINDOW_XWINDOW(widget->window));
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
GDK_WINDOW_XWINDOW (widget->window));
#endif
gst_message_unref (message);
gst_message_unref (message);
return GST_BUS_DROP;
return GST_BUS_DROP;
}
static gboolean
expose_cb(GtkWidget *widget, GdkEventExpose *event, GstElement *videosink)
static gboolean
expose_cb (GtkWidget * widget, GdkEventExpose * event, GstElement * videosink)
{
gst_x_overlay_expose (GST_X_OVERLAY (videosink));
return FALSE;
gst_x_overlay_expose (GST_X_OVERLAY (videosink));
return FALSE;
}
static void
destroy_cb (GtkWidget *widget, GdkEvent *event, GstElement *pipeline)
destroy_cb (GtkWidget * widget, GdkEvent * event, GstElement * pipeline)
{
g_message ("destroy callback");
@ -112,9 +112,8 @@ set_location_delayed (gpointer data)
static void
on_drag_data_received (GtkWidget * widget,
GdkDragContext * context, int x, int y,
GtkSelectionData * seldata, guint inf, guint time,
gpointer data)
GdkDragContext * context, int x, int y,
GtkSelectionData * seldata, guint inf, guint time, gpointer data)
{
GdkPixbufFormat *format;
SourceData *userdata = g_new0 (SourceData, 1);
@ -127,7 +126,7 @@ on_drag_data_received (GtkWidget * widget,
format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
g_return_if_fail (format);
g_print ("received %s image: %s\n", filename,
gdk_pixbuf_format_get_name (format));
gdk_pixbuf_format_get_name (format));
userdata->nick = "location";
userdata->value = g_strdup (filename);
userdata->data = data;
@ -135,9 +134,9 @@ on_drag_data_received (GtkWidget * widget,
if (delay > 0) {
g_print ("%d\n", delay);
g_timeout_add_seconds (1, set_location_delayed, userdata);
}
else
g_object_set (G_OBJECT (userdata->data), userdata->nick, userdata->value, NULL);
} else
g_object_set (G_OBJECT (userdata->data), userdata->nick, userdata->value,
NULL);
g_free (filename);
}
@ -163,11 +162,17 @@ main (gint argc, gchar * argv[])
GOptionContext *context;
GOptionEntry options[] = {
{ "source-bin", 's', 0, G_OPTION_ARG_STRING_ARRAY, &source_desc_array,
"Use a custom source bin description (gst-launch style)", NULL },
{ "method", 'm', 0, G_OPTION_ARG_INT, &method, "1 for gstdifferencematte, 2 for gloverlay", "M" },
{ "delay", 'd', 0, G_OPTION_ARG_INT, &delay, "Wait N seconds before to send the image to gstreamer (useful with differencematte)", "N" },
{ NULL }
{"source-bin", 's', 0, G_OPTION_ARG_STRING_ARRAY, &source_desc_array,
"Use a custom source bin description (gst-launch style)", NULL}
,
{"method", 'm', 0, G_OPTION_ARG_INT, &method,
"1 for gstdifferencematte, 2 for gloverlay", "M"}
,
{"delay", 'd', 0, G_OPTION_ARG_INT, &delay,
"Wait N seconds before to send the image to gstreamer (useful with differencematte)",
"N"}
,
{NULL}
};
g_thread_init (NULL);
@ -181,20 +186,23 @@ main (gint argc, gchar * argv[])
return -1;
}
g_option_context_free (context);
if (source_desc_array != NULL) {
source_desc = g_strjoinv (" ", source_desc_array);
g_strfreev (source_desc_array);
}
if (source_desc == NULL) {
source_desc = g_strdup ("videotestsrc ! video/x-raw-rgb, width=352, height=288 ! identity");
source_desc =
g_strdup
("videotestsrc ! video/x-raw-rgb, width=352, height=288 ! identity");
}
sourcebin = gst_parse_bin_from_description (g_strdup (source_desc), TRUE, &error);
sourcebin =
gst_parse_bin_from_description (g_strdup (source_desc), TRUE, &error);
g_free (source_desc);
if (error) {
g_print ("Error while parsing source bin description: %s\n",
GST_STR_NULL (error->message));
g_print ("Error while parsing source bin description: %s\n",
GST_STR_NULL (error->message));
return -1;
}
@ -221,9 +229,9 @@ main (gint argc, gchar * argv[])
}
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (destroy_cb), pipeline);
G_CALLBACK (destroy_cb), pipeline);
g_signal_connect (G_OBJECT (window), "destroy-event",
G_CALLBACK (destroy_cb), pipeline);
G_CALLBACK (destroy_cb), pipeline);
screen = gtk_drawing_area_new ();
@ -265,7 +273,7 @@ main (gint argc, gchar * argv[])
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, screen);
gst_object_unref (bus);
g_signal_connect(screen, "expose-event", G_CALLBACK(expose_cb), sink);
g_signal_connect (screen, "expose-event", G_CALLBACK (expose_cb), sink);
gtk_drag_dest_set (screen, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
gtk_drag_dest_add_uri_targets (screen);