mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
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
This commit is contained in:
parent
d9b52d1f5e
commit
be05515da7
2 changed files with 2 additions and 30 deletions
|
@ -501,9 +501,6 @@ gst_matroska_mux_init (GstMatroskaMux * mux, gpointer g_class)
|
||||||
mux->num_v_streams = 0;
|
mux->num_v_streams = 0;
|
||||||
mux->internal_toc = NULL;
|
mux->internal_toc = NULL;
|
||||||
|
|
||||||
/* create used uid list */
|
|
||||||
mux->used_uids = g_array_sized_new (FALSE, FALSE, sizeof (guint64), 10);
|
|
||||||
|
|
||||||
/* initialize remaining variables */
|
/* initialize remaining variables */
|
||||||
gst_matroska_mux_reset (GST_ELEMENT (mux));
|
gst_matroska_mux_reset (GST_ELEMENT (mux));
|
||||||
}
|
}
|
||||||
|
@ -526,8 +523,6 @@ gst_matroska_mux_finalize (GObject * object)
|
||||||
gst_object_unref (mux->ebml_write);
|
gst_object_unref (mux->ebml_write);
|
||||||
g_free (mux->writing_app);
|
g_free (mux->writing_app);
|
||||||
|
|
||||||
g_array_free (mux->used_uids, TRUE);
|
|
||||||
|
|
||||||
if (mux->internal_toc) {
|
if (mux->internal_toc) {
|
||||||
gst_toc_unref (mux->internal_toc);
|
gst_toc_unref (mux->internal_toc);
|
||||||
mux->internal_toc = NULL;
|
mux->internal_toc = NULL;
|
||||||
|
@ -541,29 +536,14 @@ gst_matroska_mux_finalize (GObject * object)
|
||||||
* gst_matroska_mux_create_uid:
|
* gst_matroska_mux_create_uid:
|
||||||
* @mux: #GstMatroskaMux to generate UID for.
|
* @mux: #GstMatroskaMux to generate UID for.
|
||||||
*
|
*
|
||||||
* Generate new unused track UID.
|
* Generate new track UID.
|
||||||
*
|
*
|
||||||
* Returns: New track UID.
|
* Returns: New track UID.
|
||||||
*/
|
*/
|
||||||
static guint64
|
static guint64
|
||||||
gst_matroska_mux_create_uid (GstMatroskaMux * mux)
|
gst_matroska_mux_create_uid (GstMatroskaMux * mux)
|
||||||
{
|
{
|
||||||
guint64 uid = 0;
|
return (((guint64) g_random_int ()) << 32) | g_random_int ();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -712,11 +692,6 @@ gst_matroska_mux_reset (GstElement * element)
|
||||||
}
|
}
|
||||||
|
|
||||||
mux->chapters_pos = 0;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -140,9 +140,6 @@ struct _GstMatroskaMux {
|
||||||
|
|
||||||
/* Flag to ease handling of WebM specifics */
|
/* Flag to ease handling of WebM specifics */
|
||||||
gboolean is_webm;
|
gboolean is_webm;
|
||||||
|
|
||||||
/* used uids */
|
|
||||||
GArray *used_uids;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _GstMatroskaMuxClass {
|
typedef struct _GstMatroskaMuxClass {
|
||||||
|
|
Loading…
Reference in a new issue