Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / tests / benchmarks / mass-elements.c
index 3a6ad4d..826d3d0 100644 (file)
@@ -2,20 +2,22 @@
  * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
+ * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Library General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
  */
 
+#include <stdlib.h>
 #include <gst/gst.h>
 
 #define IDENTITY_COUNT (1000)
 #define SINK_ELEMENT "fakesink"
 
 
-static GstClockTime
-gst_get_current_time (void)
-{
-  GTimeVal tv;
-
-  g_get_current_time (&tv);
-  return GST_TIMEVAL_TO_TIME (tv);
-}
-
 gint
 main (gint argc, gchar * argv[])
 {
+  GstMessage *msg;
   GstElement *pipeline, *src, *sink, *current, *last;
   guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
   GstClockTime start, end;
-  gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
+  const gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
 
   gst_init (&argc, &argv);
 
@@ -55,7 +49,7 @@ main (gint argc, gchar * argv[])
   g_print
       ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
       src_name, buffers, identities, sink_name);
-  start = gst_get_current_time ();
+  start = gst_util_get_timestamp ();
   pipeline = gst_element_factory_make ("pipeline", NULL);
   g_assert (pipeline);
   src = gst_element_factory_make (src_name, NULL);
@@ -83,27 +77,40 @@ main (gint argc, gchar * argv[])
   }
   if (!gst_element_link (last, sink))
     g_assert_not_reached ();
-  end = gst_get_current_time ();
+  end = gst_util_get_timestamp ();
   g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
       GST_TIME_ARGS (end - start), identities);
 
-  start = gst_get_current_time ();
-  if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
+  start = gst_util_get_timestamp ();
+  if (gst_element_set_state (pipeline,
+          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
     g_assert_not_reached ();
-  end = gst_get_current_time ();
+  if (gst_element_get_state (pipeline, NULL, NULL,
+          GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_FAILURE)
+    g_assert_not_reached ();
+  end = gst_util_get_timestamp ();
   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
       GST_TIME_ARGS (end - start));
 
-  start = gst_get_current_time ();
-  gst_bus_poll (gst_element_get_bus (pipeline),
+  start = gst_util_get_timestamp ();
+  msg = gst_bus_poll (gst_element_get_bus (pipeline),
       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
-  end = gst_get_current_time ();
+  end = gst_util_get_timestamp ();
+  gst_message_unref (msg);
   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
       GST_TIME_ARGS (end - start), buffers);
 
-  start = gst_get_current_time ();
+  start = gst_util_get_timestamp ();
+  if (gst_element_set_state (pipeline,
+          GST_STATE_NULL) != GST_STATE_CHANGE_SUCCESS)
+    g_assert_not_reached ();
+  end = gst_util_get_timestamp ();
+  g_print ("%" GST_TIME_FORMAT " - setting pipeline to NULL\n",
+      GST_TIME_ARGS (end - start));
+
+  start = gst_util_get_timestamp ();
   g_object_unref (pipeline);
-  end = gst_get_current_time ();
+  end = gst_util_get_timestamp ();
   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
       GST_TIME_ARGS (end - start));