Blame tests/icles/test-textoverlay.c

Packit 971217
/* GStreamer interactive textoverlay test
Packit 971217
 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
Packit 971217
static void
Packit 971217
set_enum_property_by_name (gpointer object, const gchar * prop,
Packit 971217
    const gchar * value)
Packit 971217
{
Packit 971217
  GParamSpec *pspec;
Packit 971217
  GValue val = { 0, };
Packit 971217
  GEnumClass *eclass;
Packit 971217
  GEnumValue *eval;
Packit 971217
Packit 971217
  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), prop);
Packit 971217
  g_return_if_fail (pspec != NULL);
Packit 971217
Packit 971217
  g_value_init (&val, pspec->value_type);
Packit 971217
  g_object_get_property (G_OBJECT (object), prop, &val;;
Packit 971217
  eclass = G_ENUM_CLASS (g_type_class_peek (G_VALUE_TYPE (&val)));
Packit 971217
  g_return_if_fail (eclass != NULL);
Packit 971217
  eval = g_enum_get_value_by_name (eclass, value);
Packit 971217
  if (eval == NULL)
Packit 971217
    eval = g_enum_get_value_by_nick (eclass, value);
Packit 971217
  g_return_if_fail (eval != NULL);
Packit 971217
  g_value_set_enum (&val, eval->value);
Packit 971217
  g_object_set_property (G_OBJECT (object), prop, &val;;
Packit 971217
  g_value_unset (&val;;
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
show_text (GstElement * textoverlay, const gchar * txt, const gchar * valign,
Packit 971217
    const gchar * halign, const gchar * line_align)
Packit 971217
{
Packit 971217
  GstElement *pipe;
Packit 971217
Packit 971217
  g_object_set (textoverlay, "text", txt, NULL);
Packit 971217
Packit 971217
  set_enum_property_by_name (textoverlay, "valignment", valign);
Packit 971217
  set_enum_property_by_name (textoverlay, "halignment", halign);
Packit 971217
  set_enum_property_by_name (textoverlay, "line-alignment", line_align);
Packit 971217
Packit 971217
  pipe = textoverlay;
Packit 971217
  while (GST_ELEMENT_PARENT (pipe))
Packit 971217
    pipe = GST_ELEMENT_PARENT (pipe);
Packit 971217
Packit 971217
  gst_element_set_state (pipe, GST_STATE_PLAYING);
Packit 971217
  gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, GST_SECOND);
Packit 971217
  gst_element_set_state (pipe, GST_STATE_NULL);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
test_textoverlay (int width, int height)
Packit 971217
{
Packit 971217
  const gchar *valigns[] = { /* "baseline", */ "bottom", "top" };
Packit 971217
  const gchar *haligns[] = { "left", "center", "right" };
Packit 971217
  const gchar *linealigns[] = { "left", "center", "right" };
Packit 971217
  GstElement *pipe, *toverlay;
Packit 971217
  gchar *pstr;
Packit 971217
  gint a, b, c;
Packit 971217
Packit 971217
  pstr = g_strdup_printf ("videotestsrc pattern=blue ! "
Packit 971217
      "video/x-raw,width=%d,height=%d ! t.video_sink "
Packit 971217
      "textoverlay name=t font-desc=\"Sans Serif, 20\" ! "
Packit 971217
      " videoconvert ! videoscale ! autovideosink", width, height);
Packit 971217
Packit 971217
  pipe = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
Packit 971217
  g_assert (pipe);
Packit 971217
Packit 971217
  toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t");
Packit 971217
  g_assert (toverlay);
Packit 971217
Packit 971217
  g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL);
Packit 971217
Packit 971217
  for (a = 0; a < G_N_ELEMENTS (valigns); ++a) {
Packit 971217
    for (b = 0; b < G_N_ELEMENTS (haligns); ++b) {
Packit 971217
      for (c = 0; c < G_N_ELEMENTS (linealigns); ++c) {
Packit 971217
        gchar *s;
Packit 971217
Packit 971217
        s = g_strdup_printf ("line-alignment = %s\n"
Packit 971217
            "<----- halignment = %s ----->\nvalignment = %s",
Packit 971217
            linealigns[c], haligns[b], valigns[a]);
Packit 971217
        show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]);
Packit 971217
        g_free (s);
Packit 971217
      }
Packit 971217
    }
Packit 971217
  }
Packit 971217
Packit 971217
  gst_object_unref (toverlay);
Packit 971217
  g_free (pstr);
Packit 971217
}
Packit 971217
Packit 971217
int
Packit 971217
main (int argc, char **argv)
Packit 971217
{
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  test_textoverlay (640, 480);
Packit 971217
Packit 971217
  g_print ("Now with odd width/height ...\n");
Packit 971217
  test_textoverlay (639, 479);
Packit 971217
Packit 971217
  /* test_textoverlay (796, 256); */
Packit 971217
Packit 971217
  return 0;
Packit 971217
}