2008-08-18 08:50:37 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-08-18 08:50:37 +00:00
|
|
|
*/
|
2013-07-10 09:24:34 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2008-08-18 08:50:37 +00:00
|
|
|
|
2012-11-04 08:15:05 +00:00
|
|
|
#define CLUTTER_VERSION_MIN_REQUIRED CLUTTER_VERSION_1_8
|
2008-08-18 08:50:37 +00:00
|
|
|
|
2008-08-17 15:45:52 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
#include <clutter/glx/clutter-glx.h>
|
|
|
|
#include <gst/gst.h>
|
2012-06-06 14:51:47 +00:00
|
|
|
#include <gst/video/videooverlay.h>
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
#define W 320
|
|
|
|
#define H 240
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
struct GstGLClutterActor_
|
|
|
|
{
|
2008-08-17 15:45:52 +00:00
|
|
|
Window win;
|
|
|
|
Window root;
|
|
|
|
ClutterActor *texture;
|
|
|
|
ClutterActor *stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct GstGLClutterActor_ GstGLClutterActor;
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-11 06:39:14 +00:00
|
|
|
create_actor (GstGLClutterActor * actor)
|
|
|
|
{
|
2011-11-16 15:53:25 +00:00
|
|
|
//ClutterKnot knot[2];
|
|
|
|
//ClutterTimeline *timeline;
|
|
|
|
ClutterAnimation *animation = NULL;
|
2008-08-17 15:45:52 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
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);
|
2008-08-17 15:45:52 +00:00
|
|
|
clutter_actor_set_opacity (actor->texture, 0);
|
2009-02-11 06:39:14 +00:00
|
|
|
clutter_actor_show (actor->texture);
|
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
//timeline =
|
|
|
|
// clutter_timeline_new (120 /* frames */ , 50 /* frames per second. */ );
|
|
|
|
//clutter_timeline_set_loop (timeline, TRUE);
|
|
|
|
//clutter_timeline_start (timeline);
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
/* Instead of our custom callback,
|
|
|
|
* we could use a standard callback. For instance, CLUTTER_ALPHA_SINE_INC.
|
|
|
|
*/
|
2011-11-16 15:53:25 +00:00
|
|
|
/*effect_template =
|
|
|
|
clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC); */
|
|
|
|
animation =
|
|
|
|
clutter_actor_animate (actor->texture, CLUTTER_LINEAR, 2400,
|
|
|
|
"x", 100.0, "y", 100.0, "opacity", 0, NULL);
|
|
|
|
|
|
|
|
/* knot[0].x = -10;
|
|
|
|
knot[0].y = -10;
|
|
|
|
knot[1].x = 160;
|
2011-11-17 10:34:20 +00:00
|
|
|
knot[1].y = 120; */
|
2011-11-16 15:53:25 +00:00
|
|
|
|
2011-11-17 10:34:20 +00:00
|
|
|
// Move the actor along the path:
|
|
|
|
/* clutter_effect_path (effect_template, actor->texture, knot,
|
2011-11-16 15:53:25 +00:00
|
|
|
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); */
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
// Also change the actor's opacity while moving it along the path:
|
|
|
|
// (You would probably want to use a different ClutterEffectTemplate,
|
|
|
|
// so you could use a different alpha callback for this.)
|
2011-11-16 15:53:25 +00:00
|
|
|
//clutter_effect_fade (effect_template, actor->texture, 255, NULL, NULL);
|
2008-08-17 15:45:52 +00:00
|
|
|
|
2011-11-16 15:53:25 +00:00
|
|
|
g_object_unref (animation);
|
|
|
|
//g_object_unref (timeline);
|
2008-08-17 15:45:52 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
return FALSE;
|
2008-08-17 15:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstBusSyncReply
|
|
|
|
create_window (GstBus * bus, GstMessage * message, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLClutterActor *actor = (GstGLClutterActor *) data;
|
2012-06-06 14:51:47 +00:00
|
|
|
// ignore anything but 'prepare-window-handle' element messages
|
2008-08-17 15:45:52 +00:00
|
|
|
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
|
|
|
|
return GST_BUS_PASS;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-06-06 14:51:47 +00:00
|
|
|
if (!gst_is_video_overlay_prepare_window_handle_message (message))
|
2008-08-17 15:45:52 +00:00
|
|
|
return GST_BUS_PASS;
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2008-08-17 15:45:52 +00:00
|
|
|
g_debug ("CREATING WINDOW");
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-06-06 14:51:47 +00:00
|
|
|
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC
|
|
|
|
(message)), actor->win);
|
2008-08-17 15:45:52 +00:00
|
|
|
clutter_threads_add_idle ((GSourceFunc) create_actor, actor);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2008-08-17 15:45:52 +00:00
|
|
|
gst_message_unref (message);
|
|
|
|
return GST_BUS_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
GstPipeline *pipeline;
|
|
|
|
GstBus *bus;
|
2008-08-17 15:45:52 +00:00
|
|
|
ClutterActor *stage;
|
|
|
|
GstGLClutterActor *actor;
|
|
|
|
Display *disp;
|
|
|
|
Window stage_win;
|
2011-11-16 15:53:25 +00:00
|
|
|
ClutterInitError clutter_err = CLUTTER_INIT_ERROR_UNKNOWN;
|
|
|
|
|
|
|
|
clutter_err = clutter_init (&argc, &argv);
|
|
|
|
if (clutter_err != CLUTTER_INIT_SUCCESS)
|
|
|
|
g_warning ("Failed to initalize clutter: %d\n", clutter_err);
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
disp = clutter_x11_get_default_display ();
|
2009-02-11 06:39:14 +00:00
|
|
|
if (!clutter_x11_has_composite_extension ()) {
|
2008-08-17 15:45:52 +00:00
|
|
|
g_error ("XComposite extension missing");
|
|
|
|
}
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
// clutter_actor_set_size (CLUTTER_ACTOR (stage), W*3+2, H);
|
|
|
|
|
|
|
|
stage_win = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
|
|
|
|
|
|
|
|
actor = g_new0 (GstGLClutterActor, 1);
|
|
|
|
actor->stage = stage;
|
|
|
|
actor->win = XCreateSimpleWindow (disp, stage_win, 0, 0, W, H, 0, 0, 0);
|
|
|
|
XCompositeRedirectWindow (disp, actor->win, CompositeRedirectManual);
|
|
|
|
XMapRaised (disp, actor->win);
|
|
|
|
XSync (disp, FALSE);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
pipeline =
|
|
|
|
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 ! "
|
2013-07-16 16:28:33 +00:00
|
|
|
"gleffects effect=twirl ! glimagesink", NULL));
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
|
2012-08-14 04:41:19 +00:00
|
|
|
gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, actor,
|
|
|
|
NULL);
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
clutter_main ();
|
2008-08-17 15:45:52 +00:00
|
|
|
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (pipeline);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2008-08-17 15:45:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|