From 8dd4c215da53dd5c5831bed3e662b79fa264c016 Mon Sep 17 00:00:00 2001
From: Thibault Saunier <tsaunier@igalia.com>
Date: Mon, 15 Aug 2022 11:36:25 -0400
Subject: [PATCH] webrtc: Make GstWebRTCIceCandidateStats a Boxed type

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2891>
---
 .../gst-plugins-bad/gst-libs/gst/webrtc/ice.c | 29 +++++++++++++++++--
 .../gst-plugins-bad/gst-libs/gst/webrtc/ice.h |  6 ++++
 2 files changed, 33 insertions(+), 2 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 a3a42053f9..d197f19ce4 100644
--- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c
+++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c
@@ -281,7 +281,7 @@ gst_webrtc_ice_get_remote_candidates (GstWebRTCICE * ice,
  * @stream: The #GstWebRTCICEStream
  * @local_stats: A pointer to #GstWebRTCICECandidateStats for local candidate
  * @remote_stats: A pointer to #GstWebRTCICECandidateStats for remote candidate
- * 
+ *
  * Returns: FALSE on failure, otherwise @local_stats @remote_stats will be set
  * Since: 1.22
  */
@@ -300,7 +300,7 @@ gst_webrtc_ice_get_selected_pair (GstWebRTCICE * ice,
 /**
  * gst_webrtc_ice_candidate_stats_free:
  * @stats: The #GstWebRTCICECandidateStats to be free'd
- * 
+ *
  * Helper function to free #GstWebRTCICECandidateStats
  * Since: 1.22
  */
@@ -315,6 +315,31 @@ gst_webrtc_ice_candidate_stats_free (GstWebRTCICECandidateStats * stats)
   g_free (stats);
 }
 
+/**
+ * gst_webrtc_ice_candidate_stats_copy:
+ * @stats: The #GstWebRTCICE
+ *
+ * Returns: (transfer full): A copy of @stats
+ * Since: 1.22
+ */
+GstWebRTCICECandidateStats *
+gst_webrtc_ice_candidate_stats_copy (GstWebRTCICECandidateStats * stats)
+{
+  GstWebRTCICECandidateStats *copy =
+      g_malloc (sizeof (GstWebRTCICECandidateStats));
+
+  *copy = *stats;
+
+  copy->ipaddr = g_strdup (stats->ipaddr);
+  copy->url = g_strdup (stats->url);
+
+  return copy;
+}
+
+G_DEFINE_BOXED_TYPE (GstWebRTCICECandidateStats, gst_webrtc_ice_candidate_stats,
+    (GBoxedCopyFunc) gst_webrtc_ice_candidate_stats_copy,
+    (GBoxedFreeFunc) gst_webrtc_ice_candidate_stats_free);
+
 /**
  * gst_webrtc_ice_set_on_ice_candidate:
  * @ice: The #GstWebRTCICE
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 a39c5a6fda..ea16441f25 100644
--- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h
+++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.h
@@ -212,8 +212,14 @@ gboolean                    gst_webrtc_ice_get_selected_pair        (GstWebRTCIC
 GST_WEBRTC_API
 void                        gst_webrtc_ice_candidate_stats_free     (GstWebRTCICECandidateStats * stats);
 
+GST_WEBRTC_API
+GType                       gst_webrtc_ice_candidate_stats_get_type (void);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstWebRTCICE, gst_object_unref)
 
+GST_WEBRTC_API
+GstWebRTCICECandidateStats * gst_webrtc_ice_candidate_stats_copy (GstWebRTCICECandidateStats *stats);
+
 G_END_DECLS
 
 #endif /* __GST_WEBRTC_ICE_H__ */