* </variablelist>
*
* A #GstBin will by default forward any event sent to it to all sink elements.
- * If all the sinks return TRUE, the bin will also return TRUE, else FALSE is
- * returned. If no sinks are in the bin, the event handler will return TRUE.
+ * If all the sinks return %TRUE, the bin will also return %TRUE, else %FALSE is
+ * returned. If no sinks are in the bin, the event handler will return %TRUE.
*
* </para>
* </refsect2>
- *
- * Last reviewed on 2012-03-28 (0.11.3)
*/
#include "gst_private.h"
gboolean message_forward;
gboolean posted_eos;
+ gboolean posted_playing;
GList *contexts;
};
static GstStateChangeReturn gst_bin_change_state_func (GstElement * element,
GstStateChange transition);
-static void gst_bin_state_changed (GstElement * element, GstState oldstate,
- GstState newstate, GstState pending);
+static gboolean gst_bin_post_message (GstElement * element, GstMessage * msg);
static GstStateChangeReturn gst_bin_get_state_func (GstElement * element,
GstState * state, GstState * pending, GstClockTime timeout);
static void bin_handle_async_done (GstBin * bin, GstStateChangeReturn ret,
/**
* GstBin:async-handling:
*
- * If set to #TRUE, the bin will handle asynchronous state changes.
+ * If set to %TRUE, the bin will handle asynchronous state changes.
* This should be used only if the bin subclass is modifying the state
* of its children on its own.
*/
* @bin: the #GstBin
*
* Will be emitted when the bin needs to perform latency calculations. This
- * signal is only emited for toplevel bins or when async-handling is
+ * signal is only emitted for toplevel bins or when async-handling is
* enabled.
*
* Only one signal handler is invoked. If no signals are connected, the
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_bin_change_state_func);
- gstelement_class->state_changed = GST_DEBUG_FUNCPTR (gst_bin_state_changed);
+ gstelement_class->post_message = GST_DEBUG_FUNCPTR (gst_bin_post_message);
gstelement_class->get_state = GST_DEBUG_FUNCPTR (gst_bin_get_state_func);
#if 0
gstelement_class->get_index = GST_DEBUG_FUNCPTR (gst_bin_get_index_func);
/**
* gst_bin_new:
- * @name: the name of the new bin
+ * @name: (allow-none): the name of the new bin
*
* Creates a new bin with the given name.
*
guint i;
for (i = 0; i < 32; i++)
- if (types & (1 << i))
- GST_DEBUG_OBJECT (bin, " %s", gst_message_type_get_name (1 << i));
+ if (types & (1U << i))
+ GST_DEBUG_OBJECT (bin, " %s", gst_message_type_get_name (1U << i));
}
#endif
}
*
* MT safe.
*
- * Returns: TRUE if the element could be added, FALSE if
+ * Returns: %TRUE if the element could be added, %FALSE if
* the bin does not want to accept the element.
*/
gboolean
*
* MT safe.
*
- * Returns: TRUE if the element could be removed, FALSE if
+ * Returns: %TRUE if the element could be removed, %FALSE if
* the bin does not want to remove the element.
*/
gboolean
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_elements (GstBin * bin)
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_recurse (GstBin * bin)
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_sinks (GstBin * bin)
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_sources (GstBin * bin)
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_sorted (GstBin * bin)
return res;
}
-static void
-gst_bin_state_changed (GstElement * element, GstState oldstate,
- GstState newstate, GstState pending)
+static gboolean
+gst_bin_post_message (GstElement * element, GstMessage * msg)
{
GstElementClass *pklass = (GstElementClass *) parent_class;
+ gboolean ret;
+
+ ret = pklass->post_message (element, gst_message_ref (msg));
+
+ if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STATE_CHANGED &&
+ GST_MESSAGE_SRC (msg) == GST_OBJECT_CAST (element)) {
+ GstState newstate, pending;
- if (newstate == GST_STATE_PLAYING && pending == GST_STATE_VOID_PENDING)
- bin_do_eos (GST_BIN_CAST (element));
+ gst_message_parse_state_changed (msg, NULL, &newstate, &pending);
+ if (newstate == GST_STATE_PLAYING && pending == GST_STATE_VOID_PENDING) {
+ GST_BIN_CAST (element)->priv->posted_playing = TRUE;
+ bin_do_eos (GST_BIN_CAST (element));
+ } else {
+ GST_BIN_CAST (element)->priv->posted_playing = FALSE;
+ }
+ }
- if (pklass->state_changed)
- pklass->state_changed (element, oldstate, newstate, pending);
+ gst_message_unref (msg);
+
+ return ret;
+}
+
+static void
+reset_state (const GValue * data, gpointer user_data)
+{
+ GstElement *e = g_value_get_object (data);
+ GstState state = GPOINTER_TO_INT (user_data);
+
+ if (gst_element_set_state (e, state) == GST_STATE_CHANGE_FAILURE)
+ GST_WARNING_OBJECT (e, "Failed to switch back down to %s",
+ gst_element_state_get_name (state));
}
static GstStateChangeReturn
GST_DEBUG_OBJECT (element, "clearing all cached messages");
bin_remove_messages (bin, NULL, GST_MESSAGE_ANY);
GST_OBJECT_UNLOCK (bin);
- if (current == GST_STATE_PAUSED)
- if (!(gst_bin_src_pads_activate (bin, FALSE)))
- goto activate_failure;
+ /* We might not have reached PAUSED yet due to async errors,
+ * make sure to always deactivate the pads nonetheless */
+ if (!(gst_bin_src_pads_activate (bin, FALSE)))
+ goto activate_failure;
break;
case GST_STATE_NULL:
if (current == GST_STATE_READY) {
if (parent == GST_OBJECT_CAST (element)) {
/* element is still in bin, really error now */
gst_object_unref (parent);
- goto done;
+ goto undo;
}
/* child removed from bin, let the resync code redo the state
* change */
"failure (de)activating src pads");
return GST_STATE_CHANGE_FAILURE;
}
+
+undo:
+ {
+ if (current < next) {
+ GstIterator *it = gst_bin_iterate_sorted (GST_BIN (element));
+ GstIteratorResult ret;
+
+ GST_DEBUG_OBJECT (element,
+ "Bin failed to change state, switching children back to %s",
+ gst_element_state_get_name (current));
+ do {
+ ret =
+ gst_iterator_foreach (it, &reset_state, GINT_TO_POINTER (current));
+ } while (ret == GST_ITERATOR_RESYNC);
+ gst_iterator_free (it);
+ }
+ goto done;
+ }
}
/*
*/
eos = GST_STATE (bin) == GST_STATE_PLAYING
&& GST_STATE_PENDING (bin) == GST_STATE_VOID_PENDING
- && is_eos (bin, &seqnum);
+ && bin->priv->posted_playing && is_eos (bin, &seqnum);
GST_OBJECT_UNLOCK (bin);
if (eos
}
}
-/* must be called with the object lock. This function releases the lock to post
- * the message. */
+/* must be called without the object lock as it posts messages */
static void
bin_do_message_forward (GstBin * bin, GstMessage * message)
{
GST_DEBUG_OBJECT (bin, "pass %s message upward",
GST_MESSAGE_TYPE_NAME (message));
- GST_OBJECT_UNLOCK (bin);
/* we need to convert these messages to element messages so that our parent
* bin can easily ignore them and so that the application can easily
"message", GST_TYPE_MESSAGE, message, NULL));
gst_element_post_message (GST_ELEMENT_CAST (bin), forwarded);
-
- GST_OBJECT_LOCK (bin);
}
}
}
}
/* Not found? Add */
- if (l != NULL)
+ if (l == NULL)
bin->priv->contexts =
g_list_prepend (bin->priv->contexts, gst_context_ref (context));
GST_OBJECT_UNLOCK (bin);
{
/* collect all eos messages from the children */
- GST_OBJECT_LOCK (bin);
bin_do_message_forward (bin, message);
+ GST_OBJECT_LOCK (bin);
/* ref message for future use */
bin_replace_message (bin, message, GST_MESSAGE_EOS);
GST_OBJECT_UNLOCK (bin);
gst_message_parse_segment_start (message, &format, &position);
seqnum = gst_message_get_seqnum (message);
- GST_OBJECT_LOCK (bin);
bin_do_message_forward (bin, message);
+
+ GST_OBJECT_LOCK (bin);
/* if this is the first segment-start, post to parent but not to the
* application */
if (!find_message (bin, NULL, GST_MESSAGE_SEGMENT_START) &&
gst_message_parse_segment_done (message, &format, &position);
seqnum = gst_message_get_seqnum (message);
- GST_OBJECT_LOCK (bin);
bin_do_message_forward (bin, message);
+
+ GST_OBJECT_LOCK (bin);
bin_replace_message (bin, message, GST_MESSAGE_SEGMENT_START);
/* if there are no more segment_start messages, everybody posted
* a segment_done and we can post one on the bus. */
GST_DEBUG_OBJECT (bin, "ASYNC_START message %p, %s", message,
src ? GST_OBJECT_NAME (src) : "(NULL)");
- GST_OBJECT_LOCK (bin);
bin_do_message_forward (bin, message);
+ GST_OBJECT_LOCK (bin);
/* we ignore the message if we are going to <= READY */
if ((target = GST_STATE_TARGET (bin)) <= GST_STATE_READY)
goto ignore_start_message;
gst_message_parse_async_done (message, &running_time);
- GST_OBJECT_LOCK (bin);
bin_do_message_forward (bin, message);
+ GST_OBJECT_LOCK (bin);
/* ignore messages if we are shutting down */
if ((target = GST_STATE_TARGET (bin)) <= GST_STATE_READY)
goto ignore_done_message;
fold->max = max;
else if (max < fold->max)
fold->max = max;
- if (fold->live == FALSE)
+ if (!fold->live)
fold->live = live;
}
} else {
static gboolean
bin_iterate_fold (GstBin * bin, GstIterator * iter, QueryInitFunction fold_init,
QueryDoneFunction fold_done, GstIteratorFoldFunction fold_func,
- QueryFold fold_data, gboolean default_return)
+ QueryFold * fold_data, gboolean default_return)
{
gboolean res = default_return;
GValue ret = { 0 };
while (TRUE) {
GstIteratorResult ires;
- ires = gst_iterator_fold (iter, fold_func, &ret, &fold_data);
+ ires = gst_iterator_fold (iter, fold_func, &ret, fold_data);
switch (ires) {
case GST_ITERATOR_RESYNC:
gst_iterator_resync (iter);
if (fold_init)
- fold_init (bin, &fold_data);
+ fold_init (bin, fold_data);
g_value_set_boolean (&ret, res);
break;
case GST_ITERATOR_OK:
case GST_ITERATOR_DONE:
res = g_value_get_boolean (&ret);
if (fold_done != NULL && res)
- fold_done (bin, &fold_data);
+ fold_done (bin, fold_data);
goto done;
default:
res = FALSE;
fold_init (bin, &fold_data);
res =
- bin_iterate_fold (bin, iter, fold_init, fold_done, fold_func, fold_data,
+ bin_iterate_fold (bin, iter, fold_init, fold_done, fold_func, &fold_data,
default_return);
gst_iterator_free (iter);
iter = gst_element_iterate_src_pads (element);
src_pads_query_result =
bin_iterate_fold (bin, iter, fold_init, fold_done, fold_func,
- fold_data, default_return);
+ &fold_data, default_return);
gst_iterator_free (iter);
if (src_pads_query_result)
children = gst_bin_iterate_elements (bin);
while (gst_iterator_foreach (children, set_context,
- context) == GST_ITERATOR_RESYNC);
+ context) == GST_ITERATOR_RESYNC)
+ gst_iterator_resync (children);
gst_iterator_free (children);
}
* Gets the element with the given name from a bin. This
* function recurses into child bins.
*
- * Returns NULL if no element with the given name is found in the bin.
+ * Returns %NULL if no element with the given name is found in the bin.
*
* MT safe. Caller owns returned reference.
*
- * Returns: (transfer full): the #GstElement with the given name, or NULL
+ * Returns: (transfer full) (nullable): the #GstElement with the given
+ * name, or %NULL
*/
GstElement *
gst_bin_get_by_name (GstBin * bin, const gchar * name)
* Gets the element with the given name from this bin. If the
* element is not found, a recursion is performed on the parent bin.
*
- * Returns NULL if:
+ * Returns %NULL if:
* - no element with the given name is found in the bin
*
* MT safe. Caller owns returned reference.
*
- * Returns: (transfer full): the #GstElement with the given name, or NULL
+ * Returns: (transfer full) (nullable): the #GstElement with the given
+ * name, or %NULL
*/
GstElement *
gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
*
* MT safe. Caller owns returned value.
*
- * Returns: (transfer full): a #GstIterator of #GstElement for all elements
- * in the bin implementing the given interface, or NULL
+ * Returns: (transfer full) (nullable): a #GstIterator of #GstElement
+ * for all elements in the bin implementing the given interface,
+ * or %NULL
*/
GstIterator *
gst_bin_iterate_all_by_interface (GstBin * bin, GType iface)