Fix the md5sum by implementing tha GMainLoop.

Original commit message from CVS:
Fix the md5sum by implementing tha GMainLoop.
This commit is contained in:
Wim Taymans 2005-01-26 14:29:05 +00:00
parent 10e648c7d9
commit a476269842
4 changed files with 69 additions and 79 deletions

View file

@ -1,3 +1,11 @@
2005-01-26 Wim Taymans <wim@fluendo.com>
* gst/elements/gstidentity.c: (gst_identity_init),
(gst_identity_event), (gst_identity_getrange),
(gst_identity_chain):
* tools/gst-md5sum.c: (message_received), (main):
Fix md5sum by implementing the mainloop.
2005-01-26 Wim Taymans <wim@fluendo.com>
* docs/design/part-scheduling.txt:

View file

@ -1,6 +1,7 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
* 2005 Wim Taymans <wim@fluendo.com>
*
* gstidentity.c:
*
@ -101,6 +102,8 @@ static GstElementStateReturn gst_identity_change_state (GstElement * element);
static gboolean gst_identity_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_identity_chain (GstPad * pad, GstBuffer * buffer);
static GstFlowReturn gst_identity_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer);
static void gst_identity_set_clock (GstElement * element, GstClock * clock);
@ -211,6 +214,8 @@ gst_identity_init (GstIdentity * identity)
identity->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate),
"src");
gst_pad_set_getrange_function (identity->srcpad,
GST_DEBUG_FUNCPTR (gst_identity_getrange));
gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
identity->loop_based = DEFAULT_LOOP_BASED;
@ -240,7 +245,7 @@ gst_identity_event (GstPad * pad, GstEvent * event)
{
GstIdentity *identity;
identity = GST_IDENTITY (gst_pad_get_parent (pad));
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
if (!identity->silent) {
g_free (identity->last_message);
@ -254,6 +259,17 @@ gst_identity_event (GstPad * pad, GstEvent * event)
return gst_pad_push_event (identity->srcpad, event);
}
static GstFlowReturn
gst_identity_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer)
{
GstIdentity *identity;
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
return gst_pad_pull_range (identity->sinkpad, offset, length, buffer);
}
static GstFlowReturn
gst_identity_chain (GstPad * pad, GstBuffer * buffer)
{
@ -266,7 +282,7 @@ gst_identity_chain (GstPad * pad, GstBuffer * buffer)
g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
identity = GST_IDENTITY (gst_pad_get_parent (pad));
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
/* see if we need to do perfect stream checking */
/* invalid timestamp drops us out of check. FIXME: maybe warn ? */
@ -374,26 +390,6 @@ gst_identity_chain (GstPad * pad, GstBuffer * buffer)
return result;
}
#if 0
static void
gst_identity_loop (GstElement * element)
{
GstIdentity *identity;
GstBuffer *buf;
GstFlowReturn ret;
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_IDENTITY (element));
identity = GST_IDENTITY (element);
ret = gst_pad_pull (identity->sinkpad, &buf);
if (ret == GST_FLOW_OK) {
gst_identity_chain (identity->sinkpad, buf);
}
}
#endif
static void
gst_identity_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)

View file

