msdk: Add method to replace internal VASurface of mfxFrameSurface

Added a utility method to replace the MemID (interanl VASurfaceID)
associated with the mfxFrameSurface. This is usefull for dmabuf-import
where we need to replace the memID dynamically

https://bugzilla.gnome.org/show_bug.cgi?id=794817
This commit is contained in:
Sreerenj Balachandran 2018-05-30 16:23:44 -08:00
parent 62d2d8ebf9
commit a7b7939dd7
2 changed files with 68 additions and 0 deletions

View file

@ -129,6 +129,10 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
vaDestroyImage (gst_msdk_context_get_handle (context),
msdk_mids[i].image.image_id);
}
} else {
/* useful to check the image mapping state later */
msdk_mids[i].image.image_id = VA_INVALID_ID;
msdk_mids[i].image.buf = VA_INVALID_ID;
}
msdk_mids[i].surface = &surfaces[i];
@ -465,3 +469,63 @@ error_create_surface:
return FALSE;
}
}
/**
* gst_msdk_replace_mfx_memid:
* This method replace the internal VA Suface in mfxSurface with a new one
*
* Caution: Not a thread-safe routine, this method is here to work around
* the dmabuf-import use case with dynamic memID replacement where msdk
* originally Inited with fake memIDs.
*
* Don't use anywhere else unless you really know what you are doing!
*/
gboolean
gst_msdk_replace_mfx_memid (GstMsdkContext * context,
mfxFrameSurface1 * mfx_surface, VASurfaceID surface_id)
{
GstMsdkMemoryID *msdk_mid = NULL;
VADisplay dpy;
VASurfaceID *old_surface_id;
VAStatus va_status;
mfxStatus status = MFX_ERR_NONE;
g_return_val_if_fail (mfx_surface != NULL, FALSE);
g_return_val_if_fail (context != NULL, FALSE);
msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
dpy = gst_msdk_context_get_handle (context);
/* Destory the underlined VAImage if already mapped */
if (msdk_mid->image.image_id != VA_INVALID_ID
&& msdk_mid->image.buf != VA_INVALID_ID) {
status =
gst_msdk_frame_unlock ((mfxHDL) context, (mfxMemId) msdk_mid, NULL);
if (status != MFX_ERR_NONE)
goto error_destroy_va_image;
}
/* Destroy the associated VASurface */
old_surface_id = msdk_mid->surface;
if (*old_surface_id != VA_INVALID_ID) {
va_status = vaDestroySurfaces (dpy, old_surface_id, 1);
status = gst_msdk_get_mfx_status_from_va_status (va_status);
if (status != MFX_ERR_NONE)
goto error_destroy_va_surface;
}
*msdk_mid->surface = surface_id;
return TRUE;
error_destroy_va_image:
{
GST_ERROR ("Failed to Destroy the VAImage");
return FALSE;
}
error_destroy_va_surface:
{
GST_ERROR ("Failed to Destroy the VASurfaceID %x", *old_surface_id);
return FALSE;
}
}

View file

@ -45,6 +45,10 @@ gboolean
gst_msdk_export_dmabuf_to_vasurface (GstMsdkContext *context,
GstVideoInfo *vinfo, gint fd, VASurfaceID *surface_id);
gboolean
gst_msdk_replace_mfx_memid (GstMsdkContext *context,
mfxFrameSurface1 *mfx_surface, VASurfaceID surface_id);
G_END_DECLS
#endif /* GST_MSDK_ALLOCATOR_LIBVA_H_ */