gst_plugins_base/tests/icles/test-textoverlay.c
changeset 0 0e761a78d257
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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, 2 * GST_SECOND);
       
    69   gst_element_set_state (pipe, GST_STATE_NULL);
       
    70 }
       
    71 
       
    72 int
       
    73 main (int argc, char **argv)
       
    74 {
       
    75   GstElement *pipe, *toverlay;
       
    76   const gchar *valigns[] = { /* "baseline", */ "bottom", "top" };
       
    77   const gchar *haligns[] = { "left", "center", "right" };
       
    78   const gchar *linealigns[] = { "left", "center", "right" };
       
    79   gint a, b, c;
       
    80 
       
    81   gst_init (&argc, &argv);
       
    82 
       
    83   pipe = gst_parse_launch ("videotestsrc pattern=black ! textoverlay name=t ! "
       
    84       " ffmpegcolorspace ! videoscale ! autovideosink", NULL);
       
    85   g_assert (pipe);
       
    86 
       
    87   toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t");
       
    88   g_assert (toverlay);
       
    89 
       
    90   g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL);
       
    91 
       
    92   for (a = 0; a < G_N_ELEMENTS (valigns); ++a) {
       
    93     for (b = 0; b < G_N_ELEMENTS (haligns); ++b) {
       
    94       for (c = 0; c < G_N_ELEMENTS (linealigns); ++c) {
       
    95         gchar *s;
       
    96 
       
    97         s = g_strdup_printf ("line-alignment = %s\n"
       
    98             "&lt;----- halignment = %s -----&gt;\nvalignment = %s",
       
    99             linealigns[c], haligns[b], valigns[a]);
       
   100         show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]);
       
   101         g_free (s);
       
   102       }
       
   103     }
       
   104   }
       
   105 
       
   106   return 0;
       
   107 }