Commit 4d860ec8 authored by Hyunjun Ko's avatar Hyunjun Ko Committed by Sreerenj Balachandran

msdk: adds frame allocator using libva

Implements msdk frame allocator which is required from the driver.
Also makes these functions global so that GstMsdkAllocator could use
the allocated video memory later and couple with GstMsdkMemory.

GstMsdkContext keeps allocation information such as mfxFrameAllocRequest
and mfxFrameAllocResponse after allocation.

https://bugzilla.gnome.org/show_bug.cgi?id=790752
parent 3ed9f7c5
......@@ -54,7 +54,8 @@ libgstmsdk_la_LIBADD = \
if USE_MSDK_LIBVA
libgstmsdk_la_SOURCES += \
msdk.c \
msdk_libva.c
msdk_libva.c \
gstmsdkallocator_libva.c
libgstmsdk_la_CFLAGS += \
$(LIBVA_DRM_CFLAGS)
libgstmsdk_la_LIBADD += \
......
/* 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.
*/
#ifndef GST_MSDK_ALLOCATOR_H_
#define GST_MSDK_ALLOCATOR_H_
#include "msdk.h"
#include "gstmsdkcontext.h"
G_BEGIN_DECLS
typedef struct _GstMsdkMemoryID GstMsdkMemoryID;
struct _GstMsdkMemoryID {
mfxU32 fourcc;
#ifndef _WIN32
VASurfaceID *surface;
VAImage image;
#endif
};
mfxStatus gst_msdk_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp);
mfxStatus gst_msdk_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp);
mfxStatus gst_msdk_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr);
mfxStatus gst_msdk_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr);
mfxStatus gst_msdk_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl);
void gst_msdk_set_frame_allocator (GstMsdkContext * context);
G_END_DECLS
#endif /* GST_MSDK_ALLOCATOR_H_ */
This diff is collapsed.
......@@ -211,3 +211,78 @@ gst_msdk_context_get_fd (GstMsdkContext * context)
return -1;
#endif
}
static gint
_find_response (gconstpointer resp, gconstpointer comp_resp)
{
GstMsdkAllocResponse *cached_resp = (GstMsdkAllocResponse *) resp;
mfxFrameAllocResponse *_resp = (mfxFrameAllocResponse *) comp_resp;
return cached_resp ? cached_resp->mem_ids != _resp->mids : -1;
}
static gint
_find_request (gconstpointer resp, gconstpointer req)
{
GstMsdkAllocResponse *cached_resp = (GstMsdkAllocResponse *) resp;
mfxFrameAllocRequest *_req = (mfxFrameAllocRequest *) req;
return cached_resp ? cached_resp->request.Type != _req->Type : -1;
}
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 =
g_list_append (context->priv->cached_alloc_responses, resp);
}
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;
}
......@@ -84,6 +84,34 @@ mfxSession gst_msdk_context_get_session (GstMsdkContext * context);
gpointer gst_msdk_context_get_handle (GstMsdkContext * context);
gint gst_msdk_context_get_fd (GstMsdkContext * context);
/* GstMsdkContext contains mfxFrameAllocResponses,
* if app calls MFXVideoCORE_SetFrameAllocator.
*/
typedef struct _GstMsdkAllocResponse GstMsdkAllocResponse;
struct _GstMsdkAllocResponse {
mfxFrameAllocResponse *response;
mfxFrameAllocRequest request;
mfxMemId *mem_ids;
gint num_used_memory;
};
GstMsdkAllocResponse *
gst_msdk_context_get_cached_alloc_responses (GstMsdkContext * context,
mfxFrameAllocResponse * resp);
GstMsdkAllocResponse *
gst_msdk_context_get_cached_alloc_responses_by_request (GstMsdkContext * context,
mfxFrameAllocRequest * req);
void
gst_msdk_context_add_alloc_response (GstMsdkContext * context,
GstMsdkAllocResponse * resp);
gboolean
gst_msdk_context_remove_alloc_response (GstMsdkContext * context,
mfxFrameAllocResponse * resp);
G_END_DECLS
#endif /* GST_MSDK_CONTEXT_H */
......@@ -19,7 +19,7 @@ msdk_sources = [
if host_machine.system() == 'windows'
msdk_sources += 'msdk_d3d.c'
else
msdk_sources += 'msdk_libva.c'
msdk_sources += ['msdk_libva.c', 'gstmsdkallocator_libva.c']
endif
msdk_root = run_command(python3, '-c', 'import os; print(os.environ.get("INTELMEDIASDKROOT", os.environ.get("MFX_HOME", "")))').stdout().strip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment