[332/906] just gst-indent and C90 on cluttershare example

This commit is contained in:
Julien Isorce 2009-04-18 16:08:23 +02:00 committed by Matthew Waters
parent f735c06c4a
commit 80e114860e

View file

@ -27,6 +27,9 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <clutter/clutter.h> #include <clutter/clutter.h>
#ifndef WIN32
#include <clutter/x11/clutter-x11.h>
#endif
#include <gst/gst.h> #include <gst/gst.h>
/* This example shows how to use textures that come from a /* This example shows how to use textures that come from a
@ -35,41 +38,46 @@
/* hack */ /* hack */
typedef struct _GstGLBuffer GstGLBuffer; typedef struct _GstGLBuffer GstGLBuffer;
struct _GstGLBuffer { struct _GstGLBuffer
GstBuffer buffer; {
GstBuffer buffer;
GObject *obj; GObject *obj;
gint width; gint width;
gint height; gint height;
GLuint texture; GLuint texture;
}; };
/* clutter scene */ /* clutter scene */
ClutterActor* ClutterActor *
setup_stage (ClutterStage * stage) setup_stage (ClutterStage * stage)
{ {
ClutterTimeline *timeline = NULL;
ClutterEffectTemplate *effect_template = NULL;
ClutterActor *texture_actor = NULL;
ClutterColor rect_color = { 125, 50, 200, 255 };
ClutterActor *actorRect = NULL;
/* timeline */ /* timeline */
ClutterTimeline *timeline = clutter_timeline_new (120, 50); timeline = clutter_timeline_new (120, 50);
clutter_timeline_set_loop (timeline, TRUE); clutter_timeline_set_loop (timeline, TRUE);
clutter_timeline_start (timeline); clutter_timeline_start (timeline);
/* effect template */ /* effect template */
ClutterEffectTemplate *effect_template = clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC); effect_template =
clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC);
/* texture actor */ /* texture actor */
ClutterActor *texture_actor = clutter_texture_new (); texture_actor = clutter_texture_new ();
clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture_actor); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture_actor);
clutter_actor_set_position (texture_actor, 300, 170); clutter_actor_set_position (texture_actor, 300, 170);
clutter_actor_set_scale (texture_actor, 0.8, 0.8); clutter_actor_set_scale (texture_actor, 0.8, 0.8);
clutter_effect_rotate (effect_template, texture_actor, clutter_effect_rotate (effect_template, texture_actor,
CLUTTER_Z_AXIS, 180.0, CLUTTER_Z_AXIS, 180.0, 50, 50, 0, CLUTTER_ROTATE_CW, NULL, NULL);
50, 50, 0,
CLUTTER_ROTATE_CW,
NULL, NULL);
clutter_actor_show (texture_actor); clutter_actor_show (texture_actor);
g_object_set_data (G_OBJECT (texture_actor), "stage", stage); g_object_set_data (G_OBJECT (texture_actor), "stage", stage);
@ -78,16 +86,12 @@ setup_stage (ClutterStage * stage)
/* rectangle actor */ /* rectangle actor */
ClutterColor rect_color = { 125, 50, 200, 255 }; actorRect = clutter_rectangle_new_with_color (&rect_color);
ClutterActor* actorRect = clutter_rectangle_new_with_color (&rect_color);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actorRect); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actorRect);
clutter_actor_set_size (actorRect, 50, 50); clutter_actor_set_size (actorRect, 50, 50);
clutter_actor_set_position (actorRect, 300, 300); clutter_actor_set_position (actorRect, 300, 300);
clutter_effect_rotate (effect_template, actorRect, clutter_effect_rotate (effect_template, actorRect,
CLUTTER_Z_AXIS, 180.0, CLUTTER_Z_AXIS, 180.0, 25, 25, 0, CLUTTER_ROTATE_CW, NULL, NULL);
25, 25, 0,
CLUTTER_ROTATE_CW,
NULL, NULL);
clutter_actor_show (actorRect); clutter_actor_show (actorRect);
return texture_actor; return texture_actor;
@ -97,58 +101,82 @@ setup_stage (ClutterStage * stage)
gboolean gboolean
update_texture_actor (gpointer data) update_texture_actor (gpointer data)
{ {
GstGLBuffer *gst_gl_buf = (GstGLBuffer *) data; GstGLBuffer *gst_gl_buf = (GstGLBuffer *) data;
CoglHandle cogl_texture = 0;
ClutterTexture *texture_actor = NULL;
ClutterActor *stage = NULL;
/* Create a cogl texture from the gst gl texture */ /* Create a cogl texture from the gst gl texture */
glEnable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, gst_gl_buf->texture); glBindTexture (GL_TEXTURE_2D, gst_gl_buf->texture);
CoglHandle cogl_texture = cogl_texture_new_from_foreign (gst_gl_buf->texture, cogl_texture = cogl_texture_new_from_foreign (gst_gl_buf->texture,
GL_TEXTURE_2D, gst_gl_buf->width, gst_gl_buf->height, 0, 0, COGL_PIXEL_FORMAT_RGBA_8888); GL_TEXTURE_2D, gst_gl_buf->width, gst_gl_buf->height, 0, 0,
cogl_texture_set_filters (cogl_texture, GL_LINEAR, GL_LINEAR); COGL_PIXEL_FORMAT_RGBA_8888);
glDisable (GL_TEXTURE_2D); cogl_texture_set_filters (cogl_texture, GL_LINEAR, GL_LINEAR);
glDisable (GL_TEXTURE_2D);
/* Previous cogl texture is replaced and so its ref counter discreases to 0. /* Previous cogl texture is replaced and so its ref counter discreases to 0.
* According to the source code, glDeleteTexture is not called when the previous * According to the source code, glDeleteTexture is not called when the previous
* ref counter of the previous cogl texture is reaching 0 because is_foreign is TRUE */ * ref counter of the previous cogl texture is reaching 0 because is_foreign is TRUE */
ClutterTexture *texture_actor = g_type_get_qdata (G_TYPE_FROM_INSTANCE (gst_gl_buf), g_quark_from_string ("texture_actor")); texture_actor =
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_actor), cogl_texture); g_type_get_qdata (G_TYPE_FROM_INSTANCE (gst_gl_buf),
cogl_texture_unref (cogl_texture); g_quark_from_string ("texture_actor"));
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_actor),
cogl_texture);
cogl_texture_unref (cogl_texture);
/* Keep a ref on the current gst_gl_buffer associated to the texture_actor. /* Keep a ref on the current gst_gl_buffer associated to the texture_actor.
* The old gst_gl_buffer is unref */ * The old gst_gl_buffer is unref */
g_object_set_data_full (G_OBJECT (texture_actor), "gst_gl_buffer", g_object_set_data_full (G_OBJECT (texture_actor), "gst_gl_buffer",
gst_gl_buf, (GDestroyNotify) gst_mini_object_unref); gst_gl_buf, (GDestroyNotify) gst_mini_object_unref);
/* we can now show the clutter scene if not yet visible */ /* we can now show the clutter scene if not yet visible */
ClutterActor *stage = g_object_get_data (G_OBJECT (texture_actor), "stage"); stage = g_object_get_data (G_OBJECT (texture_actor), "stage");
if (!CLUTTER_ACTOR_IS_VISIBLE (stage)) if (!CLUTTER_ACTOR_IS_VISIBLE (stage))
clutter_actor_show_all (stage); clutter_actor_show_all (stage);
return FALSE; return FALSE;
} }
/* fakesink handoff callback */ /* fakesink handoff callback */
void void
on_gst_buffer (GstElement* element, GstBuffer* buf, GstPad* pad, ClutterActor* texture_actor) on_gst_buffer (GstElement * element, GstBuffer * buf, GstPad * pad,
ClutterActor * texture_actor)
{ {
/* increase ref because our pipeline and clutter scene have not a same framerate */ /* increase ref because our pipeline and clutter scene have not a same framerate */
gst_buffer_ref (buf); gst_buffer_ref (buf);
/* Just to avoid a global variable of texture_actor /* Just to avoid a global variable of texture_actor
* Texture_actor is not null because callback connection is set after the * Texture_actor is not null because callback connection is set after the
* texture_actor was being setted up */ * texture_actor was being setted up */
g_assert (texture_actor); g_assert (texture_actor);
g_type_set_qdata (G_TYPE_FROM_INSTANCE (buf), g_quark_from_string ("texture_actor"), texture_actor); g_type_set_qdata (G_TYPE_FROM_INSTANCE (buf),
g_quark_from_string ("texture_actor"), texture_actor);
/* Here we are in the pipeline thread. It means that this thread may be /* Here we are in the pipeline thread. It means that this thread may be
* not the same as the clutter thread * not the same as the clutter thread
* make sure that the texture actor is updated in the clutter thread */ * make sure that the texture actor is updated in the clutter thread */
clutter_threads_add_idle (update_texture_actor, buf); clutter_threads_add_idle (update_texture_actor, buf);
} }
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
GLenum err = 0;
#ifdef WIN32
HGLRC clutter_gl_context = 0;
HDC clutter_dc = 0;
#else
Display *clutter_display = NULL;
Window clutter_win = 0;
GLXContext clutter_gl_context = NULL;
#endif
GstPipeline *pipeline = NULL;
GstElement *glupload = NULL;
GstState state = 0;
ClutterActor *stage = NULL;
ClutterActor *clutter_texture = NULL;
GstElement *fakesink = NULL;
/* init clutter then gstreamer */ /* init clutter then gstreamer */
@ -157,69 +185,73 @@ main (int argc, char *argv[])
/* init glew */ /* init glew */
GLenum err = glewInit (); err = glewInit ();
if (err != GLEW_OK) if (err != GLEW_OK)
g_debug ("failed to init GLEW: %s", glewGetErrorString (err)); g_debug ("failed to init GLEW: %s", glewGetErrorString (err));
/* retrieve and turn off clutter opengl context */ /* retrieve and turn off clutter opengl context */
stage = clutter_stage_get_default ();
#ifdef WIN32 #ifdef WIN32
HGLRC clutter_gl_context = wglGetCurrentContext (); clutter_gl_context = wglGetCurrentContext ();
HDC clutter_dc = wglGetCurrentDC (); clutter_dc = wglGetCurrentDC ();
wglMakeCurrent (0, 0); wglMakeCurrent (0, 0);
#else #else
Display *clutter_display = clutter_x11_get_default_display (); clutter_display = clutter_x11_get_default_display ();
Window clutter_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); clutter_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
GLXContext clutter_gl_context = glXGetCurrentContext (); clutter_gl_context = glXGetCurrentContext ();
glXMakeCurrent (clutter_display, None, 0); glXMakeCurrent (clutter_display, None, 0);
#endif #endif
/* setup gstreamer pipeline */ /* setup gstreamer pipeline */
GstPipeline *pipeline = pipeline =
GST_PIPELINE (gst_parse_launch GST_PIPELINE (gst_parse_launch
("videotestsrc ! video/x-raw-rgb, bpp=32, depth=32, width=320, height=240, framerate=(fraction)30/1 ! " ("videotestsrc ! video/x-raw-rgb, bpp=32, depth=32, width=320, height=240, framerate=(fraction)30/1 ! "
"glupload ! fakesink sync=1", NULL)); "glupload ! fakesink sync=1", NULL));
/* clutter_gl_context is an external OpenGL context with which gst-plugins-gl want to share textures */ /* clutter_gl_context is an external OpenGL context with which gst-plugins-gl want to share textures */
GstElement *glupload = gst_bin_get_by_name (GST_BIN (pipeline), "glupload0");
g_object_set (G_OBJECT (glupload), "external-opengl-context", (guint64) GPOINTER_TO_UINT (clutter_gl_context), NULL); glupload = gst_bin_get_by_name (GST_BIN (pipeline), "glupload0");
g_object_unref (glupload); g_object_set (G_OBJECT (glupload), "external-opengl-context",
(guint64) GPOINTER_TO_UINT (clutter_gl_context), NULL);
g_object_unref (glupload);
/* play pipeline */ /* play pipeline */
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
GstState state = GST_STATE_PLAYING; state = GST_STATE_PLAYING;
if (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) if (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
{ GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) {
g_debug ("failed to play pipeline\n"); g_debug ("failed to play pipeline\n");
return -1; return -1;
} }
/* turn on back clutter opengl context */ /* turn on back clutter opengl context */
#ifdef WIN32 #ifdef WIN32
wglMakeCurrent (clutter_dc, clutter_gl_context); wglMakeCurrent (clutter_dc, clutter_gl_context);
#else #else
glXMakeCurrent (clutter_display, clutter_win, clutter_gl_context); glXMakeCurrent (clutter_display, clutter_win, clutter_gl_context);
#endif #endif
/* clutter stage */ /* clutter stage */
ClutterActor* stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 640, 480);
clutter_actor_set_size (stage, 640, 480); clutter_actor_set_position (stage, 0, 0);
clutter_actor_set_position (stage, 0, 0); clutter_stage_set_title (CLUTTER_STAGE (stage), "clutter and gst-plugins-gl");
clutter_stage_set_title (CLUTTER_STAGE (stage), "clutter and gst-plugins-gl"); clutter_texture = setup_stage (CLUTTER_STAGE (stage));
ClutterActor *clutter_texture = setup_stage (CLUTTER_STAGE (stage));
/* set a callback to retrieve the gst gl textures */ /* set a callback to retrieve the gst gl textures */
GstElement *fakesink = gst_bin_get_by_name (GST_BIN (pipeline), "fakesink0"); fakesink = gst_bin_get_by_name (GST_BIN (pipeline), "fakesink0");
g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL); g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
g_signal_connect (fakesink, "handoff", G_CALLBACK (on_gst_buffer), clutter_texture); g_signal_connect (fakesink, "handoff", G_CALLBACK (on_gst_buffer),
g_object_unref (fakesink); clutter_texture);
g_object_unref (fakesink);
/* main loop */ /* main loop */
clutter_main (); clutter_main ();