Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <clutter-gst/clutter-gst.h>
- GMainLoop *loop;
- ClutterActor *stage, *texture;
- GstElement *pipeline = NULL, *appsrc, *ffcl, *sinkel;
- gfloat width = 1024;
- gfloat height = 768;
- static void
- texture_destroy (ClutterActor *texture, gpointer user_data) {
- g_message("*** texture_destroy ***");
- }
- static void
- size_change(ClutterActor *tex, gint width, gint height, gpointer user_data) {
- g_message("*** Size change ***");
- clutter_actor_set_size(tex, width, height);
- }
- static void
- create_texture () {
- stage = clutter_stage_get_default();
- clutter_actor_set_size (CLUTTER_ACTOR (stage), width, height);
- texture = CLUTTER_ACTOR (g_object_new(CLUTTER_TYPE_TEXTURE, "sync-size", FALSE, "disable-slicing", TRUE, NULL));
- g_signal_connect (CLUTTER_TEXTURE (texture), "size-change", G_CALLBACK (size_change), NULL);
- g_signal_connect (CLUTTER_TEXTURE (texture), "destroy", G_CALLBACK (texture_destroy), NULL);
- clutter_group_add (CLUTTER_GROUP (stage), texture);
- clutter_actor_show_all(stage);
- }
- static gboolean
- stop_pipe () {
- // should, and does call the destroy for texture
- clutter_group_remove_all(CLUTTER_GROUP (stage));
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
- // refcount is 1, unref should free pipeline resources
- g_message ("pipeline refcount=%d", GST_OBJECT_REFCOUNT_VALUE (pipeline));
- gst_object_unref (pipeline);
- // clutter_actor_destroy (texture);
- pipeline = NULL;
- return FALSE;
- }
- static gboolean
- bus_call (GstBus *bus, GstMessage *msg, gpointer user_data) {
- switch (GST_MESSAGE_TYPE (msg)) {
- case GST_MESSAGE_EOS:
- g_message ("End of display pipe");
- stop_pipe ();
- break;
- case GST_MESSAGE_ERROR: {
- gchar *debug;
- GError *error = NULL;
- gst_message_parse_error (msg, &error, &debug);
- g_free (debug);
- g_message ("Error: %s", error->message);
- g_error_free (error);
- stop_pipe ();
- } break;
- default:
- // g_message ("Unhandled message %d", GST_MESSAGE_TYPE (msg));
- break;
- }
- return TRUE;
- }
- static void
- create_and_start_pipe () {
- GstBus *bus;
- appsrc = gst_element_factory_make ("videotestsrc", NULL);
- gchar *caps_str = g_strdup_printf ("video/x-raw-yuv,framerate=25/1,width=\"%d\",height=\"%d\"", (gint)width, (gint)height);
- GstCaps *caps = gst_caps_from_string (caps_str);
- g_free (caps_str);
- ffcl = gst_element_factory_make ("ffmpegcolorspace", NULL);
- sinkel = gst_element_factory_make ("cluttersink", NULL);
- g_object_set (sinkel, "texture", CLUTTER_TEXTURE (texture), NULL);
- // g_object_set (sinkel, "sync", FALSE, NULL);
- pipeline = gst_pipeline_new (NULL);
- gst_bin_add_many (GST_BIN (pipeline), appsrc, ffcl, sinkel, NULL);
- gst_element_link_filtered (appsrc, ffcl, caps);
- gst_caps_unref (caps);
- gst_element_link_many (ffcl, sinkel, NULL);
- bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
- gst_bus_add_watch (bus, (GstBusFunc) bus_call, NULL);
- gst_object_unref (bus);
- GstStateChangeReturn stateret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
- g_message ("Done set to playing: %d", stateret);
- }
- static gboolean
- restart () {
- g_message ("\n Restarting pipe!");
- if (pipeline != NULL) {
- stop_pipe ();
- }
- create_texture ();
- create_and_start_pipe ();
- return TRUE;
- }
- int
- main (int argc, char *argv[]) {
- if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
- g_message ("Failed to initialize clutter");
- return -1;
- }
- gchar *version = gst_version_string ();
- g_message ("GStreamer version: %s", version);
- g_free (version);
- g_message ("ClutterGst version: %s", CLUTTER_GST_VERSION_S);
- restart();
- g_timeout_add_seconds(5, (GSourceFunc) restart, NULL);
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment