From be05515da797115739bf352d6efdbc34eda511bb Mon Sep 17 00:00:00 2001 From: Martin Kelly Date: Wed, 5 Sep 2018 16:11:00 -0700 Subject: [PATCH] matroskamux: don't store used UIDs Currently, whenever we generate a 128-bit UID, we store it in a list and return 0 if we ever encounter a collision. This is so mathematically improbable that it's not worth checking for, so we can save memory and time by not tracking the UID. Even if a collision happened, a list of only 10 UIDs would be unlikely to detect it. This article has a good description of how improbable a collision is: https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions https://bugzilla.gnome.org/show_bug.cgi?id=797086 --- gst/matroska/matroska-mux.c | 29 ++--------------------------- gst/matroska/matroska-mux.h | 3 --- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/gst/matroska/matroska-mux.c b/gst/matroska/matroska-mux.c index d487a8245b..6e78192b2f 100644 --- a/gst/matroska/matroska-mux.c +++ b/gst/matroska/matroska-mux.c @@ -501,9 +501,6 @@ gst_matroska_mux_init (GstMatroskaMux * mux, gpointer g_class) mux->num_v_streams = 0; mux->internal_toc = NULL; - /* create used uid list */ - mux->used_uids = g_array_sized_new (FALSE, FALSE, sizeof (guint64), 10); - /* initialize remaining variables */ gst_matroska_mux_reset (GST_ELEMENT (mux)); } @@ -526,8 +523,6 @@ gst_matroska_mux_finalize (GObject * object) gst_object_unref (mux->ebml_write); g_free (mux->writing_app); - g_array_free (mux->used_uids, TRUE); - if (mux->internal_toc) { gst_toc_unref (mux->internal_toc); mux->internal_toc = NULL; @@ -541,29 +536,14 @@ gst_matroska_mux_finalize (GObject * object) * gst_matroska_mux_create_uid: * @mux: #GstMatroskaMux to generate UID for. * - * Generate new unused track UID. + * Generate new track UID. * * Returns: New track UID. */ static guint64 gst_matroska_mux_create_uid (GstMatroskaMux * mux) { - guint64 uid = 0; - - while (!uid) { - guint i; - - uid = (((guint64) g_random_int ()) << 32) | g_random_int (); - for (i = 0; i < mux->used_uids->len; i++) { - if (g_array_index (mux->used_uids, guint64, i) == uid) { - uid = 0; - break; - } - } - g_array_append_val (mux->used_uids, uid); - } - - return uid; + return (((guint64) g_random_int ()) << 32) | g_random_int (); } @@ -712,11 +692,6 @@ gst_matroska_mux_reset (GstElement * element) } mux->chapters_pos = 0; - - /* clear used uids */ - if (mux->used_uids->len > 0) { - g_array_remove_range (mux->used_uids, 0, mux->used_uids->len); - } } /** diff --git a/gst/matroska/matroska-mux.h b/gst/matroska/matroska-mux.h index 7283840663..d1275cf1c7 100644 --- a/gst/matroska/matroska-mux.h +++ b/gst/matroska/matroska-mux.h @@ -140,9 +140,6 @@ struct _GstMatroskaMux { /* Flag to ease handling of WebM specifics */ gboolean is_webm; - - /* used uids */ - GArray *used_uids; }; typedef struct _GstMatroskaMuxClass {