gstfunnel: avoid access of freed pad
[platform/upstream/gstreamer.git] / gst / gstpad.h
index 45b6a37..4e93f07 100644 (file)
@@ -29,6 +29,7 @@
 typedef struct _GstPad GstPad;
 typedef struct _GstPadPrivate GstPadPrivate;
 typedef struct _GstPadClass GstPadClass;
+typedef struct _GstPadProbeInfo GstPadProbeInfo;
 
 /**
  * GstPadDirection:
@@ -127,7 +128,7 @@ typedef enum {
  * GstFlowReturn:
  * @GST_FLOW_OK:                Data passing was ok.
  * @GST_FLOW_NOT_LINKED:        Pad is not linked.
- * @GST_FLOW_WRONG_STATE:       Pad is in wrong state.
+ * @GST_FLOW_FLUSHING:          Pad is flushing.
  * @GST_FLOW_EOS:                Pad is EOS.
  * @GST_FLOW_NOT_NEGOTIATED:    Pad is not negotiated.
  * @GST_FLOW_ERROR:             Some (fatal) error occured. Element generating
@@ -165,7 +166,7 @@ typedef enum {
   GST_FLOW_OK            =  0,
   /* expected failures */
   GST_FLOW_NOT_LINKED     = -1,
-  GST_FLOW_WRONG_STATE    = -2,
+  GST_FLOW_FLUSHING       = -2,
   /* error cases */
   GST_FLOW_EOS            = -3,
   GST_FLOW_NOT_NEGOTIATED = -4,
@@ -325,7 +326,7 @@ typedef GstFlowReturn               (*GstPadChainListFunction)      (GstPad *pad, GstObject *paren
  * #GST_QUERY_SEEKING.
  *
  * Any @offset larger or equal than the length will make the function return
- * #GST_FLOW_UNEXPECTED, which corresponds to EOS. In this case @buffer does not
+ * #GST_FLOW_EOS, which corresponds to EOS. In this case @buffer does not
  * contain a valid buffer.
  *
  * The buffer size of @buffer will only be smaller than @length when @offset is
@@ -495,7 +496,10 @@ typedef enum
 /**
  * GstPadProbeReturn:
  * @GST_PAD_PROBE_OK: normal probe return value
- * @GST_PAD_PROBE_DROP: drop data in data probes
+ * @GST_PAD_PROBE_DROP: drop data in data probes. For push mode this means that
+ *        the data item is not sent downstream. For pull mode, it means that the
+ *        data item is not passed upstream. In both cases, this result code
+ *        returns #GST_FLOW_OK or %TRUE to the caller.
  * @GST_PAD_PROBE_REMOVE: remove probe
  * @GST_PAD_PROBE_PASS: pass the data item in the block probe and block on
  *                         the next item
@@ -514,6 +518,7 @@ typedef enum
 /**
  * GstPadProbeInfo:
  * @type: the current probe type
+ * @id: the id of the probe
  * @data: type specific data, check the @type field to know the datatype.
  *    This field can be NULL.
  * @offset: offset of pull probe, this field is valid when @type contains
@@ -523,17 +528,20 @@ typedef enum
  *
  * Info passed in the #GstPadProbeCallback.
  */
-typedef struct
+struct _GstPadProbeInfo
 {
   GstPadProbeType type;
+  gulong id;
   gpointer data;
   guint64 offset;
   guint size;
 
+  /*< private >*/
   gpointer _gst_reserved[GST_PADDING];
-} GstPadProbeInfo;
+};
 
 #define GST_PAD_PROBE_INFO_TYPE(d)         ((d)->type)
+#define GST_PAD_PROBE_INFO_ID(d)           ((d)->id)
 #define GST_PAD_PROBE_INFO_DATA(d)         ((d)->data)
 
 #define GST_PAD_PROBE_INFO_BUFFER(d)       GST_BUFFER_CAST(GST_PAD_PROBE_INFO_DATA(d))
