MSDK: Use the VA display object to replace the raw display handle.

The VA display object from VA lib is a common defined object. which
contain the whole display things. It is easier to use, and more important,
we can share it with the other VA plugins and keep all the VA related
plugins working on the same GPU device.
We also delete the useless gst_msdk_context_get_fd() API.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1087>
This commit is contained in:
He Junyan 2021-05-08 11:44:57 +08:00 committed by GStreamer Marge Bot
parent c7e3c8e9f6
commit a9aa522e26
2 changed files with 40 additions and 41 deletions

View file

@ -37,6 +37,7 @@
#include <xf86drm.h> #include <xf86drm.h>
#include <va/va_drm.h> #include <va/va_drm.h>
#include <gudev/gudev.h> #include <gudev/gudev.h>
#include <gst/va/gstvadisplay_drm.h>
#endif #endif
GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkcontext); GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkcontext);
@ -54,8 +55,7 @@ struct _GstMsdkContextPrivate
GList *child_session_list; GList *child_session_list;
GstMsdkContext *parent_context; GstMsdkContext *parent_context;
#ifndef _WIN32 #ifndef _WIN32
gint fd; GstVaDisplay *display;
VADisplay dpy;
#endif #endif
}; };
@ -67,8 +67,8 @@ G_DEFINE_TYPE_WITH_CODE (GstMsdkContext, gst_msdk_context, GST_TYPE_OBJECT,
#ifndef _WIN32 #ifndef _WIN32
static gint static char *
get_device_id (void) get_device_path (void)
{ {
GUdevClient *client = NULL; GUdevClient *client = NULL;
GUdevEnumerator *e = NULL; GUdevEnumerator *e = NULL;
@ -78,6 +78,7 @@ get_device_id (void)
const gchar *devnode_files[2] = { "renderD[0-9]*", "card[0-9]*" }; const gchar *devnode_files[2] = { "renderD[0-9]*", "card[0-9]*" };
int fd = -1, i; int fd = -1, i;
const gchar *user_choice = g_getenv ("GST_MSDK_DRM_DEVICE"); const gchar *user_choice = g_getenv ("GST_MSDK_DRM_DEVICE");
gchar *ret_path = NULL;
if (user_choice) { if (user_choice) {
if (g_str_has_prefix (user_choice, "/dev/dri/")) if (g_str_has_prefix (user_choice, "/dev/dri/"))
@ -99,7 +100,12 @@ get_device_id (void)
GST_ERROR ("The specified device isn't a valid drm device"); GST_ERROR ("The specified device isn't a valid drm device");
} }
return fd; if (fd >= 0) {
ret_path = g_strdup (user_choice);
close (fd);
}
return ret_path;
} }
client = g_udev_client_new (NULL); client = g_udev_client_new (NULL);
@ -131,6 +137,7 @@ get_device_id (void)
if (fd < 0) if (fd < 0)
continue; continue;
GST_DEBUG ("Opened the drm device node %s", devnode_path); GST_DEBUG ("Opened the drm device node %s", devnode_path);
ret_path = g_strdup (devnode_path);
break; break;
} }
@ -141,42 +148,40 @@ get_device_id (void)
} }
done: done:
if (fd >= 0)
close (fd);
if (e) if (e)
g_object_unref (e); g_object_unref (e);
if (client) if (client)
g_object_unref (client); g_object_unref (client);
return fd; return ret_path;
} }
static gboolean static gboolean
gst_msdk_context_use_vaapi (GstMsdkContext * context) gst_msdk_context_use_vaapi (GstMsdkContext * context)
{ {
gint fd; char *path;
gint maj_ver, min_ver;
VADisplay va_dpy = NULL; VADisplay va_dpy = NULL;
VAStatus va_status; GstVaDisplay *display_drm = NULL;
mfxStatus status; mfxStatus status;
GstMsdkContextPrivate *priv = context->priv; GstMsdkContextPrivate *priv = context->priv;
fd = get_device_id (); path = get_device_path ();
if (fd < 0) { if (path == NULL) {
GST_WARNING ("Couldn't find a valid drm device node"); GST_ERROR ("Couldn't find a drm device node to open");
return FALSE; return FALSE;
} }
va_dpy = vaGetDisplayDRM (fd); display_drm = gst_va_display_drm_new_from_path (path);
if (!va_dpy) { if (!display_drm) {
GST_ERROR ("Couldn't get a VA DRM display"); GST_ERROR ("Couldn't create a VA DRM display");
goto failed; goto failed;
} }
g_free (path);
va_status = vaInitialize (va_dpy, &maj_ver, &min_ver); va_dpy = gst_va_display_get_va_dpy (display_drm);
if (va_status != VA_STATUS_SUCCESS) {
GST_ERROR ("Couldn't initialize VA DRM display");
goto failed;
}
status = MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY, status = MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY,
(mfxHDL) va_dpy); (mfxHDL) va_dpy);
@ -186,15 +191,14 @@ gst_msdk_context_use_vaapi (GstMsdkContext * context)
goto failed; goto failed;
} }
priv->fd = fd; priv->display = display_drm;
priv->dpy = va_dpy;
return TRUE; return TRUE;
failed: failed:
if (va_dpy) if (display_drm)
vaTerminate (va_dpy); gst_object_unref (display_drm);
close (fd);
return FALSE; return FALSE;
} }
#endif #endif
@ -217,8 +221,6 @@ gst_msdk_context_open (GstMsdkContext * context, gboolean hardware,
goto failed; goto failed;
#ifndef _WIN32 #ifndef _WIN32
priv->fd = -1;
if (hardware) { if (hardware) {
if (!gst_msdk_context_use_vaapi (context)) if (!gst_msdk_context_use_vaapi (context))
goto failed; goto failed;
@ -277,10 +279,8 @@ gst_msdk_context_finalize (GObject * obj)
g_mutex_clear (&priv->mutex); g_mutex_clear (&priv->mutex);
#ifndef _WIN32 #ifndef _WIN32
if (priv->dpy) if (priv->display)
vaTerminate (priv->dpy); gst_object_unref (priv->display);
if (priv->fd >= 0)
close (priv->fd);
#endif #endif
done: done:
@ -395,8 +395,7 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent)
parent_priv->child_session_list = parent_priv->child_session_list =
g_list_prepend (parent_priv->child_session_list, priv->session.session); g_list_prepend (parent_priv->child_session_list, priv->session.session);
#ifndef _WIN32 #ifndef _WIN32
priv->dpy = parent_priv->dpy; priv->display = parent_priv->display;
priv->fd = parent_priv->fd;
#endif #endif
priv->parent_context = gst_object_ref (parent); priv->parent_context = gst_object_ref (parent);
@ -413,20 +412,20 @@ gpointer
gst_msdk_context_get_handle (GstMsdkContext * context) gst_msdk_context_get_handle (GstMsdkContext * context)
{ {
#ifndef _WIN32 #ifndef _WIN32
return context->priv->dpy; return gst_va_display_get_va_dpy (context->priv->display);
#else #else
return NULL; return NULL;
#endif #endif
} }
gint GstObject *
gst_msdk_context_get_fd (GstMsdkContext * context) gst_msdk_context_get_display (GstMsdkContext * context)
{ {
#ifndef _WIN32 #ifndef _WIN32
return context->priv->fd; if (context->priv->display)
#else return gst_object_ref (GST_OBJECT_CAST (context->priv->display));
return -1;
#endif #endif
return NULL;
} }
static gint static gint

View file

@ -90,7 +90,7 @@ GstMsdkContext * gst_msdk_context_new_with_parent (GstMsdkContext * parent);
mfxSession gst_msdk_context_get_session (GstMsdkContext * context); mfxSession gst_msdk_context_get_session (GstMsdkContext * context);
gpointer gst_msdk_context_get_handle (GstMsdkContext * context); gpointer gst_msdk_context_get_handle (GstMsdkContext * context);
gint gst_msdk_context_get_fd (GstMsdkContext * context); GstObject * gst_msdk_context_get_display (GstMsdkContext * context);
/* GstMsdkContext contains mfxFrameAllocResponses, /* GstMsdkContext contains mfxFrameAllocResponses,
* if app calls MFXVideoCORE_SetFrameAllocator. * if app calls MFXVideoCORE_SetFrameAllocator.