• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * text-color-example.c
3  *
4  * Builds a pipeline with [videotestsrc ! textoverlay ! ximagesink] and
5  * moves text
6  *
7  * Needs gst-plugins-base installed.
8  */
9 
10 #include <gst/gst.h>
11 #include <gst/controller/gstinterpolationcontrolsource.h>
12 #include <gst/controller/gstlfocontrolsource.h>
13 #include <gst/controller/gstargbcontrolbinding.h>
14 #include <gst/controller/gstdirectcontrolbinding.h>
15 
16 gint
main(gint argc,gchar ** argv)17 main (gint argc, gchar ** argv)
18 {
19   gint res = 1;
20   GstElement *src, *text, *sink;
21   GstElement *bin;
22   GstControlSource *cs;
23   GstClock *clock;
24   GstClockID clock_id;
25   GstClockReturn wait_ret;
26 
27   gst_init (&argc, &argv);
28 
29   /* build pipeline */
30   bin = gst_pipeline_new ("pipeline");
31   clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
32   src = gst_element_factory_make ("videotestsrc", NULL);
33   if (!src) {
34     GST_WARNING ("need videotestsrc from gst-plugins-base");
35     goto Error;
36   }
37   g_object_set (src, "pattern", /* red */ 4,
38       NULL);
39   text = gst_element_factory_make ("textoverlay", NULL);
40   if (!text) {
41     GST_WARNING ("need textoverlay from gst-plugins-base");
42     goto Error;
43   }
44   g_object_set (text,
45       "text", "GStreamer rocks!",
46       "font-desc", "Sans, 30",
47       "xpos", 0.0, "wrap-mode", -1, "halignment", /* position */ 4,
48       "valignment", /* position */ 3,
49       NULL);
50   sink = gst_element_factory_make ("ximagesink", NULL);
51   if (!sink) {
52     GST_WARNING ("need ximagesink from gst-plugins-base");
53     goto Error;
54   }
55 
56   gst_bin_add_many (GST_BIN (bin), src, text, sink, NULL);
57   if (!gst_element_link_many (src, text, sink, NULL)) {
58     GST_WARNING ("can't link elements");
59     goto Error;
60   }
61 
62   /* setup control sources */
63   cs = gst_interpolation_control_source_new ();
64   gst_object_add_control_binding (GST_OBJECT_CAST (text),
65       gst_direct_control_binding_new_absolute (GST_OBJECT_CAST (text), "deltax",
66           cs));
67 
68   g_object_set (cs, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
69 
70   // At second 0 the text will be at 0px on the x-axis
71   gst_timed_value_control_source_set ((GstTimedValueControlSource *) cs, 0, 0);
72   // At second 5 the text will be at 1000px on the x-axis
73   gst_timed_value_control_source_set ((GstTimedValueControlSource *) cs,
74       GST_SECOND * 5, 1000);
75 
76   gst_object_unref (cs);
77 
78   /* run for 10 seconds */
79   clock_id =
80       gst_clock_new_single_shot_id (clock,
81       gst_clock_get_time (clock) + (10 * GST_SECOND));
82 
83   if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
84     if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
85       GST_WARNING ("clock_id_wait returned: %d", wait_ret);
86     }
87     gst_element_set_state (bin, GST_STATE_NULL);
88   }
89 
90   /* cleanup */
91   gst_clock_id_unref (clock_id);
92   gst_object_unref (G_OBJECT (clock));
93   gst_object_unref (G_OBJECT (bin));
94   res = 0;
95 Error:
96   return (res);
97 }
98