From d13478b357d4b98a34b9963c5d208e5567d54b4f Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 29 Jun 2005 15:51:25 +0000 Subject: [PATCH] Remove old probes, add new g-signal-based probes and some utility functions. Original commit message from CVS: * docs/gst/gstreamer-sections.txt: * docs/gst/tmpl/gstpad.sgml: * docs/gst/tmpl/gstprobe.sgml: * gst/Makefile.am: * gst/gstpad.c: (_gst_do_pass_data_accumulator), (gst_pad_class_init), (gst_pad_init), (gst_pad_chain), (gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range), (gst_pad_push_event), (gst_pad_send_event): * gst/gstpad.h: * gst/gstutils.c: (gst_pad_add_data_probe), (gst_pad_add_event_probe), (gst_pad_add_buffer_probe), (gst_pad_remove_data_probe), (gst_pad_remove_event_probe), (gst_pad_remove_buffer_probe): * gst/gstutils.h: Remove old probes, add new g-signal-based probes and some utility functions. --- ChangeLog | 19 +++++ docs/gst/gstreamer-sections.txt | 31 ++----- docs/gst/tmpl/gstpad.sgml | 90 ++++++++++++++++----- docs/gst/tmpl/gstprobe.sgml | 139 -------------------------------- gst/Makefile.am | 2 - gst/gstpad.c | 109 ++++++++++++++++++++++--- gst/gstpad.h | 10 +-- gst/gstutils.c | 130 +++++++++++++++++++++++++++++ gst/gstutils.h | 20 +++++ 9 files changed, 348 insertions(+), 202 deletions(-) delete mode 100644 docs/gst/tmpl/gstprobe.sgml diff --git a/ChangeLog b/ChangeLog index cbcba64ff1..18c403ae59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-06-29 Ronald S. Bultje + + * docs/gst/gstreamer-sections.txt: + * docs/gst/tmpl/gstpad.sgml: + * docs/gst/tmpl/gstprobe.sgml: + * gst/Makefile.am: + * gst/gstpad.c: (_gst_do_pass_data_accumulator), + (gst_pad_class_init), (gst_pad_init), (gst_pad_chain), + (gst_pad_push), (gst_pad_get_range), (gst_pad_pull_range), + (gst_pad_push_event), (gst_pad_send_event): + * gst/gstpad.h: + * gst/gstutils.c: (gst_pad_add_data_probe), + (gst_pad_add_event_probe), (gst_pad_add_buffer_probe), + (gst_pad_remove_data_probe), (gst_pad_remove_event_probe), + (gst_pad_remove_buffer_probe): + * gst/gstutils.h: + Remove old probes, add new g-signal-based probes and some utility + functions. + 2005-06-29 Edward Hervey * gst/gstelementfactory.c: diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 15a068d0fe..40b8304e19 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -874,9 +874,13 @@ gst_pad_set_internal_link_function gst_pad_get_internal_links gst_pad_get_internal_links_default gst_pad_dispatcher -gst_pad_add_probe -gst_pad_remove_probe gst_pad_load_and_link +gst_pad_add_data_probe +gst_pad_add_buffer_probe +gst_pad_add_event_probe +gst_pad_remove_data_probe +gst_pad_remove_buffer_probe +gst_pad_remove_event_probe GstPadClass GST_PAD @@ -1025,29 +1029,6 @@ GST_TYPE_PLUGIN_FEATURE gst_plugin_feature_get_type -
-gstprobe -GstProbe -GstProbe -GstProbeCallback -gst_probe_new -gst_probe_destroy -gst_probe_perform -GstProbeDispatcher -gst_probe_dispatcher_new -gst_probe_dispatcher_destroy -gst_probe_dispatcher_init -gst_probe_dispatcher_set_active -gst_probe_dispatcher_add_probe -gst_probe_dispatcher_remove_probe -gst_probe_dispatcher_dispatch - -GST_PROBE -GST_TYPE_PROBE - -gst_probe_get_type -
-
gstquery GstQuery diff --git a/docs/gst/tmpl/gstpad.sgml b/docs/gst/tmpl/gstpad.sgml index 1a4287f8c9..0c0568d450 100644 --- a/docs/gst/tmpl/gstpad.sgml +++ b/docs/gst/tmpl/gstpad.sgml @@ -90,7 +90,17 @@ Last reviewed on December 13th, 2002 (0.5.0.1) @queryfunc: @intlinkfunc: @bufferallocfunc: -@probedisp: +@emit_buffer_signals: +@emit_event_signals: + + + + + + +@gstpad: the object which received the signal. +@arg1: +@Returns: @@ -795,24 +805,6 @@ Checks if the pad is a sink pad. @Returns: - - -Adds the probe to the given pad - - -@pad: The pad to add the probe to -@probe: The probe to add to the pad - - - - -Remove the probe from the pad - - -@pad: The pad to remove the probe of -@probe: The probe to remove - - @@ -822,3 +814,63 @@ Remove the probe from the pad @parent: + + + + + +@pad: +@handler: +@data: + + + + + + + +@pad: +@handler: +@data: + + + + + + + +@pad: +@handler: +@data: + + + + + + + +@pad: +@handler: +@data: + + + + + + + +@pad: +@handler: +@data: + + + + + + + +@pad: +@handler: +@data: + + diff --git a/docs/gst/tmpl/gstprobe.sgml b/docs/gst/tmpl/gstprobe.sgml deleted file mode 100644 index cd8411c538..0000000000 --- a/docs/gst/tmpl/gstprobe.sgml +++ /dev/null @@ -1,139 +0,0 @@ - -GstProbe - - -Receive callbacks of data passing - - - -PadProbes are used to be signalled with a callback when certain GstData -passes through pads. - - -Probes are usually used in combination with a probe dispatcher that will -enumerate all registered probes to signal them. - - - - - - - - - -The probe structure - - -@single_shot: -@callback: -@user_data: - - - -The function that will be called when a probe is activated. - - -@probe: The probe that signalled the callback -@data: The GstData that triggered the probe -@user_data: user data -@Returns: FALSE if the GstData should be removed from the stream. - - - - - - - -@single_shot: -@callback: -@user_data: -@Returns: - - - - - - - -@probe: - - - - - - - -@probe: -@data: -@Returns: - - - - -The structure of the probe dispatcher - - -@active: -@probes: - - - - - - -@Returns: - - - - - - - -@disp: - - - - - - - -@disp: - - - - - - - -@disp: -@active: - - - - - - - -@disp: -@probe: - - - - - - - -@disp: -@probe: - - - - - - - -@disp: -@data: -@Returns: - - diff --git a/gst/Makefile.am b/gst/Makefile.am index fea75a1db2..586dd1660a 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -100,7 +100,6 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \ gstpipeline.c \ gstplugin.c \ gstpluginfeature.c \ - gstprobe.c \ gstquery.c \ gstqueryutils.c \ gstqueue.c \ @@ -177,7 +176,6 @@ gst_headers = \ gstpipeline.h \ gstplugin.h \ gstpluginfeature.h \ - gstprobe.h \ gstquery.h \ gstqueryutils.h \ gstqueue.h \ diff --git a/gst/gstpad.c b/gst/gstpad.c index 1b1c7a901c..3467e17514 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -64,6 +64,7 @@ enum PAD_LINKED, PAD_UNLINKED, PAD_REQUEST_LINK, + PAD_HAVE_DATA, /* FILL ME */ PAD_LAST_SIGNAL }; @@ -120,6 +121,20 @@ gst_pad_get_type (void) return _gst_pad_type; } +static gboolean +_gst_do_pass_data_accumulator (GSignalInvocationHint * ihint, + GValue * return_accu, const GValue * handler_return, gpointer dummy) +{ + if (!g_value_get_boolean (handler_return)) { + g_value_set_boolean (return_accu, FALSE); + + /* stop emission here */ + return FALSE; + } + + return TRUE; +} + static void gst_pad_class_init (GstPadClass * klass) { @@ -151,6 +166,12 @@ gst_pad_class_init (GstPadClass * klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0); + gst_pad_signals[PAD_HAVE_DATA] = + g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, have_data), + _gst_do_pass_data_accumulator, + NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1, G_TYPE_POINTER); + g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS, g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad", GST_TYPE_CAPS, G_PARAM_READABLE)); @@ -188,6 +209,8 @@ gst_pad_init (GstPad * pad) pad->queryfunc = gst_pad_query_default; pad->intlinkfunc = gst_pad_get_internal_links_default; + pad->emit_buffer_signals = pad->emit_event_signals = 0; + GST_PAD_UNSET_FLUSHING (pad); pad->preroll_lock = g_mutex_new (); @@ -2658,7 +2681,7 @@ GstFlowReturn gst_pad_chain (GstPad * pad, GstBuffer * buffer) { GstCaps *caps; - gboolean caps_changed; + gboolean caps_changed, do_pass = TRUE; GstPadChainFunction chainfunc; GstFlowReturn ret; @@ -2693,11 +2716,22 @@ gst_pad_chain (GstPad * pad, GstBuffer * buffer) if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL)) goto no_function; - GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, - "calling chainfunction &%s of pad %s:%s", - GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad)); + if (g_atomic_int_get (&pad->emit_buffer_signals) >= 1) { + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, buffer, &do_pass); + } + + if (do_pass) { + GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, + "calling chainfunction &%s of pad %s:%s", + GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad)); + + ret = chainfunc (pad, buffer); + } else { + GST_DEBUG ("Dropping buffer due to FALSE probe return"); + gst_buffer_unref (buffer); + ret = GST_FLOW_UNEXPECTED; + } - ret = chainfunc (pad, buffer); GST_STREAM_UNLOCK (pad); return ret; @@ -2749,6 +2783,7 @@ gst_pad_push (GstPad * pad, GstBuffer * buffer) { GstPad *peer; GstFlowReturn ret; + gboolean do_pass = TRUE; g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR); g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR); @@ -2765,7 +2800,17 @@ gst_pad_push (GstPad * pad, GstBuffer * buffer) gst_object_ref (peer); GST_UNLOCK (pad); - ret = gst_pad_chain (peer, buffer); + if (g_atomic_int_get (&pad->emit_buffer_signals) >= 1) { + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, buffer, &do_pass); + } + + if (do_pass) { + ret = gst_pad_chain (peer, buffer); + } else { + GST_DEBUG ("Dropping buffer due to FALSE probe return"); + gst_buffer_unref (buffer); + ret = GST_FLOW_UNEXPECTED; + } gst_object_unref (peer); @@ -2891,6 +2936,18 @@ gst_pad_get_range (GstPad * pad, guint64 offset, guint size, GST_STREAM_UNLOCK (pad); + if (ret == GST_FLOW_OK && g_atomic_int_get (&pad->emit_buffer_signals) >= 1) { + gboolean do_pass = TRUE; + + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, *buffer, &do_pass); + if (!do_pass) { + GST_DEBUG ("Dropping data after FALSE probe return"); + gst_buffer_unref (*buffer); + *buffer = NULL; + ret = GST_FLOW_UNEXPECTED; + } + } + return ret; /* ERRORS */ @@ -2953,6 +3010,18 @@ gst_pad_pull_range (GstPad * pad, guint64 offset, guint size, gst_object_unref (peer); + if (ret == GST_FLOW_OK && g_atomic_int_get (&pad->emit_buffer_signals) >= 1) { + gboolean do_pass = TRUE; + + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, *buffer, &do_pass); + if (!do_pass) { + GST_DEBUG ("Dropping data after FALSE probe return"); + gst_buffer_unref (*buffer); + *buffer = NULL; + ret = GST_FLOW_UNEXPECTED; + } + } + return ret; /* ERROR recovery here */ @@ -2982,7 +3051,7 @@ gboolean gst_pad_push_event (GstPad * pad, GstEvent * event) { GstPad *peerpad; - gboolean result; + gboolean result, do_pass = TRUE; g_return_val_if_fail (GST_IS_PAD (pad), FALSE); g_return_val_if_fail (event != NULL, FALSE); @@ -2995,7 +3064,17 @@ gst_pad_push_event (GstPad * pad, GstEvent * event) gst_object_ref (peerpad); GST_UNLOCK (pad); - result = gst_pad_send_event (peerpad, event); + if (g_atomic_int_get (&pad->emit_event_signals) >= 1) { + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, event, &do_pass); + } + + if (do_pass) { + result = gst_pad_send_event (peerpad, event); + } else { + GST_DEBUG ("Dropping event after FALSE probe return"); + gst_event_unref (event); + result = FALSE; + } gst_object_unref (peerpad); @@ -3023,7 +3102,7 @@ not_linked: gboolean gst_pad_send_event (GstPad * pad, GstEvent * event) { - gboolean result = FALSE; + gboolean result = FALSE, do_pass = TRUE; GstPadEventFunction eventfunc; g_return_val_if_fail (GST_IS_PAD (pad), FALSE); @@ -3065,7 +3144,17 @@ gst_pad_send_event (GstPad * pad, GstEvent * event) gst_object_ref (pad); GST_UNLOCK (pad); - result = eventfunc (GST_PAD_CAST (pad), event); + if (g_atomic_int_get (&pad->emit_event_signals) >= 1) { + g_signal_emit (pad, gst_pad_signals[PAD_HAVE_DATA], 0, event, &do_pass); + } + + if (do_pass) { + result = eventfunc (GST_PAD_CAST (pad), event); + } else { + GST_DEBUG ("Dropping event after FALSE probe return"); + gst_event_unref (event); + result = FALSE; + } gst_object_unref (pad); diff --git a/gst/gstpad.h b/gst/gstpad.h index 168a8f02f4..6b889c28da 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -200,7 +199,8 @@ struct _GstPad { GstPadBufferAllocFunction bufferallocfunc; - GstProbeDispatcher probedisp; + /* whether to emit signals for have-data */ + gint emit_buffer_signals, emit_event_signals; /*< private >*/ gpointer _gst_reserved[GST_PADDING]; @@ -213,6 +213,7 @@ struct _GstPadClass { void (*linked) (GstPad *pad, GstPad *peer); void (*unlinked) (GstPad *pad, GstPad *peer); void (*request_link) (GstPad *pad); + gboolean (*have_data) (GstPad *pad, GstMiniObject *data); /*< private >*/ gpointer _gst_reserved[GST_PADDING]; @@ -458,11 +459,6 @@ gboolean gst_pad_query_default (GstPad *pad, GstQuery *query); /* misc helper functions */ gboolean gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch, gpointer data); -/* probes */ -#define gst_pad_add_probe(pad, probe) \ - (gst_probe_dispatcher_add_probe (&(GST_PAD_CAST (pad)->probedisp), probe)) -#define gst_pad_remove_probe(pad, probe) \ - (gst_probe_dispatcher_remove_probe (&(GST_PAD_CAST (pad)->probedisp), probe)) #ifndef GST_DISABLE_LOADSAVE void gst_pad_load_and_link (xmlNodePtr self, GstObject *parent); diff --git a/gst/gstutils.c b/gst/gstutils.c index 138aca161f..32c35bc607 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -2072,3 +2072,133 @@ gst_atomic_int_set (gint * atomic_int, gint value) *atomic_int = value; ignore = g_atomic_int_get (atomic_int); } + +/** + * gst_pad_add_data_probe: + * @pad: pad to add the data probe handler to + * @handler: function to call when data is passed over pad + * @data: data to pass along with the handler + * + * Connects a signal handler to the pad's have-data signal, and increases + * the emit_{buffer,event}_signals atomic number on the pads so that those + * signals are actually fired. + */ + +void +gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_connect (pad, "have-data", handler, data); + g_atomic_int_inc (&pad->emit_event_signals); + g_atomic_int_inc (&pad->emit_buffer_signals); +} + +/** + * gst_pad_add_event_probe: + * @pad: pad to add the event probe handler to + * @handler: function to call when data is passed over pad + * @data: data to pass along with the handler + * + * Connects a signal handler to the pad's have-data signal, and increases + * the emit_event_signals atomic number on the pads so that this signal + * is actually fired. + */ + +void +gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_connect (pad, "have-data", handler, data); + g_atomic_int_inc (&pad->emit_event_signals); +} + +/** + * gst_pad_add_buffer_probe: + * @pad: pad to add the buffer probe handler to + * @handler: function to call when data is passed over pad + * @data: data to pass along with the handler + * + * Connects a signal handler to the pad's have-data signal, and increases + * the emit_buffer_signals atomic number on the pads so that this signal + * is actually fired. + */ + +void +gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_connect (pad, "have-data", handler, data); + g_atomic_int_inc (&pad->emit_buffer_signals); +} + +#define g_atomic_int_dec(atomic) (g_atomic_int_add ((atomic), -1)) + +/** + * gst_pad_remove_data_probe: + * @pad: pad to remove the data probe handler from + * @handler: function that was assigned to the signal + * @data: data that was assigned to the signal handler + * + * Unconnects a signal handler to the pad's have-data signal, and decreases + * the emit_{buffer,event}_signals atomic number on the pads so that those + * signals are actually no more fired if no signals are connected. + */ + +void +gst_pad_remove_data_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_handlers_disconnect_by_func (pad, handler, data); + g_atomic_int_dec (&pad->emit_event_signals); + g_atomic_int_dec (&pad->emit_buffer_signals); +} + +/** + * gst_pad_remove_event_probe: + * @pad: pad to remove the event probe handler from + * @handler: function that was assigned to the signal + * @data: data that was assigned to the signal handler + * + * Unconnects a signal handler to the pad's have-data signal, and decreases + * the emit_event_signals atomic number on the pads so that this signal is + * actually no more fired if no signals are connected. + */ + +void +gst_pad_remove_event_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_handlers_disconnect_by_func (pad, handler, data); + g_atomic_int_dec (&pad->emit_event_signals); +} + +/** + * gst_pad_remove_buffer_probe: + * @pad: pad to remove the buffer probe handler from + * @handler: function that was assigned to the signal + * @data: data that was assigned to the signal handler + * + * Unconnects a signal handler to the pad's have-data signal, and decreases + * the emit_buffer_signals atomic number on the pads so that this signal is + * actually no more fired if no signals are connected. + */ + +void +gst_pad_remove_buffer_probe (GstPad * pad, GCallback handler, gpointer data) +{ + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (handler != NULL); + + g_signal_handlers_disconnect_by_func (pad, handler, data); + g_atomic_int_dec (&pad->emit_buffer_signals); +} diff --git a/gst/gstutils.h b/gst/gstutils.h index 67382bb63d..6818b28f7e 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -292,6 +292,26 @@ void gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src); /* atomic functions */ void gst_atomic_int_set (gint * atomic_int, gint value); +/* probes */ +void gst_pad_add_data_probe (GstPad * pad, + GCallback handler, + gpointer data); +void gst_pad_remove_data_probe (GstPad * pad, + GCallback handler, + gpointer data); +void gst_pad_add_event_probe (GstPad * pad, + GCallback handler, + gpointer data); +void gst_pad_remove_event_probe (GstPad * pad, + GCallback handler, + gpointer data); +void gst_pad_add_buffer_probe (GstPad * pad, + GCallback handler, + gpointer data); +void gst_pad_remove_buffer_probe (GstPad * pad, + GCallback handler, + gpointer data); + G_END_DECLS #endif /* __GST_UTILS_H__ */