2018-02-13 21:41:28 +00:00
|
|
|
/* GStreamer Intel MSDK plugin
|
|
|
|
* Copyright (c) 2018, Intel Corporation
|
|
|
|
* Copyright (c) 2018, Igalia S.L.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
|
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gstmsdkcontext.h"
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2021-01-12 07:33:49 +00:00
|
|
|
#include <xf86drm.h>
|
2018-02-13 21:41:28 +00:00
|
|
|
#include <va/va_drm.h>
|
2018-02-13 23:40:22 +00:00
|
|
|
#include <gudev/gudev.h>
|
2021-05-08 03:44:57 +00:00
|
|
|
#include <gst/va/gstvadisplay_drm.h>
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
#include <gst/d3d11/gstd3d11.h>
|
2018-02-13 21:41:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkcontext);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_msdkcontext
|
|
|
|
|
|
|
|
struct _GstMsdkContextPrivate
|
|
|
|
{
|
2021-02-04 07:27:13 +00:00
|
|
|
MsdkSession session;
|
2022-08-22 09:44:35 +00:00
|
|
|
GstBufferPool *alloc_pool;
|
2018-02-13 21:41:28 +00:00
|
|
|
GList *cached_alloc_responses;
|
2018-02-13 22:50:48 +00:00
|
|
|
gboolean hardware;
|
2018-12-29 05:56:49 +00:00
|
|
|
gboolean has_frame_allocator;
|
2018-02-13 22:50:48 +00:00
|
|
|
GstMsdkContextJobType job_type;
|
2018-02-13 22:52:14 +00:00
|
|
|
gint shared_async_depth;
|
msdk: manage MSDK surfaces seperately
Currently a gst buffer has one mfxFrameSurface when it's allocated and
can't be changed.
This is based on that the life of gst buffer and mfxFrameSurface would
be same.
But it's not true. Sometimes even if a gst buffer of a frame is finished
on downstream,
mfxFramesurface coupled with the gst buffer is still locked, which means
it's still being used in the driver.
So this patch does this.
Every time a gst buffer is acquired from the pool, it confirms if the
surface coupled with the buffer is unlocked.
If not, replace it with new unlocked one.
In this way, user(decoder or encoder) doesn't need to manage gst buffers
including locked surface.
To do that, this patch includes the following:
1. GstMsdkContext
- Manages MSDK surfaces available, used, locked respectively as the
following:
1\ surfaces_avail : surfaces which are free and unused anywhere
2\ surfaces_used : surfaces coupled with a gst buffer and being used
now.
3\ surfaces_locked : surfaces still locked even after the gst buffer
is released.
- Provide an api to get MSDK surface available.
- Provide an api to release MSDK surface.
2. GstMsdkVideoMemory
- Gets a surface available when it's allocated.
- Provide an api to get an available surface with new unlocked one.
- Provide an api to release surface in the msdk video memory.
3. GstMsdkBufferPool
- In acquire_buffer, every time a gst buffer is acquired, get new
available surface from the list.
- In release_buffer, it confirms if the buffer's surface is unlocked or
not.
- If unlocked, it is put to the available list.
- If still locked, it is put to the locked list.
This also fixes bug #793525.
https://bugzilla.gnome.org/show_bug.cgi?id=793413
https://bugzilla.gnome.org/show_bug.cgi?id=793525
2018-03-08 20:37:12 +00:00
|
|
|
GMutex mutex;
|
2018-03-08 20:38:30 +00:00
|
|
|
GList *child_session_list;
|
2021-07-17 16:51:04 +00:00
|
|
|
GstMsdkContext *parent_context;
|
2018-02-13 21:41:28 +00:00
|
|
|
#ifndef _WIN32
|
2021-05-08 03:44:57 +00:00
|
|
|
GstVaDisplay *display;
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
GstD3D11Device *device;
|
2018-02-13 21:41:28 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2018-06-23 22:17:26 +00:00
|
|
|
#define gst_msdk_context_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstMsdkContext, gst_msdk_context, GST_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (GstMsdkContext)
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_msdkcontext, "msdkcontext", 0,
|
|
|
|
"MSDK Context"));
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
#ifndef _WIN32
|
2018-02-13 23:40:22 +00:00
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
static char *
|
|
|
|
get_device_path (void)
|
2018-02-13 23:40:22 +00:00
|
|
|
{
|
|
|
|
GUdevClient *client = NULL;
|
|
|
|
GUdevEnumerator *e = NULL;
|
|
|
|
GList *devices, *l;
|
|
|
|
GUdevDevice *dev, *parent;
|
|
|
|
const gchar *devnode_path;
|
|
|
|
const gchar *devnode_files[2] = { "renderD[0-9]*", "card[0-9]*" };
|
|
|
|
int fd = -1, i;
|
2021-01-12 07:33:49 +00:00
|
|
|
const gchar *user_choice = g_getenv ("GST_MSDK_DRM_DEVICE");
|
2021-05-08 03:44:57 +00:00
|
|
|
gchar *ret_path = NULL;
|
2021-01-12 07:33:49 +00:00
|
|
|
|
|
|
|
if (user_choice) {
|
|
|
|
if (g_str_has_prefix (user_choice, "/dev/dri/"))
|
|
|
|
fd = open (user_choice, O_RDWR | O_CLOEXEC);
|
|
|
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
drmVersionPtr drm_version = drmGetVersion (fd);
|
|
|
|
|
|
|
|
if (!drm_version || strncmp (drm_version->name, "i915", 4)) {
|
2021-04-06 04:03:32 +00:00
|
|
|
GST_ERROR ("The specified device isn't an Intel device");
|
2021-01-12 07:33:49 +00:00
|
|
|
drmFreeVersion (drm_version);
|
|
|
|
close (fd);
|
|
|
|
fd = -1;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("Opened the specified drm device %s", user_choice);
|
|
|
|
drmFreeVersion (drm_version);
|
|
|
|
}
|
|
|
|
} else {
|
2021-04-06 04:03:32 +00:00
|
|
|
GST_ERROR ("The specified device isn't a valid drm device");
|
2021-01-12 07:33:49 +00:00
|
|
|
}
|
2021-04-06 04:03:32 +00:00
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
if (fd >= 0) {
|
|
|
|
ret_path = g_strdup (user_choice);
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_path;
|
2021-01-12 07:33:49 +00:00
|
|
|
}
|
2018-02-13 23:40:22 +00:00
|
|
|
|
|
|
|
client = g_udev_client_new (NULL);
|
|
|
|
if (!client)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
e = g_udev_enumerator_new (client);
|
|
|
|
if (!e)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
g_udev_enumerator_add_match_subsystem (e, "drm");
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
g_udev_enumerator_add_match_name (e, devnode_files[i]);
|
|
|
|
devices = g_udev_enumerator_execute (e);
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next) {
|
|
|
|
dev = (GUdevDevice *) l->data;
|
|
|
|
|
|
|
|
parent = g_udev_device_get_parent (dev);
|
2019-02-12 02:53:55 +00:00
|
|
|
if (strcmp (g_udev_device_get_subsystem (parent), "pci") != 0 ||
|
|
|
|
strcmp (g_udev_device_get_driver (parent), "i915") != 0) {
|
2018-02-13 23:40:22 +00:00
|
|
|
g_object_unref (parent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
g_object_unref (parent);
|
|
|
|
|
|
|
|
devnode_path = g_udev_device_get_device_file (dev);
|
|
|
|
fd = open (devnode_path, O_RDWR | O_CLOEXEC);
|
|
|
|
if (fd < 0)
|
|
|
|
continue;
|
|
|
|
GST_DEBUG ("Opened the drm device node %s", devnode_path);
|
2021-05-08 03:44:57 +00:00
|
|
|
ret_path = g_strdup (devnode_path);
|
2018-02-13 23:40:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_foreach (devices, (GFunc) gst_object_unref, NULL);
|
|
|
|
g_list_free (devices);
|
|
|
|
if (fd >= 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2021-05-08 03:44:57 +00:00
|
|
|
if (fd >= 0)
|
|
|
|
close (fd);
|
|
|
|
|
2018-02-13 23:40:22 +00:00
|
|
|
if (e)
|
|
|
|
g_object_unref (e);
|
|
|
|
if (client)
|
|
|
|
g_object_unref (client);
|
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
return ret_path;
|
2018-02-13 23:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_msdk_context_use_vaapi (GstMsdkContext * context)
|
|
|
|
{
|
2021-05-08 03:44:57 +00:00
|
|
|
char *path;
|
2018-02-13 21:41:28 +00:00
|
|
|
VADisplay va_dpy = NULL;
|
2021-05-08 03:44:57 +00:00
|
|
|
GstVaDisplay *display_drm = NULL;
|
2018-02-13 21:41:28 +00:00
|
|
|
mfxStatus status;
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
path = get_device_path ();
|
|
|
|
if (path == NULL) {
|
2022-03-02 19:57:42 +00:00
|
|
|
GST_WARNING ("Couldn't find a drm device node to open");
|
2018-02-13 21:41:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
display_drm = gst_va_display_drm_new_from_path (path);
|
|
|
|
if (!display_drm) {
|
|
|
|
GST_ERROR ("Couldn't create a VA DRM display");
|
2018-02-13 21:41:28 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
2021-05-08 03:44:57 +00:00
|
|
|
g_free (path);
|
2018-02-13 21:41:28 +00:00
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
va_dpy = gst_va_display_get_va_dpy (display_drm);
|
2018-02-13 21:41:28 +00:00
|
|
|
|
2021-02-04 07:27:13 +00:00
|
|
|
status = MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY,
|
2018-02-13 21:41:28 +00:00
|
|
|
(mfxHDL) va_dpy);
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Setting VAAPI handle failed (%s)",
|
|
|
|
msdk_status_to_string (status));
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2021-05-08 03:44:57 +00:00
|
|
|
priv->display = display_drm;
|
2018-02-13 21:41:28 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failed:
|
2021-05-08 03:44:57 +00:00
|
|
|
if (display_drm)
|
|
|
|
gst_object_unref (display_drm);
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
static GstD3D11Device *
|
|
|
|
get_device_by_index (IDXGIFactory1 * factory, guint idx)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IDXGIAdapter1 *adapter;
|
|
|
|
ID3D11Device *device_handle;
|
|
|
|
ID3D10Multithread *multi_thread;
|
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
GstD3D11Device *device = NULL;
|
|
|
|
gint64 luid;
|
|
|
|
|
|
|
|
hr = IDXGIFactory1_EnumAdapters1 (factory, idx, &adapter);
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDXGIAdapter1_GetDesc (adapter, &desc);
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
IDXGIAdapter1_Release (adapter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc.VendorId != 0x8086) {
|
|
|
|
IDXGIAdapter1_Release (adapter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
luid = gst_d3d11_luid_to_int64 (&desc.AdapterLuid);
|
|
|
|
device = gst_d3d11_device_new_for_adapter_luid (luid,
|
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT);
|
|
|
|
IDXGIAdapter1_Release (adapter);
|
|
|
|
|
|
|
|
device_handle = gst_d3d11_device_get_device_handle (device);
|
|
|
|
hr = ID3D11Device_QueryInterface (device_handle,
|
|
|
|
&IID_ID3D10Multithread, (void **) &multi_thread);
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
gst_object_unref (device);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ID3D10Multithread_SetMultithreadProtected (multi_thread, TRUE);
|
|
|
|
ID3D10Multithread_Release (multi_thread);
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_msdk_context_use_d3d11 (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IDXGIFactory1 *factory = NULL;
|
|
|
|
GstD3D11Device *device = NULL;
|
|
|
|
ID3D11Device *device_handle;
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
mfxStatus status;
|
|
|
|
guint idx = 0;
|
|
|
|
gint user_idx = -1;
|
|
|
|
const gchar *user_choice = g_getenv ("GST_MSDK_DEVICE");
|
|
|
|
|
|
|
|
hr = CreateDXGIFactory1 (&IID_IDXGIFactory1, (void **) &factory);
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
GST_ERROR ("Couldn't create DXGI factory");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_choice) {
|
|
|
|
user_idx = atoi (user_choice);
|
|
|
|
if (!(device = get_device_by_index (factory, user_idx)))
|
|
|
|
GST_WARNING
|
|
|
|
("Failed to get device by user index, try to pick the first available device");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pick the first available device */
|
|
|
|
while (!device) {
|
|
|
|
device = get_device_by_index (factory, idx++);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDXGIFactory1_Release (factory);
|
|
|
|
device_handle = gst_d3d11_device_get_device_handle (device);
|
|
|
|
|
|
|
|
status =
|
|
|
|
MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_D3D11_DEVICE,
|
|
|
|
gst_d3d11_device_get_device_handle (device));
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Setting D3D11VA handle failed (%s)",
|
|
|
|
msdk_status_to_string (status));
|
|
|
|
gst_object_unref (device);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->device = device;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-02-13 21:41:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
2023-04-07 06:09:40 +00:00
|
|
|
gst_msdk_context_open (GstMsdkContext * context, gboolean hardware)
|
2018-02-13 21:41:28 +00:00
|
|
|
{
|
2020-12-10 03:11:04 +00:00
|
|
|
mfxU16 codename;
|
2018-02-13 21:41:28 +00:00
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
2021-02-04 07:27:13 +00:00
|
|
|
MsdkSession msdk_session;
|
2022-05-07 09:10:34 +00:00
|
|
|
mfxIMPL impl;
|
2018-02-13 21:41:28 +00:00
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
priv->hardware = hardware;
|
2021-02-04 07:27:13 +00:00
|
|
|
|
2022-05-07 09:10:34 +00:00
|
|
|
impl = hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
impl |= MFX_IMPL_VIA_D3D11;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
msdk_session = msdk_open_session (impl);
|
2021-02-04 07:27:13 +00:00
|
|
|
priv->session = msdk_session;
|
|
|
|
if (!priv->session.session)
|
2018-02-13 21:41:28 +00:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
if (hardware) {
|
|
|
|
if (!gst_msdk_context_use_vaapi (context))
|
|
|
|
goto failed;
|
|
|
|
}
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
if (hardware) {
|
|
|
|
if (!gst_msdk_context_use_d3d11 (context))
|
|
|
|
goto failed;
|
|
|
|
}
|
2018-02-13 21:41:28 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-04 07:27:13 +00:00
|
|
|
codename = msdk_get_platform_codename (priv->session.session);
|
2020-12-10 03:11:04 +00:00
|
|
|
|
|
|
|
if (codename != MFX_PLATFORM_UNKNOWN)
|
|
|
|
GST_INFO ("Detected MFX platform with device code %d", codename);
|
|
|
|
else
|
|
|
|
GST_WARNING ("Unknown MFX platform");
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_msdk_context_init (GstMsdkContext * context)
|
|
|
|
{
|
2018-06-23 22:17:26 +00:00
|
|
|
GstMsdkContextPrivate *priv = gst_msdk_context_get_instance_private (context);
|
2018-02-13 21:41:28 +00:00
|
|
|
|
|
|
|
context->priv = priv;
|
msdk: manage MSDK surfaces seperately
Currently a gst buffer has one mfxFrameSurface when it's allocated and
can't be changed.
This is based on that the life of gst buffer and mfxFrameSurface would
be same.
But it's not true. Sometimes even if a gst buffer of a frame is finished
on downstream,
mfxFramesurface coupled with the gst buffer is still locked, which means
it's still being used in the driver.
So this patch does this.
Every time a gst buffer is acquired from the pool, it confirms if the
surface coupled with the buffer is unlocked.
If not, replace it with new unlocked one.
In this way, user(decoder or encoder) doesn't need to manage gst buffers
including locked surface.
To do that, this patch includes the following:
1. GstMsdkContext
- Manages MSDK surfaces available, used, locked respectively as the
following:
1\ surfaces_avail : surfaces which are free and unused anywhere
2\ surfaces_used : surfaces coupled with a gst buffer and being used
now.
3\ surfaces_locked : surfaces still locked even after the gst buffer
is released.
- Provide an api to get MSDK surface available.
- Provide an api to release MSDK surface.
2. GstMsdkVideoMemory
- Gets a surface available when it's allocated.
- Provide an api to get an available surface with new unlocked one.
- Provide an api to release surface in the msdk video memory.
3. GstMsdkBufferPool
- In acquire_buffer, every time a gst buffer is acquired, get new
available surface from the list.
- In release_buffer, it confirms if the buffer's surface is unlocked or
not.
- If unlocked, it is put to the available list.
- If still locked, it is put to the locked list.
This also fixes bug #793525.
https://bugzilla.gnome.org/show_bug.cgi?id=793413
https://bugzilla.gnome.org/show_bug.cgi?id=793525
2018-03-08 20:37:12 +00:00
|
|
|
|
|
|
|
g_mutex_init (&priv->mutex);
|
2018-02-13 21:41:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 20:38:30 +00:00
|
|
|
static void
|
|
|
|
release_child_session (gpointer session)
|
|
|
|
{
|
|
|
|
mfxStatus status;
|
|
|
|
|
|
|
|
mfxSession _session = session;
|
|
|
|
status = MFXDisjoinSession (_session);
|
|
|
|
if (status != MFX_ERR_NONE)
|
|
|
|
GST_WARNING ("failed to disjoin (%s)", msdk_status_to_string (status));
|
2021-02-04 07:27:13 +00:00
|
|
|
msdk_close_mfx_session (_session);
|
2018-03-08 20:38:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
static void
|
|
|
|
gst_msdk_context_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstMsdkContext *context = GST_MSDK_CONTEXT_CAST (obj);
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
2018-02-13 22:50:48 +00:00
|
|
|
|
2018-03-08 20:38:30 +00:00
|
|
|
/* child sessions will be closed when the parent session is closed */
|
2021-07-17 16:51:04 +00:00
|
|
|
if (priv->parent_context) {
|
|
|
|
gst_object_unref (priv->parent_context);
|
2018-02-13 22:50:48 +00:00
|
|
|
goto done;
|
2021-07-17 16:51:04 +00:00
|
|
|
} else
|
2018-03-08 20:38:30 +00:00
|
|
|
g_list_free_full (priv->child_session_list, release_child_session);
|
2018-02-13 22:50:48 +00:00
|
|
|
|
2021-02-04 07:27:13 +00:00
|
|
|
msdk_close_session (&priv->session);
|
msdk: manage MSDK surfaces seperately
Currently a gst buffer has one mfxFrameSurface when it's allocated and
can't be changed.
This is based on that the life of gst buffer and mfxFrameSurface would
be same.
But it's not true. Sometimes even if a gst buffer of a frame is finished
on downstream,
mfxFramesurface coupled with the gst buffer is still locked, which means
it's still being used in the driver.
So this patch does this.
Every time a gst buffer is acquired from the pool, it confirms if the
surface coupled with the buffer is unlocked.
If not, replace it with new unlocked one.
In this way, user(decoder or encoder) doesn't need to manage gst buffers
including locked surface.
To do that, this patch includes the following:
1. GstMsdkContext
- Manages MSDK surfaces available, used, locked respectively as the
following:
1\ surfaces_avail : surfaces which are free and unused anywhere
2\ surfaces_used : surfaces coupled with a gst buffer and being used
now.
3\ surfaces_locked : surfaces still locked even after the gst buffer
is released.
- Provide an api to get MSDK surface available.
- Provide an api to release MSDK surface.
2. GstMsdkVideoMemory
- Gets a surface available when it's allocated.
- Provide an api to get an available surface with new unlocked one.
- Provide an api to release surface in the msdk video memory.
3. GstMsdkBufferPool
- In acquire_buffer, every time a gst buffer is acquired, get new
available surface from the list.
- In release_buffer, it confirms if the buffer's surface is unlocked or
not.
- If unlocked, it is put to the available list.
- If still locked, it is put to the locked list.
This also fixes bug #793525.
https://bugzilla.gnome.org/show_bug.cgi?id=793413
https://bugzilla.gnome.org/show_bug.cgi?id=793525
2018-03-08 20:37:12 +00:00
|
|
|
g_mutex_clear (&priv->mutex);
|
2018-02-13 21:41:28 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
2021-05-08 03:44:57 +00:00
|
|
|
if (priv->display)
|
|
|
|
gst_object_unref (priv->display);
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
if (priv->device)
|
|
|
|
gst_object_unref (priv->device);
|
2018-02-13 21:41:28 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
done:
|
2018-02-13 21:41:28 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_msdk_context_class_init (GstMsdkContextClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *const g_object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_object_class->finalize = gst_msdk_context_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstMsdkContext *
|
2023-04-07 06:09:40 +00:00
|
|
|
gst_msdk_context_new (gboolean hardware)
|
2018-02-13 21:41:28 +00:00
|
|
|
{
|
|
|
|
GstMsdkContext *obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL);
|
|
|
|
|
2023-04-07 06:09:40 +00:00
|
|
|
if (obj && !gst_msdk_context_open (obj, hardware)) {
|
|
|
|
gst_object_unref (obj);
|
2018-02-13 21:41:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2023-04-07 06:09:40 +00:00
|
|
|
GstMsdkContext *
|
|
|
|
gst_msdk_context_new_with_job_type (gboolean hardware,
|
|
|
|
GstMsdkContextJobType job_type)
|
|
|
|
{
|
|
|
|
GstMsdkContext *obj = gst_msdk_context_new (hardware);
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
obj->priv->job_type = job_type;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
GstMsdkContext *
|
|
|
|
gst_msdk_context_new_with_parent (GstMsdkContext * parent)
|
|
|
|
{
|
|
|
|
mfxStatus status;
|
|
|
|
GstMsdkContext *obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL);
|
|
|
|
GstMsdkContextPrivate *priv = obj->priv;
|
|
|
|
GstMsdkContextPrivate *parent_priv = parent->priv;
|
2021-03-01 04:09:43 +00:00
|
|
|
mfxVersion version;
|
|
|
|
mfxIMPL impl;
|
|
|
|
MsdkSession child_msdk_session;
|
|
|
|
mfxHandleType handle_type = 0;
|
|
|
|
mfxHDL handle = NULL;
|
2018-02-13 22:50:48 +00:00
|
|
|
|
2021-03-01 04:09:43 +00:00
|
|
|
status = MFXQueryIMPL (parent_priv->session.session, &impl);
|
|
|
|
|
|
|
|
if (status == MFX_ERR_NONE)
|
|
|
|
status = MFXQueryVersion (parent_priv->session.session, &version);
|
|
|
|
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Failed to query the session attributes (%s)",
|
|
|
|
msdk_status_to_string (status));
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-03-01 04:09:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MFX_IMPL_VIA_VAAPI == (0x0f00 & (impl)))
|
|
|
|
handle_type = MFX_HANDLE_VA_DISPLAY;
|
2022-05-07 09:10:34 +00:00
|
|
|
else if (MFX_IMPL_VIA_D3D11 == (0x0f00 & (impl)))
|
|
|
|
handle_type = MFX_HANDLE_D3D11_DEVICE;
|
2021-03-01 04:09:43 +00:00
|
|
|
|
|
|
|
if (handle_type) {
|
|
|
|
status =
|
|
|
|
MFXVideoCORE_GetHandle (parent_priv->session.session, handle_type,
|
|
|
|
&handle);
|
|
|
|
|
|
|
|
if (status != MFX_ERR_NONE || !handle) {
|
|
|
|
GST_ERROR ("Failed to get session handle (%s)",
|
|
|
|
msdk_status_to_string (status));
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-03-01 04:09:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
child_msdk_session.loader = parent_priv->session.loader;
|
|
|
|
child_msdk_session.session = NULL;
|
|
|
|
status = msdk_init_msdk_session (impl, &version, &child_msdk_session);
|
|
|
|
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Failed to create a child mfx session (%s)",
|
|
|
|
msdk_status_to_string (status));
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-03-01 04:09:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle) {
|
|
|
|
status =
|
|
|
|
MFXVideoCORE_SetHandle (child_msdk_session.session, handle_type,
|
|
|
|
handle);
|
|
|
|
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Failed to set a HW handle (%s)",
|
|
|
|
msdk_status_to_string (status));
|
|
|
|
MFXClose (child_msdk_session.session);
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-03-01 04:09:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if (MFX_VERSION >= 1025)
|
2021-02-04 07:27:13 +00:00
|
|
|
status =
|
2021-03-01 04:09:43 +00:00
|
|
|
MFXJoinSession (parent_priv->session.session, child_msdk_session.session);
|
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
if (status != MFX_ERR_NONE) {
|
2021-03-01 04:09:43 +00:00
|
|
|
GST_ERROR ("Failed to join two sessions (%s)",
|
|
|
|
msdk_status_to_string (status));
|
|
|
|
MFXClose (child_msdk_session.session);
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2018-02-13 22:50:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-03-01 04:09:43 +00:00
|
|
|
#endif
|
2018-02-13 22:50:48 +00:00
|
|
|
|
2021-02-04 07:27:13 +00:00
|
|
|
/* Set loader to NULL for child session */
|
|
|
|
priv->session.loader = NULL;
|
2021-03-01 04:09:43 +00:00
|
|
|
priv->session.session = child_msdk_session.session;
|
2018-02-13 22:50:48 +00:00
|
|
|
priv->hardware = parent_priv->hardware;
|
|
|
|
priv->job_type = parent_priv->job_type;
|
2018-03-08 20:38:30 +00:00
|
|
|
parent_priv->child_session_list =
|
2021-02-04 07:27:13 +00:00
|
|
|
g_list_prepend (parent_priv->child_session_list, priv->session.session);
|
2018-02-13 22:50:48 +00:00
|
|
|
#ifndef _WIN32
|
2021-05-08 03:44:57 +00:00
|
|
|
priv->display = parent_priv->display;
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
priv->device = parent_priv->device;
|
2018-02-13 22:50:48 +00:00
|
|
|
#endif
|
2021-07-17 16:51:04 +00:00
|
|
|
priv->parent_context = gst_object_ref (parent);
|
2018-02-13 22:50:48 +00:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2022-05-07 09:10:34 +00:00
|
|
|
#ifndef _WIN32
|
2021-05-08 05:49:23 +00:00
|
|
|
GstMsdkContext *
|
|
|
|
gst_msdk_context_new_with_va_display (GstObject * display_obj,
|
|
|
|
gboolean hardware, GstMsdkContextJobType job_type)
|
|
|
|
{
|
|
|
|
GstMsdkContext *obj = NULL;
|
|
|
|
|
|
|
|
GstMsdkContextPrivate *priv;
|
|
|
|
mfxU16 codename;
|
|
|
|
mfxStatus status;
|
|
|
|
GstVaDisplay *va_display;
|
|
|
|
|
|
|
|
va_display = GST_VA_DISPLAY (display_obj);
|
|
|
|
if (!va_display)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL);
|
|
|
|
|
|
|
|
priv = obj->priv;
|
2022-10-31 08:59:18 +00:00
|
|
|
priv->display = gst_object_ref (va_display);
|
2021-05-08 05:49:23 +00:00
|
|
|
|
|
|
|
priv->job_type = job_type;
|
|
|
|
priv->hardware = hardware;
|
|
|
|
priv->session =
|
|
|
|
msdk_open_session (hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
|
|
|
if (!priv->session.session) {
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-05-08 05:49:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hardware) {
|
|
|
|
status =
|
|
|
|
MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_VA_DISPLAY,
|
|
|
|
(mfxHDL) gst_va_display_get_va_dpy (priv->display));
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Setting VAAPI handle failed (%s)",
|
|
|
|
msdk_status_to_string (status));
|
2022-11-01 01:47:38 +00:00
|
|
|
gst_object_unref (obj);
|
2021-05-08 05:49:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
codename = msdk_get_platform_codename (priv->session.session);
|
|
|
|
|
|
|
|
if (codename != MFX_PLATFORM_UNKNOWN)
|
|
|
|
GST_INFO ("Detected MFX platform with device code %d", codename);
|
|
|
|
else
|
|
|
|
GST_WARNING ("Unknown MFX platform");
|
|
|
|
|
2022-05-07 09:10:34 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
GstMsdkContext *
|
|
|
|
gst_msdk_context_new_with_d3d11_device (GstD3D11Device * device,
|
|
|
|
gboolean hardware, GstMsdkContextJobType job_type)
|
|
|
|
{
|
|
|
|
GstMsdkContext *obj = NULL;
|
|
|
|
GstMsdkContextPrivate *priv;
|
|
|
|
mfxU16 codename;
|
|
|
|
mfxStatus status;
|
|
|
|
ID3D10Multithread *multi_thread;
|
|
|
|
ID3D11Device *device_handle;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL);
|
|
|
|
|
|
|
|
priv = obj->priv;
|
|
|
|
priv->device = gst_object_ref (device);
|
|
|
|
|
|
|
|
priv->job_type = job_type;
|
|
|
|
priv->hardware = hardware;
|
|
|
|
priv->session =
|
|
|
|
msdk_open_session (hardware ? MFX_IMPL_HARDWARE_ANY : MFX_IMPL_SOFTWARE);
|
|
|
|
if (!priv->session.session) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_handle = gst_d3d11_device_get_device_handle (device);
|
|
|
|
hr = ID3D11Device_QueryInterface (device_handle,
|
|
|
|
&IID_ID3D10Multithread, (void **) &multi_thread);
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
GST_ERROR ("ID3D10Multithread interface is unavailable");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ID3D10Multithread_SetMultithreadProtected (multi_thread, TRUE);
|
|
|
|
ID3D10Multithread_Release (multi_thread);
|
|
|
|
|
|
|
|
if (hardware) {
|
|
|
|
status =
|
|
|
|
MFXVideoCORE_SetHandle (priv->session.session, MFX_HANDLE_D3D11_DEVICE,
|
|
|
|
device_handle);
|
|
|
|
if (status != MFX_ERR_NONE) {
|
|
|
|
GST_ERROR ("Setting D3D11VA handle failed (%s)",
|
|
|
|
msdk_status_to_string (status));
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
codename = msdk_get_platform_codename (priv->session.session);
|
|
|
|
|
|
|
|
if (codename != MFX_PLATFORM_UNKNOWN)
|
|
|
|
GST_INFO ("Detected MFX platform with device code %d", codename);
|
|
|
|
else
|
|
|
|
GST_WARNING ("Unknown MFX platform");
|
2021-05-08 05:49:23 +00:00
|
|
|
|
|
|
|
return obj;
|
2022-05-07 09:10:34 +00:00
|
|
|
|
|
|
|
failed:
|
|
|
|
gst_object_unref (obj);
|
|
|
|
gst_object_unref (device);
|
|
|
|
return NULL;
|
2021-05-08 05:49:23 +00:00
|
|
|
}
|
2022-05-07 09:10:34 +00:00
|
|
|
#endif
|
2021-05-08 05:49:23 +00:00
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
mfxSession
|
|
|
|
gst_msdk_context_get_session (GstMsdkContext * context)
|
|
|
|
{
|
2021-02-04 07:27:13 +00:00
|
|
|
return context->priv->session.session;
|
2018-02-13 21:41:28 +00:00
|
|
|
}
|
|
|
|
|
2023-04-07 06:26:55 +00:00
|
|
|
const mfxLoader *
|
|
|
|
gst_msdk_context_get_loader (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
return &context->priv->session.loader;
|
|
|
|
}
|
|
|
|
|
|
|
|
mfxU32
|
|
|
|
gst_msdk_context_get_impl_idx (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
return context->priv->session.impl_idx;
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:41:28 +00:00
|
|
|
gpointer
|
|
|
|
gst_msdk_context_get_handle (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
2021-05-08 03:44:57 +00:00
|
|
|
return gst_va_display_get_va_dpy (context->priv->display);
|
2018-02-13 21:41:28 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-07 09:10:34 +00:00
|
|
|
#ifndef _WIN32
|
2021-05-08 03:44:57 +00:00
|
|
|
GstObject *
|
2022-05-07 09:10:34 +00:00
|
|
|
gst_msdk_context_get_va_display (GstMsdkContext * context)
|
2018-02-13 21:41:28 +00:00
|
|
|
{
|
2021-05-08 03:44:57 +00:00
|
|
|
if (context->priv->display)
|
|
|
|
return gst_object_ref (GST_OBJECT_CAST (context->priv->display));
|
|
|
|
return NULL;
|
2018-02-13 21:41:28 +00:00
|
|
|
}
|
2022-05-07 09:10:34 +00:00
|
|
|
#else
|
|
|
|
GstD3D11Device *
|
|
|
|
gst_msdk_context_get_d3d11_device (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
if (context->priv->device)
|
|
|
|
return gst_object_ref (context->priv->device);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-13 21:43:42 +00:00
|
|
|
|
|
|
|
static gint
|
|
|
|
_find_response (gconstpointer resp, gconstpointer comp_resp)
|
|
|
|
{
|
|
|
|
GstMsdkAllocResponse *cached_resp = (GstMsdkAllocResponse *) resp;
|
|
|
|
mfxFrameAllocResponse *_resp = (mfxFrameAllocResponse *) comp_resp;
|
|
|
|
|
2019-09-11 02:49:10 +00:00
|
|
|
return cached_resp ? cached_resp->response.mids != _resp->mids : -1;
|
2018-02-13 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-09 14:23:17 +00:00
|
|
|
static inline gboolean
|
|
|
|
_requested_frame_size_is_equal_or_lower (mfxFrameAllocRequest * _req,
|
|
|
|
GstMsdkAllocResponse * cached_resp)
|
|
|
|
{
|
|
|
|
if (((_req->Type & MFX_MEMTYPE_EXPORT_FRAME) &&
|
|
|
|
_req->Info.Width == cached_resp->request.Info.Width &&
|
|
|
|
_req->Info.Height == cached_resp->request.Info.Height) ||
|
|
|
|
(!(_req->Type & MFX_MEMTYPE_EXPORT_FRAME) &&
|
|
|
|
_req->Info.Width <= cached_resp->request.Info.Width &&
|
|
|
|
_req->Info.Height <= cached_resp->request.Info.Height))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:43:42 +00:00
|
|
|
static gint
|
|
|
|
_find_request (gconstpointer resp, gconstpointer req)
|
|
|
|
{
|
|
|
|
GstMsdkAllocResponse *cached_resp = (GstMsdkAllocResponse *) resp;
|
|
|
|
mfxFrameAllocRequest *_req = (mfxFrameAllocRequest *) req;
|
|
|
|
|
2018-03-30 19:02:26 +00:00
|
|
|
/* Confirm if it's under the size of the cached response */
|
2020-01-09 14:23:17 +00:00
|
|
|
if (_req->NumFrameSuggested <= cached_resp->request.NumFrameSuggested &&
|
|
|
|
_requested_frame_size_is_equal_or_lower (_req, cached_resp))
|
2018-03-30 19:02:26 +00:00
|
|
|
return _req->Type & cached_resp->
|
|
|
|
request.Type & MFX_MEMTYPE_FROM_DECODE ? 0 : -1;
|
|
|
|
|
|
|
|
return -1;
|
2018-02-13 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstMsdkAllocResponse *
|
|
|
|
gst_msdk_context_get_cached_alloc_responses (GstMsdkContext * context,
|
|
|
|
mfxFrameAllocResponse * resp)
|
|
|
|
{
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
GList *l =
|
|
|
|
g_list_find_custom (priv->cached_alloc_responses, resp, _find_response);
|
|
|
|
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstMsdkAllocResponse *
|
|
|
|
gst_msdk_context_get_cached_alloc_responses_by_request (GstMsdkContext *
|
|
|
|
context, mfxFrameAllocRequest * req)
|
|
|
|
{
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
GList *l =
|
|
|
|
g_list_find_custom (priv->cached_alloc_responses, req, _find_request);
|
|
|
|
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_msdk_context_add_alloc_response (GstMsdkContext * context,
|
|
|
|
GstMsdkAllocResponse * resp)
|
|
|
|
{
|
|
|
|
context->priv->cached_alloc_responses =
|
msdk: manage MSDK surfaces seperately
Currently a gst buffer has one mfxFrameSurface when it's allocated and
can't be changed.
This is based on that the life of gst buffer and mfxFrameSurface would
be same.
But it's not true. Sometimes even if a gst buffer of a frame is finished
on downstream,
mfxFramesurface coupled with the gst buffer is still locked, which means
it's still being used in the driver.
So this patch does this.
Every time a gst buffer is acquired from the pool, it confirms if the
surface coupled with the buffer is unlocked.
If not, replace it with new unlocked one.
In this way, user(decoder or encoder) doesn't need to manage gst buffers
including locked surface.
To do that, this patch includes the following:
1. GstMsdkContext
- Manages MSDK surfaces available, used, locked respectively as the
following:
1\ surfaces_avail : surfaces which are free and unused anywhere
2\ surfaces_used : surfaces coupled with a gst buffer and being used
now.
3\ surfaces_locked : surfaces still locked even after the gst buffer
is released.
- Provide an api to get MSDK surface available.
- Provide an api to release MSDK surface.
2. GstMsdkVideoMemory
- Gets a surface available when it's allocated.
- Provide an api to get an available surface with new unlocked one.
- Provide an api to release surface in the msdk video memory.
3. GstMsdkBufferPool
- In acquire_buffer, every time a gst buffer is acquired, get new
available surface from the list.
- In release_buffer, it confirms if the buffer's surface is unlocked or
not.
- If unlocked, it is put to the available list.
- If still locked, it is put to the locked list.
This also fixes bug #793525.
https://bugzilla.gnome.org/show_bug.cgi?id=793413
https://bugzilla.gnome.org/show_bug.cgi?id=793525
2018-03-08 20:37:12 +00:00
|
|
|
g_list_prepend (context->priv->cached_alloc_responses, resp);
|
2018-02-13 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_msdk_context_remove_alloc_response (GstMsdkContext * context,
|
|
|
|
mfxFrameAllocResponse * resp)
|
|
|
|
{
|
|
|
|
GstMsdkAllocResponse *msdk_resp;
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
GList *l =
|
|
|
|
g_list_find_custom (priv->cached_alloc_responses, resp, _find_response);
|
|
|
|
|
|
|
|
if (!l)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
msdk_resp = l->data;
|
|
|
|
|
|
|
|
g_slice_free1 (sizeof (GstMsdkAllocResponse), msdk_resp);
|
|
|
|
priv->cached_alloc_responses =
|
|
|
|
g_list_delete_link (priv->cached_alloc_responses, l);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-02-13 22:50:48 +00:00
|
|
|
|
2022-08-22 09:44:35 +00:00
|
|
|
void
|
|
|
|
gst_msdk_context_set_alloc_pool (GstMsdkContext * context, GstBufferPool * pool)
|
|
|
|
{
|
|
|
|
context->priv->alloc_pool = gst_object_ref (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstBufferPool *
|
|
|
|
gst_msdk_context_get_alloc_pool (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
return context->priv->alloc_pool;
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
GstMsdkContextJobType
|
|
|
|
gst_msdk_context_get_job_type (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
return context->priv->job_type;
|
|
|
|
}
|
|
|
|
|
2023-04-07 06:09:40 +00:00
|
|
|
void
|
|
|
|
gst_msdk_context_set_job_type (GstMsdkContext * context,
|
|
|
|
GstMsdkContextJobType job_type)
|
|
|
|
{
|
|
|
|
context->priv->job_type = job_type;
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:50:48 +00:00
|
|
|
void
|
|
|
|
gst_msdk_context_add_job_type (GstMsdkContext * context,
|
|
|
|
GstMsdkContextJobType job_type)
|
|
|
|
{
|
|
|
|
context->priv->job_type |= job_type;
|
|
|
|
}
|
2018-02-13 22:52:14 +00:00
|
|
|
|
|
|
|
gint
|
|
|
|
gst_msdk_context_get_shared_async_depth (GstMsdkContext * context)
|
|
|
|
{
|
|
|
|
return context->priv->shared_async_depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_msdk_context_add_shared_async_depth (GstMsdkContext * context,
|
|
|
|
gint async_depth)
|
|
|
|
{
|
|
|
|
context->priv->shared_async_depth += async_depth;
|
|
|
|
}
|
2018-12-29 05:56:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_msdk_context_set_frame_allocator (GstMsdkContext * context,
|
|
|
|
mfxFrameAllocator * allocator)
|
|
|
|
{
|
|
|
|
GstMsdkContextPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->mutex);
|
|
|
|
|
|
|
|
if (!priv->has_frame_allocator) {
|
|
|
|
mfxStatus status;
|
|
|
|
|
2021-02-04 07:27:13 +00:00
|
|
|
status = MFXVideoCORE_SetFrameAllocator (priv->session.session, allocator);
|
2018-12-29 05:56:49 +00:00
|
|
|
|
|
|
|
if (status != MFX_ERR_NONE)
|
|
|
|
GST_ERROR ("Failed to set frame allocator");
|
|
|
|
else
|
|
|
|
priv->has_frame_allocator = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->mutex);
|
|
|
|
}
|