@ -1,6 +1,7 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
* 2005 Wim Taymans <wim@fluendo.com>
*
* gstidentity.c:
*
@ -101,6 +102,8 @@ static GstElementStateReturn gst_identity_change_state (GstElement * element);
static gboolean gst_identity_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_identity_chain (GstPad * pad, GstBuffer * buffer);
static GstFlowReturn gst_identity_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer);
static void gst_identity_set_clock (GstElement * element, GstClock * clock);
@ -211,6 +214,8 @@ gst_identity_init (GstIdentity * identity)
identity->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate),
"src");
gst_pad_set_getrange_function (identity->srcpad,
GST_DEBUG_FUNCPTR (gst_identity_getrange));
gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
identity->loop_based = DEFAULT_LOOP_BASED;
@ -240,7 +245,7 @@ gst_identity_event (GstPad * pad, GstEvent * event)
{
GstIdentity *identity;
identity = GST_IDENTITY (gst_pad_get_parent (pad));
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
if (!identity->silent) {
g_free (identity->last_message);
@ -254,6 +259,17 @@ gst_identity_event (GstPad * pad, GstEvent * event)
return gst_pad_push_event (identity->srcpad, event);
}
static GstFlowReturn
gst_identity_getrange (GstPad * pad, guint64 offset,
guint length, GstBuffer ** buffer)
{
GstIdentity *identity;
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
return gst_pad_pull_range (identity->sinkpad, offset, length, buffer);
}
static GstFlowReturn
gst_identity_chain (GstPad * pad, GstBuffer * buffer)
{
@ -266,7 +282,7 @@ gst_identity_chain (GstPad * pad, GstBuffer * buffer)
g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
identity = GST_IDENTITY (gst_pad_get_parent (pad));
identity = GST_IDENTITY (GST_PAD_PARENT (pad));
/* see if we need to do perfect stream checking */
/* invalid timestamp drops us out of check. FIXME: maybe warn ? */
@ -374,26 +390,6 @@ gst_identity_chain (GstPad * pad, GstBuffer * buffer)
return result;
}
#if 0
static void
gst_identity_loop (GstElement * element)
{
GstIdentity *identity;
GstBuffer *buf;
GstFlowReturn ret;
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_IDENTITY (element));
identity = GST_IDENTITY (element);
ret = gst_pad_pull (identity->sinkpad, &buf);
if (ret == GST_FLOW_OK) {
gst_identity_chain (identity->sinkpad, buf);
}
}
#endif
static void
gst_identity_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)

View file

@ -7,46 +7,32 @@
#include <gst/gst.h>
#include <locale.h>
static guint64 iterations = 0;
static guint64 sum = 0;
static guint64 min = G_MAXINT64;
static guint64 max = 0;
static GstClock *s_clock;
static GMainLoop *loop;
gboolean
idle_func (gpointer data)
static gboolean
message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
{
gboolean busy;
GTimeVal tfthen, tfnow;
GstClockTimeDiff diff;
if (s_clock) {
//g_print ("%lld\n", gst_clock_get_time (s_clock));
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_EOS:
if (g_main_loop_is_running (loop))
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR:
gst_object_default_error (GST_MESSAGE_SRC (message),
GST_MESSAGE_ERROR_GERROR (message),
GST_MESSAGE_ERROR_DEBUG (message));
if (g_main_loop_is_running (loop))
g_main_loop_quit (loop);
break;
default:
break;
}
gst_message_unref (message);
g_get_current_time (&tfthen);
//busy = gst_bin_iterate (GST_BIN (data));
busy = FALSE;
iterations++;
g_get_current_time (&tfnow);
diff = GST_TIMEVAL_TO_TIME (tfnow) - GST_TIMEVAL_TO_TIME (tfthen);
sum += diff;
min = MIN (min, diff);
max = MAX (max, diff);
if (!busy) {
//gst_main_quit ();
/*
g_print ("execution ended after %llu iterations (sum %llu ns, average %llu ns, min %llu ns, max %llu ns)\n",
iterations, sum, sum/iterations, min, max);
*/
}
return busy;
return TRUE;
}
int
main (int argc, char *argv[])
{
@ -121,12 +107,16 @@ main (int argc, char *argv[])
//g_signal_connect (pipeline, "error",
// G_CALLBACK (gst_object_default_error), NULL);
loop = g_main_loop_new (NULL, FALSE);
gst_bus_add_watch (gst_element_get_bus (GST_ELEMENT (pipeline)),
(GstBusHandler) message_received, pipeline);
if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
g_warning ("pipeline doesn't want to play\n");
return 0;
}
gst_main ();
g_main_loop_run (loop);
gst_element_set_state (pipeline, GST_STATE_NULL);