webrtcbin: Notify missing ice-gathering-state for COMPLETE 16/265816/7 submit/tizen/20211117.064045
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 29 Oct 2021 06:45:18 +0000 (15:45 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 16 Nov 2021 05:30:08 +0000 (14:30 +0900)
Occasionally, GATHERING_STATE_COMPLETE was obtained in _update_ice_
gathering_state_task() before consuming all the tasks for local ICE
candidates in _on_local_ice_candidate_task(). It missed notifying the
'ice-gathering-state' signal for gathering completion.
This patch fixes it.

Change-Id: Ie0a997e6976f48b876cb0741f488826a0c172116
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
ext/webrtc/gstwebrtcbin.c
ext/webrtc/gstwebrtcbin.h

index 7162e878464101a5f7c4cd32ae3540b770b2870c..76f6c448d86eaea13283af538ca34c51b78bb172 100644 (file)
@@ -1141,6 +1141,32 @@ _collate_peer_connection_states (GstWebRTCBin * webrtc)
 #undef STATE
 }
 
+#ifdef __TIZEN__
+static void
+_update_and_notify_ice_gathering_state (GstWebRTCBin * webrtc, GstWebRTCICEGatheringState state)
+{
+  GstWebRTCICEGatheringState old_state = webrtc->ice_gathering_state;
+
+  if (state != webrtc->ice_gathering_state) {
+    gchar *old_s, *new_s;
+
+    old_s = _enum_value_to_string (GST_TYPE_WEBRTC_ICE_GATHERING_STATE,
+        old_state);
+    new_s = _enum_value_to_string (GST_TYPE_WEBRTC_ICE_GATHERING_STATE,
+        state);
+    GST_INFO_OBJECT (webrtc, "ICE gathering state change from %s(%u) to %s(%u)",
+        old_s, old_state, new_s, state);
+    g_free (old_s);
+    g_free (new_s);
+
+    webrtc->ice_gathering_state = state;
+    PC_UNLOCK (webrtc);
+    g_object_notify (G_OBJECT (webrtc), "ice-gathering-state");
+    PC_LOCK (webrtc);
+  }
+}
+#endif
+
 static void
 _update_ice_gathering_state_task (GstWebRTCBin * webrtc, gpointer data)
 {
@@ -1157,11 +1183,23 @@ _update_ice_gathering_state_task (GstWebRTCBin * webrtc, gpointer data)
     ICE_LOCK (webrtc);
     if (webrtc->priv->pending_local_ice_candidates->len != 0) {
       /* ICE candidates queued for emissiong -> we're gathering, not complete */
+#ifdef __TIZEN__
+      webrtc->pending_ice_gathering_state = GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE;
+      GST_INFO_OBJECT (webrtc, "set pending_ice_gathering_state to (%u)",
+          webrtc->pending_ice_gathering_state);
+      ICE_UNLOCK (webrtc);
+      return;
+    }
+#else
       new_state = GST_WEBRTC_ICE_GATHERING_STATE_GATHERING;
     }
+#endif
     ICE_UNLOCK (webrtc);
   }
 
+#ifdef __TIZEN__
+  _update_and_notify_ice_gathering_state (webrtc, new_state);
+#else
   if (new_state != webrtc->ice_gathering_state) {
     gchar *old_s, *new_s;
 
@@ -1179,6 +1217,7 @@ _update_ice_gathering_state_task (GstWebRTCBin * webrtc, gpointer data)
     g_object_notify (G_OBJECT (webrtc), "ice-gathering-state");
     PC_LOCK (webrtc);
   }
+#endif
 }
 
 static void
@@ -5286,6 +5325,12 @@ _on_local_ice_candidate_task (GstWebRTCBin * webrtc)
 
   }
   g_array_free (items, TRUE);
+#ifdef __TIZEN__
+  if (webrtc->pending_ice_gathering_state == GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE) {
+    _update_and_notify_ice_gathering_state (webrtc, GST_WEBRTC_ICE_GATHERING_STATE_COMPLETE);
+    webrtc->pending_ice_gathering_state = GST_WEBRTC_ICE_GATHERING_STATE_NEW;
+  }
+#endif
 }
 
 static void
index f3eb9f6d60aa92f705636684273504e4eda4df49..7886700b93271f79daed856b4b3517053360246f 100644 (file)
@@ -72,6 +72,9 @@ struct _GstWebRTCBin
 
   GstWebRTCSignalingState           signaling_state;
   GstWebRTCICEGatheringState        ice_gathering_state;
+#ifdef __TIZEN__
+  GstWebRTCICEGatheringState        pending_ice_gathering_state;
+#endif
   GstWebRTCICEConnectionState       ice_connection_state;
   GstWebRTCPeerConnectionState      peer_connection_state;