vaapi: libs: video-format: Check if formats map is not NULL.
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sun, 30 Jan 2022 06:10:09 +0000 (07:10 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 31 Jan 2022 13:33:31 +0000 (13:33 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1606>

subprojects/gstreamer-vaapi/gst-libs/gst/vaapi/video-format.c

index dad7570..5fd35e3 100644 (file)
@@ -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)