Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <X11/extensions/Xcomposite.h>
- #include <clutter/clutter.h>
- #include <clutter/x11/clutter-x11.h>
- #include <gst/gst.h>
- #include <gst/video/video.h>
- #include <gst/interfaces/xoverlay.h>
- typedef struct
- {
- Window offscreen_window;
- GstElement *pipeline;
- } Example;
- static gboolean
- lay_pipeline (Example *app,
- ClutterActor *tfp_texture)
- {
- GstElement *audio_sink = NULL;
- GstElement *video_sink = NULL;
- app->pipeline = gst_element_factory_make ("playbin2", "pipeline");
- if (!app->pipeline)
- {
- g_critical ("Unable to create playbin2 element");
- return FALSE;
- }
- audio_sink = gst_element_factory_make ("gconfaudiosink", "audio-sink");
- if (!audio_sink)
- {
- audio_sink = gst_element_factory_make ("autoaudiosink", "audio-sink");
- if (!audio_sink)
- {
- audio_sink = gst_element_factory_make ("alsasink", "audio-sink");
- g_warning ("Could not create a GST audio_sink. "
- "Audio unavailable.");
- if (!audio_sink)
- audio_sink = gst_element_factory_make ("fakesink", "audio-sink");
- }
- }
- video_sink = gst_element_factory_make ("ximagesink", "video-sink");
- if (!video_sink)
- {
- g_warning ("Could not find the fluvasink element");
- /* FIXME: cleanup */
- return FALSE;
- }
- g_object_set (G_OBJECT (video_sink), "qos", TRUE, "sync", TRUE, NULL);
- g_object_set (G_OBJECT (app->pipeline),
- "video-sink", video_sink,
- "audio-sink", audio_sink,
- "subtitle-font-desc", "Sans 16",
- NULL);
- return TRUE;
- }
- static GstBusSyncReply
- bus_sync_cb (GstBus *bus,
- GstMessage *message,
- gpointer data)
- {
- Example *app = data;
- /* ignore anything but 'prepare-xwindow-id' element messages */
- if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
- return GST_BUS_PASS;
- if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
- return GST_BUS_PASS;
- g_message ("setting XOverlay window XID: %d", app->offscreen_window);
- gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
- app->offscreen_window);
- return GST_BUS_DROP;
- }
- int
- main (int argc, char **argv)
- {
- ClutterActor *stage, *tfp_texture, *rectangle;
- ClutterColor rectangle_color = {0xff, 0, 0, 0x7e};
- Display *display;
- Window stage_window;
- Example app;
- GstBus *bus;
- gst_init (&argc, &argv);
- clutter_init (&argc, &argv);
- XInitThreads ();
- if (argc != 2)
- {
- g_print ("Usage: %s <uri>\n", argv[0]);
- return 1;
- }
- stage = clutter_stage_get_default ();
- display = clutter_x11_get_default_display ();
- stage_window = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
- app.offscreen_window = XCreateSimpleWindow (display,
- clutter_x11_get_root_window (),
- 0, 0, 640, 480,
- 0, 0,
- None);
- XCompositeRedirectWindow (display,
- app.offscreen_window,
- CompositeRedirectManual);
- XMapRaised (display, app.offscreen_window);
- XSync (display, TRUE);
- tfp_texture =
- clutter_x11_texture_pixmap_new_with_window (app.offscreen_window);
- clutter_x11_texture_pixmap_set_automatic (
- CLUTTER_X11_TEXTURE_PIXMAP (tfp_texture), TRUE);
- clutter_actor_set_size (tfp_texture, 640, 480);
- clutter_actor_set_position (tfp_texture, 10, 10);
- clutter_actor_set_name (tfp_texture, "TFP texture");
- rectangle = clutter_rectangle_new_with_color (&rectangle_color);
- clutter_actor_set_size (rectangle, 100, 100);
- clutter_actor_set_position (rectangle, 20, 20);
- clutter_container_add (CLUTTER_CONTAINER (stage),
- tfp_texture,
- rectangle,
- NULL);
- lay_pipeline (&app, tfp_texture);
- bus = gst_pipeline_get_bus (GST_PIPELINE (app.pipeline));
- gst_bus_set_sync_handler (bus, bus_sync_cb, &app);
- gst_object_unref (GST_OBJECT (bus));
- g_object_set (app.pipeline, "uri", argv[1], NULL);
- gst_element_set_state (app.pipeline, GST_STATE_PLAYING);
- clutter_actor_show (stage);
- clutter_main ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement