make clutter-app, and share pipeline stuff with gtk-app
[sparrow.git] / clutter-app.c
blob02bd613dcf463ebed7dcd6ecb124b9abe8807fa6
1 /*
2 * Based on an example from the clutter-gst package:
4 * video-sink.c - A small example around the videotestsrc ! warptv !
5 * ffmpegcolorspace ! cluttersink pipeline.
7 * Copyright (C) 2007,2008 OpenedHand
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include <clutter-gst/clutter-gst.h>
26 #include "app.h"
28 void
29 size_change (ClutterTexture *texture,
30 gfloat width,
31 gfloat height,
32 gpointer user_data)
34 ClutterActor *stage;
35 gfloat new_x, new_y, new_width, new_height;
36 gfloat stage_width, stage_height;
38 stage = clutter_actor_get_stage (CLUTTER_ACTOR (texture));
39 if (stage == NULL)
40 return;
42 clutter_actor_get_size (stage, &stage_width, &stage_height);
44 new_height = (height * stage_width) / width;
45 if (new_height <= stage_height)
47 new_width = stage_width;
49 new_x = 0;
50 new_y = (stage_height - new_height) / 2;
52 else
54 new_width = (width * stage_height) / height;
55 new_height = stage_height;
57 new_x = (stage_width - new_width) / 2;
58 new_y = 0;
61 clutter_actor_set_position (CLUTTER_ACTOR (texture), new_x, new_y);
62 clutter_actor_set_size (CLUTTER_ACTOR (texture), new_width, new_height);
65 int
66 main (int argc, char *argv[])
68 ClutterTimeline *timeline;
69 ClutterActor *stage;
70 ClutterActor *texture;
72 if (argc < 1) {
73 g_error ("Usage: %s", argv[0]);
74 return 1;
77 clutter_init (&argc, &argv);
78 gst_init (&argc, &argv);
80 stage = clutter_stage_get_default ();
82 /* Make a timeline */
83 timeline = clutter_timeline_new (1000);
84 g_object_set(timeline, "loop", TRUE, NULL);
86 /* We need to set certain props on the target texture currently for
87 * efficient/corrent playback onto the texture (which sucks a bit)
89 texture = g_object_new (CLUTTER_TYPE_TEXTURE,
90 "sync-size", FALSE,
91 "disable-slicing", TRUE,
92 NULL);
94 g_signal_connect (CLUTTER_TEXTURE (texture),
95 "size-change",
96 G_CALLBACK (size_change), NULL);
100 GstElement *sink = clutter_gst_video_sink_new(CLUTTER_TEXTURE(texture));
102 GstPipeline *pipeline = make_pipeline(sink);
104 gst_element_set_state (GST_ELEMENT(pipeline), GST_STATE_PLAYING);
106 /* start the timeline */
107 clutter_timeline_start (timeline);
109 clutter_group_add (CLUTTER_GROUP (stage), texture);
110 // clutter_actor_set_opacity (texture, 0x11);
111 clutter_actor_show_all (stage);
113 clutter_main();
115 return 0;