Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <clutter-gst/clutter-gst.h>
- /*
- * clutter-gst-1.0
- * gcc clutter-gst-leak-test1.c -o clutter-gst-leak-test1 `pkg-config --cflags --libs gstreamer-0.10 clutter-gst-1.0`
- *
- * clutter-gst-2.0
- * gcc clutter-gst-leak-test1.c -o clutter-gst-leak-test1 `pkg-config --cflags --libs clutter-gst-2.0`
- */
- static GMainLoop *loop;
- ClutterActor *stage, *texture;
- GstElement *pipeline = NULL;
- gfloat width = 1024;
- gfloat height = 768;
- #define USE_YUV_CAPS
- #if CLUTTER_GST_MAJOR_VERSION == 1
- #if defined (USE_YUV_CAPS)
- #define TEST_PIPE_STR "videotestsrc ! video/x-raw-yuv,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
- #else
- #define TEST_PIPE_STR "videotestsrc ! video/x-raw-rgb,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
- #endif
- #elif CLUTTER_GST_MAJOR_VERSION == 2
- #if defined (USE_YUV_CAPS)
- #define TEST_PIPE_STR "videotestsrc ! video/x-raw,format=(string)AYUV,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
- #else
- #define TEST_PIPE_STR "videotestsrc ! video/x-raw,format=(string)RGB,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
- #endif
- #endif
- static void
- size_change (ClutterActor *texture, gint width, gint height, gpointer user_data) {
- g_message("*** size_change ***");
- clutter_actor_set_size (texture, width, height);
- }
- static void
- texture_destroy (ClutterActor *texture, gpointer user_data) {
- g_message("*** texture_destroy ***");
- }
- static gboolean
- restart_pipeline () {
- if (pipeline != NULL) {
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
- gst_object_unref (pipeline);
- clutter_actor_destroy (texture);
- pipeline = NULL;
- texture = NULL;
- } else {
- gchar *pipe_str;
- pipe_str = g_strdup_printf (TEST_PIPE_STR, (gint) width, (gint) height);
- pipeline = gst_parse_launch (pipe_str, NULL);
- g_message ("Created pipe: %s", pipe_str);
- g_free (pipe_str);
- 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);
- #if CLUTTER_GST_MAJOR_VERSION == 1
- clutter_group_add (CLUTTER_GROUP (stage), texture);
- #elif CLUTTER_GST_MAJOR_VERSION == 2
- clutter_actor_add_child (CLUTTER_ACTOR (stage), texture);
- #endif
- GstElement *sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
- g_object_set (sink, "texture", texture, NULL);
- gst_object_unref (sink);
- GstStateChangeReturn stateret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
- g_message ("done set to playing: %d", stateret);
- }
- return TRUE;
- }
- int
- main(int argc, char *argv[]) {
- if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
- g_error ("Failed to initialize clutter\n");
- 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);
- stage = clutter_stage_new ();
- clutter_actor_set_size (CLUTTER_ACTOR (stage), width, height);
- clutter_actor_show (CLUTTER_ACTOR (stage));
- restart_pipeline ();
- g_timeout_add_seconds(3, (GSourceFunc) restart_pipeline, NULL);
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment