#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;
}
}
-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");
+ GstStructure *structure = gst_caps_get_structure (caps, 0);
+ gboolean ret = gst_structure_has_name (structure, "video/x-raw-gl");
- if (!ret)
- return ret;
+ if (!ret)
+ return ret;
- ret = gst_structure_get_int (structure, "width", width);
- ret &= gst_structure_get_int (structure, "height", height);
+ ret = gst_structure_get_int (structure, "width", width);
+ ret &= gst_structure_get_int (structure, "height", height);
- return ret;
+ return ret;
}
#define DEBUG_INIT(bla) \
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display");
-GST_BOILERPLATE_FULL (GstGLDisplay, gst_gl_display, GObject, G_TYPE_OBJECT, DEBUG_INIT);
-static void gst_gl_display_finalize (GObject* object);
+GST_BOILERPLATE_FULL (GstGLDisplay, gst_gl_display, GObject, G_TYPE_OBJECT,
+ DEBUG_INIT);
+static void gst_gl_display_finalize (GObject * object);
/* Called in the gl thread, protected by lock and unlock */
-gpointer gst_gl_display_thread_create_context (GstGLDisplay* display);
-void gst_gl_display_thread_destroy_context (GstGLDisplay* display);
-void gst_gl_display_thread_run_generic (GstGLDisplay *display);
-void gst_gl_display_thread_gen_texture (GstGLDisplay* display);
-void gst_gl_display_thread_del_texture (GstGLDisplay* display);
-void gst_gl_display_thread_init_upload (GstGLDisplay* display);
-void gst_gl_display_thread_do_upload (GstGLDisplay* display);
-void gst_gl_display_thread_init_download (GstGLDisplay *display);
-void gst_gl_display_thread_do_download (GstGLDisplay* display);
-void gst_gl_display_thread_gen_fbo (GstGLDisplay *display);
-void gst_gl_display_thread_use_fbo (GstGLDisplay *display);
-void gst_gl_display_thread_del_fbo (GstGLDisplay *display);
-void gst_gl_display_thread_gen_shader (GstGLDisplay *display);
-void gst_gl_display_thread_del_shader (GstGLDisplay *display);
+gpointer gst_gl_display_thread_create_context (GstGLDisplay * display);
+void gst_gl_display_thread_destroy_context (GstGLDisplay * display);
+void gst_gl_display_thread_run_generic (GstGLDisplay * display);
+void gst_gl_display_thread_gen_texture (GstGLDisplay * display);
+void gst_gl_display_thread_del_texture (GstGLDisplay * display);
+void gst_gl_display_thread_init_upload (GstGLDisplay * display);
+void gst_gl_display_thread_do_upload (GstGLDisplay * display);
+void gst_gl_display_thread_init_download (GstGLDisplay * display);
+void gst_gl_display_thread_do_download (GstGLDisplay * display);
+void gst_gl_display_thread_gen_fbo (GstGLDisplay * display);
+void gst_gl_display_thread_use_fbo (GstGLDisplay * display);
+void gst_gl_display_thread_del_fbo (GstGLDisplay * display);
+void gst_gl_display_thread_gen_shader (GstGLDisplay * display);
+void gst_gl_display_thread_del_shader (GstGLDisplay * display);
/* private methods */
-void gst_gl_display_lock (GstGLDisplay* display);
-void gst_gl_display_unlock (GstGLDisplay* display);
-void gst_gl_display_on_resize(GstGLDisplay* display, gint width, gint height);
-void gst_gl_display_on_draw (GstGLDisplay* display);
-void gst_gl_display_on_close (GstGLDisplay* display);
-void gst_gl_display_glgen_texture (GstGLDisplay* display, GLuint* pTexture, GLint width, GLint height);
-void gst_gl_display_gldel_texture (GstGLDisplay* display, GLuint* pTexture, GLint width, GLint height);
-gboolean gst_gl_display_texture_pool_func_clean (gpointer key, gpointer value, gpointer data);
+void gst_gl_display_lock (GstGLDisplay * display);
+void gst_gl_display_unlock (GstGLDisplay * display);
+void gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height);
+void gst_gl_display_on_draw (GstGLDisplay * display);
+void gst_gl_display_on_close (GstGLDisplay * display);
+void gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
+ GLint width, GLint height);
+void gst_gl_display_gldel_texture (GstGLDisplay * display, GLuint * pTexture,
+ GLint width, GLint height);
+gboolean gst_gl_display_texture_pool_func_clean (gpointer key, gpointer value,
+ gpointer data);
void gst_gl_display_check_framebuffer_status (void);
/* To not make gst_gl_display_thread_do_upload
* and gst_gl_display_thread_do_download too big */
-void gst_gl_display_thread_init_upload_fbo (GstGLDisplay *display);
-void gst_gl_display_thread_do_upload_make (GstGLDisplay *display);
-void gst_gl_display_thread_do_upload_fill (GstGLDisplay *display);
-void gst_gl_display_thread_do_upload_draw (GstGLDisplay *display);
-void gst_gl_display_thread_do_download_draw_rgb (GstGLDisplay *display);
-void gst_gl_display_thread_do_download_draw_yuv (GstGLDisplay *display);
+void gst_gl_display_thread_init_upload_fbo (GstGLDisplay * display);
+void gst_gl_display_thread_do_upload_make (GstGLDisplay * display);
+void gst_gl_display_thread_do_upload_fill (GstGLDisplay * display);
+void gst_gl_display_thread_do_upload_draw (GstGLDisplay * display);
+void gst_gl_display_thread_do_download_draw_rgb (GstGLDisplay * display);
+void gst_gl_display_thread_do_download_draw_yuv (GstGLDisplay * display);
//------------------------------------------------------------
static void
-gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
+gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
{
//thread safe
display->mutex = g_mutex_new ();
//YUY2:r,g,a
//UYVY:a,b,r
display->text_shader_upload_YUY2_UYVY =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect Ytex, UVtex;\n"
- "void main(void) {\n"
- " float fx, fy, y, u, v, r, g, b;\n"
- " fx = gl_TexCoord[0].x;\n"
- " fy = gl_TexCoord[0].y;\n"
- " y = texture2DRect(Ytex,vec2(fx,fy)).%c;\n"
- " u = texture2DRect(UVtex,vec2(fx*0.5,fy)).%c;\n"
- " v = texture2DRect(UVtex,vec2(fx*0.5,fy)).%c;\n"
- " y=1.164*(y-0.0627);\n"
- " u=u-0.5;\n"
- " v=v-0.5;\n"
- " r = y+1.5958*v;\n"
- " g = y-0.39173*u-0.81290*v;\n"
- " b = y+2.017*u;\n"
- " gl_FragColor = vec4(r, g, b, 1.0);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect Ytex, UVtex;\n"
+ "void main(void) {\n"
+ " float fx, fy, y, u, v, r, g, b;\n"
+ " fx = gl_TexCoord[0].x;\n"
+ " fy = gl_TexCoord[0].y;\n"
+ " y = texture2DRect(Ytex,vec2(fx,fy)).%c;\n"
+ " u = texture2DRect(UVtex,vec2(fx*0.5,fy)).%c;\n"
+ " v = texture2DRect(UVtex,vec2(fx*0.5,fy)).%c;\n"
+ " y=1.164*(y-0.0627);\n"
+ " u=u-0.5;\n"
+ " v=v-0.5;\n"
+ " r = y+1.5958*v;\n"
+ " g = y-0.39173*u-0.81290*v;\n"
+ " b = y+2.017*u;\n" " gl_FragColor = vec4(r, g, b, 1.0);\n" "}\n";
//ATI: "*0.5", ""
//normal: "", "*0.5"
display->text_shader_upload_I420_YV12 =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect Ytex,Utex,Vtex;\n"
- "void main(void) {\n"
- " float r,g,b,y,u,v;\n"
- " vec2 nxy=gl_TexCoord[0].xy;\n"
- " y=texture2DRect(Ytex,nxy%s).r;\n"
- " u=texture2DRect(Utex,nxy%s).r;\n"
- " v=texture2DRect(Vtex,nxy*0.5).r;\n"
- " y=1.1643*(y-0.0625);\n"
- " u=u-0.5;\n"
- " v=v-0.5;\n"
- " r=y+1.5958*v;\n"
- " g=y-0.39173*u-0.81290*v;\n"
- " b=y+2.017*u;\n"
- " gl_FragColor=vec4(r,g,b,1.0);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect Ytex,Utex,Vtex;\n"
+ "void main(void) {\n"
+ " float r,g,b,y,u,v;\n"
+ " vec2 nxy=gl_TexCoord[0].xy;\n"
+ " y=texture2DRect(Ytex,nxy%s).r;\n"
+ " u=texture2DRect(Utex,nxy%s).r;\n"
+ " v=texture2DRect(Vtex,nxy*0.5).r;\n"
+ " y=1.1643*(y-0.0625);\n"
+ " u=u-0.5;\n"
+ " v=v-0.5;\n"
+ " r=y+1.5958*v;\n"
+ " g=y-0.39173*u-0.81290*v;\n"
+ " b=y+2.017*u;\n" " gl_FragColor=vec4(r,g,b,1.0);\n" "}\n";
display->text_shader_upload_AYUV =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect tex;\n"
- "void main(void) {\n"
- " float r,g,b,y,u,v;\n"
- " vec2 nxy=gl_TexCoord[0].xy;\n"
- " y=texture2DRect(tex,nxy).r;\n"
- " u=texture2DRect(tex,nxy).g;\n"
- " v=texture2DRect(tex,nxy).b;\n"
- " y=1.1643*(y-0.0625);\n"
- " u=u-0.5;\n"
- " v=v-0.5;\n"
- " r=clamp(y+1.5958*v, 0, 1);\n"
- " g=clamp(y-0.39173*u-0.81290*v, 0, 1);\n"
- " b=clamp(y+2.017*u, 0, 1);\n"
- " gl_FragColor=vec4(r,g,b,1.0);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect tex;\n"
+ "void main(void) {\n"
+ " float r,g,b,y,u,v;\n"
+ " vec2 nxy=gl_TexCoord[0].xy;\n"
+ " y=texture2DRect(tex,nxy).r;\n"
+ " u=texture2DRect(tex,nxy).g;\n"
+ " v=texture2DRect(tex,nxy).b;\n"
+ " y=1.1643*(y-0.0625);\n"
+ " u=u-0.5;\n"
+ " v=v-0.5;\n"
+ " r=clamp(y+1.5958*v, 0, 1);\n"
+ " g=clamp(y-0.39173*u-0.81290*v, 0, 1);\n"
+ " b=clamp(y+2.017*u, 0, 1);\n" " gl_FragColor=vec4(r,g,b,1.0);\n" "}\n";
//YUY2:y2,u,y1,v
//UYVY:v,y1,u,y2
display->text_shader_download_YUY2_UYVY =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect tex;\n"
- "void main(void) {\n"
- " float fx,fy,r,g,b,r2,g2,b2,y1,y2,u,v;\n"
- " fx = gl_TexCoord[0].x;\n"
- " fy = gl_TexCoord[0].y;\n"
- " r=texture2DRect(tex,vec2(fx*2.0,fy)).r;\n"
- " g=texture2DRect(tex,vec2(fx*2.0,fy)).g;\n"
- " b=texture2DRect(tex,vec2(fx*2.0,fy)).b;\n"
- " r2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).r;\n"
- " g2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).g;\n"
- " b2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).b;\n"
- " y1=0.299011*r + 0.586987*g + 0.114001*b;\n"
- " y2=0.299011*r2 + 0.586987*g2 + 0.114001*b2;\n"
- " u=-0.148246*r -0.29102*g + 0.439266*b;\n"
- " v=0.439271*r - 0.367833*g - 0.071438*b ;\n"
- " y1=0.858885*y1 + 0.0625;\n"
- " y2=0.858885*y2 + 0.0625;\n"
- " u=u + 0.5;\n"
- " v=v + 0.5;\n"
- " gl_FragColor=vec4(%s);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect tex;\n"
+ "void main(void) {\n"
+ " float fx,fy,r,g,b,r2,g2,b2,y1,y2,u,v;\n"
+ " fx = gl_TexCoord[0].x;\n"
+ " fy = gl_TexCoord[0].y;\n"
+ " r=texture2DRect(tex,vec2(fx*2.0,fy)).r;\n"
+ " g=texture2DRect(tex,vec2(fx*2.0,fy)).g;\n"
+ " b=texture2DRect(tex,vec2(fx*2.0,fy)).b;\n"
+ " r2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).r;\n"
+ " g2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).g;\n"
+ " b2=texture2DRect(tex,vec2(fx*2.0+1.0,fy)).b;\n"
+ " y1=0.299011*r + 0.586987*g + 0.114001*b;\n"
+ " y2=0.299011*r2 + 0.586987*g2 + 0.114001*b2;\n"
+ " u=-0.148246*r -0.29102*g + 0.439266*b;\n"
+ " v=0.439271*r - 0.367833*g - 0.071438*b ;\n"
+ " y1=0.858885*y1 + 0.0625;\n"
+ " y2=0.858885*y2 + 0.0625;\n"
+ " u=u + 0.5;\n" " v=v + 0.5;\n" " gl_FragColor=vec4(%s);\n" "}\n";
display->text_shader_download_I420_YV12 =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect tex;\n"
- "uniform float w, h;\n"
- "void main(void) {\n"
- " float r,g,b,r2,b2,g2,y,u,v;\n"
- " vec2 nxy=gl_TexCoord[0].xy;\n"
- " vec2 nxy2=mod(2.0*nxy, vec2(w, h));\n"
- " r=texture2DRect(tex,nxy).r;\n"
- " g=texture2DRect(tex,nxy).g;\n"
- " b=texture2DRect(tex,nxy).b;\n"
- " r2=texture2DRect(tex,nxy2).r;\n"
- " g2=texture2DRect(tex,nxy2).g;\n"
- " b2=texture2DRect(tex,nxy2).b;\n"
- " y=0.299011*r + 0.586987*g + 0.114001*b;\n"
- " u=-0.148246*r2 -0.29102*g2 + 0.439266*b2;\n"
- " v=0.439271*r2 - 0.367833*g2 - 0.071438*b2 ;\n"
- " y=0.858885*y + 0.0625;\n"
- " u=u + 0.5;\n"
- " v=v + 0.5;\n"
- " gl_FragData[0] = vec4(y, 0.0, 0.0, 1.0);\n"
- " gl_FragData[1] = vec4(u, 0.0, 0.0, 1.0);\n"
- " gl_FragData[2] = vec4(v, 0.0, 0.0, 1.0);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect tex;\n"
+ "uniform float w, h;\n"
+ "void main(void) {\n"
+ " float r,g,b,r2,b2,g2,y,u,v;\n"
+ " vec2 nxy=gl_TexCoord[0].xy;\n"
+ " vec2 nxy2=mod(2.0*nxy, vec2(w, h));\n"
+ " r=texture2DRect(tex,nxy).r;\n"
+ " g=texture2DRect(tex,nxy).g;\n"
+ " b=texture2DRect(tex,nxy).b;\n"
+ " r2=texture2DRect(tex,nxy2).r;\n"
+ " g2=texture2DRect(tex,nxy2).g;\n"
+ " b2=texture2DRect(tex,nxy2).b;\n"
+ " y=0.299011*r + 0.586987*g + 0.114001*b;\n"
+ " u=-0.148246*r2 -0.29102*g2 + 0.439266*b2;\n"
+ " v=0.439271*r2 - 0.367833*g2 - 0.071438*b2 ;\n"
+ " y=0.858885*y + 0.0625;\n"
+ " u=u + 0.5;\n"
+ " v=v + 0.5;\n"
+ " gl_FragData[0] = vec4(y, 0.0, 0.0, 1.0);\n"
+ " gl_FragData[1] = vec4(u, 0.0, 0.0, 1.0);\n"
+ " gl_FragData[2] = vec4(v, 0.0, 0.0, 1.0);\n" "}\n";
display->text_shader_download_AYUV =
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect tex;\n"
- "void main(void) {\n"
- " float r,g,b,y,u,v;\n"
- " vec2 nxy=gl_TexCoord[0].xy;\n"
- " r=texture2DRect(tex,nxy).r;\n"
- " g=texture2DRect(tex,nxy).g;\n"
- " b=texture2DRect(tex,nxy).b;\n"
- " y=0.299011*r + 0.586987*g + 0.114001*b;\n"
- " u=-0.148246*r -0.29102*g + 0.439266*b;\n"
- " v=0.439271*r - 0.367833*g - 0.071438*b ;\n"
- " y=0.858885*y + 0.0625;\n"
- " u=u + 0.5;\n"
- " v=v + 0.5;\n"
- " gl_FragColor=vec4(y,u,v,1.0);\n"
- "}\n";
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "uniform sampler2DRect tex;\n"
+ "void main(void) {\n"
+ " float r,g,b,y,u,v;\n"
+ " vec2 nxy=gl_TexCoord[0].xy;\n"
+ " r=texture2DRect(tex,nxy).r;\n"
+ " g=texture2DRect(tex,nxy).g;\n"
+ " b=texture2DRect(tex,nxy).b;\n"
+ " y=0.299011*r + 0.586987*g + 0.114001*b;\n"
+ " u=-0.148246*r -0.29102*g + 0.439266*b;\n"
+ " v=0.439271*r - 0.367833*g - 0.071438*b ;\n"
+ " y=0.858885*y + 0.0625;\n"
+ " u=u + 0.5;\n"
+ " v=v + 0.5;\n" " gl_FragColor=vec4(y,u,v,1.0);\n" "}\n";
}
static void
-gst_gl_display_finalize (GObject* object)
+gst_gl_display_finalize (GObject * object)
{
- GstGLDisplay* display = GST_GL_DISPLAY (object);
+ GstGLDisplay *display = GST_GL_DISPLAY (object);
- if (display->mutex && display->gl_window)
- {
+ if (display->mutex && display->gl_window) {
gst_gl_display_lock (display);
GST_INFO ("send quit gl window loop");
- gst_gl_window_quit_loop (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
+ gst_gl_window_quit_loop (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
GST_INFO ("quit sent to gl window loop");
gst_gl_display_unlock (display);
}
- if (display->gl_thread)
- {
+ if (display->gl_thread) {
gpointer ret = g_thread_join (display->gl_thread);
GST_INFO ("gl thread joined");
if (ret != NULL)
/* Called in the gl thread */
gpointer
-gst_gl_display_thread_create_context (GstGLDisplay *display)
+gst_gl_display_thread_create_context (GstGLDisplay * display)
{
GLenum err = 0;
- display->gl_window = gst_gl_window_new (display->upload_width, display->upload_height);
+ display->gl_window =
+ gst_gl_window_new (display->upload_width, display->upload_height);
- if (!display->gl_window)
- {
+ if (!display->gl_window) {
display->isAlive = FALSE;
GST_ERROR_OBJECT (display, "Failed to create gl window");
g_cond_signal (display->cond_create_context);
GST_INFO ("gl window created");
//Init glew
- err = glewInit();
- if (err != GLEW_OK)
- {
+ err = glewInit ();
+ if (err != GLEW_OK) {
GST_ERROR_OBJECT (display, "Failed to init GLEW: %s",
- glewGetErrorString (err));
+ glewGetErrorString (err));
display->isAlive = FALSE;
- }
- else
- {
+ } else {
//OpenGL > 1.2.0 and Glew > 1.4.0
- GString* opengl_version = g_string_truncate (g_string_new ((gchar*) glGetString (GL_VERSION)), 3);
+ GString *opengl_version =
+ g_string_truncate (g_string_new ((gchar *) glGetString (GL_VERSION)),
+ 3);
gint opengl_version_major = 0;
gint opengl_version_minor = 0;
- sscanf(opengl_version->str, "%d.%d", &opengl_version_major, &opengl_version_minor);
+ sscanf (opengl_version->str, "%d.%d", &opengl_version_major,
+ &opengl_version_minor);
GST_INFO ("GL_VERSION: %s", glGetString (GL_VERSION));
GST_INFO ("GLEW_VERSION: %s", glewGetString (GLEW_VERSION));
if (glGetString (GL_SHADING_LANGUAGE_VERSION))
- GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s", glGetString (GL_SHADING_LANGUAGE_VERSION));
+ GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
+ glGetString (GL_SHADING_LANGUAGE_VERSION));
else
GST_INFO ("Your driver does not support GLSL (OpenGL Shading Language)");
g_string_free (opengl_version, TRUE);
if ((opengl_version_major < 1) ||
- (GLEW_VERSION_MAJOR < 1) ||
- (opengl_version_major < 2 && opengl_version_major >= 1 && opengl_version_minor < 2) ||
- (GLEW_VERSION_MAJOR < 2 && GLEW_VERSION_MAJOR >= 1 && GLEW_VERSION_MINOR < 4) )
- {
+ (GLEW_VERSION_MAJOR < 1) ||
+ (opengl_version_major < 2 && opengl_version_major >= 1
+ && opengl_version_minor < 2) || (GLEW_VERSION_MAJOR < 2
+ && GLEW_VERSION_MAJOR >= 1 && GLEW_VERSION_MINOR < 4)) {
//turn off the pipeline, the old drivers are not yet supported
GST_WARNING ("Required OpenGL >= 1.2.0 and Glew >= 1.4.0");
display->isAlive = FALSE;
}
//setup callbacks
- gst_gl_window_set_resize_callback (display->gl_window, GST_GL_WINDOW_CB2 (gst_gl_display_on_resize), display);
- gst_gl_window_set_draw_callback (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_on_draw), display);
- gst_gl_window_set_close_callback (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_on_close), display);
+ gst_gl_window_set_resize_callback (display->gl_window,
+ GST_GL_WINDOW_CB2 (gst_gl_display_on_resize), display);
+ gst_gl_window_set_draw_callback (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_on_draw), display);
+ gst_gl_window_set_close_callback (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_on_close), display);
g_cond_signal (display->cond_create_context);
/* Called in the gl thread */
void
-gst_gl_display_thread_destroy_context (GstGLDisplay *display)
+gst_gl_display_thread_destroy_context (GstGLDisplay * display)
{
//colorspace_conversion specific
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_MESA:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- break;
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- {
- glUseProgramObjectARB (0);
- if (display->shader_upload_YUY2)
- {
- g_object_unref (G_OBJECT (display->shader_upload_YUY2));
- display->shader_upload_YUY2 = NULL;
- }
- if (display->shader_upload_UYVY)
- {
- g_object_unref (G_OBJECT (display->shader_upload_UYVY));
- display->shader_upload_UYVY = NULL;
- }
- if (display->shader_upload_I420_YV12)
- {
- g_object_unref (G_OBJECT (display->shader_upload_I420_YV12));
- display->shader_upload_I420_YV12 = NULL;
- }
- if (display->shader_upload_AYUV)
- {
- g_object_unref (G_OBJECT (display->shader_upload_AYUV));
- display->shader_upload_AYUV = NULL;
- }
- if (display->shader_download_YUY2)
- {
- g_object_unref (G_OBJECT (display->shader_download_YUY2));
- display->shader_download_YUY2 = NULL;
- }
- if (display->shader_download_UYVY)
- {
- g_object_unref (G_OBJECT (display->shader_download_UYVY));
- display->shader_download_UYVY = NULL;
- }
- if (display->shader_download_I420_YV12)
- {
- g_object_unref (G_OBJECT (display->shader_download_I420_YV12));
- display->shader_download_I420_YV12 = NULL;
- }
- if (display->shader_download_AYUV)
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ break;
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
{
- g_object_unref (G_OBJECT (display->shader_download_AYUV));
- display->shader_download_AYUV = NULL;
+ glUseProgramObjectARB (0);
+ if (display->shader_upload_YUY2) {
+ g_object_unref (G_OBJECT (display->shader_upload_YUY2));
+ display->shader_upload_YUY2 = NULL;
+ }
+ if (display->shader_upload_UYVY) {
+ g_object_unref (G_OBJECT (display->shader_upload_UYVY));
+ display->shader_upload_UYVY = NULL;
+ }
+ if (display->shader_upload_I420_YV12) {
+ g_object_unref (G_OBJECT (display->shader_upload_I420_YV12));
+ display->shader_upload_I420_YV12 = NULL;
+ }
+ if (display->shader_upload_AYUV) {
+ g_object_unref (G_OBJECT (display->shader_upload_AYUV));
+ display->shader_upload_AYUV = NULL;
+ }
+ if (display->shader_download_YUY2) {
+ g_object_unref (G_OBJECT (display->shader_download_YUY2));
+ display->shader_download_YUY2 = NULL;
+ }
+ if (display->shader_download_UYVY) {
+ g_object_unref (G_OBJECT (display->shader_download_UYVY));
+ display->shader_download_UYVY = NULL;
+ }
+ if (display->shader_download_I420_YV12) {
+ g_object_unref (G_OBJECT (display->shader_download_I420_YV12));
+ display->shader_download_I420_YV12 = NULL;
+ }
+ if (display->shader_download_AYUV) {
+ g_object_unref (G_OBJECT (display->shader_download_AYUV));
+ display->shader_download_AYUV = NULL;
+ }
}
- }
- break;
- default:
- g_assert_not_reached ();
+ break;
+ default:
+ g_assert_not_reached ();
}
- if (display->upload_fbo)
- {
+ if (display->upload_fbo) {
glDeleteFramebuffersEXT (1, &display->upload_fbo);
display->upload_fbo = 0;
}
- if (display->upload_depth_buffer)
- {
- glDeleteRenderbuffersEXT(1, &display->upload_depth_buffer);
+ if (display->upload_depth_buffer) {
+ glDeleteRenderbuffersEXT (1, &display->upload_depth_buffer);
display->upload_depth_buffer = 0;
}
- if (display->download_fbo)
- {
+ if (display->download_fbo) {
glDeleteFramebuffersEXT (1, &display->download_fbo);
display->download_fbo = 0;
}
- if (display->download_depth_buffer)
- {
- glDeleteRenderbuffersEXT(1, &display->download_depth_buffer);
+ if (display->download_depth_buffer) {
+ glDeleteRenderbuffersEXT (1, &display->download_depth_buffer);
display->download_depth_buffer = 0;
}
- if (display->download_texture)
- {
+ if (display->download_texture) {
glDeleteTextures (1, &display->download_texture);
display->download_texture = 0;
}
- if (display->download_texture_u)
- {
+ if (display->download_texture_u) {
glDeleteTextures (1, &display->download_texture_u);
display->download_texture_u = 0;
}
- if (display->download_texture_v)
- {
+ if (display->download_texture_v) {
glDeleteTextures (1, &display->download_texture_v);
display->download_texture_v = 0;
}
- if (display->upload_intex != 0)
- {
+ if (display->upload_intex != 0) {
glDeleteTextures (1, &display->upload_intex);
display->upload_intex = 0;
}
- if (display->upload_intex_u != 0)
- {
+ if (display->upload_intex_u != 0) {
glDeleteTextures (1, &display->upload_intex_u);
display->upload_intex_u = 0;
}
- if (display->upload_intex_v != 0)
- {
+ if (display->upload_intex_v != 0) {
glDeleteTextures (1, &display->upload_intex_v);
display->upload_intex_v = 0;
}
GST_INFO ("Cleaning texture pool");
//clean up the texture pool
- g_hash_table_foreach_remove (display->texture_pool, gst_gl_display_texture_pool_func_clean,
- NULL);
+ g_hash_table_foreach_remove (display->texture_pool,
+ gst_gl_display_texture_pool_func_clean, NULL);
GST_INFO ("Context destroyed");
}
void
-gst_gl_display_thread_run_generic (GstGLDisplay *display)
+gst_gl_display_thread_run_generic (GstGLDisplay * display)
{
display->generic_callback (display, display->data);
}
{
//setup a texture to render to (this one will be in a gl buffer)
gst_gl_display_glgen_texture (display, &display->gen_texture,
- display->gen_texture_width, display->gen_texture_height);
+ display->gen_texture_width, display->gen_texture_height);
}
/* Called in the gl thread */
void
-gst_gl_display_thread_del_texture (GstGLDisplay* display)
+gst_gl_display_thread_del_texture (GstGLDisplay * display)
{
gst_gl_display_gldel_texture (display, &display->del_texture,
- display->del_texture_width, display->del_texture_height);
+ display->del_texture_width, display->del_texture_height);
}
/* Called in the gl thread */
void
-gst_gl_display_thread_init_upload (GstGLDisplay *display)
+gst_gl_display_thread_init_upload (GstGLDisplay * display)
{
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- //color space conversion is not needed
- //but if the size is different we need to redraw it
- //using fbo
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
- gst_gl_display_thread_init_upload_fbo (display);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- //color space conversion is needed
- {
- //check if fragment shader is available, then load them
- /* shouldn't we require ARB_shading_language_100? --Filippo */
- if (GLEW_ARB_fragment_shader)
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ //color space conversion is not needed
+ //but if the size is different we need to redraw it
+ //using fbo
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
+ gst_gl_display_thread_init_upload_fbo (display);
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ //color space conversion is needed
{
- GST_INFO ("Context, ARB_fragment_shader supported: yes");
-
- display->upload_colorspace_conversion = GST_GL_DISPLAY_CONVERSION_GLSL;
+ //check if fragment shader is available, then load them
+ /* shouldn't we require ARB_shading_language_100? --Filippo */
+ if (GLEW_ARB_fragment_shader) {
+ GST_INFO ("Context, ARB_fragment_shader supported: yes");
- gst_gl_display_thread_init_upload_fbo (display);
- if (!display->isAlive)
- break;
+ display->upload_colorspace_conversion = GST_GL_DISPLAY_CONVERSION_GLSL;
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- {
- gchar text_shader_upload_YUY2[2048];
- sprintf (text_shader_upload_YUY2, display->text_shader_upload_YUY2_UYVY, 'r', 'g', 'a');
+ gst_gl_display_thread_init_upload_fbo (display);
+ if (!display->isAlive)
+ break;
- display->shader_upload_YUY2 = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_upload_YUY2,
- text_shader_upload_YUY2, GST_GL_SHADER_FRAGMENT_SOURCE))
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
{
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_upload_YUY2));
- display->shader_upload_YUY2 = NULL;
+ gchar text_shader_upload_YUY2[2048];
+ sprintf (text_shader_upload_YUY2,
+ display->text_shader_upload_YUY2_UYVY, 'r', 'g', 'a');
+
+ display->shader_upload_YUY2 = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_upload_YUY2,
+ text_shader_upload_YUY2, GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_upload_YUY2));
+ display->shader_upload_YUY2 = NULL;
+ }
}
- }
- break;
- case GST_VIDEO_FORMAT_UYVY:
- {
- gchar text_shader_upload_UYVY[2048];
- sprintf (text_shader_upload_UYVY, display->text_shader_upload_YUY2_UYVY, 'a', 'b', 'r');
-
- display->shader_upload_UYVY = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_upload_UYVY,
- text_shader_upload_UYVY, GST_GL_SHADER_FRAGMENT_SOURCE))
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
{
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_upload_UYVY));
- display->shader_upload_UYVY = NULL;
+ gchar text_shader_upload_UYVY[2048];
+ sprintf (text_shader_upload_UYVY,
+ display->text_shader_upload_YUY2_UYVY, 'a', 'b', 'r');
+
+ display->shader_upload_UYVY = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_upload_UYVY,
+ text_shader_upload_UYVY, GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_upload_UYVY));
+ display->shader_upload_UYVY = NULL;
+ }
}
- }
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- {
- gchar text_shader_upload_I420_YV12[2048];
- if (g_ascii_strncasecmp ("ATI", (gchar *) glGetString (GL_VENDOR), 3) == 0)
- sprintf (text_shader_upload_I420_YV12, display->text_shader_upload_I420_YV12, "*0.5", "");
- else
- sprintf (text_shader_upload_I420_YV12, display->text_shader_upload_I420_YV12, "", "*0.5");
-
- display->shader_upload_I420_YV12 = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_upload_I420_YV12,
- text_shader_upload_I420_YV12, GST_GL_SHADER_FRAGMENT_SOURCE))
+ break;
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
{
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_upload_I420_YV12));
- display->shader_upload_I420_YV12 = NULL;
+ gchar text_shader_upload_I420_YV12[2048];
+ if (g_ascii_strncasecmp ("ATI", (gchar *) glGetString (GL_VENDOR),
+ 3) == 0)
+ sprintf (text_shader_upload_I420_YV12,
+ display->text_shader_upload_I420_YV12, "*0.5", "");
+ else
+ sprintf (text_shader_upload_I420_YV12,
+ display->text_shader_upload_I420_YV12, "", "*0.5");
+
+ display->shader_upload_I420_YV12 = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check
+ (display->shader_upload_I420_YV12, text_shader_upload_I420_YV12,
+ GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_upload_I420_YV12));
+ display->shader_upload_I420_YV12 = NULL;
+ }
}
+ break;
+ case GST_VIDEO_FORMAT_AYUV:
+ display->shader_upload_AYUV = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_upload_AYUV,
+ display->text_shader_upload_AYUV,
+ GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_upload_AYUV));
+ display->shader_upload_AYUV = NULL;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
- break;
- case GST_VIDEO_FORMAT_AYUV:
- display->shader_upload_AYUV = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_upload_AYUV,
- display->text_shader_upload_AYUV, GST_GL_SHADER_FRAGMENT_SOURCE))
- {
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_upload_AYUV));
- display->shader_upload_AYUV = NULL;
+ }
+ //check if YCBCR MESA is available
+ else if (GLEW_MESA_ycbcr_texture) {
+ //GLSL and Color Matrix are not available on your drivers, switch to YCBCR MESA
+ GST_INFO ("Context, ARB_fragment_shader supported: no");
+ GST_INFO ("Context, GLEW_MESA_ycbcr_texture supported: yes");
+
+ display->upload_colorspace_conversion = GST_GL_DISPLAY_CONVERSION_MESA;
+
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ //color space conversion is not needed
+ //but if the size is different we need to redraw it
+ //using fbo
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
+ gst_gl_display_thread_init_upload_fbo (display);
+ break;
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ //turn off the pipeline because
+ //MESA only support YUY2 and UYVY
+ GST_WARNING
+ ("Your MESA version only supports YUY2 and UYVY (GLSL is required for others yuv formats");
+ display->isAlive = FALSE;
+ break;
+ default:
+ g_assert_not_reached ();
}
- break;
- default:
- g_assert_not_reached ();
}
- }
- //check if YCBCR MESA is available
- else if (GLEW_MESA_ycbcr_texture)
- {
- //GLSL and Color Matrix are not available on your drivers, switch to YCBCR MESA
- GST_INFO ("Context, ARB_fragment_shader supported: no");
- GST_INFO ("Context, GLEW_MESA_ycbcr_texture supported: yes");
-
- display->upload_colorspace_conversion = GST_GL_DISPLAY_CONVERSION_MESA;
-
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- //color space conversion is not needed
- //but if the size is different we need to redraw it
- //using fbo
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
- gst_gl_display_thread_init_upload_fbo (display);
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- //turn off the pipeline because
- //MESA only support YUY2 and UYVY
- GST_WARNING ("Your MESA version only supports YUY2 and UYVY (GLSL is required for others yuv formats");
+ //check if color matrix is available
+ else if (GLEW_ARB_imaging) {
+ //GLSL is not available on your drivers, switch to Color Matrix
+ GST_INFO ("Context, ARB_fragment_shader supported: no");
+ GST_INFO ("Context, GLEW_MESA_ycbcr_texture supported: no");
+ GST_INFO ("Context, GLEW_ARB_imaging supported: yes");
+
+ display->upload_colorspace_conversion =
+ GST_GL_DISPLAY_CONVERSION_MATRIX;
+
+ //turn off the pipeline because we do not support it yet
+ GST_WARNING
+ ("Colorspace conversion using Color Matrix is not yet supported");
display->isAlive = FALSE;
- break;
- default:
- g_assert_not_reached ();
- }
- }
- //check if color matrix is available
- else if (GLEW_ARB_imaging)
- {
- //GLSL is not available on your drivers, switch to Color Matrix
- GST_INFO ("Context, ARB_fragment_shader supported: no");
- GST_INFO ("Context, GLEW_MESA_ycbcr_texture supported: no");
- GST_INFO ("Context, GLEW_ARB_imaging supported: yes");
-
- display->upload_colorspace_conversion = GST_GL_DISPLAY_CONVERSION_MATRIX;
-
- //turn off the pipeline because we do not support it yet
- GST_WARNING ("Colorspace conversion using Color Matrix is not yet supported");
- display->isAlive = FALSE;
- }
- else
- {
- GST_WARNING ("Context, ARB_fragment_shader supported: no");
- GST_WARNING ("Context, GLEW_ARB_imaging supported: no");
- GST_WARNING ("Context, GLEW_MESA_ycbcr_texture supported: no");
+ } else {
+ GST_WARNING ("Context, ARB_fragment_shader supported: no");
+ GST_WARNING ("Context, GLEW_ARB_imaging supported: no");
+ GST_WARNING ("Context, GLEW_MESA_ycbcr_texture supported: no");
- //turn off the pipeline because colorspace conversion is not possible
- display->isAlive = FALSE;
+ //turn off the pipeline because colorspace conversion is not possible
+ display->isAlive = FALSE;
+ }
}
- }
- break;
- default:
- g_assert_not_reached ();
+ break;
+ default:
+ g_assert_not_reached ();
}
}
/* Called by the idle function */
void
-gst_gl_display_thread_do_upload (GstGLDisplay *display)
+gst_gl_display_thread_do_upload (GstGLDisplay * display)
{
gst_gl_display_thread_do_upload_fill (display);
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- //color space conversion is not needed
- //but if the size is different we need to redraw it
- //using fbo
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
- gst_gl_display_thread_do_upload_draw (display);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- {
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- //color space conversion is needed
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ //color space conversion is not needed
+ //but if the size is different we need to redraw it
+ //using fbo
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
gst_gl_display_thread_do_upload_draw (display);
- break;
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- //color space conversion is needed
- //not yet supported
- break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
- //color space conversion is not needed
- //but if the size is different we need to redraw it
- //using fbo
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ {
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ //color space conversion is needed
gst_gl_display_thread_do_upload_draw (display);
- break;
- default:
- g_assert_not_reached ();
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ //color space conversion is needed
+ //not yet supported
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ //color space conversion is not needed
+ //but if the size is different we need to redraw it
+ //using fbo
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
+ gst_gl_display_thread_do_upload_draw (display);
+ break;
+ default:
+ g_assert_not_reached ();
}
}
- break;
- default:
- g_assert_not_reached ();
+ break;
+ default:
+ g_assert_not_reached ();
}
}
/* Called in the gl thread */
void
-gst_gl_display_thread_init_download (GstGLDisplay *display)
+gst_gl_display_thread_init_download (GstGLDisplay * display)
{
- switch (display->download_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- //color space conversion is not needed
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- //color space conversion is needed
- {
-
- if (GLEW_EXT_framebuffer_object)
+ switch (display->download_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ //color space conversion is not needed
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ //color space conversion is needed
{
- GST_INFO ("Context, EXT_framebuffer_object supported: yes");
-
- //-- init output frame buffer object (GL -> video)
-
- //setup FBO
- glGenFramebuffersEXT (1, &display->download_fbo);
- glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->download_fbo);
-
- //setup the render buffer for depth
- glGenRenderbuffersEXT(1, &display->download_depth_buffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, display->download_depth_buffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
- display->download_width, display->download_height);
-
- //setup a first texture to render to
- glGenTextures (1, &display->download_texture);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->download_texture);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- display->download_width, display->download_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);
-
- //attach the first texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_RECTANGLE_ARB, display->download_texture, 0);
-
- switch (display->download_video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_AYUV:
- //only one attached texture is needed
- break;
-
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- //setup a second texture to render to
- glGenTextures (1, &display->download_texture_u);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->download_texture_u);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- display->download_width, display->download_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);
-
- //attach the second texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
- GL_TEXTURE_RECTANGLE_ARB, display->download_texture_u, 0);
-
- //setup a third texture to render to
- glGenTextures (1, &display->download_texture_v);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->download_texture_v);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- display->download_width, display->download_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);
-
- //attach the third texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT,
- GL_TEXTURE_RECTANGLE_ARB, display->download_texture_v, 0);
-
- display->multipleRT[0] = GL_COLOR_ATTACHMENT0_EXT;
- display->multipleRT[1] = GL_COLOR_ATTACHMENT1_EXT;
- display->multipleRT[2] = GL_COLOR_ATTACHMENT2_EXT;
- break;
- default:
- g_assert_not_reached ();
- }
- //attach the depth render buffer to the FBO
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
- GL_RENDERBUFFER_EXT, display->download_depth_buffer);
+ if (GLEW_EXT_framebuffer_object) {
+ GST_INFO ("Context, EXT_framebuffer_object supported: yes");
- gst_gl_display_check_framebuffer_status();
+ //-- init output frame buffer object (GL -> video)
- g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
- GL_FRAMEBUFFER_COMPLETE_EXT);
+ //setup FBO
+ glGenFramebuffersEXT (1, &display->download_fbo);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->download_fbo);
- //unbind the FBO
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- }
- else
- {
+ //setup the render buffer for depth
+ glGenRenderbuffersEXT (1, &display->download_depth_buffer);
+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT,
+ display->download_depth_buffer);
+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
+ display->download_width, display->download_height);
+
+ //setup a first texture to render to
+ glGenTextures (1, &display->download_texture);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->download_texture);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ display->download_width, display->download_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);
+
+ //attach the first texture to the FBO to renderer to
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_RECTANGLE_ARB, display->download_texture, 0);
+
+ switch (display->download_video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_AYUV:
+ //only one attached texture is needed
+ break;
+
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ //setup a second texture to render to
+ glGenTextures (1, &display->download_texture_u);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB,
+ display->download_texture_u);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ display->download_width, display->download_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);
+
+ //attach the second texture to the FBO to renderer to
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB,
+ display->download_texture_u, 0);
+
+ //setup a third texture to render to
+ glGenTextures (1, &display->download_texture_v);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB,
+ display->download_texture_v);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ display->download_width, display->download_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);
+
+ //attach the third texture to the FBO to renderer to
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_RECTANGLE_ARB,
+ display->download_texture_v, 0);
+
+ display->multipleRT[0] = GL_COLOR_ATTACHMENT0_EXT;
+ display->multipleRT[1] = GL_COLOR_ATTACHMENT1_EXT;
+ display->multipleRT[2] = GL_COLOR_ATTACHMENT2_EXT;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ //attach the depth render buffer to the FBO
+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
+ display->download_depth_buffer);
+
+ gst_gl_display_check_framebuffer_status ();
+
+ g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
+ GL_FRAMEBUFFER_COMPLETE_EXT);
+
+ //unbind the FBO
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
+ } else {
//turn off the pipeline because Frame buffer object is a requirement when using filters
//or when using GLSL colorspace conversion
GST_WARNING ("Context, EXT_framebuffer_object supported: no");
display->isAlive = FALSE;
}
}
- break;
- default:
- g_assert_not_reached ();
+ break;
+ default:
+ g_assert_not_reached ();
}
- switch (display->download_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- //color space conversion is not needed
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- //color space conversion is needed
- {
- //check if fragment shader is available, then load them
- //GLSL is a requirement for donwload
- if (GLEW_ARB_fragment_shader)
- {
- switch (display->download_video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- {
- gchar text_shader_download_YUY2[2048];
- sprintf (text_shader_download_YUY2, display->text_shader_download_YUY2_UYVY, "y2,u,y1,v");
-
- display->shader_download_YUY2 = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_download_YUY2,
- text_shader_download_YUY2, GST_GL_SHADER_FRAGMENT_SOURCE))
- {
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_download_YUY2));
- display->shader_download_YUY2 = NULL;
- }
- }
+ switch (display->download_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ //color space conversion is not needed
break;
- case GST_VIDEO_FORMAT_UYVY:
- {
- gchar text_shader_download_UYVY[2048];
- sprintf (text_shader_download_UYVY, display->text_shader_download_YUY2_UYVY, "v,y1,u,y2");
-
- display->shader_download_UYVY = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_download_UYVY,
- text_shader_download_UYVY, GST_GL_SHADER_FRAGMENT_SOURCE))
- {
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_download_UYVY));
- display->shader_download_UYVY = NULL;
- }
- }
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- display->shader_download_I420_YV12 = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_download_I420_YV12,
- display->text_shader_download_I420_YV12, GST_GL_SHADER_FRAGMENT_SOURCE))
- {
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_download_I420_YV12));
- display->shader_download_I420_YV12 = NULL;
- }
- break;
- case GST_VIDEO_FORMAT_AYUV:
- display->shader_download_AYUV = gst_gl_shader_new ();
- if(!gst_gl_shader_compile_and_check (display->shader_download_AYUV,
- display->text_shader_download_AYUV, GST_GL_SHADER_FRAGMENT_SOURCE))
- {
- display->isAlive = FALSE;
- g_object_unref (G_OBJECT (display->shader_download_AYUV));
- display->shader_download_AYUV = NULL;
- }
- break;
- default:
- g_assert_not_reached ();
- }
- }
- else
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ //color space conversion is needed
{
- //turn off the pipeline because colorspace conversion is not possible
- GST_WARNING ("Context, ARB_fragment_shader supported: no");
- display->isAlive = FALSE;
+ //check if fragment shader is available, then load them
+ //GLSL is a requirement for donwload
+ if (GLEW_ARB_fragment_shader) {
+ switch (display->download_video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
+ {
+ gchar text_shader_download_YUY2[2048];
+ sprintf (text_shader_download_YUY2,
+ display->text_shader_download_YUY2_UYVY, "y2,u,y1,v");
+
+ display->shader_download_YUY2 = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_download_YUY2,
+ text_shader_download_YUY2, GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_download_YUY2));
+ display->shader_download_YUY2 = NULL;
+ }
+ }
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
+ {
+ gchar text_shader_download_UYVY[2048];
+ sprintf (text_shader_download_UYVY,
+ display->text_shader_download_YUY2_UYVY, "v,y1,u,y2");
+
+ display->shader_download_UYVY = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_download_UYVY,
+ text_shader_download_UYVY, GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_download_UYVY));
+ display->shader_download_UYVY = NULL;
+ }
+ }
+ break;
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ display->shader_download_I420_YV12 = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check
+ (display->shader_download_I420_YV12,
+ display->text_shader_download_I420_YV12,
+ GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_download_I420_YV12));
+ display->shader_download_I420_YV12 = NULL;
+ }
+ break;
+ case GST_VIDEO_FORMAT_AYUV:
+ display->shader_download_AYUV = gst_gl_shader_new ();
+ if (!gst_gl_shader_compile_and_check (display->shader_download_AYUV,
+ display->text_shader_download_AYUV,
+ GST_GL_SHADER_FRAGMENT_SOURCE)) {
+ display->isAlive = FALSE;
+ g_object_unref (G_OBJECT (display->shader_download_AYUV));
+ display->shader_download_AYUV = NULL;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ } else {
+ //turn off the pipeline because colorspace conversion is not possible
+ GST_WARNING ("Context, ARB_fragment_shader supported: no");
+ display->isAlive = FALSE;
+ }
}
- }
- break;
- default:
- g_assert_not_reached ();
+ break;
+ default:
+ g_assert_not_reached ();
}
}
void
gst_gl_display_thread_do_download (GstGLDisplay * display)
{
- switch (display->download_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- //color space conversion is not needed
- gst_gl_display_thread_do_download_draw_rgb (display);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- //color space conversion is needed
- gst_gl_display_thread_do_download_draw_yuv (display);
- break;
- default:
- g_assert_not_reached ();
+ switch (display->download_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ //color space conversion is not needed
+ gst_gl_display_thread_do_download_draw_rgb (display);
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ //color space conversion is needed
+ gst_gl_display_thread_do_download_draw_yuv (display);
+ break;
+ default:
+ g_assert_not_reached ();
}
}
/* Called in the gl thread */
void
-gst_gl_display_thread_gen_fbo (GstGLDisplay *display)
+gst_gl_display_thread_gen_fbo (GstGLDisplay * display)
{
//a texture must be attached to the FBO
GLuint fake_texture = 0;
display->isAlive = FALSE;
return;
}
-
//setup FBO
glGenFramebuffersEXT (1, &display->generated_fbo);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->generated_fbo);
//setup the render buffer for depth
- glGenRenderbuffersEXT(1, &display->generated_depth_buffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, display->generated_depth_buffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
- display->gen_fbo_width, display->gen_fbo_height);
+ glGenRenderbuffersEXT (1, &display->generated_depth_buffer);
+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, display->generated_depth_buffer);
+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
+ display->gen_fbo_width, display->gen_fbo_height);
//setup a texture to render to
glGenTextures (1, &fake_texture);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, fake_texture);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- display->gen_fbo_width, display->gen_fbo_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, fake_texture);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ display->gen_fbo_width, display->gen_fbo_height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, NULL);
//attach the texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_RECTANGLE_ARB, fake_texture, 0);
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_RECTANGLE_ARB, fake_texture, 0);
//attach the depth render buffer to the FBO
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
- GL_RENDERBUFFER_EXT, display->generated_depth_buffer);
+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+ GL_RENDERBUFFER_EXT, display->generated_depth_buffer);
g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
- GL_FRAMEBUFFER_COMPLETE_EXT);
+ GL_FRAMEBUFFER_COMPLETE_EXT);
//unbind the FBO
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glDeleteTextures (1, &fake_texture);
}
/* Called in the gl thread */
void
-gst_gl_display_thread_use_fbo (GstGLDisplay *display)
+gst_gl_display_thread_use_fbo (GstGLDisplay * display)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, display->use_fbo);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->use_fbo);
//setup a texture to render to
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture);
//attach the texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture, 0);
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_RECTANGLE_ARB, display->use_fbo_texture, 0);
if (GLEW_ARB_fragment_shader)
gst_gl_shader_use (NULL);
- glPushAttrib(GL_VIEWPORT_BIT);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- switch (display->use_fbo_projection)
- {
- case GST_GL_DISPLAY_PROJECTION_ORTHO2D:
- gluOrtho2D(display->use_fbo_proj_param1, display->use_fbo_proj_param2,
- display->use_fbo_proj_param3, display->use_fbo_proj_param4);
- break;
- case GST_GL_DISPLAY_PROJECTION_PERSPECIVE:
- gluPerspective(display->use_fbo_proj_param1, display->use_fbo_proj_param2,
- display->use_fbo_proj_param3, display->use_fbo_proj_param4);
- break;
- default:
- g_assert_not_reached ();
+ glPushAttrib (GL_VIEWPORT_BIT);
+
+ glMatrixMode (GL_PROJECTION);
+ glPushMatrix ();
+ glLoadIdentity ();
+
+ switch (display->use_fbo_projection) {
+ case GST_GL_DISPLAY_PROJECTION_ORTHO2D:
+ gluOrtho2D (display->use_fbo_proj_param1, display->use_fbo_proj_param2,
+ display->use_fbo_proj_param3, display->use_fbo_proj_param4);
+ break;
+ case GST_GL_DISPLAY_PROJECTION_PERSPECIVE:
+ gluPerspective (display->use_fbo_proj_param1,
+ display->use_fbo_proj_param2, display->use_fbo_proj_param3,
+ display->use_fbo_proj_param4);
+ break;
+ default:
+ g_assert_not_reached ();
}
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ glMatrixMode (GL_MODELVIEW);
+ glPushMatrix ();
+ glLoadIdentity ();
- glViewport(0, 0, display->use_fbo_width, display->use_fbo_height);
+ glViewport (0, 0, display->use_fbo_width, display->use_fbo_height);
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
+ glClearColor (0.0, 0.0, 0.0, 0.0);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//the opengl scene
- display->use_fbo_scene_cb (display->input_texture_width, display->input_texture_height,
- display->input_texture, display->use_fbo_stuff);
+ display->use_fbo_scene_cb (display->input_texture_width,
+ display->input_texture_height, display->input_texture,
+ display->use_fbo_stuff);
- glDrawBuffer(GL_NONE);
+ glDrawBuffer (GL_NONE);
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glPopAttrib();
+ glMatrixMode (GL_PROJECTION);
+ glPopMatrix ();
+ glMatrixMode (GL_MODELVIEW);
+ glPopMatrix ();
+ glPopAttrib ();
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
}
/* Called in the gl thread */
void
-gst_gl_display_thread_del_fbo (GstGLDisplay* display)
+gst_gl_display_thread_del_fbo (GstGLDisplay * display)
{
- if (display->del_fbo)
- {
+ if (display->del_fbo) {
glDeleteFramebuffersEXT (1, &display->del_fbo);
display->del_fbo = 0;
}
- if (display->del_depth_buffer)
- {
- glDeleteRenderbuffersEXT(1, &display->del_depth_buffer);
+ if (display->del_depth_buffer) {
+ glDeleteRenderbuffersEXT (1, &display->del_depth_buffer);
display->del_depth_buffer = 0;
}
}
/* Called in the gl thread */
void
-gst_gl_display_thread_gen_shader (GstGLDisplay* display)
+gst_gl_display_thread_gen_shader (GstGLDisplay * display)
{
- if (GLEW_ARB_fragment_shader)
- {
+ if (GLEW_ARB_fragment_shader) {
if (display->gen_shader_vertex_source ||
- display->gen_shader_fragment_source)
- {
+ display->gen_shader_fragment_source) {
gboolean isAlive = TRUE;
GError *error = NULL;
display->gen_shader = gst_gl_shader_new ();
if (display->gen_shader_vertex_source)
- gst_gl_shader_set_vertex_source(display->gen_shader, display->gen_shader_vertex_source);
+ gst_gl_shader_set_vertex_source (display->gen_shader,
+ display->gen_shader_vertex_source);
if (display->gen_shader_fragment_source)
- gst_gl_shader_set_fragment_source(display->gen_shader, display->gen_shader_fragment_source);
+ gst_gl_shader_set_fragment_source (display->gen_shader,
+ display->gen_shader_fragment_source);
gst_gl_shader_compile (display->gen_shader, &error);
- if (error)
- {
+ if (error) {
GST_ERROR ("%s", error->message);
g_error_free (error);
error = NULL;
isAlive = FALSE;
}
- if (!isAlive)
- {
+ if (!isAlive) {
display->isAlive = FALSE;
g_object_unref (G_OBJECT (display->gen_shader));
display->gen_shader = NULL;
}
}
- }
- else
- {
+ } else {
GST_WARNING ("One of the filter required ARB_fragment_shader");
display->isAlive = FALSE;
display->gen_shader = NULL;
/* Called in the gl thread */
void
-gst_gl_display_thread_del_shader (GstGLDisplay* display)
+gst_gl_display_thread_del_shader (GstGLDisplay * display)
{
- if (display->del_shader)
- {
+ if (display->del_shader) {
g_object_unref (G_OBJECT (display->del_shader));
display->del_shader = NULL;
}
void
-gst_gl_display_on_resize (GstGLDisplay* display, gint width, gint height)
+gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height)
{
//check if a client reshape callback is registered
if (display->clientReshapeCallback)
- display->clientReshapeCallback(width, height);
+ display->clientReshapeCallback (width, height);
//default reshape
- else
- {
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0, width, 0, height);
- glMatrixMode(GL_MODELVIEW);
+ else {
+ glViewport (0, 0, width, height);
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ gluOrtho2D (0, width, 0, height);
+ glMatrixMode (GL_MODELVIEW);
}
}
-void gst_gl_display_on_draw(GstGLDisplay* display)
+void
+gst_gl_display_on_draw (GstGLDisplay * display)
{
//check if tecture is ready for being drawn
if (!display->redisplay_texture)
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
//check if a client draw callback is registered
- if (display->clientDrawCallback)
- {
+ if (display->clientDrawCallback) {
gboolean doRedisplay =
- display->clientDrawCallback (display->redisplay_texture,
- display->redisplay_texture_width, display->redisplay_texture_height);
+ display->clientDrawCallback (display->redisplay_texture,
+ display->redisplay_texture_width, display->redisplay_texture_height);
if (doRedisplay && display->gl_window)
gst_gl_window_draw_unlocked (display->gl_window);
}
//default opengl scene
- else
- {
+ else {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glVertex2f (-1.0f, 1.0f);
glTexCoord2i (0, display->redisplay_texture_height);
glVertex2f (-1.0f, -1.0f);
- glTexCoord2i (display->redisplay_texture_width, display->redisplay_texture_height);
+ glTexCoord2i (display->redisplay_texture_width,
+ display->redisplay_texture_height);
glVertex2f (1.0f, -1.0f);
glEnd ();
- glDisable(GL_TEXTURE_RECTANGLE_ARB);
- }//end default opengl scene
+ glDisable (GL_TEXTURE_RECTANGLE_ARB);
+ } //end default opengl scene
}
-void gst_gl_display_on_close (GstGLDisplay* display)
+void
+gst_gl_display_on_close (GstGLDisplay * display)
{
GST_INFO ("on close");
/* Generate a texture if no one is available in the pool
* Called in the gl thread */
void
-gst_gl_display_glgen_texture (GstGLDisplay* display, GLuint* pTexture, GLint width, GLint height)
+gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
+ GLint width, GLint height)
{
- if (display->isAlive)
- {
- GQueue* sub_texture_pool = NULL;
+ if (display->isAlive) {
+ GQueue *sub_texture_pool = NULL;
//make a unique key from w and h
//the key cannot be w*h because (4*6 = 6*4 = 2*12 = 12*2)
- guint key = (gint)width;
+ guint key = (gint) width;
key <<= 16;
- key |= (gint)height;
- sub_texture_pool = g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
+ key |= (gint) height;
+ sub_texture_pool =
+ g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
//if there is a sub texture pool associated to th given key
- if (sub_texture_pool && g_queue_get_length(sub_texture_pool) > 0)
- {
+ if (sub_texture_pool && g_queue_get_length (sub_texture_pool) > 0) {
//a texture is available in the pool
- GstGLDisplayTex* tex = g_queue_pop_head (sub_texture_pool);
+ GstGLDisplayTex *tex = g_queue_pop_head (sub_texture_pool);
*pTexture = tex->texture;
g_free (tex);
GST_LOG ("get texture id:%d from the sub texture pool: %d",
- *pTexture, key);
- }
- else
- {
+ *pTexture, key);
+ } else {
//sub texture pool does not exist yet or empty
glGenTextures (1, pTexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
- switch (display->upload_video_format)
- {
+ switch (display->upload_video_format) {
case GST_VIDEO_FORMAT_RGB:
case GST_VIDEO_FORMAT_BGR:
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRA:
case GST_VIDEO_FORMAT_ARGB:
case GST_VIDEO_FORMAT_ABGR:
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
case GST_VIDEO_FORMAT_YUY2:
case GST_VIDEO_FORMAT_UYVY:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- else
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA,width, height,
- 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
- break;
- default:
- g_assert_not_reached ();
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ else
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
+ height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
+ break;
+ default:
+ g_assert_not_reached ();
}
break;
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
case GST_VIDEO_FORMAT_AYUV:
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
- 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_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);
GST_LOG ("generate texture id:%d", *pTexture);
}
- }
- else
+ } else
*pTexture = 0;
}
/* Delete a texture, actually the texture is just added to the pool
* Called in the gl thread */
void
-gst_gl_display_gldel_texture (GstGLDisplay* display, GLuint* pTexture, GLint width, GLint height)
+gst_gl_display_gldel_texture (GstGLDisplay * display, GLuint * pTexture,
+ GLint width, GLint height)
{
//Each existing texture is destroyed only when the pool is destroyed
//The pool of textures is deleted in the GstGLDisplay destructor
- GQueue* sub_texture_pool = NULL;
- GstGLDisplayTex* tex = NULL;
+ GQueue *sub_texture_pool = NULL;
+ GstGLDisplayTex *tex = NULL;
//make a unique key from w and h
//the key cannot be w*h because (4*6 = 6*4 = 2*12 = 12*2)
- guint key = (gint)width;
+ guint key = (gint) width;
key <<= 16;
- key |= (gint)height;
- sub_texture_pool = g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
+ key |= (gint) height;
+ sub_texture_pool =
+ g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
//if the size is known
- if (!sub_texture_pool)
- {
+ if (!sub_texture_pool) {
sub_texture_pool = g_queue_new ();
- g_hash_table_insert (display->texture_pool, GUINT_TO_POINTER (key), sub_texture_pool);
+ g_hash_table_insert (display->texture_pool, GUINT_TO_POINTER (key),
+ sub_texture_pool);
GST_INFO ("one more sub texture pool inserted: %d ", key);
- GST_INFO ("nb sub texture pools: %d", g_hash_table_size (display->texture_pool));
+ GST_INFO ("nb sub texture pools: %d",
+ g_hash_table_size (display->texture_pool));
}
-
//contruct a sub texture pool element
tex = g_new0 (GstGLDisplayTex, 1);
tex->texture = *pTexture;
//add tex to the pool, it makes texture allocation reusable
g_queue_push_tail (sub_texture_pool, tex);
GST_LOG ("texture id:%d added to the sub texture pool: %d",
- tex->texture, key);
+ tex->texture, key);
GST_LOG ("%d texture(s) in the sub texture pool: %d",
- g_queue_get_length (sub_texture_pool), key);
+ g_queue_get_length (sub_texture_pool), key);
}
/* call when a sub texture pool is removed from the texture pool (ghash table) */
-gboolean gst_gl_display_texture_pool_func_clean (gpointer key, gpointer value, gpointer data)
+gboolean
+gst_gl_display_texture_pool_func_clean (gpointer key, gpointer value,
+ gpointer data)
{
- GQueue* sub_texture_pool = (GQueue*) value;
+ GQueue *sub_texture_pool = (GQueue *) value;
- while (g_queue_get_length (sub_texture_pool) > 0)
- {
- GstGLDisplayTex* tex = g_queue_pop_head (sub_texture_pool);
+ while (g_queue_get_length (sub_texture_pool) > 0) {
+ GstGLDisplayTex *tex = g_queue_pop_head (sub_texture_pool);
GST_INFO ("trying to delete texture id: %d deleted", tex->texture);
glDeleteTextures (1, &tex->texture);
GST_INFO ("texture id: %d deleted", tex->texture);
/* called in the gl thread */
void
-gst_gl_display_check_framebuffer_status(void)
+gst_gl_display_check_framebuffer_status (void)
{
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ GLenum status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
- switch(status)
- {
- case GL_FRAMEBUFFER_COMPLETE_EXT:
- break;
+ switch (status) {
+ case GL_FRAMEBUFFER_COMPLETE_EXT:
+ break;
- case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
- GST_ERROR ("GL_FRAMEBUFFER_UNSUPPORTED_EXT");
- break;
+ case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
+ GST_ERROR ("GL_FRAMEBUFFER_UNSUPPORTED_EXT");
+ break;
- default:
- GST_ERROR ("General FBO error");
+ default:
+ GST_ERROR ("General FBO error");
}
}
/* Called by the first gl element of a video/x-raw-gl flow */
-GstGLDisplay*
+GstGLDisplay *
gst_gl_display_new (void)
{
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
/* Create an opengl context (one context for one GstGLDisplay)
* Called by the first gl element of a video/x-raw-gl flow */
void
-gst_gl_display_create_context (GstGLDisplay *display,
- GLint width, GLint height)
+gst_gl_display_create_context (GstGLDisplay * display,
+ GLint width, GLint height)
{
gst_gl_display_lock (display);
display->upload_height = height;
display->gl_thread = g_thread_create (
- (GThreadFunc) gst_gl_display_thread_create_context, display, TRUE, NULL);
+ (GThreadFunc) gst_gl_display_thread_create_context, display, TRUE, NULL);
g_cond_wait (display->cond_create_context, display->mutex);
/* Called by the glimagesink element */
gboolean
-gst_gl_display_redisplay (GstGLDisplay* display, GLuint texture, gint width, gint height)
+gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
+ gint height)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
- if (isAlive)
- {
- if (texture)
- {
+ if (isAlive) {
+ if (texture) {
display->redisplay_texture = texture;
display->redisplay_texture_width = width;
display->redisplay_texture_height = height;
}
void
-gst_gl_display_thread_add (GstGLDisplay *display,
- GstGLDisplayThreadFunc func, gpointer data)
+gst_gl_display_thread_add (GstGLDisplay * display,
+ GstGLDisplayThreadFunc func, gpointer data)
{
gst_gl_display_lock (display);
display->data = data;
display->generic_callback = func;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_run_generic), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_run_generic), display);
gst_gl_display_unlock (display);
}
/* Called by gst_gl_buffer_new */
void
-gst_gl_display_gen_texture (GstGLDisplay* display, GLuint* pTexture, GLint width, GLint height)
+gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
+ GLint width, GLint height)
{
gst_gl_display_lock (display);
display->gen_texture_width = width;
display->gen_texture_height = height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_gen_texture), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_gen_texture), display);
*pTexture = display->gen_texture;
gst_gl_display_unlock (display);
}
/* Called by gst_gl_buffer_finalize */
void
-gst_gl_display_del_texture (GstGLDisplay* display, GLuint texture, GLint width, GLint height)
+gst_gl_display_del_texture (GstGLDisplay * display, GLuint texture, GLint width,
+ GLint height)
{
gst_gl_display_lock (display);
- if (texture)
- {
+ if (texture) {
display->del_texture = texture;
display->del_texture_width = width;
display->del_texture_height = height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_del_texture), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_del_texture), display);
}
gst_gl_display_unlock (display);
}
/* Called by the first gl element of a video/x-raw-gl flow */
void
-gst_gl_display_init_upload (GstGLDisplay* display, GstVideoFormat video_format,
- guint gl_width, guint gl_height,
- gint video_width, gint video_height)
+gst_gl_display_init_upload (GstGLDisplay * display, GstVideoFormat video_format,
+ guint gl_width, guint gl_height, gint video_width, gint video_height)
{
gst_gl_display_lock (display);
display->upload_video_format = video_format;
display->upload_height = gl_height;
display->upload_data_width = video_width;
display->upload_data_height = video_height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_init_upload), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_init_upload), display);
gst_gl_display_unlock (display);
}
/* Called by the first gl element of a video/x-raw-gl flow */
gboolean
-gst_gl_display_do_upload (GstGLDisplay *display, GLuint texture,
- gint data_width, gint data_height,
- gpointer data)
+gst_gl_display_do_upload (GstGLDisplay * display, GLuint texture,
+ gint data_width, gint data_height, gpointer data)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
- if (isAlive)
- {
+ if (isAlive) {
display->upload_outtex = texture;
display->upload_data_width = data_width;
display->upload_data_height = data_height;
display->upload_data = data;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_do_upload), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_do_upload), display);
}
gst_gl_display_unlock (display);
/* Called by the gldownload and glcolorscale element */
void
-gst_gl_display_init_download (GstGLDisplay* display, GstVideoFormat video_format,
- gint width, gint height)
+gst_gl_display_init_download (GstGLDisplay * display,
+ GstVideoFormat video_format, gint width, gint height)
{
gst_gl_display_lock (display);
display->download_video_format = video_format;
display->download_width = width;
display->download_height = height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_init_download), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_init_download), display);
gst_gl_display_unlock (display);
}
/* Called by the gldownload and glcolorscale element */
gboolean
-gst_gl_display_do_download (GstGLDisplay* display, GLuint texture,
- gint width, gint height,
- gpointer data)
+gst_gl_display_do_download (GstGLDisplay * display, GLuint texture,
+ gint width, gint height, gpointer data)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
- if (isAlive)
- {
+ if (isAlive) {
//data size is aocciated to the glcontext size
display->download_data = data;
display->ouput_texture = texture;
display->ouput_texture_width = width;
display->ouput_texture_height = height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_do_download), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_do_download), display);
}
gst_gl_display_unlock (display);
/* Called by gltestsrc and glfilter */
void
-gst_gl_display_gen_fbo (GstGLDisplay* display, gint width, gint height,
- GLuint* fbo, GLuint* depthbuffer)
+gst_gl_display_gen_fbo (GstGLDisplay * display, gint width, gint height,
+ GLuint * fbo, GLuint * depthbuffer)
{
gst_gl_display_lock (display);
- if (display->isAlive)
- {
+ if (display->isAlive) {
display->gen_fbo_width = width;
display->gen_fbo_height = height;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_gen_fbo), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_gen_fbo), display);
*fbo = display->generated_fbo;
*depthbuffer = display->generated_depth_buffer;
}
* GstGLDisplay *display and gpointer data, or just gpointer data */
/* ..everything here has to be simplified! */
gboolean
-gst_gl_display_use_fbo (GstGLDisplay* display, gint texture_fbo_width, gint texture_fbo_height,
- GLuint fbo, GLuint depth_buffer, GLuint texture_fbo, GLCB cb,
- gint input_texture_width, gint input_texture_height, GLuint input_texture,
- gdouble proj_param1, gdouble proj_param2,
- gdouble proj_param3, gdouble proj_param4,
- GstGLDisplayProjection projection, gpointer* stuff)
+gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
+ gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
+ GLuint texture_fbo, GLCB cb, gint input_texture_width,
+ gint input_texture_height, GLuint input_texture, gdouble proj_param1,
+ gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
+ GstGLDisplayProjection projection, gpointer * stuff)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
- if (isAlive)
- {
+ if (isAlive) {
display->use_fbo = fbo;
display->use_depth_buffer = depth_buffer;
display->use_fbo_texture = texture_fbo;
display->input_texture_width = input_texture_width;
display->input_texture_height = input_texture_height;
display->input_texture = input_texture;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_use_fbo), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_use_fbo), display);
}
gst_gl_display_unlock (display);
/* Called by gltestsrc and glfilter */
void
-gst_gl_display_del_fbo (GstGLDisplay* display, GLuint fbo,
- GLuint depth_buffer)
+gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo, GLuint depth_buffer)
{
gst_gl_display_lock (display);
display->del_fbo = fbo;
display->del_depth_buffer = depth_buffer;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_del_fbo), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_del_fbo), display);
gst_gl_display_unlock (display);
}
/* Called by glfilter */
void
-gst_gl_display_gen_shader (GstGLDisplay* display,
- const gchar* shader_vertex_source,
- const gchar* shader_fragment_source,
- GstGLShader** shader)
+gst_gl_display_gen_shader (GstGLDisplay * display,
+ const gchar * shader_vertex_source,
+ const gchar * shader_fragment_source, GstGLShader ** shader)
{
gst_gl_display_lock (display);
display->gen_shader_vertex_source = shader_vertex_source;
display->gen_shader_fragment_source = shader_fragment_source;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_gen_shader), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_gen_shader), display);
if (shader)
*shader = display->gen_shader;
display->gen_shader = NULL;
/* Called by glfilter */
void
-gst_gl_display_del_shader (GstGLDisplay* display, GstGLShader* shader)
+gst_gl_display_del_shader (GstGLDisplay * display, GstGLShader * shader)
{
gst_gl_display_lock (display);
display->del_shader = shader;
- gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (gst_gl_display_thread_del_shader), display);
+ gst_gl_window_send_message (display->gl_window,
+ GST_GL_WINDOW_CB (gst_gl_display_thread_del_shader), display);
gst_gl_display_unlock (display);
}
/* Called by the glimagesink */
void
-gst_gl_display_set_window_id (GstGLDisplay* display, gulong window_id)
+gst_gl_display_set_window_id (GstGLDisplay * display, gulong window_id)
{
gst_gl_display_lock (display);
gst_gl_window_set_external_window_id (display->gl_window, window_id);
//------------------------------------------------------------
/* called by gst_gl_display_thread_init_upload (in the gl thread) */
-void gst_gl_display_thread_init_upload_fbo (GstGLDisplay *display)
+void
+gst_gl_display_thread_init_upload_fbo (GstGLDisplay * display)
{
//Frame buffer object is a requirement for every cases
- if (GLEW_EXT_framebuffer_object)
- {
+ if (GLEW_EXT_framebuffer_object) {
//a texture must be attached to the FBO
GLuint fake_texture = 0;
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->upload_fbo);
//setup the render buffer for depth
- glGenRenderbuffersEXT(1, &display->upload_depth_buffer);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, display->upload_depth_buffer);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
- display->upload_width, display->upload_height);
+ glGenRenderbuffersEXT (1, &display->upload_depth_buffer);
+ glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, display->upload_depth_buffer);
+ glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
+ display->upload_width, display->upload_height);
//a fake texture is attached to the upload FBO (cannot init without it)
glGenTextures (1, &fake_texture);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, fake_texture);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- display->upload_width, display->upload_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, fake_texture);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ display->upload_width, display->upload_height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, NULL);
//attach the texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_RECTANGLE_ARB, fake_texture, 0);
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_RECTANGLE_ARB, fake_texture, 0);
//attach the depth render buffer to the FBO
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
- GL_RENDERBUFFER_EXT, display->upload_depth_buffer);
+ glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+ GL_RENDERBUFFER_EXT, display->upload_depth_buffer);
- gst_gl_display_check_framebuffer_status();
+ gst_gl_display_check_framebuffer_status ();
g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
GL_FRAMEBUFFER_COMPLETE_EXT);
//unbind the FBO
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glDeleteTextures (1, &fake_texture);
//alloc texture (related to upload) memory only on time
gst_gl_display_thread_do_upload_make (display);
- }
- else
- {
+ } else {
//turn off the pipeline because Frame buffer object is a not present
GST_WARNING ("Context, EXT_framebuffer_object supported: no");
display->isAlive = FALSE;
}
/* called by gst_gl_display_thread_do_upload (in the gl thread) */
-void gst_gl_display_thread_do_upload_make (GstGLDisplay *display)
+void
+gst_gl_display_thread_do_upload_make (GstGLDisplay * display)
{
gint width = display->upload_data_width;
gint height = display->upload_data_height;
glGenTextures (1, &display->upload_intex);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
- width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- break;
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
- width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
- break;
- case GST_VIDEO_FORMAT_AYUV:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
- width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, NULL);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA,
- width, height,
- 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
- glGenTextures (1, &display->upload_intex_u);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height,
- 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
- break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width, height,
- 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
- break;
- default:
- g_assert_not_reached ();
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
+ width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ break;
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
+ width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ break;
+ case GST_VIDEO_FORMAT_AYUV:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
+ width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, NULL);
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA,
+ width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ glGenTextures (1, &display->upload_intex_u);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
+ height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
+ break;
+ default:
+ g_assert_not_reached ();
}
- break;
- case GST_VIDEO_FORMAT_UYVY:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA,
- width, height,
- 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
- glGenTextures (1, &display->upload_intex_u);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
- width, height,
- 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
- break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width, height,
- 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
- break;
- default:
- g_assert_not_reached ();
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA,
+ width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ glGenTextures (1, &display->upload_intex_u);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
+ width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
+ height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
+ break;
+ default:
+ g_assert_not_reached ();
}
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
- width, height,
- 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
-
- glGenTextures (1, &display->upload_intex_u);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
- GST_ROUND_UP_2 (width) / 2,
- GST_ROUND_UP_2 (height) / 2,
- 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
-
- glGenTextures (1, &display->upload_intex_v);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
- glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
- GST_ROUND_UP_2 (width) / 2,
- GST_ROUND_UP_2 (height) / 2,
- 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
- break;
-
- default:
- g_assert_not_reached ();
+ break;
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
+ width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
+
+ glGenTextures (1, &display->upload_intex_u);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
+ GST_ROUND_UP_2 (width) / 2,
+ GST_ROUND_UP_2 (height) / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
+
+ glGenTextures (1, &display->upload_intex_v);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
+ glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE,
+ GST_ROUND_UP_2 (width) / 2,
+ GST_ROUND_UP_2 (height) / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
+ break;
+
+ default:
+ g_assert_not_reached ();
}
}
/* called by gst_gl_display_thread_do_upload (in the gl thread) */
void
-gst_gl_display_thread_do_upload_fill (GstGLDisplay *display)
+gst_gl_display_thread_do_upload_fill (GstGLDisplay * display)
{
gint width = display->upload_data_width;
gint height = display->upload_data_height;
gpointer data = display->upload_data;
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- //color space conversion is not needed
- if (display->upload_width != display->upload_data_width ||
- display->upload_height != display->upload_data_height)
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- else
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- case GST_VIDEO_FORMAT_AYUV:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ //color space conversion is not needed
if (display->upload_width != display->upload_data_width ||
display->upload_height != display->upload_data_height)
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
else
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex);
break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ case GST_VIDEO_FORMAT_AYUV:
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ if (display->upload_width != display->upload_data_width ||
+ display->upload_height != display->upload_data_height)
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ else
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ break;
default:
- g_assert_not_reached();
- }
- break;
- default:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
switch (display->upload_video_format) {
- case GST_VIDEO_FORMAT_RGB:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_RGB, GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_BGR:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_BGR, GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_RGBA:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_RGBA, GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_BGRA:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_BGRA, GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_AYUV:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_ARGB:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, data);
- break;
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_ABGR:
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, data);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ case GST_VIDEO_FORMAT_RGB:
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
-
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
- GST_ROUND_UP_2 (width) / 2, height,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
+ GL_RGB, GL_UNSIGNED_BYTE, data);
break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
+ case GST_VIDEO_FORMAT_BGR:
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, data);
+ GL_BGR, GL_UNSIGNED_BYTE, data);
break;
- default:
- g_assert_not_reached ();
- }
- break;
- case GST_VIDEO_FORMAT_UYVY:
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_RGBA:
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
-
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
- GST_ROUND_UP_2 (width) / 2, height,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
+ GL_RGBA, GL_UNSIGNED_BYTE, data);
break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_BGRA:
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data);
+ GL_BGRA, GL_UNSIGNED_BYTE, data);
break;
- default:
- g_assert_not_reached ();
- }
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- {
- gint offsetU = 0;
- gint offsetV = 0;
-
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_I420:
- offsetU = 1;
- offsetV = 2;
+ case GST_VIDEO_FORMAT_AYUV:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_ARGB:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, data);
break;
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_ABGR:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, data);
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
+
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
+ GST_ROUND_UP_2 (width) / 2, height,
+ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, data);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
+
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
+ GST_ROUND_UP_2 (width) / 2, height,
+ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ break;
+ case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
+ {
+ gint offsetU = 0;
+ gint offsetV = 0;
+
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_I420:
+ offsetU = 1;
+ offsetV = 2;
+ break;
+ case GST_VIDEO_FORMAT_YV12:
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
- //WIN32
- offsetU = 2;
- offsetV = 1;
+ //WIN32
+ offsetU = 2;
+ offsetV = 1;
#else
- //LINUX
- offsetU = 1;
- offsetV = 2;
+ //LINUX
+ offsetU = 1;
+ offsetV = 2;
#endif
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
+
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
+ GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE,
+ (guint8 *) data +
+ gst_video_format_get_component_offset (display->upload_video_format,
+ offsetU, width, height));
+
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
+ glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
+ GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE,
+ (guint8 *) data +
+ gst_video_format_get_component_offset (display->upload_video_format,
+ offsetV, width, height));
+ }
break;
default:
g_assert_not_reached ();
- }
-
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
-
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
- GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
- GL_LUMINANCE, GL_UNSIGNED_BYTE,
- (guint8 *) data +
- gst_video_format_get_component_offset (display->upload_video_format, offsetU, width, height));
-
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
- glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0,
- GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
- GL_LUMINANCE, GL_UNSIGNED_BYTE,
- (guint8 *) data +
- gst_video_format_get_component_offset (display->upload_video_format, offsetV, width, height));
- }
- break;
- default:
- g_assert_not_reached ();
}
}
/* called by gst_gl_display_thread_do_upload (in the gl thread) */
void
-gst_gl_display_thread_do_upload_draw (GstGLDisplay *display)
+gst_gl_display_thread_do_upload_draw (GstGLDisplay * display)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, display->upload_fbo);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->upload_fbo);
//setup a texture to render to
glEnable (GL_TEXTURE_RECTANGLE_ARB);
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex);
//attach the texture to the FBO to renderer to
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex, 0);
+ glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_RECTANGLE_ARB, display->upload_outtex, 0);
if (GLEW_ARB_fragment_shader)
gst_gl_shader_use (NULL);
- glPushAttrib(GL_VIEWPORT_BIT);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(0.0, display->upload_width, 0.0, display->upload_height);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- glViewport(0, 0, display->upload_width, display->upload_height);
-
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_ARGB:
- case GST_VIDEO_FORMAT_ABGR:
- case GST_VIDEO_FORMAT_RGB:
- case GST_VIDEO_FORMAT_BGR:
- {
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
-
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- 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);
- }
- break;
-
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- {
- switch (display->upload_colorspace_conversion)
- {
- case GST_GL_DISPLAY_CONVERSION_GLSL:
- case GST_GL_DISPLAY_CONVERSION_MATRIX:
- {
- GstGLShader* shader_upload_YUY2_UYVY = NULL;
+ glPushAttrib (GL_VIEWPORT_BIT);
- switch (display->upload_video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- shader_upload_YUY2_UYVY = display->shader_upload_YUY2;
- break;
- case GST_VIDEO_FORMAT_UYVY:
- shader_upload_YUY2_UYVY = display->shader_upload_UYVY;
- break;
- default:
- g_assert_not_reached ();
- }
+ glMatrixMode (GL_PROJECTION);
+ glPushMatrix ();
+ glLoadIdentity ();
+ gluOrtho2D (0.0, display->upload_width, 0.0, display->upload_height);
- gst_gl_shader_use (shader_upload_YUY2_UYVY);
+ glMatrixMode (GL_MODELVIEW);
+ glPushMatrix ();
+ glLoadIdentity ();
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ glViewport (0, 0, display->upload_width, display->upload_height);
- glActiveTextureARB(GL_TEXTURE1_ARB);
- gst_gl_shader_set_uniform_1i (shader_upload_YUY2_UYVY, "UVtex", 1);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- 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);
+ glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
+ glClearColor (0.0, 0.0, 0.0, 0.0);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (shader_upload_YUY2_UYVY, "Ytex", 0);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- 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);
- }
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_ARGB:
+ case GST_VIDEO_FORMAT_ABGR:
+ case GST_VIDEO_FORMAT_RGB:
+ case GST_VIDEO_FORMAT_BGR:
+ {
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+ glEnable (GL_TEXTURE_RECTANGLE_ARB);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ 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);
+ }
break;
- case GST_GL_DISPLAY_CONVERSION_MESA:
- {
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- 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);
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ {
+ switch (display->upload_colorspace_conversion) {
+ case GST_GL_DISPLAY_CONVERSION_GLSL:
+ case GST_GL_DISPLAY_CONVERSION_MATRIX:
+ {
+ GstGLShader *shader_upload_YUY2_UYVY = NULL;
+
+ switch (display->upload_video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
+ shader_upload_YUY2_UYVY = display->shader_upload_YUY2;
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
+ shader_upload_YUY2_UYVY = display->shader_upload_UYVY;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ gst_gl_shader_use (shader_upload_YUY2_UYVY);
+
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+ glActiveTextureARB (GL_TEXTURE1_ARB);
+ gst_gl_shader_set_uniform_1i (shader_upload_YUY2_UYVY, "UVtex", 1);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ 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);
+
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (shader_upload_YUY2_UYVY, "Ytex", 0);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ 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);
+ }
+ break;
+ case GST_GL_DISPLAY_CONVERSION_MESA:
+ {
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+
+ glEnable (GL_TEXTURE_RECTANGLE_ARB);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ 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);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
- break;
- default:
- g_assert_not_reached ();
}
- }
- break;
+ break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- {
- gst_gl_shader_use (display->shader_upload_I420_YV12);
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ {
+ gst_gl_shader_use (display->shader_upload_I420_YV12);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
- glActiveTextureARB(GL_TEXTURE1_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Utex", 1);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
- 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);
-
- glActiveTextureARB(GL_TEXTURE2_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Vtex", 2);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
- 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);
-
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Ytex", 0);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- 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);
- }
- break;
+ glActiveTextureARB (GL_TEXTURE1_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Utex",
+ 1);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u);
+ 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);
+
+ glActiveTextureARB (GL_TEXTURE2_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Vtex",
+ 2);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v);
+ 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);
+
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_upload_I420_YV12, "Ytex",
+ 0);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ 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);
+ }
+ break;
- case GST_VIDEO_FORMAT_AYUV:
- {
- gst_gl_shader_use (display->shader_upload_AYUV);
+ case GST_VIDEO_FORMAT_AYUV:
+ {
+ gst_gl_shader_use (display->shader_upload_AYUV);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_upload_AYUV, "tex", 0);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
- 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);
- }
- break;
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_upload_AYUV, "tex", 0);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex);
+ 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);
+ }
+ break;
- default:
- g_assert_not_reached ();
+ default:
+ g_assert_not_reached ();
- }//end switch display->currentVideo_format
+ } //end switch display->currentVideo_format
glBegin (GL_QUADS);
glTexCoord2i (display->upload_data_width, 0);
glVertex2f (1.0f, 1.0f);
glEnd ();
- glDrawBuffer(GL_NONE);
+ glDrawBuffer (GL_NONE);
//we are done with the shader
if (display->upload_colorspace_conversion == GST_GL_DISPLAY_CONVERSION_GLSL)
glUseProgramObjectARB (0);
- glDisable(GL_TEXTURE_RECTANGLE_ARB);
+ glDisable (GL_TEXTURE_RECTANGLE_ARB);
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glPopAttrib();
+ glMatrixMode (GL_PROJECTION);
+ glPopMatrix ();
+ glMatrixMode (GL_MODELVIEW);
+ glPopMatrix ();
+ glPopAttrib ();
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
- gst_gl_display_check_framebuffer_status();
+ gst_gl_display_check_framebuffer_status ();
}
/* called by gst_gl_display_thread_do_download (in the gl thread) */
void
-gst_gl_display_thread_do_download_draw_rgb (GstGLDisplay *display)
+gst_gl_display_thread_do_download_draw_rgb (GstGLDisplay * display)
{
GstVideoFormat video_format = display->download_video_format;
gpointer data = display->download_data;
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
- switch (video_format)
- {
- case GST_VIDEO_FORMAT_RGBA:
- case GST_VIDEO_FORMAT_RGBx:
- case GST_VIDEO_FORMAT_xRGB:
- case GST_VIDEO_FORMAT_ARGB:
- glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_BGRx:
- case GST_VIDEO_FORMAT_BGRA:
- case GST_VIDEO_FORMAT_xBGR:
- case GST_VIDEO_FORMAT_ABGR:
- glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA,
- GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_RGB:
- glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
- GL_UNSIGNED_BYTE, data);
- break;
- case GST_VIDEO_FORMAT_BGR:
- glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGR,
- GL_UNSIGNED_BYTE, data);
- break;
- default:
+ switch (video_format) {
+ case GST_VIDEO_FORMAT_RGBA:
+ case GST_VIDEO_FORMAT_RGBx:
+ case GST_VIDEO_FORMAT_xRGB:
+ case GST_VIDEO_FORMAT_ARGB:
+ glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, data);
+ break;
+ case GST_VIDEO_FORMAT_BGRx:
+ case GST_VIDEO_FORMAT_BGRA:
+ case GST_VIDEO_FORMAT_xBGR:
+ case GST_VIDEO_FORMAT_ABGR:
+ glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA,
+ GL_UNSIGNED_BYTE, data);
+ break;
+ case GST_VIDEO_FORMAT_RGB:
+ glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
+ GL_UNSIGNED_BYTE, data);
+ break;
+ case GST_VIDEO_FORMAT_BGR:
+ glGetTexImage (GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGR,
+ GL_UNSIGNED_BYTE, data);
+ break;
+ default:
g_assert_not_reached ();
- }
+ }
}
/* called by gst_gl_display_thread_do_download (in the gl thread) */
void
-gst_gl_display_thread_do_download_draw_yuv (GstGLDisplay *display)
+gst_gl_display_thread_do_download_draw_yuv (GstGLDisplay * display)
{
gint width = display->download_width;
gint height = display->download_height;
GstVideoFormat video_format = display->download_video_format;
gpointer data = display->download_data;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, display->download_fbo);
-
- glPushAttrib(GL_VIEWPORT_BIT);
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->download_fbo);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(0.0, width, 0.0, height);
+ glPushAttrib (GL_VIEWPORT_BIT);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ glMatrixMode (GL_PROJECTION);
+ glPushMatrix ();
+ glLoadIdentity ();
+ gluOrtho2D (0.0, width, 0.0, height);
- glViewport(0, 0, width, height);
+ glMatrixMode (GL_MODELVIEW);
+ glPushMatrix ();
+ glLoadIdentity ();
- switch (video_format)
- {
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- {
- GstGLShader* shader_download_YUY2_UYVY = NULL;
+ glViewport (0, 0, width, height);
- switch (video_format)
- {
+ switch (video_format) {
case GST_VIDEO_FORMAT_YUY2:
- shader_download_YUY2_UYVY = display->shader_download_YUY2;
- break;
case GST_VIDEO_FORMAT_UYVY:
- shader_download_YUY2_UYVY = display->shader_download_UYVY;
- break;
- default:
- g_assert_not_reached ();
- }
+ {
+ GstGLShader *shader_download_YUY2_UYVY = NULL;
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ switch (video_format) {
+ case GST_VIDEO_FORMAT_YUY2:
+ shader_download_YUY2_UYVY = display->shader_download_YUY2;
+ break;
+ case GST_VIDEO_FORMAT_UYVY:
+ shader_download_YUY2_UYVY = display->shader_download_UYVY;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
- gst_gl_shader_use (shader_download_YUY2_UYVY);
+ glClearColor (0.0, 0.0, 0.0, 0.0);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ gst_gl_shader_use (shader_download_YUY2_UYVY);
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (shader_download_YUY2_UYVY, "tex", 0);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
- }
- break;
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- {
- glDrawBuffers(3, display->multipleRT);
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (shader_download_YUY2_UYVY, "tex", 0);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
+ }
+ break;
+
+ case GST_VIDEO_FORMAT_I420:
+ case GST_VIDEO_FORMAT_YV12:
+ {
+ glDrawBuffers (3, display->multipleRT);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClearColor (0.0, 0.0, 0.0, 0.0);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- gst_gl_shader_use (display->shader_download_I420_YV12);
+ gst_gl_shader_use (display->shader_download_I420_YV12);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_download_I420_YV12, "tex", 0);
- gst_gl_shader_set_uniform_1f (display->shader_download_I420_YV12, "w",
- (gfloat)display->ouput_texture_width);
- gst_gl_shader_set_uniform_1f (display->shader_download_I420_YV12, "h",
- (gfloat)display->ouput_texture_height);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
- }
- break;
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_download_I420_YV12, "tex",
+ 0);
+ gst_gl_shader_set_uniform_1f (display->shader_download_I420_YV12, "w",
+ (gfloat) display->ouput_texture_width);
+ gst_gl_shader_set_uniform_1f (display->shader_download_I420_YV12, "h",
+ (gfloat) display->ouput_texture_height);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
+ }
+ break;
- case GST_VIDEO_FORMAT_AYUV:
- {
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ case GST_VIDEO_FORMAT_AYUV:
+ {
+ glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClearColor (0.0, 0.0, 0.0, 0.0);
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- gst_gl_shader_use (display->shader_download_AYUV);
+ gst_gl_shader_use (display->shader_download_AYUV);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
- glActiveTextureARB(GL_TEXTURE0_ARB);
- gst_gl_shader_set_uniform_1i (display->shader_download_AYUV, "tex", 0);
- glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
- }
- break;
+ glActiveTextureARB (GL_TEXTURE0_ARB);
+ gst_gl_shader_set_uniform_1i (display->shader_download_AYUV, "tex", 0);
+ glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->ouput_texture);
+ }
+ break;
- default:
- g_assert_not_reached ();
+ default:
+ g_assert_not_reached ();
- }//end switch display->currentVideo_format
+ } //end switch display->currentVideo_format
glBegin (GL_QUADS);
glTexCoord2i (0, 0);
glVertex2f (-1.0f, 1.0f);
glEnd ();
- glDrawBuffer(GL_NONE);
+ glDrawBuffer (GL_NONE);
//dot not check if GLSL is available
//because for now download is not available
//without GLSL
glUseProgramObjectARB (0);
- glDisable(GL_TEXTURE_RECTANGLE_ARB);
+ glDisable (GL_TEXTURE_RECTANGLE_ARB);
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glPopAttrib();
+ glMatrixMode (GL_PROJECTION);
+ glPopMatrix ();
+ glMatrixMode (GL_MODELVIEW);
+ glPopMatrix ();
+ glPopAttrib ();
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
- gst_gl_display_check_framebuffer_status();
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, display->download_fbo);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
-
- switch (video_format)
- {
- case GST_VIDEO_FORMAT_AYUV:
- case GST_VIDEO_FORMAT_xRGB:
- glReadPixels (0, 0, width, height, GL_BGRA,
- GL_UNSIGNED_INT_8_8_8_8, data);
- break;
- case GST_VIDEO_FORMAT_YUY2:
- case GST_VIDEO_FORMAT_UYVY:
- glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2, height, GL_BGRA,
- GL_UNSIGNED_INT_8_8_8_8_REV, data);
- break;
- case GST_VIDEO_FORMAT_I420:
- case GST_VIDEO_FORMAT_YV12:
- {
- gint offsetU = 0;
- gint offsetV = 0;
-
- switch (video_format)
- {
- case GST_VIDEO_FORMAT_I420:
- offsetU = 1;
- offsetV = 2;
+ gst_gl_display_check_framebuffer_status ();
+
+ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->download_fbo);
+ glReadBuffer (GL_COLOR_ATTACHMENT0_EXT);
+
+ switch (video_format) {
+ case GST_VIDEO_FORMAT_AYUV:
+ case GST_VIDEO_FORMAT_xRGB:
+ glReadPixels (0, 0, width, height, GL_BGRA,
+ GL_UNSIGNED_INT_8_8_8_8, data);
+ break;
+ case GST_VIDEO_FORMAT_YUY2:
+ case GST_VIDEO_FORMAT_UYVY:
+ glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2, height, GL_BGRA,
+ GL_UNSIGNED_INT_8_8_8_8_REV, data);
break;
+ case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_YV12:
+ {
+ gint offsetU = 0;
+ gint offsetV = 0;
+
+ switch (video_format) {
+ case GST_VIDEO_FORMAT_I420:
+ offsetU = 1;
+ offsetV = 2;
+ break;
+ case GST_VIDEO_FORMAT_YV12:
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)
- //WIN32
- offsetU = 2;
- offsetV = 1;
+ //WIN32
+ offsetU = 2;
+ offsetV = 1;
#else
- //LINUX
- offsetU = 1;
- offsetV = 2;
+ //LINUX
+ offsetU = 1;
+ offsetV = 2;
#endif
- break;
- default:
- g_assert_not_reached ();
- }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
- glReadPixels (0, 0, width, height, GL_LUMINANCE,
- GL_UNSIGNED_BYTE, data);
+ glReadPixels (0, 0, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
- glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
- glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
- GL_LUMINANCE, GL_UNSIGNED_BYTE,
- (guint8 *) data +
- gst_video_format_get_component_offset (video_format, offsetU, width, height));
+ glReadBuffer (GL_COLOR_ATTACHMENT1_EXT);
+ glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2,
+ GST_ROUND_UP_2 (height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
+ (guint8 *) data + gst_video_format_get_component_offset (video_format,
+ offsetU, width, height));
- glReadBuffer(GL_COLOR_ATTACHMENT2_EXT);
- glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2, GST_ROUND_UP_2 (height) / 2,
- GL_LUMINANCE, GL_UNSIGNED_BYTE,
- (guint8 *) data +
- gst_video_format_get_component_offset (video_format, offsetV, width, height));
- }
- break;
- default:
- g_assert_not_reached ();
+ glReadBuffer (GL_COLOR_ATTACHMENT2_EXT);
+ glReadPixels (0, 0, GST_ROUND_UP_2 (width) / 2,
+ GST_ROUND_UP_2 (height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
+ (guint8 *) data + gst_video_format_get_component_offset (video_format,
+ offsetV, width, height));
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
- gst_gl_display_check_framebuffer_status();
+ gst_gl_display_check_framebuffer_status ();
}
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
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
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;
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;
}
}
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);
}
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);
}
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);
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);
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;
}
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)
}
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);
}
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;
}
}
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);
}
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);
/* 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);
}
}
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);
_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 *
}
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;
#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))
}
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);
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;
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);
_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 */
{
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);
priv->visible = FALSE;
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
- height += 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION);
-
- priv->internal_win_id = CreateWindowEx (
- 0,
- "GSTGL",
- "OpenGL renderer",
- WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
- x, y, width, height,
- (HWND) NULL,
- (HMENU) NULL,
- hinstance,
- window
- );
-
- if (!priv->internal_win_id)
- {
+ 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);
+
+ if (!priv->internal_win_id) {
g_debug ("failed to create gl window: %d\n", priv->internal_win_id);
return NULL;
}
}
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;
/* 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;
/* 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;
}
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;
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");
/* 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");
}
/* 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));
}
}
/* 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;
-
- 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);
-
- pixelformat = ChoosePixelFormat (priv->device, &pfd );
-
- g_assert (pixelformat);
-
- res = SetPixelFormat (priv->device, pixelformat, &pfd);
-
- g_assert (res);
+ 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.cColorBits = (BYTE) GetDeviceCaps (priv->device, BITSPIXEL);
+
+ pixelformat = ChoosePixelFormat (priv->device, &pfd);
+
+ g_assert (pixelformat);
+
+ res = SetPixelFormat (priv->device, pixelformat, &pfd);
+
+ 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");
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);
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);
ShowWindowAsync (priv->internal_win_id, SW_HIDE);
if (priv->close_cb)
- 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->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;
break;
}
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");
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");
}
case WM_GST_GL_WINDOW_CUSTOM:
{
- if (!priv->is_closed)
- {
+ if (!priv->is_closed) {
GstGLWindowCB custom_cb = (GstGLWindowCB) lParam;
custom_cb ((gpointer) wParam);
}
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);
}
-
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
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;
}
}
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);
}
static void
-gst_gl_window_init (GstGLWindow *window)
+gst_gl_window_init (GstGLWindow * window)
{
window->priv = GST_GL_WINDOW_GET_PRIVATE (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 */
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 ();
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;
}
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);
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;
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);
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);
/* 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;
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);
}
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;
}
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;
}
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;
/* 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;
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;
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);
}
}
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);
}
/* Called in the gl thread */
void
-gst_gl_window_run_loop (GstGLWindow *window)
+gst_gl_window_run_loop (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;
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:
{
g_debug ("Cannot create WM_QUIT_LOOP\n");
/* Message sent with gst_gl_window_send_message */
- if (wm_gl != None && event.xclient.message_type == wm_gl)
- {
- if (priv->running)
- {
+ if (wm_gl != None && event.xclient.message_type == wm_gl) {
+ if (priv->running) {
GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer custom_data = (gpointer) event.xclient.data.l[1];
}
/* 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);
}
/* message sent with gst_gl_window_quit_loop */
- else if (wm_quit_loop != None && event.xclient.message_type == wm_quit_loop)
- {
+ else if (wm_quit_loop != None
+ && event.xclient.message_type == wm_quit_loop) {
GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer destroy_data = (gpointer) event.xclient.data.l[1];
- 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;
/* make sure last pendings send message calls are executed */
XFlush (priv->device);
- while (XCheckTypedEvent (priv->device, ClientMessage, &pending_event))
- {
- GstGLWindowCB custom_cb = (GstGLWindowCB) pending_event.xclient.data.l[0];
+ while (XCheckTypedEvent (priv->device, ClientMessage, &pending_event)) {
+ GstGLWindowCB custom_cb =
+ (GstGLWindowCB) pending_event.xclient.data.l[0];
gpointer custom_data = (gpointer) pending_event.xclient.data.l[1];
g_debug ("execute last pending custom x events\n");
destroy_cb (destroy_data);
- }
- else
- g_debug("client message not reconized \n");
+ } else
+ g_debug ("client message not reconized \n");
break;
}
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;
}
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);
break;
default:
- g_debug("unknown xvisibility event: %d\n", event.xvisibility.state);
+ g_debug ("unknown xvisibility event: %d\n",
+ event.xvisibility.state);
break;
}
break;
g_debug ("unknow\n");
break;
- }// switch
+ } // switch
- }// while running
+ } // while running
g_mutex_unlock (priv->x_lock);
/* 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;
event.xclient.data.l[0] = (long) callback;
event.xclient.data.l[1] = (long) data;
- 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);
}
/* 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;
event.xclient.data.l[0] = (long) callback;
event.xclient.data.l[1] = (long) data;
- 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 */
#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);
}
#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);
}
#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 ();
}
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 ();
}
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 ();
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);
}
#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 ();
}
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);
}
#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 ();
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);
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);
}
-
#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);
}
#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 ();
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);
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);
}
#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);
}
#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);
}
#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);
}
/* 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;"
- "}";
-
-
-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);"
- "}";
+ "#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 *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);"
- "}";
-
-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);"
+ " 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 *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)));"
+ "}";
#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);
}
#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);
}
#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);
}
/* 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 ();
}
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 ();
}
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 ();
}
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 ();
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);
}
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 ();
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 ();
}
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 ();
}
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 ();
}
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>");
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";
//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);
bumper->pixbuf = gdk_pixbuf_new_from_file (bumper->location, &error);
bumper->bumpmap_width = gdk_pixbuf_get_width (bumper->pixbuf);
bumper->bumpmap_height = gdk_pixbuf_get_height (bumper->pixbuf);
-
+
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,
- gdk_pixbuf_get_has_alpha (bumper->pixbuf) ? GL_RGBA : GL_RGB,
- GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (bumper->pixbuf));
+ bumper->bumpmap_width, bumper->bumpmap_height, 0,
+ gdk_pixbuf_get_has_alpha (bumper->pixbuf) ? GL_RGBA : GL_RGB,
+ GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (bumper->pixbuf));
}
//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;
}
}
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;
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->pixbuf = NULL;
- bumper->location = NULL;
+ bumper->shader = NULL;
+ bumper->bumpmap = 0;
+ bumper->bumpmap_width = 0;
+ bumper->bumpmap_height = 0;
+ bumper->pixbuf = NULL;
+ 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;
}
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);
//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);
-
- // 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
-
- // 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
-
- // 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();
-
- glUseProgram(0);
- glDisable(GL_LIGHT0);
- glDisable(GL_LIGHT1);
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
-
- xrot+=1.0f;
- yrot+=0.9f;
- zrot+=1.1f;
+ 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
+
+ // 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
+
+ // 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
+
+ // 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);
+
+ xrot += 1.0f;
+ yrot += 0.9f;
+ zrot += 1.1f;
}
#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 ";"
/* Properties */
enum
{
- PROP_0
+ PROP_0
};
#define DEBUG_INIT(bla) \
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_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_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_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;
-
- 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;
+ 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;
+
+ 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);
-
- 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;
-
- gint count = 0, w = 0, h = 0;
-
- guint num, den;
-
- //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);
-
- //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);
+ 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");
+
+ //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;
+
+ guint num, den;
+
+ //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);
+
+ //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);
}
- 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);
- }
- }
+
+ 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_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
+ 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;
-
- 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 TRUE;
+ 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);
+ }
+
+ 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;
}
GstGLFilter filter;
GstGLShader *shader[4];
-
+
gchar *location;
gboolean bg_has_changed;
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 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
{
/* 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]);
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);
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;
}
static void
-gst_gl_differencematte_reset_resources (GstGLFilter* filter)
+gst_gl_differencematte_reset_resources (GstGLFilter * filter)
{
// GstGLDifferenceMatte* differencematte = GST_GL_DIFFERENCEMATTE(filter);
}
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;
}
}
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,
- gdk_pixbuf_get_has_alpha (differencematte->pixbuf) ? GL_RGBA : GL_RGB,
- GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (differencematte->pixbuf));
+ filter->width, filter->height, 0,
+ gdk_pixbuf_get_has_alpha (differencematte->pixbuf) ? GL_RGBA : GL_RGB,
+ GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (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 ();
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);
}
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 ();
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 ();
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 ();
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);
}
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 ();
}
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);
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_file (differencematte->location, &error);
if (pixbuf) {
differencematte->pixbuf = gdk_pixbuf_scale_simple (pixbuf,
- filter->width,
- filter->height,
- GDK_INTERP_BILINEAR);
+ filter->width, filter->height, GDK_INTERP_BILINEAR);
gdk_pixbuf_unref (pixbuf);
if (differencematte->pixbuf != NULL) {
- 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);
gdk_pixbuf_unref (differencematte->pixbuf);
}
} else {
if (error != NULL && error->message != NULL)
- g_warning ("unable to load %s: %s", differencematte->location, error->message);
+ g_warning ("unable to load %s: %s", differencematte->location,
+ error->message);
}
differencematte->bg_has_changed = FALSE;
}
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;
}
#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 ";"
enum
{
- PROP_0
+ PROP_0
};
#define DEBUG_INIT(bla) \
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;
-
- 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;
+ 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;
+
+ 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);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ //GstGLDownload *download = GST_GL_DOWNLOAD (object);
+
+ 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;
-
- download = GST_GL_DOWNLOAD (bt);
-
- GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
-
- 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");
-
- 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);
+ 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);
+
+ GST_DEBUG ("transform caps %" GST_PTR_FORMAT, caps);
+
+ 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");
+
+ 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_DEBUG ("new caps %" GST_PTR_FORMAT, newcaps);
-
- return newcaps;
+ 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);
+ 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);
+
+ 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;
-
- 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;
+ 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);
+ }
+
+ 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);
-
- 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);
-
- 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;
+ 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);
+
+ //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));
+
+ //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;
}
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,
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;
}
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
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);
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);
}
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
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;
}
}
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
}
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;
#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) \
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
}
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);
-
- 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;
+ 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)
+gst_gl_filter_app_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
{
- //GstGLFilterApp* filter = GST_GL_FILTER_APP (object);
+ //GstGLFilterApp* filter = GST_GL_FILTER_APP (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_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);
-
- 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;
+ 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);
+ }
+
+ 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);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- 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 ();
+ 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 ();
+
+ 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 ();
}
/* 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);
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);
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;
}
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);
}
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
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);
}
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 ();
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);
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 ();
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);
#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) \
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);
-
- 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;
- }
+ 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;
+ }
}
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);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ //GstGLFilterCube* filter = GST_GL_FILTER_CUBE (object);
+
+ 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);
-
- return TRUE;
+ 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);
+
+ 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;
-
- GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE (stuff);
-
- 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);
-
- 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);
-
- glRotatef(xrot,1.0f,0.0f,0.0f);
- glRotatef(yrot,0.0f,1.0f,0.0f);
- glRotatef(zrot,0.0f,0.0f,1.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();
-
- xrot+=0.3f;
- yrot+=0.2f;
- zrot+=0.4f;
-
- glDisable(GL_DEPTH_TEST);
+ static GLfloat xrot = 0;
+ static GLfloat yrot = 0;
+ static GLfloat zrot = 0;
+
+ GstGLFilterCube *cube_filter = GST_GL_FILTER_CUBE (stuff);
+
+ 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);
+
+ 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);
+
+ glRotatef (xrot, 1.0f, 0.0f, 0.0f);
+ glRotatef (yrot, 0.0f, 1.0f, 0.0f);
+ glRotatef (zrot, 0.0f, 0.0f, 1.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 ();
+
+ xrot += 0.3f;
+ yrot += 0.2f;
+ zrot += 0.4f;
+
+ glDisable (GL_DEPTH_TEST);
}
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
{
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)
}
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;
}
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;
}
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);
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.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.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);
glEnd ();
gst_gl_shader_use (0);
//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);
//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);
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
{
#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)
}
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;
}
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 ();
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);
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);
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;
}
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);
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;
}
}
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
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 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
};
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);
}
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",
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,
NULL
};
- static const GInterfaceInfo xoverlay_info = {
+ static const GInterfaceInfo xoverlay_info = {
(GInterfaceInitFunc) gst_glimage_sink_xoverlay_init,
NULL,
NULL,
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
}
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;
}
+ 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;
+ }
}
static void
-gst_glimage_sink_finalize (GObject* object)
+gst_glimage_sink_finalize (GObject * object)
{
- 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);
- if (glimage_sink->caps)
- gst_caps_unref (glimage_sink->caps);
+ if (glimage_sink->caps)
+ gst_caps_unref (glimage_sink->caps);
- g_free (glimage_sink->display_name);
+ g_free (glimage_sink->display_name);
- GST_DEBUG ("finalized");
+ GST_DEBUG ("finalized");
}
static void
-gst_glimage_sink_get_property (GObject* object, guint prop_id,
- GValue* value, GParamSpec* pspec)
+gst_glimage_sink_get_property (GObject * object, guint prop_id,
+ 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)
- {
- 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;
- }
+ 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;
+ }
}
/*
*/
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;
-
- GST_DEBUG ("change state");
-
- 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;
- }
-
+ GstGLImageSink *glimage_sink;
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+
+ GST_DEBUG ("change state");
+
+ 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;
+ }
+
+ return ret;
}
/*
*/
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;
-
- 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);
- }
- }
+ GstGLImageSink *glimagesink;
+
+ 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);
+ }
}
+ }
}
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;
-
- GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
-
- 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);
-
- 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;
-
- if (!glimage_sink->window_id)
- gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink));
-
- return TRUE;
+ 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);
+
+ 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);
+
+ 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;
+
+ if (!glimage_sink->window_id)
+ gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (glimage_sink));
+
+ 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 ();
-
- //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);
-
- //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_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
+ }
+ //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);
+
+ 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);
+
+ 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);
- //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;
}
GST_DEBUG_CATEGORY_INIT (gst_gl_pixbufoverlay_debug, "glpixbufoverlay", 0, "glpixbufoverlay element");
GST_BOILERPLATE_FULL (GstGLPixbufOverlay, gst_gl_pixbufoverlay, GstGLFilter,
- GST_TYPE_GL_FILTER, DEBUG_INIT);
+ GST_TYPE_GL_FILTER, DEBUG_INIT);
static void gst_gl_pixbufoverlay_set_property (GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec);
+ const GValue * value, GParamSpec * pspec);
static void gst_gl_pixbufoverlay_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
+ GValue * value, GParamSpec * pspec);
-static void gst_gl_pixbufoverlay_init_resources (GstGLFilter* filter);
-static void gst_gl_pixbufoverlay_reset_resources (GstGLFilter* filter);
+static void gst_gl_pixbufoverlay_init_resources (GstGLFilter * filter);
+static void gst_gl_pixbufoverlay_reset_resources (GstGLFilter * filter);
static gboolean gst_gl_pixbufoverlay_filter (GstGLFilter * filter,
- GstGLBuffer * inbuf, GstGLBuffer * outbuf);
+ GstGLBuffer * inbuf, GstGLBuffer * outbuf);
-static const GstElementDetails element_details = GST_ELEMENT_DETAILS (
- "Gstreamer OpenGL PixbufOverlay",
- "Filter/Effect",
- "Overlay GL video texture with a gdkpixbuf",
- "Filippo Argiolas <filippo.argiolas@gmail.com>");
+static const GstElementDetails element_details =
+GST_ELEMENT_DETAILS ("Gstreamer OpenGL PixbufOverlay",
+ "Filter/Effect",
+ "Overlay GL video texture with a gdkpixbuf",
+ "Filippo Argiolas <filippo.argiolas@gmail.com>");
enum
{
/* init resources that need a gl context */
static void
-gst_gl_pixbufoverlay_init_gl_resources (GstGLFilter *filter)
+gst_gl_pixbufoverlay_init_gl_resources (GstGLFilter * filter)
{
// GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (filter);
}
/* free resources that need a gl context */
static void
-gst_gl_pixbufoverlay_reset_gl_resources (GstGLFilter *filter)
+gst_gl_pixbufoverlay_reset_gl_resources (GstGLFilter * filter)
{
GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (filter);
-
+
glDeleteTextures (1, &pixbufoverlay->pbuftexture);
}
gobject_class->get_property = gst_gl_pixbufoverlay_get_property;
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_pixbufoverlay_filter;
- GST_GL_FILTER_CLASS (klass)->display_init_cb = gst_gl_pixbufoverlay_init_gl_resources;
- GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_pixbufoverlay_reset_gl_resources;
+ GST_GL_FILTER_CLASS (klass)->display_init_cb =
+ gst_gl_pixbufoverlay_init_gl_resources;
+ GST_GL_FILTER_CLASS (klass)->display_reset_cb =
+ gst_gl_pixbufoverlay_reset_gl_resources;
GST_GL_FILTER_CLASS (klass)->onStart = gst_gl_pixbufoverlay_init_resources;
GST_GL_FILTER_CLASS (klass)->onStop = gst_gl_pixbufoverlay_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
-gst_gl_pixbufoverlay_draw_texture (GstGLPixbufOverlay * pixbufoverlay, GLuint tex)
+gst_gl_pixbufoverlay_draw_texture (GstGLPixbufOverlay * pixbufoverlay,
+ GLuint tex)
{
GstGLFilter *filter = GST_GL_FILTER (pixbufoverlay);
glEnd ();
- if (pixbufoverlay->pbuftexture == 0) return;
+ if (pixbufoverlay->pbuftexture == 0)
+ return;
// if (pixbufoverlay->stretch) {
- width = pixbufoverlay->width;
- height = pixbufoverlay->height;
+ width = pixbufoverlay->width;
+ height = pixbufoverlay->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, pixbufoverlay->pbuftexture);
}
static void
-gst_gl_pixbufoverlay_init (GstGLPixbufOverlay * pixbufoverlay,
- GstGLPixbufOverlayClass * klass)
+gst_gl_pixbufoverlay_init (GstGLPixbufOverlay * pixbufoverlay,
+ GstGLPixbufOverlayClass * klass)
{
pixbufoverlay->location = NULL;
pixbufoverlay->pixbuf = NULL;
}
static void
-gst_gl_pixbufoverlay_reset_resources (GstGLFilter* filter)
+gst_gl_pixbufoverlay_reset_resources (GstGLFilter * filter)
{
// GstGLPixbufOverlay* pixbufoverlay = GST_GL_PIXBUFOVERLAY(filter);
}
gst_gl_pixbufoverlay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
- GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (object);
+ GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (object);
switch (prop_id) {
- case PROP_LOCATION:
- if (pixbufoverlay->location != NULL) g_free (pixbufoverlay->location);
- pixbufoverlay->pbuf_has_changed = TRUE;
- pixbufoverlay->location = g_value_dup_string (value);
- break;
+ case PROP_LOCATION:
+ if (pixbufoverlay->location != NULL)
+ g_free (pixbufoverlay->location);
+ pixbufoverlay->pbuf_has_changed = TRUE;
+ pixbufoverlay->location = g_value_dup_string (value);
+ break;
/* case PROP_STRETCH:
pixbufoverlay->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;
}
}
GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (object);
switch (prop_id) {
- case PROP_LOCATION:
- g_value_set_string (value, pixbufoverlay->location);
- break;
+ case PROP_LOCATION:
+ g_value_set_string (value, pixbufoverlay->location);
+ break;
/* case PROP_STRETCH:
g_value_set_boolean (value, pixbufoverlay->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_pixbufoverlay_init_resources (GstGLFilter* filter)
+gst_gl_pixbufoverlay_init_resources (GstGLFilter * filter)
{
// GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (filter);
}
static void
-gst_gl_pixbufoverlay_callback (gint width, gint height, guint texture, gpointer stuff)
+gst_gl_pixbufoverlay_callback (gint width, gint height, guint texture,
+ gpointer stuff)
{
- GstGLPixbufOverlay* pixbufoverlay = GST_GL_PIXBUFOVERLAY (stuff);
-
+ GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (stuff);
+
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gst_gl_pixbufoverlay_draw_texture (pixbufoverlay, texture);
}
-static void init_pixbuf_texture (GstGLDisplay *display, gpointer data)
+static void
+init_pixbuf_texture (GstGLDisplay * display, gpointer data)
{
GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (data);
-
+
glDeleteTextures (1, &pixbufoverlay->pbuftexture);
glGenTextures (1, &pixbufoverlay->pbuftexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixbufoverlay->pbuftexture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
- (gint)pixbufoverlay->width, (gint)pixbufoverlay->height, 0,
- gdk_pixbuf_get_has_alpha (pixbufoverlay->pixbuf) ? GL_RGBA : GL_RGB,
- GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (pixbufoverlay->pixbuf));
+ (gint) pixbufoverlay->width, (gint) pixbufoverlay->height, 0,
+ gdk_pixbuf_get_has_alpha (pixbufoverlay->pixbuf) ? GL_RGBA : GL_RGB,
+ GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (pixbufoverlay->pixbuf));
}
static gboolean
-gst_gl_pixbufoverlay_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
- GstGLBuffer* outbuf)
+gst_gl_pixbufoverlay_filter (GstGLFilter * filter, GstGLBuffer * inbuf,
+ GstGLBuffer * outbuf)
{
- GstGLPixbufOverlay* pixbufoverlay = GST_GL_PIXBUFOVERLAY(filter);
+ GstGLPixbufOverlay *pixbufoverlay = GST_GL_PIXBUFOVERLAY (filter);
GError *error = NULL;
if (pixbufoverlay->pbuf_has_changed && (pixbufoverlay->location != NULL)) {
- pixbufoverlay->pixbuf = gdk_pixbuf_new_from_file (pixbufoverlay->location, &error);
+ pixbufoverlay->pixbuf =
+ gdk_pixbuf_new_from_file (pixbufoverlay->location, &error);
if (pixbufoverlay->pixbuf != NULL) {
- pixbufoverlay->width = (gfloat) gdk_pixbuf_get_width (pixbufoverlay->pixbuf);
- pixbufoverlay->height = (gfloat) gdk_pixbuf_get_height (pixbufoverlay->pixbuf);
- gst_gl_display_thread_add (filter->display, init_pixbuf_texture, pixbufoverlay);
+ pixbufoverlay->width =
+ (gfloat) gdk_pixbuf_get_width (pixbufoverlay->pixbuf);
+ pixbufoverlay->height =
+ (gfloat) gdk_pixbuf_get_height (pixbufoverlay->pixbuf);
+ gst_gl_display_thread_add (filter->display, init_pixbuf_texture,
+ pixbufoverlay);
gdk_pixbuf_unref (pixbufoverlay->pixbuf);
} else {
- if (error != NULL && error->message != NULL)
- g_warning ("unable to load %s: %s", pixbufoverlay->location, error->message);
+ if (error != NULL && error->message != NULL)
+ g_warning ("unable to load %s: %s", pixbufoverlay->location,
+ error->message);
}
pixbufoverlay->pbuf_has_changed = FALSE;
}
-
+
gst_gl_filter_render_to_target (filter, inbuf->texture, outbuf->texture,
- gst_gl_pixbufoverlay_callback, pixbufoverlay);
+ gst_gl_pixbufoverlay_callback, pixbufoverlay);
return TRUE;
}
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}
- };
-
- 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 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;
}
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;
-
- 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->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));
-
- 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;
+ GObjectClass *gobject_class;
+ GstBaseSrcClass *gstbasesrc_class;
+ GstPushSrcClass *gstpushsrc_class;
+
+ 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->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));
+
+ 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;
}
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;
-
- 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 ();
- }
+ gltestsrc->pattern_type = 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 ();
+ }
}
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);
-
- 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;
- }
+ 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;
+ }
}
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);
-
- 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;
- }
+ 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;
+ }
}
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;
-
- 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;
+ 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;
+ }
+
+ 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);
-
- 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;
+ /* 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 (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;
+ }
+
+ src->running_time = next_time;
- *buffer = GST_BUFFER (outbuf);
+ *buffer = GST_BUFFER (outbuf);
- return GST_FLOW_OK;
+ return GST_FLOW_OK;
not_negotiated:
{
}
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);
}
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 =
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 ";"
/* Properties */
enum
{
- PROP_0
+ PROP_0
};
#define DEBUG_INIT(bla) \
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_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_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_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;
-
- 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;
+ 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;
+
+ 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);
-
- 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;
-
- gint count = 0, w = 0, h = 0;
-
- guint num, den;
-
- //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);
-
- //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);
+ 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");
+
+ //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;
+
+ guint num, den;
+
+ //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);
+
+ //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);
}
- 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);
- }
- }
+
+ 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_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
+ 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;
- GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
-
- GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
+ GstGLUpload *upload = GST_GL_UPLOAD (bt);
+ gboolean ret = FALSE;
+ GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
- ret = gst_video_format_parse_caps (outcaps, &video_format,
- &upload->gl_width, &upload->gl_height);
+ GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
- ret |= gst_video_format_parse_caps (incaps, &upload->video_format,
- &upload->video_width, &upload->video_height);
+ ret = gst_video_format_parse_caps (outcaps, &video_format,
+ &upload->gl_width, &upload->gl_height);
- if (!ret)
- {
- GST_DEBUG ("caps connot be parsed");
- return FALSE;
- }
+ ret |= gst_video_format_parse_caps (incaps, &upload->video_format,
+ &upload->video_width, &upload->video_height);
- //we have video and gl size, we can now init OpenGL stuffs
- upload->display = gst_gl_display_new ();
+ 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 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);
+ //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;
+ return ret;
}
static gboolean
-gst_gl_upload_get_unit_size (GstBaseTransform* trans, GstCaps* caps,
- guint* size)
+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;
+ 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);
- }
+ 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);
-
- 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;
+ 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));
+
+ //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;
}
}
#ifdef HAVE_GDKPIXBUF
if (!gst_element_register (plugin, "glpixbufoverlay",
- GST_RANK_NONE, gst_gl_pixbufoverlay_get_type())) {
+ GST_RANK_NONE, gst_gl_pixbufoverlay_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;
}
#endif
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;
}
#define W 320
#define H 240
-struct GstGLClutterActor_ {
+struct GstGLClutterActor_
+{
Window win;
Window root;
ClutterActor *texture;
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,
g_object_unref (effect_template);
g_object_unref (timeline);
- return FALSE;
+ return FALSE;
}
static GstBusSyncReply
// 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;
}
int
main (int argc, char *argv[])
{
- GstPipeline *pipeline;
- GstBus *bus;
+ GstPipeline *pipeline;
+ GstBus *bus;
ClutterActor *stage;
GstGLClutterActor *actor;
Display *disp;
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);
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));
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;
}
#define W 160
#define H 120
-struct GstGLClutterActor_ {
+struct GstGLClutterActor_
+{
Window win;
Window root;
ClutterActor *texture;
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;
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++;
}
#if 0
void
-apply_fx (GstElement *element, const gchar *fx)
+apply_fx (GstElement * element, const gchar * fx)
{
GEnumClass *p_class;
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];
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);
"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));
clutter_actor_show_all (stage);
- clutter_main();
+ clutter_main ();
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
g_object_unref (pipeline);
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
}
static void
-destroy_cb (GtkWidget *widget, GdkEvent *event, GstElement *pipeline)
+destroy_cb (GtkWidget * widget, GdkEvent * event, GstElement * pipeline)
{
g_message ("destroy callback");
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);
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;
}
}
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 ();
};
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");
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);
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;
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);
}
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 gstpixbufoverlay", "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 gstpixbufoverlay", "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);
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;
}
}
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 ();
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);