From 74598fdf6cd6e0071cb29cb1e87c40f8c4431ad0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 23 Dec 2000 03:17:52 +0000 Subject: [PATCH] Added handoff signals to fakesrc and fakesink Original commit message from CVS: Added handoff signals to fakesrc and fakesink Added scheduling property to identity Added GST_STATE_TRANSITION macro to check for state changes. Modified gstbin and gstthread to the new state change macros --- gst/elements/gstasyncdisksrc.c | 4 ++-- gst/elements/gstdisksrc.c | 14 +++++++------- gst/elements/gstfakesrc.c | 2 +- gst/elements/gstidentity.c | 7 +++++-- gst/gstbin.c | 19 +++++++++++++------ gst/gstelement.c | 6 +++--- gst/gstelement.h | 8 ++++++++ gst/gstelementfactory.c | 10 ++++++++++ gst/gstpipeline.c | 4 ++-- gst/gstthread.c | 18 ++++++++++-------- plugins/elements/gstasyncdisksrc.c | 4 ++-- plugins/elements/gstdisksrc.c | 14 +++++++------- plugins/elements/gstfakesrc.c | 2 +- plugins/elements/gstidentity.c | 7 +++++-- 14 files changed, 76 insertions(+), 43 deletions(-) diff --git a/gst/elements/gstasyncdisksrc.c b/gst/elements/gstasyncdisksrc.c index 06961c083a..11d6aed538 100644 --- a/gst/elements/gstasyncdisksrc.c +++ b/gst/elements/gstasyncdisksrc.c @@ -296,8 +296,8 @@ gst_asyncdisksrc_get_region (GstPad *pad, gulong offset, gulong size) } else GST_BUFFER_SIZE (buf) = size; - /* we're done, push the buffer off now */ - gst_pad_push (pad,buf); + /* we're done, return the buffer off now */ + return buf; } diff --git a/gst/elements/gstdisksrc.c b/gst/elements/gstdisksrc.c index 7df94eb4f7..c893ce084a 100644 --- a/gst/elements/gstdisksrc.c +++ b/gst/elements/gstdisksrc.c @@ -206,30 +206,30 @@ gst_disksrc_get (GstPad *pad) GstBuffer *buf; glong readbytes; - g_return_if_fail (pad != NULL); + g_return_val_if_fail (pad != NULL, NULL); src = GST_DISKSRC(gst_pad_get_parent(pad)); - g_return_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN)); - g_return_if_fail (GST_STATE (src) >= GST_STATE_READY); + g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN), NULL); + g_return_val_if_fail (GST_STATE (src) >= GST_STATE_READY, NULL); /* create the buffer */ // FIXME: should eventually use a bufferpool for this buf = gst_buffer_new (); - g_return_if_fail (buf); + g_return_val_if_fail (buf, NULL); /* allocate the space for the buffer data */ GST_BUFFER_DATA (buf) = g_malloc (src->bytes_per_read); - g_return_if_fail (GST_BUFFER_DATA (buf) != NULL); + g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL); /* read it in from the file */ readbytes = read (src->fd, GST_BUFFER_DATA (buf), src->bytes_per_read); if (readbytes == -1) { perror ("read()"); gst_buffer_unref (buf); - return; + return NULL; } else if (readbytes == 0) { gst_src_signal_eos (GST_SRC (src)); gst_buffer_unref (buf); - return; + return NULL; } /* if we didn't get as many bytes as we asked for, we're at EOF */ diff --git a/gst/elements/gstfakesrc.c b/gst/elements/gstfakesrc.c index ecb7592d25..0225ebfcd0 100644 --- a/gst/elements/gstfakesrc.c +++ b/gst/elements/gstfakesrc.c @@ -138,7 +138,7 @@ gst_fakesrc_set_arg (GtkObject *object, GtkArg *arg, guint id) gst_pad_set_get_function(pad,gst_fakesrc_get); gst_element_add_pad(GST_ELEMENT(src),pad); src->srcpads = g_slist_append(src->srcpads,pad); - src->numsrcpads; + src->numsrcpads++; } } break; diff --git a/gst/elements/gstidentity.c b/gst/elements/gstidentity.c index 3aa6f1d18b..5622f31152 100644 --- a/gst/elements/gstidentity.c +++ b/gst/elements/gstidentity.c @@ -132,9 +132,12 @@ gst_identity_loop (GstElement *element) identity = GST_IDENTITY (element); - buf = gst_pad_pull (identity->sinkpad); + do { + buf = gst_pad_pull (identity->sinkpad); - gst_pad_push (identity->srcpad, buf); + gst_pad_push (identity->srcpad, buf); + + } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element)); } static void diff --git a/gst/gstbin.c b/gst/gstbin.c index f1c1e10ceb..c540a539f7 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -17,7 +17,7 @@ * Boston, MA 02111-1307, USA. */ -//#define GST_DEBUG_ENABLED +#define GST_DEBUG_ENABLED #include "gstbin.h" #include "gstdebug.h" @@ -247,13 +247,20 @@ gst_bin_change_state (GstElement *element) } // g_print("<-- \"%s\"\n",gst_object_get_name(GST_OBJECT(bin))); - if (GST_STATE_PENDING (element) == GST_STATE_READY) { - GstObject *parent; + switch (GST_STATE_TRANSITION (element)) { + case GST_STATE_NULL_TO_READY: + { + GstObject *parent; - parent = gst_object_get_parent (GST_OBJECT (element)); + parent = gst_object_get_parent (GST_OBJECT (element)); - if (!parent || !GST_IS_BIN (parent)) - gst_bin_create_plan (bin); + if (!parent || !GST_IS_BIN (parent)) + gst_bin_create_plan (bin); + + break; + } + default: + break; } return gst_bin_change_state_norecurse (bin); diff --git a/gst/gstelement.c b/gst/gstelement.c index f68099ec46..ab08021518 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -619,14 +619,14 @@ gst_element_load_thyself (xmlNodePtr parent, } children = children->next; } - g_assert (name != NULL); - g_assert (type != NULL); + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (type != NULL, NULL); g_print ("gstelement: loading \"%s\" of type \"%s\"\n", name, type); element = gst_elementfactory_make (type, name); - g_assert (element != NULL); + g_return_val_if_fail (element != NULL, NULL); g_hash_table_insert (elements, g_strdup (gst_element_get_name (element)), element); diff --git a/gst/gstelement.h b/gst/gstelement.h index 468bf66227..e0f8858301 100644 --- a/gst/gstelement.h +++ b/gst/gstelement.h @@ -63,6 +63,14 @@ static inline char *_gst_print_statename(int state) { #define GST_STATE(obj) (GST_ELEMENT(obj)->current_state) #define GST_STATE_PENDING(obj) (GST_ELEMENT(obj)->pending_state) +#define GST_STATE_TRANSITION(obj) ((GST_STATE(obj)<<4) | GST_STATE_PENDING(obj)) +#define GST_STATE_NULL_TO_READY ((GST_STATE_NULL<<4) | GST_STATE_READY) +#define GST_STATE_READY_TO_PLAYING ((GST_STATE_READY<<4) | GST_STATE_PLAYING) +#define GST_STATE_PLAYING_TO_PAUSED ((GST_STATE_PLAYING<<4) | GST_STATE_PAUSED) +#define GST_STATE_PAUSED_TO_PLAYING ((GST_STATE_PAUSED<<4) | GST_STATE_PLAYING) +#define GST_STATE_PLAYING_TO_READY ((GST_STATE_PLAYING<<4) | GST_STATE_READY) +#define GST_STATE_READY_TO_NULL ((GST_STATE_READY<<4) | GST_STATE_NULL) + #define GST_TYPE_ELEMENT \ (gst_element_get_type()) #define GST_ELEMENT(obj) \ diff --git a/gst/gstelementfactory.c b/gst/gstelementfactory.c index 3093b4c438..d521bee91d 100644 --- a/gst/gstelementfactory.c +++ b/gst/gstelementfactory.c @@ -63,6 +63,8 @@ gst_elementfactory_find (gchar *name) GList *walk; GstElementFactory *factory; + g_return_val_if_fail(name != NULL, NULL); + DEBUG("gstelementfactory: find \"%s\"\n", name); walk = _gst_elementfactories; @@ -107,6 +109,8 @@ gst_elementfactory_new (gchar *name, GtkType type, { GstElementFactory *factory = g_new0(GstElementFactory, 1); + g_return_val_if_fail(name != NULL, NULL); + factory->name = g_strdup(name); factory->type = type; factory->details = details; @@ -136,6 +140,7 @@ gst_elementfactory_create (GstElementFactory *factory, GstElementClass *oclass; g_return_val_if_fail(factory != NULL, NULL); + g_return_val_if_fail(name != NULL, NULL); DEBUG("gstelementfactory: create \"%s\" \"%s\"\n", factory->name, name); @@ -180,6 +185,9 @@ gst_elementfactory_make (gchar *factoryname, gchar *name) GstElementFactory *factory; GstElement *element; + g_return_val_if_fail(factoryname != NULL, NULL); + g_return_val_if_fail(name != NULL, NULL); + DEBUG("gstelementfactory: make \"%s\" \"%s\"\n", factoryname, name); //gst_plugin_load_elementfactory(factoryname); @@ -269,6 +277,8 @@ gst_elementfactory_save_thyself (GstElementFactory *factory, { GList *pads; + g_return_val_if_fail(factory != NULL, NULL); + xmlNewChild(parent,NULL,"name",factory->name); xmlNewChild(parent,NULL,"longname", factory->details->longname); xmlNewChild(parent,NULL,"class", factory->details->klass); diff --git a/gst/gstpipeline.c b/gst/gstpipeline.c index 7bc3d20ffc..dbcdb225c5 100644 --- a/gst/gstpipeline.c +++ b/gst/gstpipeline.c @@ -486,8 +486,8 @@ gst_pipeline_change_state (GstElement *element) pipeline = GST_PIPELINE (element); - switch (GST_STATE_PENDING (pipeline)) { - case GST_STATE_READY: + switch (GST_STATE_TRANSITION (pipeline)) { + case GST_STATE_NULL_TO_READY: // we need to set up internal state gst_pipeline_prepare (pipeline); break; diff --git a/gst/gstthread.c b/gst/gstthread.c index 972e70a11d..2b56b93ef8 100644 --- a/gst/gstthread.c +++ b/gst/gstthread.c @@ -200,7 +200,7 @@ gst_thread_change_state (GstElement *element) { GstThread *thread; gboolean stateset = GST_STATE_SUCCESS; - gint pending; + gint pending, transition; g_return_val_if_fail (GST_IS_THREAD(element), FALSE); DEBUG_ENTER("(\"%s\")",gst_element_get_name(element)); @@ -212,6 +212,7 @@ gst_thread_change_state (GstElement *element) GST_STATE_PENDING (element)); pending = GST_STATE_PENDING (element); + transition = GST_STATE_TRANSITION (element); if (pending == GST_STATE (element)) return GST_STATE_SUCCESS; @@ -220,11 +221,11 @@ gst_thread_change_state (GstElement *element) if (GST_ELEMENT_CLASS (parent_class)->change_state) stateset = GST_ELEMENT_CLASS (parent_class)->change_state (element); - gst_info("gstthread: stateset %d %d %d\n", GST_STATE (element), stateset, - GST_STATE_PENDING (element)); + gst_info("gstthread: stateset %d %d %d %02x\n", GST_STATE (element), stateset, + GST_STATE_PENDING (element), GST_STATE_TRANSITION (element)); - switch (pending) { - case GST_STATE_READY: + switch (transition) { + case GST_STATE_NULL_TO_READY: if (!stateset) return FALSE; // we want to prepare our internal state for doing the iterations gst_info("gstthread: preparing thread \"%s\" for iterations:\n", @@ -247,7 +248,8 @@ gst_thread_change_state (GstElement *element) } return GST_STATE_ASYNC; break; - case GST_STATE_PLAYING: + case GST_STATE_PAUSED_TO_PLAYING: + case GST_STATE_READY_TO_PLAYING: if (!stateset) return FALSE; gst_info("gstthread: starting thread \"%s\"\n", gst_element_get_name (GST_ELEMENT (element))); @@ -255,14 +257,14 @@ gst_thread_change_state (GstElement *element) GST_FLAG_SET (thread, GST_THREAD_STATE_SPINNING); gst_thread_signal_thread (thread); break; - case GST_STATE_PAUSED: + case GST_STATE_PLAYING_TO_PAUSED: gst_info("gstthread: pausing thread \"%s\"\n", gst_element_get_name (GST_ELEMENT (element))); //GST_FLAG_UNSET(thread,GST_THREAD_STATE_SPINNING); gst_thread_signal_thread (thread); break; - case GST_STATE_NULL: + case GST_STATE_READY_TO_NULL: gst_info("gstthread: stopping thread \"%s\"\n", gst_element_get_name (GST_ELEMENT (element))); diff --git a/plugins/elements/gstasyncdisksrc.c b/plugins/elements/gstasyncdisksrc.c index 06961c083a..11d6aed538 100644 --- a/plugins/elements/gstasyncdisksrc.c +++ b/plugins/elements/gstasyncdisksrc.c @@ -296,8 +296,8 @@ gst_asyncdisksrc_get_region (GstPad *pad, gulong offset, gulong size) } else GST_BUFFER_SIZE (buf) = size; - /* we're done, push the buffer off now */ - gst_pad_push (pad,buf); + /* we're done, return the buffer off now */ + return buf; } diff --git a/plugins/elements/gstdisksrc.c b/plugins/elements/gstdisksrc.c index 7df94eb4f7..c893ce084a 100644 --- a/plugins/elements/gstdisksrc.c +++ b/plugins/elements/gstdisksrc.c @@ -206,30 +206,30 @@ gst_disksrc_get (GstPad *pad) GstBuffer *buf; glong readbytes; - g_return_if_fail (pad != NULL); + g_return_val_if_fail (pad != NULL, NULL); src = GST_DISKSRC(gst_pad_get_parent(pad)); - g_return_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN)); - g_return_if_fail (GST_STATE (src) >= GST_STATE_READY); + g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN), NULL); + g_return_val_if_fail (GST_STATE (src) >= GST_STATE_READY, NULL); /* create the buffer */ // FIXME: should eventually use a bufferpool for this buf = gst_buffer_new (); - g_return_if_fail (buf); + g_return_val_if_fail (buf, NULL); /* allocate the space for the buffer data */ GST_BUFFER_DATA (buf) = g_malloc (src->bytes_per_read); - g_return_if_fail (GST_BUFFER_DATA (buf) != NULL); + g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL); /* read it in from the file */ readbytes = read (src->fd, GST_BUFFER_DATA (buf), src->bytes_per_read); if (readbytes == -1) { perror ("read()"); gst_buffer_unref (buf); - return; + return NULL; } else if (readbytes == 0) { gst_src_signal_eos (GST_SRC (src)); gst_buffer_unref (buf); - return; + return NULL; } /* if we didn't get as many bytes as we asked for, we're at EOF */ diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index ecb7592d25..0225ebfcd0 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -138,7 +138,7 @@ gst_fakesrc_set_arg (GtkObject *object, GtkArg *arg, guint id) gst_pad_set_get_function(pad,gst_fakesrc_get); gst_element_add_pad(GST_ELEMENT(src),pad); src->srcpads = g_slist_append(src->srcpads,pad); - src->numsrcpads; + src->numsrcpads++; } } break; diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index 3aa6f1d18b..5622f31152 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -132,9 +132,12 @@ gst_identity_loop (GstElement *element) identity = GST_IDENTITY (element); - buf = gst_pad_pull (identity->sinkpad); + do { + buf = gst_pad_pull (identity->sinkpad); - gst_pad_push (identity->srcpad, buf); + gst_pad_push (identity->srcpad, buf); + + } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element)); } static void