Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #include <X11/extensions/Xcomposite.h>
  2.  
  3. #include <clutter/clutter.h>
  4. #include <clutter/x11/clutter-x11.h>
  5.  
  6. #include <gst/gst.h>
  7. #include <gst/video/video.h>
  8. #include <gst/interfaces/xoverlay.h>
  9.  
  10. typedef struct
  11. {
  12. Window offscreen_window;
  13. GstElement *pipeline;
  14. } Example;
  15.  
  16. static gboolean
  17. lay_pipeline (Example *app,
  18. ClutterActor *tfp_texture)
  19. {
  20. GstElement *audio_sink = NULL;
  21. GstElement *video_sink = NULL;
  22.  
  23. app->pipeline = gst_element_factory_make ("playbin2", "pipeline");
  24. if (!app->pipeline)
  25. {
  26. g_critical ("Unable to create playbin2 element");
  27. return FALSE;
  28. }
  29.  
  30. audio_sink = gst_element_factory_make ("gconfaudiosink", "audio-sink");
  31. if (!audio_sink)
  32. {
  33. audio_sink = gst_element_factory_make ("autoaudiosink", "audio-sink");
  34. if (!audio_sink)
  35. {
  36. audio_sink = gst_element_factory_make ("alsasink", "audio-sink");
  37. g_warning ("Could not create a GST audio_sink. "
  38. "Audio unavailable.");
  39.  
  40. if (!audio_sink)
  41. audio_sink = gst_element_factory_make ("fakesink", "audio-sink");
  42. }
  43. }
  44.  
  45. video_sink = gst_element_factory_make ("ximagesink", "video-sink");
  46. if (!video_sink)
  47. {
  48. g_warning ("Could not find the fluvasink element");
  49. /* FIXME: cleanup */
  50. return FALSE;
  51. }
  52.  
  53. g_object_set (G_OBJECT (video_sink), "qos", TRUE, "sync", TRUE, NULL);
  54. g_object_set (G_OBJECT (app->pipeline),
  55. "video-sink", video_sink,
  56. "audio-sink", audio_sink,
  57. "subtitle-font-desc", "Sans 16",
  58. NULL);
  59.  
  60. return TRUE;
  61. }
  62.  
  63. static GstBusSyncReply
  64. bus_sync_cb (GstBus *bus,
  65. GstMessage *message,
  66. gpointer data)
  67. {
  68. Example *app = data;
  69.  
  70. /* ignore anything but 'prepare-xwindow-id' element messages */
  71. if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
  72. return GST_BUS_PASS;
  73.  
  74. if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
  75. return GST_BUS_PASS;
  76.  
  77. g_message ("setting XOverlay window XID: %d", app->offscreen_window);
  78.  
  79. gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
  80. app->offscreen_window);
  81.  
  82. return GST_BUS_DROP;
  83.  
  84. }
  85.  
  86. int
  87. main (int argc, char **argv)
  88. {
  89. ClutterActor *stage, *tfp_texture, *rectangle;
  90. ClutterColor rectangle_color = {0xff, 0, 0, 0x7e};
  91. Display *display;
  92. Window stage_window;
  93. Example app;
  94. GstBus *bus;
  95.  
  96. gst_init (&argc, &argv);
  97. clutter_init (&argc, &argv);
  98. XInitThreads ();
  99.  
  100. if (argc != 2)
  101. {
  102. g_print ("Usage: %s <uri>\n", argv[0]);
  103. return 1;
  104. }
  105.  
  106. stage = clutter_stage_get_default ();
  107.  
  108. display = clutter_x11_get_default_display ();
  109. stage_window = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
  110.  
  111. app.offscreen_window = XCreateSimpleWindow (display,
  112. clutter_x11_get_root_window (),
  113. 0, 0, 640, 480,
  114. 0, 0,
  115. None);
  116. XCompositeRedirectWindow (display,
  117. app.offscreen_window,
  118. CompositeRedirectManual);
  119. XMapRaised (display, app.offscreen_window);
  120. XSync (display, TRUE);
  121.  
  122. tfp_texture =
  123. clutter_x11_texture_pixmap_new_with_window (app.offscreen_window);
  124. clutter_x11_texture_pixmap_set_automatic (
  125. CLUTTER_X11_TEXTURE_PIXMAP (tfp_texture), TRUE);
  126. clutter_actor_set_size (tfp_texture, 640, 480);
  127. clutter_actor_set_position (tfp_texture, 10, 10);
  128. clutter_actor_set_name (tfp_texture, "TFP texture");
  129.  
  130. rectangle = clutter_rectangle_new_with_color (&rectangle_color);
  131. clutter_actor_set_size (rectangle, 100, 100);
  132. clutter_actor_set_position (rectangle, 20, 20);
  133.  
  134. clutter_container_add (CLUTTER_CONTAINER (stage),
  135. tfp_texture,
  136. rectangle,
  137. NULL);
  138.  
  139. lay_pipeline (&app, tfp_texture);
  140.  
  141. bus = gst_pipeline_get_bus (GST_PIPELINE (app.pipeline));
  142. gst_bus_set_sync_handler (bus, bus_sync_cb, &app);
  143. gst_object_unref (GST_OBJECT (bus));
  144.  
  145. g_object_set (app.pipeline, "uri", argv[1], NULL);
  146. gst_element_set_state (app.pipeline, GST_STATE_PLAYING);
  147.  
  148. clutter_actor_show (stage);
  149.  
  150. clutter_main ();
  151.  
  152. return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement