diff --git a/subprojects/gstreamer/gst/glib-compat-private.h b/subprojects/gstreamer/gst/glib-compat-private.h index 617a50e4d1..18f6424628 100644 --- a/subprojects/gstreamer/gst/glib-compat-private.h +++ b/subprojects/gstreamer/gst/glib-compat-private.h @@ -34,6 +34,26 @@ G_BEGIN_DECLS #define g_memdup2(ptr,sz) ((G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)) #endif +#if !GLIB_CHECK_VERSION(2, 81, 1) +#define g_sort_array(a,n,s,f,udata) gst_g_sort_array(a,n,s,f,udata) + +// Don't need to maintain ABI compat here (n_elements), since we never pass +// the function as pointer but always call it directly ourselves. +static inline void +gst_g_sort_array (const void *array, + gssize n_elements, + size_t element_size, + GCompareDataFunc compare_func, + void *user_data) +{ + if (n_elements >= 0 && n_elements <= G_MAXINT) { + g_qsort_with_data (array, n_elements, element_size, compare_func, user_data); + } else { + g_abort (); + } +} +#endif + G_END_DECLS #endif diff --git a/subprojects/gstreamer/gst/gstpreset.c b/subprojects/gstreamer/gst/gstpreset.c index ed25b5bd08..e0d4597f7c 100644 --- a/subprojects/gstreamer/gst/gstpreset.c +++ b/subprojects/gstreamer/gst/gstpreset.c @@ -90,6 +90,8 @@ extern HMODULE _priv_gst_dll_handle; #endif +#include "glib-compat-private.h" + #define GST_CAT_DEFAULT preset_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); @@ -546,7 +548,7 @@ gst_preset_default_get_preset_names (GstPreset * preset) } /* sort the array now */ - g_qsort_with_data (groups, num_groups, sizeof (gchar *), + g_sort_array (groups, num_groups, sizeof (gchar *), (GCompareDataFunc) compare_strings, NULL); return groups; diff --git a/subprojects/gstreamer/gst/gstvecdeque.c b/subprojects/gstreamer/gst/gstvecdeque.c index dd1ba81ed1..356dcce2ac 100644 --- a/subprojects/gstreamer/gst/gstvecdeque.c +++ b/subprojects/gstreamer/gst/gstvecdeque.c @@ -37,6 +37,8 @@ #include #include "gstvecdeque.h" +#include "glib-compat-private.h" + #define gst_vec_deque_idx(a, i) \ ((a)->array + (((a)->head + (i)) % (a)->size) * (a)->elt_size) @@ -607,7 +609,7 @@ gst_vec_deque_sort (GstVecDeque * array, GCompareDataFunc compare_func, if (array->length == 0) return; - /* To be able to use g_qsort_with_data, we might need to rearrange: + /* To be able to use g_sort_array, we might need to rearrange: * [0-----TAIL][HEAD-----SIZE] -> [HEAD-------TAIL] */ if (array->head >= array->tail) { gsize t1 = array->head; @@ -631,7 +633,7 @@ gst_vec_deque_sort (GstVecDeque * array, GCompareDataFunc compare_func, } if (array->struct_array) { - g_qsort_with_data (array->array + + g_sort_array (array->array + (array->head % array->size) * array->elt_size, array->length, array->elt_size, compare_func, user_data); } else { @@ -639,7 +641,7 @@ gst_vec_deque_sort (GstVecDeque * array, GCompareDataFunc compare_func, * to dereference our pointers before passing them for comparison. * This matches the behaviour of gst_vec_deque_find(). */ QueueSortData sort_data = { compare_func, user_data }; - g_qsort_with_data (array->array + + g_sort_array (array->array + (array->head % array->size) * array->elt_size, array->length, array->elt_size, (GCompareDataFunc) compare_wrapper, &sort_data); } diff --git a/subprojects/gstreamer/libs/gst/net/gstnetclientclock.c b/subprojects/gstreamer/libs/gst/net/gstnetclientclock.c index 54f6de7eb1..dfa487ba3b 100644 --- a/subprojects/gstreamer/libs/gst/net/gstnetclientclock.c +++ b/subprojects/gstreamer/libs/gst/net/gstnetclientclock.c @@ -63,6 +63,8 @@ #include "gstnetclientclock.h" #include "gstnetutils.h" +#include "gst/glib-compat-private.h" + #include #include @@ -427,7 +429,7 @@ gst_net_client_internal_clock_observe_times (GstNetClientInternalClock * self, self->last_rtts_missing--; } else { memcpy (&last_rtts, &self->last_rtts, sizeof (last_rtts)); - g_qsort_with_data (&last_rtts, + g_sort_array (&last_rtts, MEDIAN_PRE_FILTERING_WINDOW, sizeof (GstClockTime), (GCompareDataFunc) compare_clock_time, NULL); diff --git a/subprojects/gstreamer/libs/gst/net/gstptpclock.c b/subprojects/gstreamer/libs/gst/net/gstptpclock.c index 2868452f70..8e026ae358 100644 --- a/subprojects/gstreamer/libs/gst/net/gstptpclock.c +++ b/subprojects/gstreamer/libs/gst/net/gstptpclock.c @@ -60,6 +60,8 @@ #include +#include "gst/glib-compat-private.h" + #ifdef G_OS_WIN32 #define WIN32_LEAN_AND_MEAN #include @@ -1457,7 +1459,7 @@ update_mean_path_delay (PtpDomainData * domain, PtpPendingSync * sync) } else { memcpy (&last_path_delays, &domain->last_path_delays, sizeof (last_path_delays)); - g_qsort_with_data (&last_path_delays, + g_sort_array (&last_path_delays, MEDIAN_PRE_FILTERING_WINDOW, sizeof (GstClockTime), (GCompareDataFunc) compare_clock_time, NULL); diff --git a/subprojects/gstreamer/tools/gst-inspect.c b/subprojects/gstreamer/tools/gst-inspect.c index a413340196..e31900c10a 100644 --- a/subprojects/gstreamer/tools/gst-inspect.c +++ b/subprojects/gstreamer/tools/gst-inspect.c @@ -50,6 +50,8 @@ #include #endif +#include "gst/glib-compat-private.h" + /* "R" : support color * "X" : do not clear the screen when leaving the pager * "F" : skip the pager if content fit into the screen @@ -429,7 +431,7 @@ print_object_properties_info (GObject * obj, GObjectClass * obj_class, gboolean first_flag; property_specs = g_object_class_list_properties (obj_class, &num_properties); - g_qsort_with_data (property_specs, num_properties, sizeof (gpointer), + g_sort_array (property_specs, num_properties, sizeof (gpointer), (GCompareDataFunc) sort_gparamspecs, NULL); n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);