2009-04-18 11:57:44 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <GL/wglew.h>
|
|
|
|
#else
|
|
|
|
#include <GL/glxew.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GL/gl.h>
|
2012-11-04 08:15:05 +00:00
|
|
|
|
|
|
|
#define CLUTTER_VERSION_MIN_REQUIRED CLUTTER_VERSION_1_8
|
2009-04-18 11:57:44 +00:00
|
|
|
#include <clutter/clutter.h>
|
2009-04-18 14:08:23 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
#endif
|
2012-08-14 04:41:19 +00:00
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
#include <gst/gst.h>
|
2012-08-14 04:41:19 +00:00
|
|
|
#include <gst/video/video.h>
|
2012-09-25 09:26:17 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
#include <gst/gl/gstglmemory.h>
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
/* This example shows how to use textures that come from a
|
|
|
|
* gst-plugins-gl pipeline, into the clutter framework
|
2009-05-08 19:43:56 +00:00
|
|
|
* It requires at least clutter 0.8.6
|
2009-04-18 11:57:44 +00:00
|
|
|
*/
|
|
|
|
|
2009-05-08 19:43:56 +00:00
|
|
|
/* rotation */
|
|
|
|
void
|
2011-11-16 15:53:25 +00:00
|
|
|
on_new_frame (ClutterTimeline * timeline, gint msecs, gpointer data)
|
2009-05-08 19:43:56 +00:00
|
|
|
{
|
|
|
|
ClutterActor *rect_actor = CLUTTER_ACTOR (data);
|
|
|
|
ClutterActor *texture_actor =
|
|
|
|
g_object_get_data (G_OBJECT (timeline), "texture_actor");
|
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
clutter_actor_set_rotation (rect_actor, CLUTTER_Z_AXIS,
|
|
|
|
60.0 * (gdouble) msecs / 1000.0, clutter_actor_get_width (rect_actor) / 2,
|
2009-05-08 19:43:56 +00:00
|
|
|
clutter_actor_get_height (rect_actor) / 2, 0);
|
|
|
|
|
|
|
|
clutter_actor_set_rotation (texture_actor, CLUTTER_Z_AXIS,
|
2011-11-16 15:53:25 +00:00
|
|
|
60.0 * (gdouble) msecs / 1000.0,
|
|
|
|
clutter_actor_get_width (texture_actor) / 6,
|
2009-05-11 16:06:18 +00:00
|
|
|
clutter_actor_get_height (texture_actor) / 6, 0);
|
2009-05-08 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
/* clutter scene */
|
2009-04-18 14:08:23 +00:00
|
|
|
ClutterActor *
|
2009-04-18 11:57:44 +00:00
|
|
|
setup_stage (ClutterStage * stage)
|
|
|
|
{
|
2009-04-18 14:08:23 +00:00
|
|
|
ClutterTimeline *timeline = NULL;
|
|
|
|
ClutterActor *texture_actor = NULL;
|
|
|
|
ClutterColor rect_color = { 125, 50, 200, 255 };
|
2009-05-08 19:43:56 +00:00
|
|
|
ClutterActor *rect_actor = NULL;
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
/* texture actor */
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
texture_actor = clutter_texture_new ();
|
2009-04-18 11:57:44 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture_actor);
|
|
|
|
clutter_actor_set_position (texture_actor, 300, 170);
|
2009-05-08 19:43:56 +00:00
|
|
|
clutter_actor_set_scale (texture_actor, 0.6, 0.6);
|
2009-04-18 11:57:44 +00:00
|
|
|
clutter_actor_show (texture_actor);
|
|
|
|
g_object_set_data (G_OBJECT (texture_actor), "stage", stage);
|
|
|
|
|
|
|
|
/* rectangle actor */
|
|
|
|
|
2009-05-08 19:43:56 +00:00
|
|
|
rect_actor = clutter_rectangle_new_with_color (&rect_color);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect_actor);
|
|
|
|
clutter_actor_set_size (rect_actor, 50, 50);
|
|
|
|
clutter_actor_set_position (rect_actor, 300, 300);
|
|
|
|
clutter_actor_show (rect_actor);
|
|
|
|
|
|
|
|
/* timeline */
|
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
timeline = clutter_timeline_new (6000);
|
2009-05-08 19:43:56 +00:00
|
|
|
g_object_set_data (G_OBJECT (timeline), "texture_actor", texture_actor);
|
|
|
|
clutter_timeline_set_loop (timeline, TRUE);
|
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
g_signal_connect (timeline, "new-frame", G_CALLBACK (on_new_frame),
|
|
|
|
rect_actor);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
return texture_actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put a gst gl buffer in the texture actor */
|
|
|
|
gboolean
|
|
|
|
update_texture_actor (gpointer data)
|
|
|
|
{
|
2009-05-02 12:27:23 +00:00
|
|
|
ClutterTexture *texture_actor = (ClutterTexture *) data;
|
2009-05-09 18:51:36 +00:00
|
|
|
GAsyncQueue *queue_input_buf =
|
2009-05-08 19:43:56 +00:00
|
|
|
g_object_get_data (G_OBJECT (texture_actor), "queue_input_buf");
|
2009-05-09 18:51:36 +00:00
|
|
|
GAsyncQueue *queue_output_buf =
|
2009-05-08 19:43:56 +00:00
|
|
|
g_object_get_data (G_OBJECT (texture_actor), "queue_output_buf");
|
2012-08-14 04:41:19 +00:00
|
|
|
GstBuffer *inbuf = g_async_queue_pop (queue_input_buf);
|
2009-05-02 12:27:23 +00:00
|
|
|
ClutterActor *stage = g_object_get_data (G_OBJECT (texture_actor), "stage");
|
2009-04-18 14:08:23 +00:00
|
|
|
CoglHandle cogl_texture = 0;
|
2012-08-14 04:41:19 +00:00
|
|
|
GstVideoMeta *v_meta;
|
2012-09-25 09:26:17 +00:00
|
|
|
GstVideoInfo info;
|
|
|
|
GstVideoFrame frame;
|
|
|
|
guint tex_id;
|
2012-08-14 04:41:19 +00:00
|
|
|
|
|
|
|
v_meta = gst_buffer_get_video_meta (inbuf);
|
2012-09-25 09:26:17 +00:00
|
|
|
if (!v_meta) {
|
2012-08-14 04:41:19 +00:00
|
|
|
g_warning ("Required Meta was not found on buffers");
|
2012-09-25 09:26:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_info_set_format (&info, v_meta->format, v_meta->width,
|
|
|
|
v_meta->height);
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&frame, &info, inbuf, GST_MAP_READ | GST_MAP_GL)) {
|
|
|
|
g_warning ("Failed to map video frame");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_is_gl_memory (frame.map[0].memory)) {
|
|
|
|
g_warning ("Input buffer does not have GLMemory");
|
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex_id = *(guint *) frame.data[0];
|
2009-04-18 14:08:23 +00:00
|
|
|
|
|
|
|
/* Create a cogl texture from the gst gl texture */
|
2009-05-08 19:43:56 +00:00
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
2012-09-25 09:26:17 +00:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex_id);
|
2009-05-08 19:43:56 +00:00
|
|
|
if (glGetError () != GL_NO_ERROR)
|
|
|
|
g_debug ("failed to bind texture that comes from gst-gl\n");
|
2012-09-25 09:26:17 +00:00
|
|
|
cogl_texture = cogl_texture_new_from_foreign (tex_id,
|
2012-08-14 04:41:19 +00:00
|
|
|
GL_TEXTURE_RECTANGLE_ARB, v_meta->width, v_meta->height, 0, 0,
|
2009-04-18 14:08:23 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888);
|
2009-05-08 19:43:56 +00:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2012-09-25 09:26:17 +00:00
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
/* 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
|
|
|
|
* ref counter of the previous cogl texture is reaching 0 because is_foreign is TRUE */
|
2009-05-08 19:43:56 +00:00
|
|
|
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_actor),
|
|
|
|
cogl_texture);
|
2011-11-16 15:53:25 +00:00
|
|
|
cogl_handle_unref (cogl_texture);
|
2009-04-18 14:08:23 +00:00
|
|
|
|
|
|
|
/* we can now show the clutter scene if not yet visible */
|
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (stage))
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
/* push buffer so it can be unref later */
|
2012-08-14 04:41:19 +00:00
|
|
|
g_async_queue_push (queue_output_buf, inbuf);
|
2009-05-02 12:27:23 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
return FALSE;
|
2009-04-18 11:57:44 +00:00
|
|
|
}
|
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
/* fakesink handoff callback */
|
|
|
|
void
|
2009-04-18 14:08:23 +00:00
|
|
|
on_gst_buffer (GstElement * element, GstBuffer * buf, GstPad * pad,
|
|
|
|
ClutterActor * texture_actor)
|
2009-04-18 11:57:44 +00:00
|
|
|
{
|
2009-05-09 18:51:36 +00:00
|
|
|
GAsyncQueue *queue_input_buf = NULL;
|
|
|
|
GAsyncQueue *queue_output_buf = NULL;
|
2009-04-30 21:40:38 +00:00
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
/* ref then push buffer to use it in clutter */
|
2009-04-18 14:08:23 +00:00
|
|
|
gst_buffer_ref (buf);
|
2009-05-08 19:43:56 +00:00
|
|
|
queue_input_buf =
|
|
|
|
g_object_get_data (G_OBJECT (texture_actor), "queue_input_buf");
|
2009-05-09 18:51:36 +00:00
|
|
|
g_async_queue_push (queue_input_buf, buf);
|
|
|
|
if (g_async_queue_length (queue_input_buf) > 2)
|
|
|
|
clutter_threads_add_idle_full (G_PRIORITY_HIGH, update_texture_actor,
|
|
|
|
texture_actor, NULL);
|
2009-05-02 12:27:23 +00:00
|
|
|
|
|
|
|
/* pop then unref buffer we have finished to use in clutter */
|
2009-05-08 19:43:56 +00:00
|
|
|
queue_output_buf =
|
|
|
|
g_object_get_data (G_OBJECT (texture_actor), "queue_output_buf");
|
2009-05-09 18:51:36 +00:00
|
|
|
if (g_async_queue_length (queue_output_buf) > 2) {
|
|
|
|
GstBuffer *buf_old = g_async_queue_pop (queue_output_buf);
|
|
|
|
gst_buffer_unref (buf_old);
|
2009-05-08 19:43:56 +00:00
|
|
|
}
|
2009-04-18 11:57:44 +00:00
|
|
|
}
|
|
|
|
|
2009-05-09 19:26:42 +00:00
|
|
|
/* gst bus signal watch callback */
|
|
|
|
void
|
|
|
|
end_stream_cb (GstBus * bus, GstMessage * msg, gpointer data)
|
|
|
|
{
|
|
|
|
switch (GST_MESSAGE_TYPE (msg)) {
|
|
|
|
|
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
g_print ("End-of-stream\n");
|
|
|
|
g_print
|
|
|
|
("For more information, try to run: GST_DEBUG=gldisplay:2 ./cluttershare\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
{
|
|
|
|
gchar *debug = NULL;
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
gst_message_parse_error (msg, &err, &debug);
|
|
|
|
|
|
|
|
g_print ("Error: %s\n", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
g_print ("Debug deails: %s\n", debug);
|
|
|
|
g_free (debug);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2011-11-16 15:53:25 +00:00
|
|
|
ClutterInitError clutter_err = CLUTTER_INIT_ERROR_UNKNOWN;
|
2009-04-18 14:08:23 +00:00
|
|
|
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;
|
2009-05-09 19:26:42 +00:00
|
|
|
GstBus *bus = NULL;
|
2009-11-17 22:47:24 +00:00
|
|
|
GstElement *glfilter = NULL;
|
2009-04-18 14:08:23 +00:00
|
|
|
GstState state = 0;
|
|
|
|
ClutterActor *stage = NULL;
|
|
|
|
ClutterActor *clutter_texture = NULL;
|
2009-05-09 18:51:36 +00:00
|
|
|
GAsyncQueue *queue_input_buf = NULL;
|
|
|
|
GAsyncQueue *queue_output_buf = NULL;
|
2009-04-18 14:08:23 +00:00
|
|
|
GstElement *fakesink = NULL;
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-30 21:40:38 +00:00
|
|
|
/* init gstreamer then clutter */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-05-08 19:43:56 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
clutter_threads_init ();
|
2011-11-16 15:53:25 +00:00
|
|
|
clutter_err = clutter_init (&argc, &argv);
|
|
|
|
if (clutter_err != CLUTTER_INIT_SUCCESS)
|
|
|
|
g_warning ("Failed to initalize clutter: %d\n", clutter_err);
|
2009-04-30 21:40:38 +00:00
|
|
|
clutter_threads_enter ();
|
2009-05-08 19:43:56 +00:00
|
|
|
g_print ("clutter version: %s\n", CLUTTER_VERSION_S);
|
2011-11-16 15:53:25 +00:00
|
|
|
clutter_set_default_frame_rate (2);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
/* init glew */
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
err = glewInit ();
|
2009-04-18 11:57:44 +00:00
|
|
|
if (err != GLEW_OK)
|
|
|
|
g_debug ("failed to init GLEW: %s", glewGetErrorString (err));
|
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
/* avoid to dispatch unecesary events */
|
|
|
|
|
|
|
|
clutter_ungrab_keyboard ();
|
|
|
|
clutter_ungrab_pointer ();
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* retrieve and turn off clutter opengl context */
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
/* retrieve and turn off clutter opengl context */
|
2009-04-30 21:40:38 +00:00
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
#ifdef WIN32
|
2009-04-18 14:08:23 +00:00
|
|
|
clutter_gl_context = wglGetCurrentContext ();
|
|
|
|
clutter_dc = wglGetCurrentDC ();
|
|
|
|
wglMakeCurrent (0, 0);
|
2009-04-18 11:57:44 +00:00
|
|
|
#else
|
2009-04-18 14:08:23 +00:00
|
|
|
clutter_display = clutter_x11_get_default_display ();
|
|
|
|
clutter_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
|
|
|
|
clutter_gl_context = glXGetCurrentContext ();
|
|
|
|
glXMakeCurrent (clutter_display, None, 0);
|
2009-04-18 11:57:44 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* setup gstreamer pipeline */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
pipeline =
|
2009-04-18 11:57:44 +00:00
|
|
|
GST_PIPELINE (gst_parse_launch
|
2012-06-06 14:51:47 +00:00
|
|
|
("videotestsrc ! video/x-raw, width=320, height=240, framerate=(fraction)30/1 ! "
|
2009-05-09 19:30:30 +00:00
|
|
|
"glupload ! gleffects effect=5 ! glfiltercube ! fakesink sync=1",
|
|
|
|
NULL));
|
2009-04-18 14:08:23 +00:00
|
|
|
|
2009-05-09 19:26:42 +00:00
|
|
|
/* setup bus */
|
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message::error", G_CALLBACK (end_stream_cb), NULL);
|
|
|
|
g_signal_connect (bus, "message::warning", G_CALLBACK (end_stream_cb), NULL);
|
|
|
|
g_signal_connect (bus, "message::eos", G_CALLBACK (end_stream_cb), NULL);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* clutter_gl_context is an external OpenGL context with which gst-plugins-gl want to share textures */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
glfilter = gst_bin_get_by_name (GST_BIN (pipeline), "glfiltercube0");
|
2009-11-17 22:47:24 +00:00
|
|
|
g_object_set (G_OBJECT (glfilter), "external-opengl-context",
|
2009-04-20 21:48:15 +00:00
|
|
|
clutter_gl_context, NULL);
|
2009-11-17 22:47:24 +00:00
|
|
|
g_object_unref (glfilter);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-05-02 12:27:23 +00:00
|
|
|
/* NULL to PAUSED state pipeline to make sure the gst opengl context is created and
|
|
|
|
* shared with the clutter one */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-30 21:40:38 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
|
|
|
state = GST_STATE_PAUSED;
|
2009-04-18 14:08:23 +00:00
|
|
|
if (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
|
|
|
|
GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) {
|
2009-04-30 21:40:38 +00:00
|
|
|
g_debug ("failed to pause pipeline\n");
|
2009-04-18 14:08:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* turn on back clutter opengl context */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2009-04-18 14:08:23 +00:00
|
|
|
wglMakeCurrent (clutter_dc, clutter_gl_context);
|
2009-04-18 11:57:44 +00:00
|
|
|
#else
|
2009-04-18 14:08:23 +00:00
|
|
|
glXMakeCurrent (clutter_display, clutter_win, clutter_gl_context);
|
2009-04-18 11:57:44 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* clutter stage */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
clutter_actor_set_size (stage, 640, 480);
|
|
|
|
clutter_actor_set_position (stage, 0, 0);
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "clutter and gst-plugins-gl");
|
|
|
|
clutter_texture = setup_stage (CLUTTER_STAGE (stage));
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-30 21:40:38 +00:00
|
|
|
/* append a gst-gl texture to this queue when you do not need it no more */
|
|
|
|
|
2009-05-09 18:51:36 +00:00
|
|
|
queue_input_buf = g_async_queue_new ();
|
|
|
|
queue_output_buf = g_async_queue_new ();
|
2009-05-08 19:43:56 +00:00
|
|
|
g_object_set_data (G_OBJECT (clutter_texture), "queue_input_buf",
|
|
|
|
queue_input_buf);
|
|
|
|
g_object_set_data (G_OBJECT (clutter_texture), "queue_output_buf",
|
|
|
|
queue_output_buf);
|
2009-04-30 21:40:38 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* set a callback to retrieve the gst gl textures */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
fakesink = gst_bin_get_by_name (GST_BIN (pipeline), "fakesink0");
|
|
|
|
g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
|
|
|
|
g_signal_connect (fakesink, "handoff", G_CALLBACK (on_gst_buffer),
|
|
|
|
clutter_texture);
|
|
|
|
g_object_unref (fakesink);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2009-04-30 21:40:38 +00:00
|
|
|
/* play gst */
|
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
|
2009-04-18 14:08:23 +00:00
|
|
|
/* main loop */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-04-30 21:40:38 +00:00
|
|
|
/* before to deinitialize the gst-gl-opengl context,
|
|
|
|
* no shared context (here the clutter one) must be current
|
|
|
|
*/
|
|
|
|
#ifdef WIN32
|
|
|
|
wglMakeCurrent (0, 0);
|
|
|
|
#else
|
|
|
|
glXMakeCurrent (clutter_display, None, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
clutter_threads_leave ();
|
|
|
|
|
2009-05-09 13:44:09 +00:00
|
|
|
/* stop and clean up the pipeline */
|
2009-04-18 11:57:44 +00:00
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
|
|
|
g_object_unref (pipeline);
|
|
|
|
|
2009-11-17 22:47:24 +00:00
|
|
|
/* make sure there is no pending gst gl buffer in the communication queues
|
2009-05-09 13:44:09 +00:00
|
|
|
* between clutter and gst-gl
|
|
|
|
*/
|
|
|
|
|
2009-05-09 18:51:36 +00:00
|
|
|
while (g_async_queue_length (queue_input_buf) > 0) {
|
|
|
|
GstBuffer *buf = g_async_queue_pop (queue_input_buf);
|
2009-05-09 13:44:09 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
2009-05-09 18:51:36 +00:00
|
|
|
while (g_async_queue_length (queue_output_buf) > 0) {
|
|
|
|
GstBuffer *buf = g_async_queue_pop (queue_output_buf);
|
2009-05-09 13:44:09 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
g_print ("END\n");
|
|
|
|
|
2009-04-18 11:57:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|