Blame tests/benchmarks/mass-elements.c

Packit a6ee4b
/*
Packit a6ee4b
 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
#include <stdlib.h>
Packit a6ee4b
#include <gst/gst.h>
Packit a6ee4b
Packit a6ee4b
#define IDENTITY_COUNT (1000)
Packit a6ee4b
#define BUFFER_COUNT (1000)
Packit a6ee4b
#define SRC_ELEMENT "fakesrc"
Packit a6ee4b
#define SINK_ELEMENT "fakesink"
Packit a6ee4b
Packit a6ee4b
Packit a6ee4b
gint
Packit a6ee4b
main (gint argc, gchar * argv[])
Packit a6ee4b
{
Packit a6ee4b
  GstMessage *msg;
Packit a6ee4b
  GstElement *pipeline, *src, *sink, *current, *last;
Packit a6ee4b
  guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
Packit a6ee4b
  GstClockTime start, end;
Packit a6ee4b
  const gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
Packit a6ee4b
Packit a6ee4b
  gst_init (&argc, &argv);
Packit a6ee4b
Packit a6ee4b
  if (argc > 1)
Packit a6ee4b
    identities = atoi (argv[1]);
Packit a6ee4b
  if (argc > 2)
Packit a6ee4b
    buffers = atoi (argv[2]);
Packit a6ee4b
  if (argc > 3)
Packit a6ee4b
    src_name = argv[3];
Packit a6ee4b
  if (argc > 4)
Packit a6ee4b
    sink_name = argv[4];
Packit a6ee4b
Packit a6ee4b
  g_print
Packit a6ee4b
      ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
Packit a6ee4b
      src_name, buffers, identities, sink_name);
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  pipeline = gst_element_factory_make ("pipeline", NULL);
Packit a6ee4b
  g_assert (pipeline);
Packit a6ee4b
  src = gst_element_factory_make (src_name, NULL);
Packit a6ee4b
  if (!src) {
Packit a6ee4b
    g_print ("no element named \"%s\" found, aborting...\n", src_name);
Packit a6ee4b
    return 1;
Packit a6ee4b
  }
Packit a6ee4b
  g_object_set (src, "num-buffers", buffers, NULL);
Packit a6ee4b
  sink = gst_element_factory_make (sink_name, NULL);
Packit a6ee4b
  if (!sink) {
Packit a6ee4b
    g_print ("no element named \"%s\" found, aborting...\n", sink_name);
Packit a6ee4b
    return 1;
Packit a6ee4b
  }
Packit a6ee4b
  last = src;
Packit a6ee4b
  gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
Packit a6ee4b
  for (i = 0; i < identities; i++) {
Packit a6ee4b
    current = gst_element_factory_make ("identity", NULL);
Packit a6ee4b
    g_assert (current);
Packit a6ee4b
    /* shut this element up (no g_strdup_printf please) */
Packit a6ee4b
    g_object_set (current, "silent", TRUE, NULL);
Packit a6ee4b
    gst_bin_add (GST_BIN (pipeline), current);
Packit a6ee4b
    if (!gst_element_link (last, current))
Packit a6ee4b
      g_assert_not_reached ();
Packit a6ee4b
    last = current;
Packit a6ee4b
  }
Packit a6ee4b
  if (!gst_element_link (last, sink))
Packit a6ee4b
    g_assert_not_reached ();
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start), identities);
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  if (gst_element_set_state (pipeline,
Packit a6ee4b
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
Packit a6ee4b
    g_assert_not_reached ();
Packit a6ee4b
  if (gst_element_get_state (pipeline, NULL, NULL,
Packit a6ee4b
          GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_FAILURE)
Packit a6ee4b
    g_assert_not_reached ();
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  msg = gst_bus_poll (gst_element_get_bus (pipeline),
Packit a6ee4b
      GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  gst_message_unref (msg);
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start), buffers);
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  if (gst_element_set_state (pipeline,
Packit a6ee4b
          GST_STATE_NULL) != GST_STATE_CHANGE_SUCCESS)
Packit a6ee4b
    g_assert_not_reached ();
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT " - setting pipeline to NULL\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  start = gst_util_get_timestamp ();
Packit a6ee4b
  g_object_unref (pipeline);
Packit a6ee4b
  end = gst_util_get_timestamp ();
Packit a6ee4b
  g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
Packit a6ee4b
      GST_TIME_ARGS (end - start));
Packit a6ee4b
Packit a6ee4b
  return 0;
Packit a6ee4b
}