1
2 #include <directfb.h>
3
4 #ifdef __no_instrument_function__
5 #undef __no_instrument_function__
6 #endif
7
8 #include <stdio.h>
9 #include <gst/gst.h>
10
11 static IDirectFB *dfb = NULL;
12 static IDirectFBSurface *primary = NULL;
13 static GMainLoop *loop;
14
15 #define DFBCHECK(x...) \
16 { \
17 DFBResult err = x; \
18 \
19 if (err != DFB_OK) \
20 { \
21 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
22 DirectFBErrorFatal( #x, err ); \
23 } \
24 }
25
26 static gboolean
get_me_out(gpointer data)27 get_me_out (gpointer data)
28 {
29 g_main_loop_quit (loop);
30 return FALSE;
31 }
32
33 int
main(int argc,char * argv[])34 main (int argc, char *argv[])
35 {
36 DFBSurfaceDescription dsc;
37 GstElement *pipeline, *src, *sink;
38
39 /* Init both GStreamer and DirectFB */
40 DFBCHECK (DirectFBInit (&argc, &argv));
41 gst_init (&argc, &argv);
42
43 /* Creates DirectFB main context and set it to fullscreen layout */
44 DFBCHECK (DirectFBCreate (&dfb));
45 DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
46
47 /* We want a double buffered primary surface */
48 dsc.flags = DSDESC_CAPS;
49 dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
50
51 DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));
52
53 /* Creating our pipeline : videotestsrc ! dfbvideosink */
54 pipeline = gst_pipeline_new (NULL);
55 g_assert (pipeline);
56 src = gst_element_factory_make ("videotestsrc", NULL);
57 g_assert (src);
58 sink = gst_element_factory_make ("dfbvideosink", NULL);
59 g_assert (sink);
60 /* That's the interesting part, giving the primary surface to dfbvideosink */
61 g_object_set (sink, "surface", primary, NULL);
62
63 /* Adding elements to the pipeline */
64 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
65 if (!gst_element_link (src, sink))
66 g_error ("Couldn't link videotestsrc and dfbvideosink");
67
68 /* Let's play ! */
69 gst_element_set_state (pipeline, GST_STATE_PLAYING);
70
71 /* we need to run a GLib main loop to get out of here */
72 loop = g_main_loop_new (NULL, FALSE);
73 /* Get us out after 20 seconds */
74 g_timeout_add (20000, get_me_out, NULL);
75 g_main_loop_run (loop);
76
77 /* Release elements and stop playback */
78 gst_element_set_state (pipeline, GST_STATE_NULL);
79
80 /* Free the main loop */
81 g_main_loop_unref (loop);
82
83 /* Release DirectFB context and surface */
84 primary->Release (primary);
85 dfb->Release (dfb);
86
87 return 0;
88 }
89