gstpad: Probes that return HANDLED can reset the data info field
[platform/upstream/gstreamer.git] / gst / gstpad.c
index 80d1232..dcd52f2 100644 (file)
@@ -169,7 +169,7 @@ typedef struct
   gboolean handled;
   gboolean marshalled;
 
-  GHook **called_probes;
+  gulong *called_probes;
   guint n_called_probes;
   guint called_probes_size;
   gboolean retry;
@@ -832,8 +832,7 @@ gst_pad_get_property (GObject * object, guint prop_id,
  * will be assigned.
  * This function makes a copy of the name so you can safely free the name.
  *
- * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
- * case of an error.
+ * Returns: (transfer floating): a new #GstPad.
  *
  * MT safe.
  */
@@ -854,8 +853,7 @@ gst_pad_new (const gchar * name, GstPadDirection direction)
  * will be assigned.
  * This function makes a copy of the name so you can safely free the name.
  *
- * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
- * case of an error.
+ * Returns: (transfer floating): a new #GstPad.
  */
 GstPad *
 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
@@ -880,8 +878,7 @@ gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
  * will be assigned.
  * This function makes a copy of the name so you can safely free the name.
  *
- * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
- * case of an error.
+ * Returns: (transfer floating): a new #GstPad.
  */
 GstPad *
 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
@@ -1372,6 +1369,9 @@ cleanup_hook (GstPad * pad, GHook * hook)
 {
   GstPadProbeType type;
 
+  GST_DEBUG_OBJECT (pad,
+      "cleaning up hook %lu with flags %08x", hook->hook_id, hook->flags);
+
   if (!G_HOOK_IS_VALID (hook))
     return;
 
@@ -2082,6 +2082,10 @@ gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
  *
  * Sets the given unlink function for the pad. It will be called
  * when the pad is unlinked.
+ *
+ * Note that the pad's lock is already held when the unlink
+ * function is called, so most pad functions cannot be called
+ * from within the callback.
  */
 void
 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
@@ -3243,8 +3247,7 @@ done:
 typedef struct
 {
   gboolean live;
-  GstClockTime live_min, live_max;
-  GstClockTime non_live_min, non_live_max;
+  GstClockTime min, max;
 } LatencyFoldData;
 
 static gboolean
@@ -3268,7 +3271,6 @@ query_latency_default_fold (const GValue * item, GValue * ret,
   if (res) {
     gboolean live;
     GstClockTime min, max;
-    GstClockTime *min_store, *max_store;
 
     gst_query_parse_latency (query, &live, &min, &max);
 
@@ -3276,21 +3278,16 @@ query_latency_default_fold (const GValue * item, GValue * ret,
         " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
 
     if (live) {
-      min_store = &fold_data->live_min;
-      max_store = &fold_data->live_max;
-      fold_data->live = live;
-    } else {
-      min_store = &fold_data->non_live_min;
-      max_store = &fold_data->non_live_max;
-    }
+      if (min > fold_data->min)
+        fold_data->min = min;
 
-    if (min > *min_store)
-      *min_store = min;
+      if (fold_data->max == GST_CLOCK_TIME_NONE)
+        fold_data->max = max;
+      else if (max < fold_data->max)
+        fold_data->max = max;
 
-    if (*max_store == GST_CLOCK_TIME_NONE)
-      *max_store = max;
-    else if (max < *max_store)
-      *max_store = max;
+      fold_data->live = TRUE;
+    }
   } else if (peer) {
     GST_DEBUG_OBJECT (pad, "latency query failed");
     g_value_set_boolean (ret, FALSE);
@@ -3322,8 +3319,8 @@ gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
 
 retry:
   fold_data.live = FALSE;
-  fold_data.live_min = fold_data.non_live_min = 0;
-  fold_data.live_max = fold_data.non_live_max = GST_CLOCK_TIME_NONE;
+  fold_data.min = 0;
+  fold_data.max = GST_CLOCK_TIME_NONE;
 
   g_value_set_boolean (&ret, TRUE);
   res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
@@ -3347,24 +3344,15 @@ retry:
 
   query_ret = g_value_get_boolean (&ret);
   if (query_ret) {
-    GstClockTime min, max;
-
-    if (fold_data.live) {
-      min = fold_data.live_min;
-      max = fold_data.live_max;
-    } else {
-      min = fold_data.non_live_min;
-      max = fold_data.non_live_max;
-    }
-
     GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
-        " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false", min, max);
+        " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
+        fold_data.min, fold_data.max);
 
-    if (min > max) {
+    if (fold_data.min > fold_data.max) {
       GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
     }
 
-    gst_query_set_latency (query, fold_data.live, min, max);
+    gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
   } else {
     GST_LOG_OBJECT (pad, "latency query failed");
   }
@@ -3431,6 +3419,10 @@ gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
       ret = gst_pad_query_latency_default (pad, query);
       forward = FALSE;
       break;
+    case GST_QUERY_BITRATE:
+      /* FIXME: better default handling */
+      forward = TRUE;
+      break;
     case GST_QUERY_POSITION:
     case GST_QUERY_SEEKING:
     case GST_QUERY_FORMATS:
@@ -3484,7 +3476,7 @@ probe_hook_marshal (GHook * hook, ProbeMarshall * data)
    * if we're actually calling probes a second time */
   if (data->retry) {
     for (i = 0; i < data->n_called_probes; i++) {
-      if (data->called_probes[i] == hook) {
+      if (data->called_probes[i] == hook->hook_id) {
         GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
             "hook %lu already called", hook->hook_id);
         return;
@@ -3497,17 +3489,17 @@ probe_hook_marshal (GHook * hook, ProbeMarshall * data)
     if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
       data->called_probes_size *= 2;
       data->called_probes =
-          g_renew (GHook *, data->called_probes, data->called_probes_size);
+          g_renew (gulong, data->called_probes, data->called_probes_size);
     } else {
-      GHook **tmp = data->called_probes;
+      gulong *tmp = data->called_probes;
 
       data->called_probes_size *= 2;
-      data->called_probes = g_new (GHook *, data->called_probes_size);
+      data->called_probes = g_new (gulong, data->called_probes_size);
       memcpy (data->called_probes, tmp,
-          N_STACK_ALLOCATE_PROBES * sizeof (GHook *));
+          N_STACK_ALLOCATE_PROBES * sizeof (gulong));
     }
   }
-  data->called_probes[data->n_called_probes++] = hook;
+  data->called_probes[data->n_called_probes++] = hook->hook_id;
 
   flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
   type = info->type;
@@ -3577,7 +3569,8 @@ probe_hook_marshal (GHook * hook, ProbeMarshall * data)
   if ((flags & GST_PAD_PROBE_TYPE_IDLE))
     pad->priv->idle_running--;
 
-  if (original_data != NULL && info->data == NULL) {
+  if (ret != GST_PAD_PROBE_HANDLED && original_data != NULL
+      && info->data == NULL) {
     GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
     info->type = GST_PAD_PROBE_TYPE_INVALID;
     data->dropped = TRUE;
@@ -3703,7 +3696,7 @@ do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
   ProbeMarshall data;
   guint cookie;
   gboolean is_block;
-  GHook *called_probes[N_STACK_ALLOCATE_PROBES];
+  gulong called_probes[N_STACK_ALLOCATE_PROBES];
 
   data.pad = pad;
   data.info = info;