From 2fc4e928d6b0440f666f901b6ebef43b9199d9e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Sun, 30 Jan 2022 07:10:09 +0100 Subject: [PATCH] vaapi: libs: video-format: Check if formats map is not NULL. Formats map is instantiated at the end of the display instantiation. The problem is the Wayland display which looks for a format in a callback, before the map is populated. If user compiles gstreamer-vaapi with DRM support, the map is populated with a DRM display at GStreamer plugin registration. But if not, or a VA driver is not available, the plugin will try with a Wayland driver, which cause the NULL de-reference. Nevertheless, in the case of no DRM support, and if the Wayland display doesn't get a reply from the format conversion is not a problem. So the solution is the trivial one, check if the format map is already populated before de-reference it. Fixes: #977 Part-of: --- .../gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/subprojects/gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c b/subprojects/gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c index dad7570..5fd35e3 100644 --- a/subprojects/gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c +++ b/subprojects/gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c @@ -185,7 +185,7 @@ static const GstVideoFormatMap gst_vaapi_video_default_formats[] = { #undef DEF_RGB #undef DEF_YUV -static GArray *gst_vaapi_video_formats_map; +static GArray *gst_vaapi_video_formats_map = NULL; static inline gboolean va_format_is_rgb (const VAImageFormat * va_format) @@ -254,6 +254,9 @@ get_map_by_gst_format (const GArray * formats, GstVideoFormat format) const GstVideoFormatMap *entry; guint i; + if (!formats) + return NULL; + for (i = 0; i < formats->len; i++) { entry = &g_array_index (formats, GstVideoFormatMap, i); if (entry->format == format) @@ -269,6 +272,9 @@ get_map_by_va_format (const VAImageFormat * va_format) const GstVideoFormatMap *entry; guint i; + if (!formats) + return NULL; + for (i = 0; i < formats->len; i++) { entry = &g_array_index (formats, GstVideoFormatMap, i); if (va_format_is_same (&entry->va_format, va_format)) @@ -642,6 +648,9 @@ gst_vaapi_drm_format_from_va_fourcc (guint32 fourcc) const GstVideoFormatMap *m; guint i; + if (!map) + return GST_VIDEO_FORMAT_UNKNOWN; + /* Note: VA fourcc values are now standardized and shall represent a unique format. The associated VAImageFormat is just a hint to determine RGBA component ordering */ @@ -675,6 +684,9 @@ gst_vaapi_video_format_from_drm_format (guint drm_format) const GstVideoFormatMap *m; guint i; + if (!map) + return GST_VIDEO_FORMAT_UNKNOWN; + for (i = 0; i < map->len; i++) { m = &g_array_index (map, GstVideoFormatMap, i); if (m->drm_format == drm_format) -- 2.7.4