Blame tests/icles/test-box.c

Packit 971217
/* GStreamer interactive videoscale test
Packit 971217
 * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
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 <stdlib.h>
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
Packit 971217
#define CAPS " capsfilter caps=\"video/x-raw, format=(string)I420, width=(int)640, height=(int)480\" "
Packit 971217
Packit 971217
static GstElement *
Packit 971217
make_pipeline (gint type)
Packit 971217
{
Packit 971217
  GstElement *result;
Packit 971217
  gchar *pstr;
Packit 971217
Packit 971217
  switch (type) {
Packit 971217
    case 0:
Packit 971217
      pstr =
Packit 971217
          g_strdup_printf ("videotestsrc ! " CAPS
Packit 971217
          " ! videobox name=box ! videoscale ! " CAPS
Packit 971217
          " ! videoconvert ! ximagesink");
Packit 971217
      break;
Packit 971217
    default:
Packit 971217
      return NULL;
Packit 971217
  }
Packit 971217
Packit 971217
  result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
Packit 971217
  g_print ("created test %d: \"%s\"\n", type, pstr);
Packit 971217
  g_free (pstr);
Packit 971217
Packit 971217
  return result;
Packit 971217
}
Packit 971217
Packit 971217
#define MAX_ROUND 100
Packit 971217
Packit 971217
int
Packit 971217
main (int argc, char **argv)
Packit 971217
{
Packit 971217
  GstElement *pipe, *filter;
Packit 971217
  gint left, right;
Packit 971217
  gint top, bottom;
Packit 971217
  gint rdir, ldir;
Packit 971217
  gint tdir, bdir;
Packit 971217
  gint round, type, stop;
Packit 971217
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  type = 0;
Packit 971217
  stop = -1;
Packit 971217
Packit 971217
  if (argc > 1) {
Packit 971217
    type = atoi (argv[1]);
Packit 971217
    stop = type + 1;
Packit 971217
  }
Packit 971217
Packit 971217
  while (TRUE) {
Packit 971217
    GstMessage *message;
Packit 971217
Packit 971217
    pipe = make_pipeline (type);
Packit 971217
    if (pipe == NULL)
Packit 971217
      break;
Packit 971217
Packit 971217
    filter = gst_bin_get_by_name (GST_BIN (pipe), "box");
Packit 971217
    g_assert (filter);
Packit 971217
Packit 971217
    /* start with no borders or cropping */
Packit 971217
    left = right = top = bottom = 0;
Packit 971217
    rdir = ldir = tdir = bdir = -10;
Packit 971217
Packit 971217
    for (round = 0; round < MAX_ROUND; round++) {
Packit 971217
      g_print ("box to %dx%d %dx%d (%d/%d)   \r", left, right, top, bottom,
Packit 971217
          round, MAX_ROUND);
Packit 971217
Packit 971217
      g_object_set (filter, "left", left, "right", right, "top", top, "bottom",
Packit 971217
          bottom, NULL);
Packit 971217
Packit 971217
      if (round == 0)
Packit 971217
        gst_element_set_state (pipe, GST_STATE_PLAYING);
Packit 971217
Packit 971217
      left += ldir;
Packit 971217
      if (left >= 40)
Packit 971217
        ldir = -10;
Packit 971217
      else if (left < -30)
Packit 971217
        ldir = 10;
Packit 971217
Packit 971217
      right += rdir;
Packit 971217
      if (right >= 30)
Packit 971217
        rdir = -10;
Packit 971217
      else if (right < -20)
Packit 971217
        rdir = 10;
Packit 971217
Packit 971217
      top += tdir;
Packit 971217
      if (top >= 20)
Packit 971217
        tdir = -10;
Packit 971217
      else if (top < -30)
Packit 971217
        tdir = 10;
Packit 971217
Packit 971217
      bottom += bdir;
Packit 971217
      if (bottom >= 60)
Packit 971217
        bdir = -10;
Packit 971217
      else if (bottom < -40)
Packit 971217
        bdir = 10;
Packit 971217
Packit 971217
      message =
Packit 971217
          gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR,
Packit 971217
          50 * GST_MSECOND);
Packit 971217
      if (message) {
Packit 971217
        g_print ("got error                                 \n");
Packit 971217
Packit 971217
        gst_message_unref (message);
Packit 971217
      }
Packit 971217
    }
Packit 971217
    g_print ("test %d done                    \n", type);
Packit 971217
Packit 971217
    gst_object_unref (filter);
Packit 971217
    gst_element_set_state (pipe, GST_STATE_NULL);
Packit 971217
    gst_object_unref (pipe);
Packit 971217
Packit 971217
    type++;
Packit 971217
    if (type == stop)
Packit 971217
      break;
Packit 971217
  }
Packit 971217
  return 0;
Packit 971217
}