gstreamer/subprojects/gst-docs/examples/tutorials/basic-tutorial-15.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.4 KiB
C
Raw Normal View History

2012-07-09 12:44:44 +00:00
#include <clutter-gst/clutter-gst.h>
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
2012-07-09 12:44:44 +00:00
/* Setup the video texture once its size is known */
2019-02-07 19:32:58 +00:00
void
size_change (ClutterActor * texture, gint width, gint height,
gpointer user_data)
{
2012-07-09 12:44:44 +00:00
ClutterActor *stage;
gfloat new_x, new_y, new_width, new_height;
gfloat stage_width, stage_height;
ClutterAnimation *animation = NULL;
2012-07-09 12:44:44 +00:00
stage = clutter_actor_get_stage (texture);
if (stage == NULL)
return;
2012-07-09 12:44:44 +00:00
clutter_actor_get_size (stage, &stage_width, &stage_height);
2012-07-10 14:21:33 +00:00
/* Center video on window and calculate new size preserving aspect ratio */
2012-07-09 12:44:44 +00:00
new_height = (height * stage_width) / width;
if (new_height <= stage_height) {
new_width = stage_width;
2012-07-09 12:44:44 +00:00
new_x = 0;
new_y = (stage_height - new_height) / 2;
} else {
2019-02-07 19:32:58 +00:00
new_width = (width * stage_height) / height;
2012-07-09 12:44:44 +00:00
new_height = stage_height;
2012-07-09 12:44:44 +00:00
new_x = (stage_width - new_width) / 2;
new_y = 0;
}
clutter_actor_set_position (texture, new_x, new_y);
clutter_actor_set_size (texture, new_width, new_height);
2019-02-07 19:32:58 +00:00
clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, stage_width / 2, 0,
0);
2012-07-10 14:21:33 +00:00
/* Animate it */
2019-02-07 19:32:58 +00:00
animation =
clutter_actor_animate (texture, CLUTTER_LINEAR, 10000, "rotation-angle-y",
360.0, NULL);
2012-07-09 12:44:44 +00:00
clutter_animation_set_loop (animation, TRUE);
}
2019-02-07 19:32:58 +00:00
int
tutorial_main (int argc, char *argv[])
2019-02-07 19:32:58 +00:00
{
2012-07-09 12:44:44 +00:00
GstElement *pipeline, *sink;
ClutterTimeline *timeline;
ClutterActor *stage, *texture;
2012-07-10 14:21:33 +00:00
/* clutter-gst takes care of initializing Clutter and GStreamer */
2012-07-09 12:44:44 +00:00
if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
g_error ("Failed to initialize clutter\n");
return -1;
}
2012-07-09 12:44:44 +00:00
stage = clutter_stage_get_default ();
2012-07-09 12:44:44 +00:00
/* Make a timeline */
timeline = clutter_timeline_new (1000);
2019-02-07 19:32:58 +00:00
g_object_set (timeline, "loop", TRUE, NULL);
2012-07-10 14:21:33 +00:00
/* Create new texture and disable slicing so the video is properly mapped onto it */
2019-02-07 19:32:58 +00:00
texture =
CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "disable-slicing",
TRUE, NULL));
2012-07-09 12:44:44 +00:00
g_signal_connect (texture, "size-change", G_CALLBACK (size_change), NULL);
2012-07-10 14:21:33 +00:00
/* Build the GStreamer pipeline */
2019-02-07 19:32:58 +00:00
pipeline =
gst_parse_launch
("playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm",
2019-02-07 19:32:58 +00:00
NULL);
2012-07-09 12:44:44 +00:00
/* Instantiate the Clutter sink */
sink = gst_element_factory_make ("autocluttersink", NULL);
if (sink == NULL) {
/* Revert to the older cluttersink, in case autocluttersink was not found */
sink = gst_element_factory_make ("cluttersink", NULL);
}
if (sink == NULL) {
2012-07-10 14:21:33 +00:00
g_printerr ("Unable to find a Clutter sink.\n");
2012-07-09 12:44:44 +00:00
return -1;
}
2019-02-07 19:32:58 +00:00
/* Link GStreamer with Clutter by passing the Clutter texture to the Clutter sink */
2012-07-09 12:44:44 +00:00
g_object_set (sink, "texture", texture, NULL);
2012-07-09 12:44:44 +00:00
/* Add the Clutter sink to the pipeline */
g_object_set (pipeline, "video-sink", sink, NULL);
2012-07-09 12:44:44 +00:00
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
2012-07-09 12:44:44 +00:00
/* start the timeline */
clutter_timeline_start (timeline);
2012-07-10 14:21:33 +00:00
/* Add texture to the stage, and show it */
2012-07-09 12:44:44 +00:00
clutter_group_add (CLUTTER_GROUP (stage), texture);
clutter_actor_show_all (stage);
2019-02-07 19:32:58 +00:00
clutter_main ();
2012-07-09 12:44:44 +00:00
/* Free resources */
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main (tutorial_main, argc, argv, NULL);
#else
return tutorial_main (argc, argv);
#endif
}