Commit 9d81fe82 authored by Wim Taymans's avatar Wim Taymans
Browse files

gst/gstpad.c: Use some more macros where it makes sense.

Original commit message from CVS:
* gst/gstpad.c: (gst_pad_init), (gst_pad_activate_pull),
(gst_pad_activate_push):
Use some more macros where it makes sense.
Allow pad mode switching instead of asserting. When a pad
is activated in one mode and we activate it in another,
deactivate it first before activating it in a different mode.
Fixes #329198.
parent 2ef04375
2006-07-09 Wim Taymans <wim@fluendo.com>
* gst/gstpad.c: (gst_pad_init), (gst_pad_activate_pull),
(gst_pad_activate_push):
Use some more macros where it makes sense.
Allow pad mode switching instead of asserting. When a pad
is activated in one mode and we activate it in another,
deactivate it first before activating it in a different mode.
Fixes #329198.
2006-07-08 Andy Wingo <wingo@pobox.com> 2006-07-08 Andy Wingo <wingo@pobox.com>
   
* tools/gst-launch.c (main): Handle err == NULL. * tools/gst-launch.c (main): Handle err == NULL.
......
...@@ -330,26 +330,29 @@ gst_pad_class_init (GstPadClass * klass) ...@@ -330,26 +330,29 @@ gst_pad_class_init (GstPadClass * klass)
static void static void
gst_pad_init (GstPad * pad) gst_pad_init (GstPad * pad)
{ {
pad->direction = GST_PAD_UNKNOWN; GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
pad->peer = NULL; GST_PAD_PEER (pad) = NULL;
pad->chainfunc = NULL; GST_PAD_CHAINFUNC (pad) = NULL;
pad->caps = NULL; GST_PAD_LINKFUNC (pad) = NULL;
pad->linkfunc = NULL; GST_PAD_CAPS (pad) = NULL;
pad->getcapsfunc = NULL; GST_PAD_GETCAPSFUNC (pad) = NULL;
pad->activatefunc = GST_DEBUG_FUNCPTR (gst_pad_activate_default); GST_PAD_ACTIVATEFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_activate_default);
pad->eventfunc = GST_DEBUG_FUNCPTR (gst_pad_event_default); GST_PAD_EVENTFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_event_default);
pad->querytypefunc = GST_DEBUG_FUNCPTR (gst_pad_get_query_types_default); GST_PAD_QUERYTYPEFUNC (pad) =
pad->queryfunc = GST_DEBUG_FUNCPTR (gst_pad_query_default); GST_DEBUG_FUNCPTR (gst_pad_get_query_types_default);
pad->intlinkfunc = GST_DEBUG_FUNCPTR (gst_pad_get_internal_links_default); GST_PAD_QUERYFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_query_default);
GST_PAD_INTLINKFUNC (pad) =
GST_DEBUG_FUNCPTR (gst_pad_get_internal_links_default);
GST_PAD_ACCEPTCAPSFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_acceptcaps_default); GST_PAD_ACCEPTCAPSFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_acceptcaps_default);
pad->do_buffer_signals = 0; pad->do_buffer_signals = 0;
pad->do_event_signals = 0; pad->do_event_signals = 0;
/* FIXME, should be set flushing initially, see #339326 */
GST_PAD_UNSET_FLUSHING (pad); GST_PAD_UNSET_FLUSHING (pad);
pad->preroll_lock = g_mutex_new (); pad->preroll_lock = g_mutex_new ();
...@@ -697,24 +700,43 @@ gst_pad_activate_pull (GstPad * pad, gboolean active) ...@@ -697,24 +700,43 @@ gst_pad_activate_pull (GstPad * pad, gboolean active)
old = GST_PAD_ACTIVATE_MODE (pad); old = GST_PAD_ACTIVATE_MODE (pad);
GST_OBJECT_UNLOCK (pad); GST_OBJECT_UNLOCK (pad);
if ((active && old == GST_ACTIVATE_PULL)
|| (!active && old == GST_ACTIVATE_NONE))
goto was_ok;
if (active) { if (active) {
g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE); switch (old) {
case GST_ACTIVATE_PULL:
goto was_ok;
case GST_ACTIVATE_PUSH:
/* pad was activate in the wrong direction, deactivate it
* and reactivate it in pull mode */
if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
goto deactivate_failed;
/* fallthrough, pad is deactivated now. */
case GST_ACTIVATE_NONE:
break;
}
} else { } else {
g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE); switch (old) {
case GST_ACTIVATE_NONE:
goto was_ok;
case GST_ACTIVATE_PUSH:
/* pad was activated in the other direction, deactivate it
* in push mode, this should not happen... */
if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
goto deactivate_failed;
/* everything is fine now */
goto was_ok;
case GST_ACTIVATE_PULL:
break;
}
} }
if (gst_pad_get_direction (pad) == GST_PAD_SINK) { if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
if ((peer = gst_pad_get_peer (pad))) { if ((peer = gst_pad_get_peer (pad))) {
if (!gst_pad_activate_pull (peer, active)) if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
goto peer_failed; goto peer_failed;
gst_object_unref (peer); gst_object_unref (peer);
} }
} else { } else {
if (GST_PAD_GETRANGEFUNC (pad) == NULL) if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
goto failure; /* Can't activate pull on a src without a goto failure; /* Can't activate pull on a src without a
getrange function */ getrange function */
} }
...@@ -723,7 +745,7 @@ gst_pad_activate_pull (GstPad * pad, gboolean active) ...@@ -723,7 +745,7 @@ gst_pad_activate_pull (GstPad * pad, gboolean active)
pre_activate (pad, new); pre_activate (pad, new);
if (GST_PAD_ACTIVATEPULLFUNC (pad)) { if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
if (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)) if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
goto failure; goto failure;
} else { } else {
/* can happen for sinks of passthrough elements */ /* can happen for sinks of passthrough elements */
...@@ -733,6 +755,7 @@ gst_pad_activate_pull (GstPad * pad, gboolean active) ...@@ -733,6 +755,7 @@ gst_pad_activate_pull (GstPad * pad, gboolean active)
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode", GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
active ? "activated" : "deactivated"); active ? "activated" : "deactivated");
return TRUE; return TRUE;
was_ok: was_ok:
...@@ -741,6 +764,13 @@ was_ok: ...@@ -741,6 +764,13 @@ was_ok:
active ? "activated" : "deactivated"); active ? "activated" : "deactivated");
return TRUE; return TRUE;
} }
deactivate_failed:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
"failed to %s pad (%s:%s) in switch to pull from mode %d",
(active ? "activate" : "deactivate"), GST_DEBUG_PAD_NAME (pad), old);
return FALSE;
}
peer_failed: peer_failed:
{ {
GST_OBJECT_LOCK (peer); GST_OBJECT_LOCK (peer);
...@@ -787,21 +817,40 @@ gst_pad_activate_push (GstPad * pad, gboolean active) ...@@ -787,21 +817,40 @@ gst_pad_activate_push (GstPad * pad, gboolean active)
old = GST_PAD_ACTIVATE_MODE (pad); old = GST_PAD_ACTIVATE_MODE (pad);
GST_OBJECT_UNLOCK (pad); GST_OBJECT_UNLOCK (pad);
if ((active && old == GST_ACTIVATE_PUSH)
|| (!active && old == GST_ACTIVATE_NONE))
goto was_ok;
if (active) { if (active) {
g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE); switch (old) {
case GST_ACTIVATE_PUSH:
goto was_ok;
case GST_ACTIVATE_PULL:
/* pad was activate in the wrong direction, deactivate it
* an reactivate it in push mode */
if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
goto deactivate_failed;
/* fallthrough, pad is deactivated now. */
case GST_ACTIVATE_NONE:
break;
}
} else { } else {
g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE); switch (old) {
case GST_ACTIVATE_NONE:
goto was_ok;
case GST_ACTIVATE_PULL:
/* pad was activated in the other direction, deactivate it
* in pull mode, this should not happen... */
if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
goto deactivate_failed;
/* everything is fine now */
goto was_ok;
case GST_ACTIVATE_PUSH:
break;
}
} }
new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE; new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
pre_activate (pad, new); pre_activate (pad, new);
if (GST_PAD_ACTIVATEPUSHFUNC (pad)) { if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
if (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) { if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
goto failure; goto failure;
} }
} else { } else {
...@@ -820,6 +869,13 @@ was_ok: ...@@ -820,6 +869,13 @@ was_ok:
active ? "activated" : "deactivated"); active ? "activated" : "deactivated");
return TRUE; return TRUE;
} }
deactivate_failed:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
"failed to %s pad (%s:%s) in switch to push from mode %d",
(active ? "activate" : "deactivate"), GST_DEBUG_PAD_NAME (pad), old);
return FALSE;
}
failure: failure:
{ {
GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode", GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment