mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
msdk: Let deviceID config the mfx implementation
In multi-card scenario, user can set GST_MSDK_DRM_DEVICE env variable to choose the device. This patch can align vpl's queried results with the users' choice by passing deviceID when creating mfx implementation. Co-authored-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com> Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5697>
This commit is contained in:
parent
4a3aa20af7
commit
be7e502769
3 changed files with 92 additions and 39 deletions
|
@ -168,9 +168,7 @@ static gboolean
|
|||
gst_msdk_context_use_vaapi (GstMsdkContext * context)
|
||||
{
|
||||
char *path;
|
||||
VADisplay va_dpy = NULL;
|
||||
GstVaDisplay *display_drm = NULL;
|
||||
mfxStatus status;
|
||||
GstMsdkContextPrivate *priv = context->priv;
|
||||
|
||||
path = get_device_path ();
|
||||
|
@ -186,16 +184,6 @@ gst_msdk_context_use_vaapi (GstMsdkContext * context)
|
|||
}
|
||||
g_free (path);
|
||||
|
||||
va_dpy = gst_va_display_get_va_dpy (display_drm);
|
||||
|
||||
status = MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY,
|
||||
(mfxHDL) va_dpy);
|
||||
if (status != MFX_ERR_NONE) {
|
||||
GST_ERROR ("Setting VAAPI handle failed (%s)",
|
||||
msdk_status_to_string (status));
|
||||
goto failed;
|
||||
}
|
||||
|
||||
priv->display = display_drm;
|
||||
|
||||
return TRUE;
|
||||
|
@ -310,6 +298,10 @@ gst_msdk_context_open (GstMsdkContext * context, gboolean hardware)
|
|||
GstMsdkContextPrivate *priv = context->priv;
|
||||
MsdkSession msdk_session;
|
||||
mfxIMPL impl;
|
||||
mfxHDL handle = NULL;
|
||||
#ifndef _WIN32
|
||||
mfxStatus status;
|
||||
#endif
|
||||
|
||||
priv->hardware = hardware;
|
||||
|
||||
|
@ -319,23 +311,36 @@ gst_msdk_context_open (GstMsdkContext * context, gboolean hardware)
|
|||
impl |= MFX_IMPL_VIA_D3D11;
|
||||
#endif
|
||||
|
||||
msdk_session = msdk_open_session (impl);
|
||||
priv->session = msdk_session;
|
||||
if (!priv->session.session)
|
||||
goto failed;
|
||||
|
||||
#ifndef _WIN32
|
||||
if (hardware) {
|
||||
if (!gst_msdk_context_use_vaapi (context))
|
||||
goto failed;
|
||||
}
|
||||
#else
|
||||
if (hardware) {
|
||||
if (!gst_msdk_context_use_d3d11 (context))
|
||||
goto failed;
|
||||
return FALSE;
|
||||
|
||||
handle = (mfxHDL) gst_va_display_get_va_dpy (priv->display);
|
||||
}
|
||||
#endif
|
||||
|
||||
msdk_session = msdk_open_session (handle, impl);
|
||||
if (!msdk_session.session)
|
||||
return FALSE;
|
||||
|
||||
priv->session = msdk_session;
|
||||
|
||||
if (hardware) {
|
||||
#ifndef _WIN32
|
||||
status = MFXVideoCORE_SetHandle (priv->session.session,
|
||||
MFX_HANDLE_VA_DISPLAY, handle);
|
||||
if (status != MFX_ERR_NONE) {
|
||||
GST_ERROR ("Setting VAAPI handle failed (%s)",
|
||||
msdk_status_to_string (status));
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
if (!gst_msdk_context_use_d3d11 (context))
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
codename = msdk_get_platform_codename (priv->session.session);
|
||||
|
||||
if (codename != MFX_PLATFORM_UNKNOWN)
|
||||
|
@ -344,9 +349,6 @@ gst_msdk_context_open (GstMsdkContext * context, gboolean hardware)
|
|||
GST_WARNING ("Unknown MFX platform");
|
||||
|
||||
return TRUE;
|
||||
|
||||
failed:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -443,7 +445,7 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent)
|
|||
mfxIMPL impl;
|
||||
MsdkSession child_msdk_session;
|
||||
mfxHandleType handle_type = 0;
|
||||
mfxHDL handle = NULL;
|
||||
mfxHDL handle = NULL, hardware_handle = NULL;
|
||||
|
||||
status = MFXQueryIMPL (parent_priv->session.session, &impl);
|
||||
|
||||
|
@ -477,7 +479,12 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent)
|
|||
|
||||
child_msdk_session.loader = parent_priv->session.loader;
|
||||
child_msdk_session.session = NULL;
|
||||
status = msdk_init_msdk_session (impl, &version, &child_msdk_session);
|
||||
#ifndef _WIN32
|
||||
hardware_handle = (mfxHDL) gst_va_display_get_va_dpy (parent_priv->display);
|
||||
#endif
|
||||
|
||||
status = msdk_init_msdk_session (hardware_handle, impl, &version,
|
||||
&child_msdk_session);
|
||||
|
||||
if (status != MFX_ERR_NONE) {
|
||||
GST_ERROR ("Failed to create a child mfx session (%s)",
|
||||
|
@ -540,6 +547,7 @@ gst_msdk_context_new_with_va_display (GstObject * display_obj,
|
|||
mfxU16 codename;
|
||||
mfxStatus status;
|
||||
GstVaDisplay *va_display;
|
||||
mfxHDL handle;
|
||||
|
||||
va_display = GST_VA_DISPLAY (display_obj);
|
||||
if (!va_display)
|
||||
|
@ -552,8 +560,10 @@ gst_msdk_context_new_with_va_display (GstObject * display_obj,
|
|||
|
||||
priv->job_type = job_type;
|
||||
priv->hardware = hardware;
|
||||
priv->session =
|
||||
msdk_open_session (hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
||||
|
||||
handle = (mfxHDL) gst_va_display_get_va_dpy (priv->display);
|
||||
priv->session = msdk_open_session (handle,
|
||||
hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
||||
if (!priv->session.session) {
|
||||
gst_object_unref (obj);
|
||||
return NULL;
|
||||
|
@ -562,7 +572,7 @@ gst_msdk_context_new_with_va_display (GstObject * display_obj,
|
|||
if (hardware) {
|
||||
status =
|
||||
MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY,
|
||||
(mfxHDL) gst_va_display_get_va_dpy (priv->display));
|
||||
handle);
|
||||
if (status != MFX_ERR_NONE) {
|
||||
GST_ERROR ("Setting VAAPI handle failed (%s)",
|
||||
msdk_status_to_string (status));
|
||||
|
@ -600,8 +610,8 @@ gst_msdk_context_new_with_d3d11_device (GstD3D11Device * device,
|
|||
|
||||
priv->job_type = job_type;
|
||||
priv->hardware = hardware;
|
||||
priv->session =
|
||||
msdk_open_session (hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
||||
priv->session = msdk_open_session (NULL,
|
||||
hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
||||
if (!priv->session.session) {
|
||||
goto failed;
|
||||
}
|
||||
|
|
|
@ -213,8 +213,43 @@ msdk_release_impl_description (const mfxLoader * loader, gpointer impl_desc)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static mfxStatus
|
||||
_set_pci_id (mfxHDL handle, mfxConfig cfg)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
VAStatus va_status;
|
||||
mfxStatus mfx_status;
|
||||
VADisplay dpy = handle;
|
||||
mfxVariant impl_value = {
|
||||
.Type = MFX_VARIANT_TYPE_U16,
|
||||
};
|
||||
VADisplayAttribute attr = {
|
||||
.type = VADisplayPCIID,
|
||||
};
|
||||
|
||||
va_status = vaGetDisplayAttributes (dpy, &attr, 1);
|
||||
if (va_status != VA_STATUS_SUCCESS ||
|
||||
attr.flags == VA_DISPLAY_ATTRIB_NOT_SUPPORTED)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
impl_value.Data.U16 = (attr.value & 0xFFFF);
|
||||
mfx_status = MFXSetConfigFilterProperty (cfg,
|
||||
(const mfxU8 *) "mfxImplDescription.mfxDeviceDescription.DeviceID",
|
||||
impl_value);
|
||||
|
||||
if (mfx_status != MFX_ERR_NONE) {
|
||||
GST_ERROR ("Failed to add an additional MFX configuration (%s)",
|
||||
msdk_status_to_string (mfx_status));
|
||||
}
|
||||
|
||||
return mfx_status;
|
||||
#else
|
||||
return MFX_ERR_NONE;
|
||||
#endif
|
||||
}
|
||||
|
||||
mfxStatus
|
||||
msdk_init_msdk_session (mfxIMPL impl, mfxVersion * pver,
|
||||
msdk_init_msdk_session (mfxHDL handle, mfxIMPL impl, mfxVersion * pver,
|
||||
MsdkSession * msdk_session)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
@ -272,6 +307,13 @@ msdk_init_msdk_session (mfxIMPL impl, mfxVersion * pver,
|
|||
MFXUnload (loader);
|
||||
return sts;
|
||||
}
|
||||
|
||||
sts = _set_pci_id (handle, cfg);
|
||||
|
||||
if (sts != MFX_ERR_NONE) {
|
||||
MFXUnload (loader);
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
@ -330,8 +372,9 @@ msdk_release_impl_description (const mfxLoader * loader, gpointer impl_desc)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* handle is not used here */
|
||||
mfxStatus
|
||||
msdk_init_msdk_session (mfxIMPL impl, mfxVersion * pver,
|
||||
msdk_init_msdk_session (mfxHDL handle, mfxIMPL impl, mfxVersion * pver,
|
||||
MsdkSession * msdk_session)
|
||||
{
|
||||
mfxStatus status;
|
||||
|
@ -388,7 +431,7 @@ msdk_close_session (MsdkSession * msdk_session)
|
|||
}
|
||||
|
||||
MsdkSession
|
||||
msdk_open_session (mfxIMPL impl)
|
||||
msdk_open_session (mfxHDL handle, mfxIMPL impl)
|
||||
{
|
||||
mfxSession session = NULL;
|
||||
mfxVersion version = { {1, 1}
|
||||
|
@ -405,7 +448,7 @@ msdk_open_session (mfxIMPL impl)
|
|||
msdk_session.session = NULL;
|
||||
msdk_session.loader = NULL;
|
||||
msdk_session.impl_idx = 0;
|
||||
status = msdk_init_msdk_session (impl, &version, &msdk_session);
|
||||
status = msdk_init_msdk_session (handle, impl, &version, &msdk_session);
|
||||
|
||||
if (status != MFX_ERR_NONE)
|
||||
return msdk_session;
|
||||
|
|
|
@ -116,7 +116,7 @@ struct _MsdkSession
|
|||
mfxLoader loader;
|
||||
};
|
||||
|
||||
MsdkSession msdk_open_session (mfxIMPL impl);
|
||||
MsdkSession msdk_open_session (mfxHDL handle, mfxIMPL impl);
|
||||
void msdk_close_mfx_session (mfxSession session);
|
||||
void msdk_close_session (MsdkSession * session);
|
||||
|
||||
|
@ -160,7 +160,7 @@ mfxU16
|
|||
msdk_get_platform_codename (mfxSession session);
|
||||
|
||||
mfxStatus
|
||||
msdk_init_msdk_session (mfxIMPL impl, mfxVersion * pver,
|
||||
msdk_init_msdk_session (mfxHDL handle, mfxIMPL impl, mfxVersion * pver,
|
||||
MsdkSession * msdk_session);
|
||||
|
||||
gpointer
|
||||
|
|
Loading…
Reference in a new issue