@@ -582,12 +590,14 @@ typedef gboolean  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent **
 /**
  * GstPadFlags:
  * @GST_PAD_FLAG_BLOCKED: is dataflow on a pad blocked
- * @GST_PAD_FLAG_FLUSHING: is pad refusing buffers
+ * @GST_PAD_FLAG_FLUSHING: is pad flushing
+ * @GST_PAD_FLAG_EOS: is pad in EOS state
  * @GST_PAD_FLAG_BLOCKING: is pad currently blocking on a buffer or event
+ * @GST_PAD_FLAG_NEED_PARENT: ensure that there is a parent object before calling
+ *                       into the pad callbacks.
  * @GST_PAD_FLAG_NEED_RECONFIGURE: the pad should be reconfigured/renegotiated.
  *                            The flag has to be unset manually after
  *                            reconfiguration happened.
- *                            Since: 0.10.34.
  * @GST_PAD_FLAG_PENDING_EVENTS: the pad has pending events
  * @GST_PAD_FLAG_FIXED_CAPS: the pad is using fixed caps this means that once the
  *                      caps are set on the pad, the caps query function only
@@ -595,8 +605,9 @@ typedef gboolean  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent **
  * @GST_PAD_FLAG_PROXY_CAPS: the default event and query handler will forward
  *                      all events and queries to the internally linked pads
  *                      instead of discarding them.
- * @GST_PAD_FLAG_NEED_PARENT: ensure that there is a parent object before calling
- *                       into the pad callbacks.
+ * @GST_PAD_FLAG_PROXY_ALLOCATION: the default query handler will forward
+ *                      allocation queries to the internally linked pads
+ *                      instead of discarding them.
  * @GST_PAD_FLAG_LAST: offset to define more flags
  *
  * Pad state flags
@@ -604,12 +615,14 @@ typedef gboolean  (*GstPadStickyEventsForeachFunction) (GstPad *pad, GstEvent **
 typedef enum {
   GST_PAD_FLAG_BLOCKED          = (GST_OBJECT_FLAG_LAST << 0),
   GST_PAD_FLAG_FLUSHING         = (GST_OBJECT_FLAG_LAST << 1),
-  GST_PAD_FLAG_BLOCKING         = (GST_OBJECT_FLAG_LAST << 2),
-  GST_PAD_FLAG_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 3),
-  GST_PAD_FLAG_PENDING_EVENTS   = (GST_OBJECT_FLAG_LAST << 4),
-  GST_PAD_FLAG_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 5),
-  GST_PAD_FLAG_PROXY_CAPS       = (GST_OBJECT_FLAG_LAST << 6),
-  GST_PAD_FLAG_NEED_PARENT      = (GST_OBJECT_FLAG_LAST << 7),
+  GST_PAD_FLAG_EOS              = (GST_OBJECT_FLAG_LAST << 2),
+  GST_PAD_FLAG_BLOCKING         = (GST_OBJECT_FLAG_LAST << 3),
+  GST_PAD_FLAG_NEED_PARENT      = (GST_OBJECT_FLAG_LAST << 4),
+  GST_PAD_FLAG_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 5),
+  GST_PAD_FLAG_PENDING_EVENTS   = (GST_OBJECT_FLAG_LAST << 6),
+  GST_PAD_FLAG_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 7),
+  GST_PAD_FLAG_PROXY_CAPS       = (GST_OBJECT_FLAG_LAST << 8),
+  GST_PAD_FLAG_PROXY_ALLOCATION = (GST_OBJECT_FLAG_LAST << 9),
   /* padding */
   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
 } GstPadFlags;
