mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-03 17:22:29 +00:00
msdk: implements GstMsdkContext.
Makes GstMsdkContext to be a descendant of GstObject so that we could track the life-cycle of the session of the driver. Also replaces MsdkContext with this one. Keeps msdk_d3d.c alive for the future. https://bugzilla.gnome.org/show_bug.cgi?id=790752
This commit is contained in:
parent
3f9d0fcaa9
commit
6ce9a66b80
15 changed files with 339 additions and 154 deletions
|
@ -1,6 +1,7 @@
|
||||||
plugin_LTLIBRARIES = libgstmsdk.la
|
plugin_LTLIBRARIES = libgstmsdk.la
|
||||||
|
|
||||||
libgstmsdk_la_SOURCES = \
|
libgstmsdk_la_SOURCES = \
|
||||||
|
gstmsdkcontext.c \
|
||||||
gstmsdkh264dec.c \
|
gstmsdkh264dec.c \
|
||||||
gstmsdkh264enc.c \
|
gstmsdkh264enc.c \
|
||||||
gstmsdkh265dec.c \
|
gstmsdkh265dec.c \
|
||||||
|
@ -20,6 +21,7 @@ nodist_EXTRA_libgstmsdk_la_SOURCES = not_present.cxx
|
||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
msdk.h \
|
msdk.h \
|
||||||
|
gstmsdkcontext.h \
|
||||||
gstmsdkh264dec.h \
|
gstmsdkh264dec.h \
|
||||||
gstmsdkh264enc.h \
|
gstmsdkh264enc.h \
|
||||||
gstmsdkh265dec.h \
|
gstmsdkh265dec.h \
|
||||||
|
|
213
sys/msdk/gstmsdkcontext.c
Normal file
213
sys/msdk/gstmsdkcontext.c
Normal file
|
@ -0,0 +1,213 @@
|
||||||
|
/* 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>
|
||||||
|
#include <va/va_drm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkcontext);
|
||||||
|
#define GST_CAT_DEFAULT gst_debug_msdkcontext
|
||||||
|
|
||||||
|
#define GST_MSDK_CONTEXT_GET_PRIVATE(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_MSDK_CONTEXT, \
|
||||||
|
GstMsdkContextPrivate))
|
||||||
|
|
||||||
|
#define gst_msdk_context_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GstMsdkContext, gst_msdk_context, GST_TYPE_OBJECT,
|
||||||
|
GST_DEBUG_CATEGORY_INIT (gst_debug_msdkcontext, "msdkcontext", 0,
|
||||||
|
"MSDK Context"));
|
||||||
|
|
||||||
|
struct _GstMsdkContextPrivate
|
||||||
|
{
|
||||||
|
mfxSession session;
|
||||||
|
GList *cached_alloc_responses;
|
||||||
|
#ifndef _WIN32
|
||||||
|
gint fd;
|
||||||
|
VADisplay dpy;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
static gboolean
|
||||||
|
gst_msdk_context_use_vaapi (GstMsdkContext * context)
|
||||||
|
{
|
||||||
|
gint fd;
|
||||||
|
gint maj_ver, min_ver;
|
||||||
|
VADisplay va_dpy = NULL;
|
||||||
|
VAStatus va_status;
|
||||||
|
mfxStatus status;
|
||||||
|
GstMsdkContextPrivate *priv = context->priv;
|
||||||
|
|
||||||
|
/* maybe /dev/dri/renderD128 */
|
||||||
|
static const gchar *dri_path = "/dev/dri/card0";
|
||||||
|
|
||||||
|
fd = open (dri_path, O_RDWR);
|
||||||
|
if (fd < 0) {
|
||||||
|
GST_ERROR ("Couldn't open %s", dri_path);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_dpy = vaGetDisplayDRM (fd);
|
||||||
|
if (!va_dpy) {
|
||||||
|
GST_ERROR ("Couldn't get a VA DRM display");
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_status = vaInitialize (va_dpy, &maj_ver, &min_ver);
|
||||||
|
if (va_status != VA_STATUS_SUCCESS) {
|
||||||
|
GST_ERROR ("Couldn't initialize VA DRM display");
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = MFXVideoCORE_SetHandle (priv->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->fd = fd;
|
||||||
|
priv->dpy = va_dpy;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
failed:
|
||||||
|
if (va_dpy)
|
||||||
|
vaTerminate (va_dpy);
|
||||||
|
close (fd);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_msdk_context_open (GstMsdkContext * context, gboolean hardware)
|
||||||
|
{
|
||||||
|
GstMsdkContextPrivate *priv = context->priv;
|
||||||
|
|
||||||
|
priv->session = msdk_open_session (hardware);
|
||||||
|
if (!priv->session)
|
||||||
|
goto failed;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
priv->fd = -1;
|
||||||
|
|
||||||
|
if (hardware) {
|
||||||
|
if (!gst_msdk_context_use_vaapi (context))
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
failed:
|
||||||
|
msdk_close_session (priv->session);
|
||||||
|
gst_object_unref (context);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_msdk_context_init (GstMsdkContext * context)
|
||||||
|
{
|
||||||
|
GstMsdkContextPrivate *priv = GST_MSDK_CONTEXT_GET_PRIVATE (context);
|
||||||
|
|
||||||
|
context->priv = priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_msdk_context_finalize (GObject * obj)
|
||||||
|
{
|
||||||
|
GstMsdkContext *context = GST_MSDK_CONTEXT_CAST (obj);
|
||||||
|
GstMsdkContextPrivate *priv = context->priv;
|
||||||
|
msdk_close_session (priv->session);
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
if (priv->dpy)
|
||||||
|
vaTerminate (priv->dpy);
|
||||||
|
if (priv->fd >= 0)
|
||||||
|
close (priv->fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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_type_class_add_private (klass, sizeof (GstMsdkContextPrivate));
|
||||||
|
|
||||||
|
g_object_class->finalize = gst_msdk_context_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
GstMsdkContext *
|
||||||
|
gst_msdk_context_new (gboolean hardware)
|
||||||
|
{
|
||||||
|
GstMsdkContext *obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL);
|
||||||
|
|
||||||
|
if (obj && !gst_msdk_context_open (obj, hardware)) {
|
||||||
|
if (obj)
|
||||||
|
gst_object_unref (obj);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
mfxSession
|
||||||
|
gst_msdk_context_get_session (GstMsdkContext * context)
|
||||||
|
{
|
||||||
|
return context->priv->session;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpointer
|
||||||
|
gst_msdk_context_get_handle (GstMsdkContext * context)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
return context->priv->dpy;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
gst_msdk_context_get_fd (GstMsdkContext * context)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
return context->priv->fd;
|
||||||
|
#else
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
89
sys/msdk/gstmsdkcontext.h
Normal file
89
sys/msdk/gstmsdkcontext.h
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/* 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_CONTEXT_H
|
||||||
|
#define GST_MSDK_CONTEXT_H
|
||||||
|
|
||||||
|
#include "msdk.h"
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <va/va.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GST_TYPE_MSDK_CONTEXT \
|
||||||
|
(gst_msdk_context_get_type ())
|
||||||
|
#define GST_MSDK_CONTEXT(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MSDK_CONTEXT, \
|
||||||
|
GstMsdkContext))
|
||||||
|
#define GST_MSDK_CONTEXT_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MSDK_CONTEXT, \
|
||||||
|
GstMsdkContextClass))
|
||||||
|
#define GST_IS_MSDK_CONTEXT(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MSDK_CONTEXT))
|
||||||
|
#define GST_IS_MSDK_CONTEXT_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MSDK_CONTEXT))
|
||||||
|
#define GST_MSDK_CONTEXT_CAST(obj) ((GstMsdkContext*)(obj))
|
||||||
|
|
||||||
|
typedef struct _GstMsdkContext GstMsdkContext;
|
||||||
|
typedef struct _GstMsdkContextClass GstMsdkContextClass;
|
||||||
|
typedef struct _GstMsdkContextPrivate GstMsdkContextPrivate;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GstMsdkContext:
|
||||||
|
*/
|
||||||
|
struct _GstMsdkContext
|
||||||
|
{
|
||||||
|
GstObject parent_instance;
|
||||||
|
|
||||||
|
GstMsdkContextPrivate *priv;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GstMsdkContextClass:
|
||||||
|
*/
|
||||||
|
struct _GstMsdkContextClass
|
||||||
|
{
|
||||||
|
GstObjectClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
GType gst_msdk_context_get_type (void);
|
||||||
|
|
||||||
|
GstMsdkContext * gst_msdk_context_new (gboolean hardware);
|
||||||
|
mfxSession gst_msdk_context_get_session (GstMsdkContext * context);
|
||||||
|
|
||||||
|
gpointer gst_msdk_context_get_handle (GstMsdkContext * context);
|
||||||
|
gint gst_msdk_context_get_fd (GstMsdkContext * context);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* GST_MSDK_CONTEXT_H */
|
|
@ -190,7 +190,7 @@ gst_msdkdec_close_decoder (GstMsdkDec * thiz)
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (thiz, "Closing decoder 0x%p", thiz->context);
|
GST_DEBUG_OBJECT (thiz, "Closing decoder 0x%p", thiz->context);
|
||||||
|
|
||||||
status = MFXVideoDECODE_Close (msdk_context_get_session (thiz->context));
|
status = MFXVideoDECODE_Close (gst_msdk_context_get_session (thiz->context));
|
||||||
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
||||||
GST_WARNING_OBJECT (thiz, "Decoder close failed (%s)",
|
GST_WARNING_OBJECT (thiz, "Decoder close failed (%s)",
|
||||||
msdk_status_to_string (status));
|
msdk_status_to_string (status));
|
||||||
|
@ -200,8 +200,8 @@ gst_msdkdec_close_decoder (GstMsdkDec * thiz)
|
||||||
g_array_set_size (thiz->surfaces, 0);
|
g_array_set_size (thiz->surfaces, 0);
|
||||||
g_ptr_array_set_size (thiz->extra_params, 0);
|
g_ptr_array_set_size (thiz->extra_params, 0);
|
||||||
|
|
||||||
msdk_close_context (thiz->context);
|
if (thiz->context)
|
||||||
thiz->context = NULL;
|
gst_object_replace ((GstObject **) & thiz->context, NULL);
|
||||||
memset (&thiz->param, 0, sizeof (thiz->param));
|
memset (&thiz->param, 0, sizeof (thiz->param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz)
|
||||||
/* make sure that the decoder is closed */
|
/* make sure that the decoder is closed */
|
||||||
gst_msdkdec_close_decoder (thiz);
|
gst_msdkdec_close_decoder (thiz);
|
||||||
|
|
||||||
thiz->context = msdk_open_context (thiz->hardware);
|
thiz->context = gst_msdk_context_new (thiz->hardware);
|
||||||
if (!thiz->context) {
|
if (!thiz->context) {
|
||||||
GST_ERROR_OBJECT (thiz, "Context creation failed");
|
GST_ERROR_OBJECT (thiz, "Context creation failed");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -257,7 +257,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz)
|
||||||
thiz->param.NumExtParam = thiz->extra_params->len;
|
thiz->param.NumExtParam = thiz->extra_params->len;
|
||||||
thiz->param.ExtParam = (mfxExtBuffer **) thiz->extra_params->pdata;
|
thiz->param.ExtParam = (mfxExtBuffer **) thiz->extra_params->pdata;
|
||||||
|
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
/* validate parameters and allow the Media SDK to make adjustments */
|
/* validate parameters and allow the Media SDK to make adjustments */
|
||||||
status = MFXVideoDECODE_Query (session, &thiz->param, &thiz->param);
|
status = MFXVideoDECODE_Query (session, &thiz->param, &thiz->param);
|
||||||
if (status < MFX_ERR_NONE) {
|
if (status < MFX_ERR_NONE) {
|
||||||
|
@ -324,7 +324,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz)
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
GST_OBJECT_UNLOCK (thiz);
|
GST_OBJECT_UNLOCK (thiz);
|
||||||
msdk_close_context (thiz->context);
|
gst_object_replace ((GstObject **) & thiz->context, NULL);
|
||||||
thiz->context = NULL;
|
thiz->context = NULL;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -392,8 +392,8 @@ gst_msdkdec_finish_task (GstMsdkDec * thiz, MsdkDecTask * task)
|
||||||
|
|
||||||
if (G_LIKELY (task->sync_point)) {
|
if (G_LIKELY (task->sync_point)) {
|
||||||
status =
|
status =
|
||||||
MFXVideoCORE_SyncOperation (msdk_context_get_session (thiz->context),
|
MFXVideoCORE_SyncOperation (gst_msdk_context_get_session
|
||||||
task->sync_point, 10000);
|
(thiz->context), task->sync_point, 10000);
|
||||||
if (status != MFX_ERR_NONE)
|
if (status != MFX_ERR_NONE)
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
frame = gst_video_decoder_get_oldest_frame (decoder);
|
frame = gst_video_decoder_get_oldest_frame (decoder);
|
||||||
|
@ -426,10 +426,10 @@ static gboolean
|
||||||
gst_msdkdec_close (GstVideoDecoder * decoder)
|
gst_msdkdec_close (GstVideoDecoder * decoder)
|
||||||
{
|
{
|
||||||
GstMsdkDec *thiz = GST_MSDKDEC (decoder);
|
GstMsdkDec *thiz = GST_MSDKDEC (decoder);
|
||||||
if (thiz->context) {
|
|
||||||
msdk_close_context (thiz->context);
|
if (thiz->context)
|
||||||
thiz->context = NULL;
|
gst_object_replace ((GstObject **) & thiz->context, NULL);
|
||||||
}
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ gst_msdkdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
|
||||||
bitstream.DataLength = map_info.size;
|
bitstream.DataLength = map_info.size;
|
||||||
bitstream.MaxLength = map_info.size;
|
bitstream.MaxLength = map_info.size;
|
||||||
|
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
|
task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
|
||||||
flow = gst_msdkdec_finish_task (thiz, task);
|
flow = gst_msdkdec_finish_task (thiz, task);
|
||||||
|
@ -684,7 +684,7 @@ gst_msdkdec_drain (GstVideoDecoder * decoder)
|
||||||
|
|
||||||
if (!thiz->context)
|
if (!thiz->context)
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
|
task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include "msdk.h"
|
#include "msdk.h"
|
||||||
|
#include "gstmsdkcontext.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ struct _GstMsdkDec
|
||||||
GstVideoInfo pool_info;
|
GstVideoInfo pool_info;
|
||||||
|
|
||||||
/* MFX context */
|
/* MFX context */
|
||||||
MsdkContext *context;
|
GstMsdkContext *context;
|
||||||
mfxVideoParam param;
|
mfxVideoParam param;
|
||||||
GPtrArray *extra_params;
|
GPtrArray *extra_params;
|
||||||
GArray *surfaces;
|
GArray *surfaces;
|
||||||
|
|
|
@ -231,14 +231,14 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
|
||||||
/* make sure that the encoder is closed */
|
/* make sure that the encoder is closed */
|
||||||
gst_msdkenc_close_encoder (thiz);
|
gst_msdkenc_close_encoder (thiz);
|
||||||
|
|
||||||
thiz->context = msdk_open_context (thiz->hardware);
|
thiz->context = gst_msdk_context_new (thiz->hardware);
|
||||||
if (!thiz->context) {
|
if (!thiz->context) {
|
||||||
GST_ERROR_OBJECT (thiz, "Context creation failed");
|
GST_ERROR_OBJECT (thiz, "Context creation failed");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_OBJECT_LOCK (thiz);
|
GST_OBJECT_LOCK (thiz);
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
|
|
||||||
thiz->has_vpp = FALSE;
|
thiz->has_vpp = FALSE;
|
||||||
if (info->finfo->format != GST_VIDEO_FORMAT_NV12) {
|
if (info->finfo->format != GST_VIDEO_FORMAT_NV12) {
|
||||||
|
@ -477,8 +477,8 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
|
||||||
no_vpp:
|
no_vpp:
|
||||||
failed:
|
failed:
|
||||||
GST_OBJECT_UNLOCK (thiz);
|
GST_OBJECT_UNLOCK (thiz);
|
||||||
msdk_close_context (thiz->context);
|
if (thiz->context)
|
||||||
thiz->context = NULL;
|
gst_object_replace ((GstObject **) & thiz->context, NULL);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz)
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (thiz, "Closing encoder 0x%p", thiz->context);
|
GST_DEBUG_OBJECT (thiz, "Closing encoder 0x%p", thiz->context);
|
||||||
|
|
||||||
status = MFXVideoENCODE_Close (msdk_context_get_session (thiz->context));
|
status = MFXVideoENCODE_Close (gst_msdk_context_get_session (thiz->context));
|
||||||
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
||||||
GST_WARNING_OBJECT (thiz, "Encoder close failed (%s)",
|
GST_WARNING_OBJECT (thiz, "Encoder close failed (%s)",
|
||||||
msdk_status_to_string (status));
|
msdk_status_to_string (status));
|
||||||
|
@ -513,7 +513,7 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz)
|
||||||
/* Close VPP before freeing the surfaces. They are shared between encoder
|
/* Close VPP before freeing the surfaces. They are shared between encoder
|
||||||
* and VPP */
|
* and VPP */
|
||||||
if (thiz->has_vpp) {
|
if (thiz->has_vpp) {
|
||||||
status = MFXVideoVPP_Close (msdk_context_get_session (thiz->context));
|
status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
|
||||||
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
|
||||||
GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
|
GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
|
||||||
msdk_status_to_string (status));
|
msdk_status_to_string (status));
|
||||||
|
@ -538,8 +538,9 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz)
|
||||||
thiz->vpp_surfaces = NULL;
|
thiz->vpp_surfaces = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
msdk_close_context (thiz->context);
|
if (thiz->context)
|
||||||
thiz->context = NULL;
|
gst_object_replace ((GstObject **) & thiz->context, NULL);
|
||||||
|
|
||||||
memset (&thiz->param, 0, sizeof (thiz->param));
|
memset (&thiz->param, 0, sizeof (thiz->param));
|
||||||
thiz->num_extra_params = 0;
|
thiz->num_extra_params = 0;
|
||||||
}
|
}
|
||||||
|
@ -663,7 +664,7 @@ gst_msdkenc_finish_frame (GstMsdkEnc * thiz, MsdkEncTask * task,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for encoding operation to complete */
|
/* Wait for encoding operation to complete */
|
||||||
MFXVideoCORE_SyncOperation (msdk_context_get_session (thiz->context),
|
MFXVideoCORE_SyncOperation (gst_msdk_context_get_session (thiz->context),
|
||||||
task->sync_point, 10000);
|
task->sync_point, 10000);
|
||||||
if (!discard && task->output_bitstream.DataLength) {
|
if (!discard && task->output_bitstream.DataLength) {
|
||||||
GstBuffer *out_buf = NULL;
|
GstBuffer *out_buf = NULL;
|
||||||
|
@ -706,7 +707,7 @@ gst_msdkenc_encode_frame (GstMsdkEnc * thiz, mfxFrameSurface1 * surface,
|
||||||
gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (thiz), input_frame);
|
gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (thiz), input_frame);
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
}
|
}
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
|
|
||||||
task = gst_msdkenc_get_free_task (thiz);
|
task = gst_msdkenc_get_free_task (thiz);
|
||||||
|
|
||||||
|
@ -895,7 +896,7 @@ gst_msdkenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
|
||||||
surface->Data.TimeStamp = MFX_TIMESTAMP_UNKNOWN;
|
surface->Data.TimeStamp = MFX_TIMESTAMP_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
session = msdk_context_get_session (thiz->context);
|
session = gst_msdk_context_get_session (thiz->context);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status =
|
status =
|
||||||
MFXVideoVPP_RunFrameVPPAsync (session, vpp_surface, surface, NULL,
|
MFXVideoVPP_RunFrameVPPAsync (session, vpp_surface, surface, NULL,
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/video/gstvideoencoder.h>
|
#include <gst/video/gstvideoencoder.h>
|
||||||
#include "msdk.h"
|
#include "msdk.h"
|
||||||
|
#include "gstmsdkcontext.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ struct _GstMsdkEnc
|
||||||
GList *pending_frames;
|
GList *pending_frames;
|
||||||
|
|
||||||
/* MFX context */
|
/* MFX context */
|
||||||
MsdkContext *context;
|
GstMsdkContext *context;
|
||||||
mfxVideoParam param;
|
mfxVideoParam param;
|
||||||
guint num_surfaces;
|
guint num_surfaces;
|
||||||
mfxFrameSurface1 *surfaces;
|
mfxFrameSurface1 *surfaces;
|
||||||
|
|
|
@ -65,7 +65,7 @@ gst_msdkh265dec_configure (GstMsdkDec * decoder)
|
||||||
mfxStatus status;
|
mfxStatus status;
|
||||||
const mfxPluginUID *uid;
|
const mfxPluginUID *uid;
|
||||||
|
|
||||||
session = msdk_context_get_session (decoder->context);
|
session = gst_msdk_context_get_session (decoder->context);
|
||||||
|
|
||||||
if (decoder->hardware)
|
if (decoder->hardware)
|
||||||
uid = &MFX_PLUGINID_HEVCD_HW;
|
uid = &MFX_PLUGINID_HEVCD_HW;
|
||||||
|
|
|
@ -71,7 +71,7 @@ gst_msdkh265enc_configure (GstMsdkEnc * encoder)
|
||||||
mfxStatus status;
|
mfxStatus status;
|
||||||
const mfxPluginUID *uid;
|
const mfxPluginUID *uid;
|
||||||
|
|
||||||
session = msdk_context_get_session (encoder->context);
|
session = gst_msdk_context_get_session (encoder->context);
|
||||||
|
|
||||||
if (encoder->hardware)
|
if (encoder->hardware)
|
||||||
uid = &MFX_PLUGINID_HEVCE_HW;
|
uid = &MFX_PLUGINID_HEVCE_HW;
|
||||||
|
|
|
@ -64,7 +64,7 @@ gst_msdkvp8dec_configure (GstMsdkDec * decoder)
|
||||||
mfxStatus status;
|
mfxStatus status;
|
||||||
const mfxPluginUID *uid;
|
const mfxPluginUID *uid;
|
||||||
|
|
||||||
session = msdk_context_get_session (decoder->context);
|
session = gst_msdk_context_get_session (decoder->context);
|
||||||
|
|
||||||
uid = &MFX_PLUGINID_VP8D_HW;
|
uid = &MFX_PLUGINID_VP8D_HW;
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ gst_msdkvp8enc_configure (GstMsdkEnc * encoder)
|
||||||
mfxStatus status;
|
mfxStatus status;
|
||||||
|
|
||||||
if (encoder->hardware) {
|
if (encoder->hardware) {
|
||||||
session = msdk_context_get_session (encoder->context);
|
session = gst_msdk_context_get_session (encoder->context);
|
||||||
status = MFXVideoUSER_Load (session, &MFX_PLUGINID_VP8E_HW, 1);
|
status = MFXVideoUSER_Load (session, &MFX_PLUGINID_VP8E_HW, 1);
|
||||||
if (status < MFX_ERR_NONE) {
|
if (status < MFX_ERR_NONE) {
|
||||||
GST_ERROR_OBJECT (thiz, "Media SDK Plugin load failed (%s)",
|
GST_ERROR_OBJECT (thiz, "Media SDK Plugin load failed (%s)",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
msdk_sources = [
|
msdk_sources = [
|
||||||
'gstmsdk.c',
|
'gstmsdk.c',
|
||||||
|
'gstmsdkcontext.c',
|
||||||
'gstmsdkdec.c',
|
'gstmsdkdec.c',
|
||||||
'gstmsdkenc.c',
|
'gstmsdkenc.c',
|
||||||
'gstmsdkh264dec.c',
|
'gstmsdkh264dec.c',
|
||||||
|
|
|
@ -49,17 +49,11 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _MsdkContext MsdkContext;
|
|
||||||
|
|
||||||
mfxSession msdk_open_session (gboolean hardware);
|
mfxSession msdk_open_session (gboolean hardware);
|
||||||
void msdk_close_session (mfxSession session);
|
void msdk_close_session (mfxSession session);
|
||||||
|
|
||||||
gboolean msdk_is_available (void);
|
gboolean msdk_is_available (void);
|
||||||
|
|
||||||
MsdkContext *msdk_open_context (gboolean hardware);
|
|
||||||
void msdk_close_context (MsdkContext * context);
|
|
||||||
mfxSession msdk_context_get_session (MsdkContext * context);
|
|
||||||
|
|
||||||
mfxFrameSurface1 *msdk_get_free_surface (mfxFrameSurface1 * surfaces,
|
mfxFrameSurface1 *msdk_get_free_surface (mfxFrameSurface1 * surfaces,
|
||||||
guint size);
|
guint size);
|
||||||
void msdk_frame_to_surface (GstVideoFrame * frame, mfxFrameSurface1 * surface);
|
void msdk_frame_to_surface (GstVideoFrame * frame, mfxFrameSurface1 * surface);
|
||||||
|
|
|
@ -30,21 +30,3 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "msdk.h"
|
#include "msdk.h"
|
||||||
|
|
||||||
MsdkContext *
|
|
||||||
msdk_open_context (gboolean hardware)
|
|
||||||
{
|
|
||||||
return (MsdkContext *) msdk_open_session (hardware);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
msdk_close_context (MsdkContext * context)
|
|
||||||
{
|
|
||||||
msdk_close_session ((mfxSession) context);
|
|
||||||
}
|
|
||||||
|
|
||||||
mfxSession
|
|
||||||
msdk_context_get_session (MsdkContext * context)
|
|
||||||
{
|
|
||||||
return (mfxSession) context;
|
|
||||||
}
|
|
||||||
|
|
|
@ -79,105 +79,6 @@ static const struct rt_map gst_msdk_rt_mfx_to_va[] = {
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MsdkContext
|
|
||||||
{
|
|
||||||
mfxSession session;
|
|
||||||
gint fd;
|
|
||||||
VADisplay dpy;
|
|
||||||
};
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
msdk_use_vaapi_on_context (MsdkContext * context)
|
|
||||||
{
|
|
||||||
gint fd;
|
|
||||||
gint maj_ver, min_ver;
|
|
||||||
VADisplay va_dpy = NULL;
|
|
||||||
VAStatus va_status;
|
|
||||||
mfxStatus status;
|
|
||||||
/* maybe /dev/dri/renderD128 */
|
|
||||||
static const gchar *dri_path = "/dev/dri/card0";
|
|
||||||
|
|
||||||
fd = open (dri_path, O_RDWR);
|
|
||||||
if (fd < 0) {
|
|
||||||
GST_ERROR ("Couldn't open %s", dri_path);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_dpy = vaGetDisplayDRM (fd);
|
|
||||||
if (!va_dpy) {
|
|
||||||
GST_ERROR ("Couldn't get a VA DRM display");
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_status = vaInitialize (va_dpy, &maj_ver, &min_ver);
|
|
||||||
if (va_status != VA_STATUS_SUCCESS) {
|
|
||||||
GST_ERROR ("Couldn't initialize VA DRM display");
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MFXVideoCORE_SetHandle (context->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
context->fd = fd;
|
|
||||||
context->dpy = va_dpy;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
if (va_dpy)
|
|
||||||
vaTerminate (va_dpy);
|
|
||||||
close (fd);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
MsdkContext *
|
|
||||||
msdk_open_context (gboolean hardware)
|
|
||||||
{
|
|
||||||
MsdkContext *context = g_slice_new0 (MsdkContext);
|
|
||||||
context->fd = -1;
|
|
||||||
|
|
||||||
context->session = msdk_open_session (hardware);
|
|
||||||
if (!context->session)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
if (hardware) {
|
|
||||||
if (!msdk_use_vaapi_on_context (context))
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return context;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
msdk_close_session (context->session);
|
|
||||||
g_slice_free (MsdkContext, context);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
msdk_close_context (MsdkContext * context)
|
|
||||||
{
|
|
||||||
if (!context)
|
|
||||||
return;
|
|
||||||
|
|
||||||
msdk_close_session (context->session);
|
|
||||||
if (context->dpy)
|
|
||||||
vaTerminate (context->dpy);
|
|
||||||
if (context->fd >= 0)
|
|
||||||
close (context->fd);
|
|
||||||
g_slice_free (MsdkContext, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
mfxSession
|
|
||||||
msdk_context_get_session (MsdkContext * context)
|
|
||||||
{
|
|
||||||
return context->session;
|
|
||||||
}
|
|
||||||
|
|
||||||
mfxStatus
|
mfxStatus
|
||||||
gst_msdk_get_mfx_status_from_va_status (VAStatus va_res)
|
gst_msdk_get_mfx_status_from_va_status (VAStatus va_res)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue