mozgovipc

Cluttersink memory leak

Dec 13th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.37 KB | None | 0 0
  1. #include <gst/gst.h>
  2. #include <clutter-gst/clutter-gst.h>
  3.  
  4. /*
  5.  * clutter-gst-1.0
  6.  * gcc clutter-gst-leak-test1.c -o clutter-gst-leak-test1 `pkg-config --cflags --libs gstreamer-0.10 clutter-gst-1.0`
  7.  *
  8.  * clutter-gst-2.0
  9.  * gcc clutter-gst-leak-test1.c -o clutter-gst-leak-test1 `pkg-config --cflags --libs clutter-gst-2.0`
  10. */
  11.  
  12. static GMainLoop *loop;
  13. ClutterActor *stage, *texture;
  14. GstElement *pipeline = NULL;
  15. gfloat width = 1024;
  16. gfloat height = 768;
  17.  
  18. #define USE_YUV_CAPS
  19.  
  20. #if CLUTTER_GST_MAJOR_VERSION == 1
  21.     #if defined (USE_YUV_CAPS)
  22.         #define TEST_PIPE_STR "videotestsrc ! video/x-raw-yuv,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
  23.     #else
  24.         #define TEST_PIPE_STR "videotestsrc ! video/x-raw-rgb,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
  25.     #endif
  26. #elif CLUTTER_GST_MAJOR_VERSION == 2
  27.     #if defined (USE_YUV_CAPS)
  28.         #define TEST_PIPE_STR "videotestsrc ! video/x-raw,format=(string)AYUV,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
  29.     #else
  30.         #define TEST_PIPE_STR "videotestsrc ! video/x-raw,format=(string)RGB,framerate=25/1,width=%d,height=%d ! cluttersink name=sink"
  31.     #endif
  32. #endif
  33.  
  34. static void
  35. size_change (ClutterActor *texture, gint width, gint height, gpointer user_data) {
  36.     g_message("*** size_change ***");
  37.     clutter_actor_set_size (texture, width, height);
  38. }
  39.  
  40. static void
  41. texture_destroy (ClutterActor *texture, gpointer user_data) {
  42.     g_message("*** texture_destroy ***");
  43. }
  44.  
  45. static gboolean
  46. restart_pipeline () {
  47.     if (pipeline != NULL) {
  48.         gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
  49.         gst_object_unref (pipeline);
  50.         clutter_actor_destroy (texture);
  51.         pipeline = NULL;
  52.         texture = NULL;
  53.     } else {
  54.         gchar *pipe_str;
  55.         pipe_str = g_strdup_printf (TEST_PIPE_STR, (gint) width, (gint) height);
  56.         pipeline = gst_parse_launch (pipe_str, NULL);
  57.         g_message ("Created pipe: %s", pipe_str);
  58.         g_free (pipe_str);
  59.  
  60.         texture = CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "sync-size", FALSE, "disable-slicing", TRUE, NULL));
  61.         g_signal_connect (CLUTTER_TEXTURE (texture), "size-change", G_CALLBACK (size_change), NULL);
  62.         g_signal_connect (CLUTTER_TEXTURE (texture), "destroy", G_CALLBACK (texture_destroy), NULL);
  63. #if CLUTTER_GST_MAJOR_VERSION == 1
  64.         clutter_group_add (CLUTTER_GROUP (stage), texture);
  65. #elif CLUTTER_GST_MAJOR_VERSION == 2
  66.         clutter_actor_add_child (CLUTTER_ACTOR (stage), texture);
  67. #endif
  68.  
  69.         GstElement *sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
  70.         g_object_set (sink, "texture", texture, NULL);
  71.         gst_object_unref (sink);
  72.  
  73.         GstStateChangeReturn stateret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  74.         g_message ("done set to playing: %d", stateret);
  75.     }
  76.     return TRUE;
  77. }
  78.  
  79. int
  80. main(int argc, char *argv[]) {
  81.     if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
  82.         g_error ("Failed to initialize clutter\n");
  83.         return -1;
  84.     }
  85.  
  86.     gchar *version = gst_version_string ();
  87.     g_message ("GStreamer version: %s", version);
  88.     g_free (version);
  89.  
  90.     g_message ("ClutterGst version: %s", CLUTTER_GST_VERSION_S);
  91.  
  92.     stage = clutter_stage_new ();
  93.     clutter_actor_set_size (CLUTTER_ACTOR (stage), width, height);
  94.     clutter_actor_show (CLUTTER_ACTOR (stage));
  95.  
  96.     restart_pipeline ();
  97.     g_timeout_add_seconds(3, (GSourceFunc) restart_pipeline, NULL);
  98.  
  99.     loop = g_main_loop_new (NULL, FALSE);
  100.     g_main_loop_run (loop);
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment