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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1606>
This commit is contained in:
Víctor Manuel Jáquez Leal 2022-01-30 07:10:09 +01:00 committed by GStreamer Marge Bot
parent fb1c062626
commit 2fc4e928d6

View file

@ -185,7 +185,7 @@ static const GstVideoFormatMap gst_vaapi_video_default_formats[] = {
#undef DEF_RGB #undef DEF_RGB
#undef DEF_YUV #undef DEF_YUV
static GArray *gst_vaapi_video_formats_map; static GArray *gst_vaapi_video_formats_map = NULL;
static inline gboolean static inline gboolean
va_format_is_rgb (const VAImageFormat * va_format) 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; const GstVideoFormatMap *entry;
guint i; guint i;
if (!formats)
return NULL;
for (i = 0; i < formats->len; i++) { for (i = 0; i < formats->len; i++) {
entry = &g_array_index (formats, GstVideoFormatMap, i); entry = &g_array_index (formats, GstVideoFormatMap, i);
if (entry->format == format) if (entry->format == format)
@ -269,6 +272,9 @@ get_map_by_va_format (const VAImageFormat * va_format)
const GstVideoFormatMap *entry; const GstVideoFormatMap *entry;
guint i; guint i;
if (!formats)
return NULL;
for (i = 0; i < formats->len; i++) { for (i = 0; i < formats->len; i++) {
entry = &g_array_index (formats, GstVideoFormatMap, i); entry = &g_array_index (formats, GstVideoFormatMap, i);
if (va_format_is_same (&entry->va_format, va_format)) 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; const GstVideoFormatMap *m;
guint i; guint i;
if (!map)
return GST_VIDEO_FORMAT_UNKNOWN;
/* Note: VA fourcc values are now standardized and shall represent /* Note: VA fourcc values are now standardized and shall represent
a unique format. The associated VAImageFormat is just a hint to a unique format. The associated VAImageFormat is just a hint to
determine RGBA component ordering */ determine RGBA component ordering */
@ -675,6 +684,9 @@ gst_vaapi_video_format_from_drm_format (guint drm_format)
const GstVideoFormatMap *m; const GstVideoFormatMap *m;
guint i; guint i;
if (!map)
return GST_VIDEO_FORMAT_UNKNOWN;
for (i = 0; i < map->len; i++) { for (i = 0; i < map->len; i++) {
m = &g_array_index (map, GstVideoFormatMap, i); m = &g_array_index (map, GstVideoFormatMap, i);
if (m->drm_format == drm_format) if (m->drm_format == drm_format)