1 /* GStreamer interactive textoverlay test
2 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
27 set_enum_property_by_name (gpointer object, const gchar * prop,
35 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), prop);
36 g_return_if_fail (pspec != NULL);
38 g_value_init (&val, pspec->value_type);
39 g_object_get_property (G_OBJECT (object), prop, &val);
40 eclass = G_ENUM_CLASS (g_type_class_peek (G_VALUE_TYPE (&val)));
41 g_return_if_fail (eclass != NULL);
42 eval = g_enum_get_value_by_name (eclass, value);
44 eval = g_enum_get_value_by_nick (eclass, value);
45 g_return_if_fail (eval != NULL);
46 g_value_set_enum (&val, eval->value);
47 g_object_set_property (G_OBJECT (object), prop, &val);
52 show_text (GstElement * textoverlay, const gchar * txt, const gchar * valign,
53 const gchar * halign, const gchar * line_align)
57 g_object_set (textoverlay, "text", txt, NULL);
59 set_enum_property_by_name (textoverlay, "valignment", valign);
60 set_enum_property_by_name (textoverlay, "halignment", halign);
61 set_enum_property_by_name (textoverlay, "line-alignment", line_align);
64 while (GST_ELEMENT_PARENT (pipe))
65 pipe = GST_ELEMENT_PARENT (pipe);
67 gst_element_set_state (pipe, GST_STATE_PLAYING);
68 gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, GST_SECOND);
69 gst_element_set_state (pipe, GST_STATE_NULL);
73 test_textoverlay (int width, int height)
75 const gchar *valigns[] = { /* "baseline", */ "bottom", "top" };
76 const gchar *haligns[] = { "left", "center", "right" };
77 const gchar *linealigns[] = { "left", "center", "right" };
78 GstElement *pipe, *toverlay;
82 pstr = g_strdup_printf ("videotestsrc pattern=blue ! "
83 "video/x-raw-yuv,width=%d,height=%d ! t.video_sink "
84 "textoverlay name=t font-desc=\"Sans Serif, 20\" ! "
85 " ffmpegcolorspace ! videoscale ! autovideosink", width, height);
87 pipe = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
90 toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t");
93 g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL);
95 for (a = 0; a < G_N_ELEMENTS (valigns); ++a) {
96 for (b = 0; b < G_N_ELEMENTS (haligns); ++b) {
97 for (c = 0; c < G_N_ELEMENTS (linealigns); ++c) {
100 s = g_strdup_printf ("line-alignment = %s\n"
101 "<----- halignment = %s ----->\nvalignment = %s",
102 linealigns[c], haligns[b], valigns[a]);
103 show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]);
113 main (int argc, char **argv)
115 gst_init (&argc, &argv);
117 test_textoverlay (640, 480);
119 g_print ("Now with odd width/height ...\n");
120 test_textoverlay (639, 479);
122 /* test_textoverlay (796, 256); */