From 59d56bcb3f69e4a3b64f905f0f3bf23509862b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 20 Aug 2024 02:01:34 +0100 Subject: [PATCH] gst-plugins-bad: use g_sort_array() instead of deprecated g_qsort_with_data() Fixes compiler warnings with the latest GLib versions. See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4127 Part-of: --- .../gst-libs/gst/codecs/gsth264decoder.c | 16 ++++++++------- .../gst-libs/gst/glib-compat-private.h | 20 +++++++++++++++++++ .../gst-plugins-bad/sys/va/gstvaav1enc.c | 4 +++- .../gst-plugins-bad/sys/va/gstvah264enc.c | 10 ++++++---- .../gst-plugins-bad/sys/va/gstvah265enc.c | 6 ++++-- .../gst-plugins-bad/sys/va/gstvavp9enc.c | 4 +++- .../gst-plugins-bad/sys/va/meson.build | 2 +- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c index ec9665c99c..369c6d839e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c @@ -62,6 +62,8 @@ #include "gsth264decoder.h" #include "gsth264picture-private.h" +#include "gst/glib-compat-private.h" + GST_DEBUG_CATEGORY (gst_h264_decoder_debug); #define GST_CAT_DEFAULT gst_h264_decoder_debug @@ -2664,7 +2666,7 @@ construct_ref_pic_lists_p (GstH264Decoder * self, pos = priv->ref_pic_list_p0->len; gst_h264_dpb_get_pictures_long_term_ref (priv->dpb, FALSE, priv->ref_pic_list_p0); - g_qsort_with_data (&g_array_index (priv->ref_pic_list_p0, gpointer, pos), + g_sort_array (&g_array_index (priv->ref_pic_list_p0, gpointer, pos), priv->ref_pic_list_p0->len - pos, sizeof (gpointer), (GCompareDataFunc) long_term_pic_num_asc_compare, NULL); @@ -2913,14 +2915,14 @@ construct_ref_pic_lists_b (GstH264Decoder * self, GST_DEBUG_OBJECT (self, "split point %i", pos); /* and sort [1] descending, thus finishing sequence [1] [2]. */ - g_qsort_with_data (priv->ref_pic_list_b0->data, pos, sizeof (gpointer), + g_sort_array (priv->ref_pic_list_b0->data, pos, sizeof (gpointer), (GCompareDataFunc) poc_desc_compare, NULL); /* Now add [3] and sort by ascending long_term_pic_num. */ pos = priv->ref_pic_list_b0->len; gst_h264_dpb_get_pictures_long_term_ref (priv->dpb, FALSE, priv->ref_pic_list_b0); - g_qsort_with_data (&g_array_index (priv->ref_pic_list_b0, gpointer, pos), + g_sort_array (&g_array_index (priv->ref_pic_list_b0, gpointer, pos), priv->ref_pic_list_b0->len - pos, sizeof (gpointer), (GCompareDataFunc) long_term_pic_num_asc_compare, NULL); @@ -2941,14 +2943,14 @@ construct_ref_pic_lists_b (GstH264Decoder * self, (GCompareFunc) poc_desc_compare); /* and sort [1] ascending. */ - g_qsort_with_data (priv->ref_pic_list_b1->data, pos, sizeof (gpointer), + g_sort_array (priv->ref_pic_list_b1->data, pos, sizeof (gpointer), (GCompareDataFunc) poc_asc_compare, NULL); /* Now add [3] and sort by ascending long_term_pic_num */ pos = priv->ref_pic_list_b1->len; gst_h264_dpb_get_pictures_long_term_ref (priv->dpb, FALSE, priv->ref_pic_list_b1); - g_qsort_with_data (&g_array_index (priv->ref_pic_list_b1, gpointer, pos), + g_sort_array (&g_array_index (priv->ref_pic_list_b1, gpointer, pos), priv->ref_pic_list_b1->len - pos, sizeof (gpointer), (GCompareDataFunc) long_term_pic_num_asc_compare, NULL); @@ -3010,7 +3012,7 @@ construct_ref_field_pic_lists_b (GstH264Decoder * self, GST_DEBUG_OBJECT (self, "split point %i", pos); /* and sort [1] descending, thus finishing sequence [1] [2]. */ - g_qsort_with_data (priv->ref_frame_list_0_short_term->data, pos, + g_sort_array (priv->ref_frame_list_0_short_term->data, pos, sizeof (gpointer), (GCompareDataFunc) poc_desc_compare, NULL); /* refFrameList1ShortTerm (8.2.4.2.4) [[1] [2]], where: @@ -3031,7 +3033,7 @@ construct_ref_field_pic_lists_b (GstH264Decoder * self, (GCompareFunc) poc_desc_compare); /* and sort [1] ascending. */ - g_qsort_with_data (priv->ref_frame_list_1_short_term->data, pos, + g_sort_array (priv->ref_frame_list_1_short_term->data, pos, sizeof (gpointer), (GCompareDataFunc) poc_asc_compare, NULL); /* 8.2.4.2.2 refFrameList0LongTerm,: diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/glib-compat-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/glib-compat-private.h index 1a4aa7d6b2..6210d41472 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/glib-compat-private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/glib-compat-private.h @@ -27,6 +27,26 @@ G_BEGIN_DECLS +#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/gst-plugins-bad/sys/va/gstvaav1enc.c b/subprojects/gst-plugins-bad/sys/va/gstvaav1enc.c index ce6ec5da84..101a1aa766 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvaav1enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvaav1enc.c @@ -58,6 +58,8 @@ #include "gstvadisplay_priv.h" #include "gstvapluginutils.h" +#include "gst/glib-compat-private.h" + GST_DEBUG_CATEGORY_STATIC (gst_va_av1enc_debug); #define GST_CAT_DEFAULT gst_va_av1enc_debug @@ -1489,7 +1491,7 @@ _av1_assign_ref_index (GstVaAV1Enc * self, GstVideoCodecFrame * frame) return FALSE; } - g_qsort_with_data (all_refs, ref_num, sizeof (GstVaAV1Ref), + g_sort_array (all_refs, ref_num, sizeof (GstVaAV1Ref), _av1_sort_by_frame_num, NULL); /* Assign the forward references in order of: diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c index bfb2d5dfc3..cb22ed9fe8 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c @@ -68,6 +68,8 @@ #include "vacompat.h" #include "gstvapluginutils.h" +#include "gst/glib-compat-private.h" + GST_DEBUG_CATEGORY_STATIC (gst_va_h264enc_debug); #define GST_CAT_DEFAULT gst_va_h264enc_debug @@ -2647,10 +2649,10 @@ _insert_ref_pic_list_modification (GstH264SliceHdr * slice_hdr, memcpy (list_by_pic_num, list, sizeof (GstVaH264EncFrame *) * total_list_num); if (is_asc) { - g_qsort_with_data (list_by_pic_num, total_list_num, sizeof (gpointer), + g_sort_array (list_by_pic_num, total_list_num, sizeof (gpointer), (GCompareDataFunc) _frame_num_asc_compare, NULL); } else { - g_qsort_with_data (list_by_pic_num, total_list_num, sizeof (gpointer), + g_sort_array (list_by_pic_num, total_list_num, sizeof (gpointer), (GCompareDataFunc) _frame_num_des_compare, NULL); } @@ -3051,7 +3053,7 @@ _encode_one_frame (GstVaH264Enc * self, GstVideoCodecFrame * gst_frame) } /* reorder to select the most nearest forward frames. */ - g_qsort_with_data (list0, total_list0_num, sizeof (gpointer), + g_sort_array (list0, total_list0_num, sizeof (gpointer), (GCompareDataFunc) _poc_des_compare, NULL); list0_num = total_list0_num; @@ -3074,7 +3076,7 @@ _encode_one_frame (GstVaH264Enc * self, GstVideoCodecFrame * gst_frame) } /* reorder to select the most nearest backward frames. */ - g_qsort_with_data (list1, total_list1_num, sizeof (gpointer), + g_sort_array (list1, total_list1_num, sizeof (gpointer), (GCompareDataFunc) _poc_asc_compare, NULL); list1_num = total_list1_num; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c index a54065ee8a..4cc04620ad 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c @@ -58,6 +58,8 @@ #include "gstvadisplay_priv.h" #include "gstvapluginutils.h" +#include "gst/glib-compat-private.h" + GST_DEBUG_CATEGORY_STATIC (gst_va_h265enc_debug); #define GST_CAT_DEFAULT gst_va_h265enc_debug @@ -1918,7 +1920,7 @@ _h265_encode_one_frame (GstVaH265Enc * self, GstVideoCodecFrame * gst_frame) } /* reorder to select the most nearest forward frames. */ - g_qsort_with_data (list_forward, list_forward_num, sizeof (gpointer), + g_sort_array (list_forward, list_forward_num, sizeof (gpointer), (GCompareDataFunc) _poc_des_compare, NULL); num_negative_pics = list_forward_num; @@ -1956,7 +1958,7 @@ _h265_encode_one_frame (GstVaH265Enc * self, GstVideoCodecFrame * gst_frame) } /* reorder to select the most nearest backward frames. */ - g_qsort_with_data (list_backward, list_backward_num, sizeof (gpointer), + g_sort_array (list_backward, list_backward_num, sizeof (gpointer), (GCompareDataFunc) _poc_asc_compare, NULL); num_positive_pics = list_backward_num; diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp9enc.c b/subprojects/gst-plugins-bad/sys/va/gstvavp9enc.c index 10dafa1f3e..204ae1366c 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp9enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp9enc.c @@ -59,6 +59,8 @@ #include "gstvadisplay_priv.h" #include "gstvapluginutils.h" +#include "gst/glib-compat-private.h" + GST_DEBUG_CATEGORY_STATIC (gst_va_vp9enc_debug); #define GST_CAT_DEFAULT gst_va_vp9enc_debug @@ -1239,7 +1241,7 @@ _vp9_assign_ref_index (GstVaVp9Enc * self, GstVideoCodecFrame * frame) return FALSE; } - g_qsort_with_data (all_refs, ref_num, sizeof (GstVaVp9Ref), + g_sort_array (all_refs, ref_num, sizeof (GstVaVp9Ref), _vp9_sort_by_frame_num, NULL); /* Assign the forward references in order of: diff --git a/subprojects/gst-plugins-bad/sys/va/meson.build b/subprojects/gst-plugins-bad/sys/va/meson.build index d498a7b6d7..ef3958d8be 100644 --- a/subprojects/gst-plugins-bad/sys/va/meson.build +++ b/subprojects/gst-plugins-bad/sys/va/meson.build @@ -80,7 +80,7 @@ gstva = library('gstva', va_sources, c_args : gst_plugins_bad_args + extra_args, cpp_args : gst_plugins_bad_args + extra_args, - include_directories : [configinc], + include_directories : [configinc, libsinc], dependencies : [gstcodecs_dep, gstva_dep, libgudev_dep, libm] + extra_dep, override_options : c_std_arg, install : true,