@@ -635,34 +648,42 @@ struct _GstPad {
 
   /*< private >*/
   /* streaming rec_lock */
-  GStaticRecMutex               stream_rec_lock;
+  GRecMutex                     stream_rec_lock;
   GstTask                      *task;
 
   /* block cond, mutex is from the object */
-  GCond                                *block_cond;
+  GCond                                 block_cond;
   GHookList                      probes;
 
   GstPadMode                    mode;
   GstPadActivateFunction        activatefunc;
+  gpointer                       activatedata;
   GDestroyNotify                 activatenotify;
   GstPadActivateModeFunction    activatemodefunc;
+  gpointer                       activatemodedata;
   GDestroyNotify                 activatemodenotify;
 
   /* pad link */
   GstPad                       *peer;
   GstPadLinkFunction            linkfunc;
+  gpointer                       linkdata;
   GDestroyNotify                 linknotify;
   GstPadUnlinkFunction          unlinkfunc;
+  gpointer                       unlinkdata;
   GDestroyNotify                 unlinknotify;
 
   /* data transport functions */
   GstPadChainFunction           chainfunc;
+  gpointer                       chaindata;
   GDestroyNotify                 chainnotify;
   GstPadChainListFunction        chainlistfunc;
+  gpointer                       chainlistdata;
   GDestroyNotify                 chainlistnotify;
   GstPadGetRangeFunction        getrangefunc;
+  gpointer                       getrangedata;
   GDestroyNotify                 getrangenotify;
   GstPadEventFunction           eventfunc;
+  gpointer                       eventdata;
   GDestroyNotify                 eventnotify;
 
   /* pad offset */
@@ -670,10 +691,12 @@ struct _GstPad {
 
   /* generic query method */
   GstPadQueryFunction           queryfunc;
+  gpointer                       querydata;
   GDestroyNotify                 querynotify;
 
   /* internal links */
   GstPadIterIntLinkFunction      iterintlinkfunc;
+  gpointer                       iterintlinkdata;
   GDestroyNotify                 iterintlinknotify;
 
   /* counts number of probes attached. */
@@ -734,6 +757,8 @@ struct _GstPadClass {
 #define GST_PAD_SET_FLUSHING(pad)      (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FLUSHING))
 #define GST_PAD_UNSET_FLUSHING(pad)    (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_FLUSHING))
 
+#define GST_PAD_IS_EOS(pad)            (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_EOS))
+
 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE))
 #define GST_PAD_HAS_PENDING_EVENTS(pad) (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PENDING_EVENTS))
 #define GST_PAD_IS_FIXED_CAPS(pad)     (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_FIXED_CAPS))
@@ -743,6 +768,10 @@ struct _GstPadClass {
 #define GST_PAD_SET_PROXY_CAPS(pad)     (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_CAPS))
 #define GST_PAD_UNSET_PROXY_CAPS(pad)   (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_CAPS))
 
+#define GST_PAD_IS_PROXY_ALLOCATION(pad)    (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
+#define GST_PAD_SET_PROXY_ALLOCATION(pad)   (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
+#define GST_PAD_UNSET_PROXY_ALLOCATION(pad) (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PROXY_ALLOCATION))
+
 /**
  * GST_PAD_GET_STREAM_LOCK:
  * @pad: a #GstPad
@@ -757,7 +786,7 @@ struct _GstPadClass {
  *
  * Lock the stream lock of @pad.
  */
-#define GST_PAD_STREAM_LOCK(pad)        (g_static_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad)))
+#define GST_PAD_STREAM_LOCK(pad)        g_rec_mutex_lock(GST_PAD_GET_STREAM_LOCK(pad))
 /**
  * GST_PAD_STREAM_TRYLOCK:
  * @pad: a #GstPad
@@ -765,16 +794,16 @@ struct _GstPadClass {
  * Try to Lock the stream lock of the pad, return TRUE if the lock could be
  * taken.
  */
-#define GST_PAD_STREAM_TRYLOCK(pad)     (g_static_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad)))
+#define GST_PAD_STREAM_TRYLOCK(pad)     g_rec_mutex_trylock(GST_PAD_GET_STREAM_LOCK(pad))
 /**
  * GST_PAD_STREAM_UNLOCK:
  * @pad: a #GstPad
  *
  * Unlock the stream lock of @pad.
  */
-#define GST_PAD_STREAM_UNLOCK(pad)      (g_static_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad)))
+#define GST_PAD_STREAM_UNLOCK(pad)      g_rec_mutex_unlock(GST_PAD_GET_STREAM_LOCK(pad))
 
-#define GST_PAD_BLOCK_GET_COND(pad)     (GST_PAD_CAST(pad)->block_cond)
+#define GST_PAD_BLOCK_GET_COND(pad)     (&GST_PAD_CAST(pad)->block_cond)
 #define GST_PAD_BLOCK_WAIT(pad)         (g_cond_wait(GST_PAD_BLOCK_GET_COND (pad), GST_OBJECT_GET_LOCK (pad)))
 #define GST_PAD_BLOCK_SIGNAL(pad)       (g_cond_signal(GST_PAD_BLOCK_GET_COND (pad)))
 #define GST_PAD_BLOCK_BROADCAST(pad)    (g_cond_broadcast(GST_PAD_BLOCK_GET_COND (pad)))
@@ -840,41 +869,49 @@ void                    gst_pad_sticky_events_foreach           (GstPad *pad, Gs
 /* data passing setup functions */
 void                   gst_pad_set_activate_function_full      (GstPad *pad,
                                                                  GstPadActivateFunction activate,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 void                   gst_pad_set_activatemode_function_full  (GstPad *pad,
                                                                  GstPadActivateModeFunction activatemode,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 /* data passing functions */
 void                   gst_pad_set_chain_function_full         (GstPad *pad,
                                                                  GstPadChainFunction chain,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 void                   gst_pad_set_chain_list_function_full    (GstPad *pad,
                                                                  GstPadChainListFunction chainlist,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 void                   gst_pad_set_getrange_function_full      (GstPad *pad,
                                                                  GstPadGetRangeFunction get,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 void                   gst_pad_set_event_function_full         (GstPad *pad,
                                                                  GstPadEventFunction event,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 
-#define gst_pad_set_activate_function(p,f)      gst_pad_set_activate_function_full((p),(f),NULL)
-#define gst_pad_set_activatemode_function(p,f)  gst_pad_set_activatemode_function_full((p),(f),NULL)
-#define gst_pad_set_chain_function(p,f)         gst_pad_set_chain_function_full((p),(f),NULL)
-#define gst_pad_set_chain_list_function(p,f)    gst_pad_set_chain_list_function_full((p),(f),NULL)
-#define gst_pad_set_getrange_function(p,f)      gst_pad_set_getrange_function_full((p),(f),NULL)
-#define gst_pad_set_event_function(p,f)         gst_pad_set_event_function_full((p),(f),NULL)
+#define gst_pad_set_activate_function(p,f)      gst_pad_set_activate_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_activatemode_function(p,f)  gst_pad_set_activatemode_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_chain_function(p,f)         gst_pad_set_chain_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_chain_list_function(p,f)    gst_pad_set_chain_list_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_getrange_function(p,f)      gst_pad_set_getrange_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_event_function(p,f)         gst_pad_set_event_function_full((p),(f),NULL,NULL)
 
 /* pad links */
 void                   gst_pad_set_link_function_full          (GstPad *pad,
                                                                  GstPadLinkFunction link,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 void                   gst_pad_set_unlink_function_full        (GstPad *pad,
                                                                  GstPadUnlinkFunction unlink,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 
-#define gst_pad_set_link_function(p,f)          gst_pad_set_link_function_full((p),(f),NULL)
-#define gst_pad_set_unlink_function(p,f)        gst_pad_set_unlink_function_full((p),(f),NULL)
+#define gst_pad_set_link_function(p,f)          gst_pad_set_link_function_full((p),(f),NULL,NULL)
+#define gst_pad_set_unlink_function(p,f)        gst_pad_set_unlink_function_full((p),(f),NULL,NULL)
 
 gboolean                gst_pad_can_link                        (GstPad *srcpad, GstPad *sinkpad);
 GstPadLinkReturn        gst_pad_link                           (GstPad *srcpad, GstPad *sinkpad);
@@ -923,21 +960,23 @@ gboolean          gst_pad_stop_task                       (GstPad *pad);
 /* internal links */
 void                    gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
                                                                  GstPadIterIntLinkFunction iterintlink,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 GstIterator *           gst_pad_iterate_internal_links          (GstPad * pad);
 GstIterator *           gst_pad_iterate_internal_links_default  (GstPad * pad, GstObject *parent);
 
-#define gst_pad_set_iterate_internal_links_function(p,f) gst_pad_set_iterate_internal_links_function_full((p),(f),NULL)
+#define gst_pad_set_iterate_internal_links_function(p,f) gst_pad_set_iterate_internal_links_function_full((p),(f),NULL,NULL)
 
 /* generic query function */
 gboolean               gst_pad_query                           (GstPad *pad, GstQuery *query);
 gboolean               gst_pad_peer_query                      (GstPad *pad, GstQuery *query);
 void                   gst_pad_set_query_function_full         (GstPad *pad, GstPadQueryFunction query,
+                                                                 gpointer user_data,
                                                                  GDestroyNotify notify);
 gboolean               gst_pad_query_default                   (GstPad *pad, GstObject *parent,
                                                                  GstQuery *query);
 
-#define gst_pad_set_query_function(p,f)   gst_pad_set_query_function_full((p),(f),NULL)
+#define gst_pad_set_query_function(p,f)   gst_pad_set_query_function_full((p),(f),NULL,NULL)
 
 /* misc helper functions */
 gboolean               gst_pad_forward                         (GstPad *pad, GstPadForwardFunction forward,