Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / icles / test-textoverlay.c
1 /* GStreamer interactive textoverlay test
2  * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gst.h>
25
26 static void
27 set_enum_property_by_name (gpointer object, const gchar * prop,
28     const gchar * value)
29 {
30   GParamSpec *pspec;
31   GValue val = { 0, };
32   GEnumClass *eclass;
33   GEnumValue *eval;
34
35   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), prop);
36   g_return_if_fail (pspec != NULL);
37
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);
43   if (eval == NULL)
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);
48   g_value_unset (&val);
49 }
50
51 static void
52 show_text (GstElement * textoverlay, const gchar * txt, const gchar * valign,
53     const gchar * halign, const gchar * line_align)
54 {
55   GstElement *pipe;
56
57   g_object_set (textoverlay, "text", txt, NULL);
58
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);
62
63   pipe = textoverlay;
64   while (GST_ELEMENT_PARENT (pipe))
65     pipe = GST_ELEMENT_PARENT (pipe);
66
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);
70 }
71
72 static void
73 test_textoverlay (int width, int height)
74 {
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;
79   gchar *pstr;
80   gint a, b, c;
81
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);
86
87   pipe = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
88   g_assert (pipe);
89
90   toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t");
91   g_assert (toverlay);
92
93   g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL);
94
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) {
98         gchar *s;
99
100         s = g_strdup_printf ("line-alignment = %s\n"
101             "&lt;----- halignment = %s -----&gt;\nvalignment = %s",
102             linealigns[c], haligns[b], valigns[a]);
103         show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]);
104         g_free (s);
105       }
106     }
107   }
108
109   g_free (pstr);
110 }
111
112 int
113 main (int argc, char **argv)
114 {
115   gst_init (&argc, &argv);
116
117   test_textoverlay (640, 480);
118
119   g_print ("Now with odd width/height ...\n");
120   test_textoverlay (639, 479);
121
122   /* test_textoverlay (796, 256); */
123
124   return 0;
125 }