From 9a6fa2e6a106c5586da4eab41767528a578f6a8a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 22 Feb 2023 15:26:58 +0100 Subject: [PATCH] module-rtp: use new random functions --- src/modules/module-rtp-sap.c | 4 +--- src/modules/module-rtp-sink.c | 18 ++++-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index 173d85d8e..dd0323590 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -647,9 +647,7 @@ static struct session *session_new_announce(struct impl *impl, struct node *node sess->announce = true; - if ((res = pw_getrandom(&sdp->hash, sizeof(sdp->hash), 0)) < 0) - return NULL; - + sdp->hash = pw_rand32(); sdp->ntp = (uint32_t) time(NULL) + 2208988800U; sess->props = props; diff --git a/src/modules/module-rtp-sink.c b/src/modules/module-rtp-sink.c index b5212b1fd..ca22d8c78 100644 --- a/src/modules/module-rtp-sink.c +++ b/src/modules/module-rtp-sink.c @@ -892,16 +892,6 @@ static void copy_props(struct impl *impl, struct pw_properties *props, const cha } } -static uint32_t make_random(void) -{ - int res; - uint32_t val; - do { - res = pw_getrandom(&val, sizeof(val), 0); - } while ((res == -1) && (errno == EINTR)); - return val; -} - SPA_EXPORT int pipewire__module_init(struct pw_impl_module *module, const char *args) { @@ -1020,8 +1010,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) break; } impl->payload = 127; - impl->seq = make_random(); - impl->ssrc = make_random(); + impl->seq = pw_rand32(); + impl->ssrc = pw_rand32(); str = pw_properties_get(props, "local.ifname"); impl->ifname = str ? strdup(str) : NULL; @@ -1033,7 +1023,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) goto out; } - impl->dst_port = DEFAULT_PORT + ((uint32_t) (make_random() % 512) << 1); + impl->dst_port = DEFAULT_PORT + ((uint32_t) (pw_rand32() % 512) << 1); impl->dst_port = pw_properties_get_uint32(props, "destination.port", impl->dst_port); if ((str = pw_properties_get(props, "destination.ip")) == NULL) str = DEFAULT_DESTINATION_IP; @@ -1048,7 +1038,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) impl->dscp = pw_properties_get_uint32(props, "net.dscp", DEFAULT_DSCP); ts_offset = pw_properties_get_int64(props, "sess.ts-offset", DEFAULT_TS_OFFSET); - impl->ts_offset = ts_offset < 0 ? make_random() : ts_offset; + impl->ts_offset = ts_offset < 0 ? pw_rand32() : ts_offset; str = pw_properties_get(props, "sess.ts-refclk"); impl->ts_refclk = str ? strdup(str) : NULL;