[gst-cvs] gst-plugins-base: basertppayload: Make instance init faster by not reading /dev/urandom 3 times

Sebastian Dröge slomo at kemper.freedesktop.org
Tue Sep 1 01:41:51 PDT 2009


Module: gst-plugins-base
Branch: master
Commit: ec91d508af9fb359ebab7240497bd043d84d652e
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=ec91d508af9fb359ebab7240497bd043d84d652e

Author: Jonas Holmberg <jonas.holmberg at axis.com>
Date:   Tue Sep  1 10:39:52 2009 +0200

basertppayload: Make instance init faster by not reading /dev/urandom 3 times

... which is the default seed when creating a new GRand. Because
GLib in older versions used buffered IO this would take a lot of time.

Instead use the global GRand for getting random numbers and keep the
three instance GRand for backward compatibility with a simple seed.

Fixes bug #593284.

---

 gst-libs/gst/rtp/gstbasertppayload.c |   13 ++++++-------
 gst-libs/gst/rtp/gstbasertppayload.h |    1 +
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gst-libs/gst/rtp/gstbasertppayload.c b/gst-libs/gst/rtp/gstbasertppayload.c
index 861bb60..f01b1a5 100644
--- a/gst-libs/gst/rtp/gstbasertppayload.c
+++ b/gst-libs/gst/rtp/gstbasertppayload.c
@@ -241,9 +241,9 @@ gst_basertppayload_init (GstBaseRTPPayload * basertppayload, gpointer g_class)
       gst_basertppayload_chain);
   gst_element_add_pad (GST_ELEMENT (basertppayload), basertppayload->sinkpad);
 
-  basertppayload->seq_rand = g_rand_new ();
-  basertppayload->ssrc_rand = g_rand_new ();
-  basertppayload->ts_rand = g_rand_new ();
+  basertppayload->seq_rand = g_rand_new_with_seed (g_random_int ());
+  basertppayload->ssrc_rand = g_rand_new_with_seed (g_random_int ());
+  basertppayload->ts_rand = g_rand_new_with_seed (g_random_int ());
 
   basertppayload->mtu = DEFAULT_MTU;
   basertppayload->pt = DEFAULT_PT;
@@ -902,20 +902,19 @@ gst_basertppayload_change_state (GstElement * element,
       gst_segment_init (&basertppayload->segment, GST_FORMAT_UNDEFINED);
 
       if (priv->seqnum_offset_random)
-        basertppayload->seqnum_base =
-            g_rand_int_range (basertppayload->seq_rand, 0, G_MAXUINT16);
+        basertppayload->seqnum_base = g_random_int_range (0, G_MAXUINT16);
       else
         basertppayload->seqnum_base = basertppayload->seqnum_offset;
       priv->next_seqnum = basertppayload->seqnum_base;
       basertppayload->seqnum = basertppayload->seqnum_base;
 
       if (priv->ssrc_random)
-        basertppayload->current_ssrc = g_rand_int (basertppayload->ssrc_rand);
+        basertppayload->current_ssrc = g_random_int ();
       else
         basertppayload->current_ssrc = basertppayload->ssrc;
 
       if (priv->ts_offset_random)
-        basertppayload->ts_base = g_rand_int (basertppayload->ts_rand);
+        basertppayload->ts_base = g_random_int ();
       else
         basertppayload->ts_base = basertppayload->ts_offset;
       basertppayload->timestamp = basertppayload->ts_base;
diff --git a/gst-libs/gst/rtp/gstbasertppayload.h b/gst-libs/gst/rtp/gstbasertppayload.h
index b790bb7..18d3778 100644
--- a/gst-libs/gst/rtp/gstbasertppayload.h
+++ b/gst-libs/gst/rtp/gstbasertppayload.h
@@ -79,6 +79,7 @@ struct _GstBaseRTPPayload
   GstPad  *sinkpad;
   GstPad  *srcpad;
 
+  /* FIXME 0.11: none of these GRands are used anymore, remove them */
   GRand   *seq_rand;
   GRand   *ssrc_rand;
   GRand   *ts_rand;





More information about the Gstreamer-commits mailing list