webrtcstats: Avoid copy of GstStructure
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Sat, 10 Oct 2020 00:59:58 +0000 (20:59 -0400)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 18 Aug 2021 06:39:53 +0000 (06:39 +0000)
Instead transfer the ownership to the new structure

Change-Id: I08281880d7267ddddd39eb867669df48af5156d8
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1766>

ext/webrtc/gstwebrtcstats.c

index a251018..4505f5b 100644 (file)
@@ -81,6 +81,20 @@ _get_peer_connection_stats (GstWebRTCBin * webrtc)
   return s;
 }
 
+static void
+_gst_structure_take_structure (GstStructure * s, const char *fieldname,
+    GstStructure ** value_s)
+{
+  GValue v = G_VALUE_INIT;
+
+  g_value_init (&v, GST_TYPE_STRUCTURE);
+  g_value_take_boxed (&v, *value_s);
+
+  gst_structure_take_value (s, fieldname, &v);
+
+  *value_s = NULL;
+}
+
 #define CLOCK_RATE_VALUE_TO_SECONDS(v,r) ((double) v / (double) clock_rate)
 #define FIXED_16_16_TO_DOUBLE(v) ((double) ((v & 0xffff0000) >> 16) + ((v & 0xffff) / 65536.0))
 #define FIXED_32_32_TO_DOUBLE(v) ((double) ((v & G_GUINT64_CONSTANT (0xffffffff00000000)) >> 32) + ((v & G_GUINT64_CONSTANT (0xffffffff)) / 4294967296.0))
@@ -244,11 +258,8 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
        DOMString            encoderImplementation;
      */
 
-    gst_structure_set (s, out_id, GST_TYPE_STRUCTURE, out, NULL);
-    gst_structure_set (s, r_in_id, GST_TYPE_STRUCTURE, r_in, NULL);
-
-    gst_structure_free (out);
-    gst_structure_free (r_in);
+    _gst_structure_take_structure (s, out_id, &out);
+    _gst_structure_take_structure (s, r_in_id, &r_in);
 
     g_free (out_id);
     g_free (r_in_id);
@@ -483,11 +494,8 @@ _get_stats_from_rtp_source_stats (GstWebRTCBin * webrtc,
 
     gst_structure_free (jb_stats);
 
-    gst_structure_set (s, in_id, GST_TYPE_STRUCTURE, in, NULL);
-    gst_structure_set (s, r_out_id, GST_TYPE_STRUCTURE, r_out, NULL);
-
-    gst_structure_free (in);
-    gst_structure_free (r_out);
+    _gst_structure_take_structure (s, in_id, &in);
+    _gst_structure_take_structure (s, r_out_id, &r_out);
 
     g_free (in_id);
     g_free (r_out_id);