nlecomposition: Fix small remaining race in previous commit
authorSebastian Dröge <sebastian@centricular.com>
Thu, 10 Nov 2016 13:17:50 +0000 (15:17 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 11 Nov 2016 05:44:28 +0000 (07:44 +0200)
The seek action might currently be handled (in which case it is not in
the actions list and the action lock is not locked), but not actually
handled completely yet (the seqnum is not stored yet).

To prevent this, we remember what the current action is that is being
handled, and also compare to that.

https://bugzilla.gnome.org/show_bug.cgi?id=774149

plugins/nle/nlecomposition.c

index b817876..67027b9 100644 (file)
@@ -105,6 +105,12 @@ typedef struct
   NleUpdateStackReason reason;
 } UpdateCompositionData;
 
+typedef struct _Action
+{
+  GCClosure closure;
+  gint priority;
+} Action;
+
 struct _NleCompositionPrivate
 {
   gboolean dispose_has_run;
@@ -161,6 +167,7 @@ struct _NleCompositionPrivate
   GMutex actions_lock;
   GCond actions_cond;
   GList *actions;
+  Action *current_action;
 
   gboolean running;
   gboolean initialized;
@@ -181,12 +188,6 @@ struct _NleCompositionPrivate
   NleUpdateStackReason updating_reason;
 };
 
-typedef struct _Action
-{
-  GCClosure closure;
-  gint priority;
-} Action;
-
 #define ACTION_CALLBACK(__action) (((GCClosure*) (__action))->callback)
 
 static guint _signals[LAST_SIGNAL] = { 0 };
@@ -379,14 +380,19 @@ _execute_actions (NleComposition * comp)
 
     lact = g_list_first (priv->actions);
     priv->actions = g_list_remove_link (priv->actions, lact);
+    priv->current_action = lact->data;
     ACTIONS_UNLOCK (comp);
 
     GST_INFO_OBJECT (comp, "Invoking %p:%s",
         lact->data, GST_DEBUG_FUNCPTR_NAME ((ACTION_CALLBACK (lact->data))));
     g_closure_invoke (lact->data, NULL, 1, params, NULL);
     g_value_unset (&params[0]);
+
+    ACTIONS_LOCK (comp);
     g_closure_unref (lact->data);
     g_list_free (lact);
+    priv->current_action = NULL;
+    ACTIONS_UNLOCK (comp);
 
     GST_LOG_OBJECT (comp, "remaining actions [%d]",
         g_list_length (priv->actions));
@@ -852,6 +858,20 @@ _add_seek_action (NleComposition * comp, GstEvent * event)
     }
   }
 
+  /* Check if this seqnum is currently being handled */
+  if (comp->priv->current_action) {
+    Action *act = comp->priv->current_action;
+    if (ACTION_CALLBACK (act) == G_CALLBACK (_seek_pipeline_func)) {
+      SeekData *tmp_data = ((GClosure *) act)->data;
+
+      if (gst_event_get_seqnum (tmp_data->event) == seqnum) {
+        GST_DEBUG_OBJECT (comp,
+            "Not adding Action, same seqnum as previous seek");
+        ACTIONS_UNLOCK (comp);
+        return;
+      }
+    }
+  }
 
   GST_DEBUG_OBJECT (comp, "Adding Action");