Blame tests/icles/test-scale.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
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 = g_strdup_printf ("videotestsrc ! capsfilter name=filter ! "
Packit 971217
          "ximagesink");
Packit 971217
      break;
Packit 971217
    case 1:
Packit 971217
      pstr = g_strdup_printf ("videotestsrc ! queue ! capsfilter name=filter ! "
Packit 971217
          "ximagesink");
Packit 971217
      break;
Packit 971217
    case 2:
Packit 971217
      pstr = g_strdup_printf ("videotestsrc ! videoscale ! "
Packit 971217
          "capsfilter name=filter ! " "ximagesink");
Packit 971217
      break;
Packit 971217
    case 3:
Packit 971217
      pstr =
Packit 971217
          g_strdup_printf ("videotestsrc ! queue ! videoscale ! "
Packit 971217
          "capsfilter name=filter ! " "ximagesink");
Packit 971217
      break;
Packit 971217
    case 4:
Packit 971217
      pstr =
Packit 971217
          g_strdup_printf ("videotestsrc ! videoscale ! queue ! "
Packit 971217
          "capsfilter name=filter ! " "ximagesink");
Packit 971217
      break;
Packit 971217
    case 5:
Packit 971217
      pstr = g_strdup_printf ("v4l2src ! videoconvert ! videoscale ! "
Packit 971217
          "capsfilter name=filter ! " "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
  GstCaps *caps;
Packit 971217
  gint width, height;
Packit 971217
  gint xdir, ydir;
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), "filter");
Packit 971217
    g_assert (filter);
Packit 971217
Packit 971217
    width = 320;
Packit 971217
    height = 240;
Packit 971217
    xdir = ydir = -10;
Packit 971217
Packit 971217
    for (round = 0; round < MAX_ROUND; round++) {
Packit 971217
      gchar *capsstr;
Packit 971217
      g_print ("resize to %dx%d (%d/%d)   \r", width, height, round, MAX_ROUND);
Packit 971217
Packit 971217
      /* we prefer our fixed width and height but allow other dimensions to pass
Packit 971217
       * as well */
Packit 971217
      capsstr =
Packit 971217
          g_strdup_printf ("video/x-raw, width=(int)%d, height=(int)%d;"
Packit 971217
          "video/x-raw", width, height);
Packit 971217
Packit 971217
      caps = gst_caps_from_string (capsstr);
Packit 971217
      g_free (capsstr);
Packit 971217
      g_object_set (filter, "caps", caps, NULL);
Packit 971217
      gst_caps_unref (caps);
Packit 971217
Packit 971217
      if (round == 0)
Packit 971217
        gst_element_set_state (pipe, GST_STATE_PLAYING);
Packit 971217
Packit 971217
      width += xdir;
Packit 971217
      if (width >= 320)
Packit 971217
        xdir = -10;
Packit 971217
      else if (width < 200)
Packit 971217
        xdir = 10;
Packit 971217
Packit 971217
      height += ydir;
Packit 971217
      if (height >= 240)
Packit 971217
        ydir = -10;
Packit 971217
      else if (height < 150)
Packit 971217
        ydir = 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
}