From d04a80676e3c9aa65c41ff186a0587600bd2b8ab Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 19 Aug 2022 09:07:50 -0400 Subject: [PATCH] webrtc:ice: Fix candidate stats related APIs for bindings null-terminated arrays of structures is not usable. Part-of: --- .../gst-plugins-bad/gst-libs/gst/webrtc/ice.c | 4 ++-- .../gst-plugins-bad/gst-libs/gst/webrtc/ice.h | 8 +++---- .../gst-libs/gst/webrtc/nice/nice.c | 27 ++++++++++++---------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c index 829f2e3..de08b3d 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c @@ -254,7 +254,7 @@ gst_webrtc_ice_set_tos (GstWebRTCICE * ice, GstWebRTCICEStream * stream, * Returns: (transfer full)(array zero-terminated=1): List of local candidates * Since: 1.22 */ -GstWebRTCICECandidateStats * +GstWebRTCICECandidateStats ** gst_webrtc_ice_get_local_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream) { @@ -272,7 +272,7 @@ gst_webrtc_ice_get_local_candidates (GstWebRTCICE * ice, * Returns: (transfer full) (array zero-terminated=1): List of remote candidates * Since: 1.22 */ -GstWebRTCICECandidateStats * +GstWebRTCICECandidateStats ** gst_webrtc_ice_get_remote_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream) { diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h index ee17cd5..3affca1 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h @@ -113,9 +113,9 @@ struct _GstWebRTCICEClass { GstWebRTCICEOnCandidateFunc func, gpointer user_data, GDestroyNotify notify); - GstWebRTCICECandidateStats* (*get_local_candidates) (GstWebRTCICE * ice, + GstWebRTCICECandidateStats** (*get_local_candidates)(GstWebRTCICE * ice, GstWebRTCICEStream * stream); - GstWebRTCICECandidateStats* (*get_remote_candidates)(GstWebRTCICE * ice, + GstWebRTCICECandidateStats**(*get_remote_candidates)(GstWebRTCICE * ice, GstWebRTCICEStream * stream); gboolean (*get_selected_pair) (GstWebRTCICE * ice, GstWebRTCICEStream * stream, @@ -198,11 +198,11 @@ void gst_webrtc_ice_set_tos (GstWebRTCIC guint tos); GST_WEBRTC_API -GstWebRTCICECandidateStats* gst_webrtc_ice_get_local_candidates (GstWebRTCICE * ice, +GstWebRTCICECandidateStats** gst_webrtc_ice_get_local_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream); GST_WEBRTC_API -GstWebRTCICECandidateStats* gst_webrtc_ice_get_remote_candidates (GstWebRTCICE * ice, +GstWebRTCICECandidateStats** gst_webrtc_ice_get_remote_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream); GST_WEBRTC_API diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c index 2248c79..d2ba844 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c @@ -1177,27 +1177,30 @@ _populate_candidate_stats (GstWebRTCNice * ice, NiceCandidate * cand, static void _populate_candidate_list_stats (GstWebRTCNice * ice, GSList * cands, - GstWebRTCICEStream * stream, GArray * result, gboolean is_local) + GstWebRTCICEStream * stream, GPtrArray * result, gboolean is_local) { GSList *item; for (item = cands; item != NULL; item = item->next) { - GstWebRTCICECandidateStats stats; + GstWebRTCICECandidateStats *stats = + g_malloc0 (sizeof (GstWebRTCICECandidateStats)); NiceCandidate *c = item->data; - _populate_candidate_stats (ice, c, stream, &stats, is_local); - g_array_append_val (result, stats); + _populate_candidate_stats (ice, c, stream, stats, is_local); + g_ptr_array_add (result, stats); } + + g_ptr_array_add (result, NULL); } -static GstWebRTCICECandidateStats * +static GstWebRTCICECandidateStats ** gst_webrtc_nice_get_local_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream) { GstWebRTCNice *nice = GST_WEBRTC_NICE (ice); GSList *cands = NULL; - GArray *result = - g_array_new (TRUE, TRUE, sizeof (GstWebRTCICECandidateStats)); + /* TODO: Use a g_ptr_array_new_null_terminated once when we depend on GLib 2.74 */ + GPtrArray *result = g_ptr_array_new (); cands = nice_agent_get_local_candidates (nice->priv->nice_agent, stream->stream_id, NICE_COMPONENT_TYPE_RTP); @@ -1205,18 +1208,18 @@ gst_webrtc_nice_get_local_candidates (GstWebRTCICE * ice, _populate_candidate_list_stats (nice, cands, stream, result, TRUE); g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free); - return (GstWebRTCICECandidateStats *) g_array_free (result, FALSE); + return (GstWebRTCICECandidateStats **) g_ptr_array_free (result, FALSE); } -static GstWebRTCICECandidateStats * +static GstWebRTCICECandidateStats ** gst_webrtc_nice_get_remote_candidates (GstWebRTCICE * ice, GstWebRTCICEStream * stream) { GstWebRTCNice *nice = GST_WEBRTC_NICE (ice); GSList *cands = NULL; - GArray *result = - g_array_new (TRUE, TRUE, sizeof (GstWebRTCICECandidateStats)); + /* TODO: Use a g_ptr_array_new_null_terminated once when we depend on GLib 2.74 */ + GPtrArray *result = g_ptr_array_new (); cands = nice_agent_get_remote_candidates (nice->priv->nice_agent, stream->stream_id, NICE_COMPONENT_TYPE_RTP); @@ -1224,7 +1227,7 @@ gst_webrtc_nice_get_remote_candidates (GstWebRTCICE * ice, _populate_candidate_list_stats (nice, cands, stream, result, FALSE); g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free); - return (GstWebRTCICECandidateStats *) g_array_free (result, FALSE); + return (GstWebRTCICECandidateStats **) g_ptr_array_free (result, FALSE); } static gboolean -- 2.7.4