From 6ce9a66b80c6b5d72feff1d74bf08f3e71e18330 Mon Sep 17 00:00:00 2001 From: Hyunjun Ko Date: Tue, 13 Feb 2018 12:41:28 -0900 Subject: 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 --- sys/msdk/Makefile.am | 2 + sys/msdk/gstmsdkcontext.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++ sys/msdk/gstmsdkcontext.h | 89 +++++++++++++++++++ sys/msdk/gstmsdkdec.c | 28 +++--- sys/msdk/gstmsdkdec.h | 3 +- sys/msdk/gstmsdkenc.c | 23 ++--- sys/msdk/gstmsdkenc.h | 3 +- sys/msdk/gstmsdkh265dec.c | 2 +- sys/msdk/gstmsdkh265enc.c | 2 +- sys/msdk/gstmsdkvp8dec.c | 2 +- sys/msdk/gstmsdkvp8enc.c | 2 +- sys/msdk/meson.build | 1 + sys/msdk/msdk.h | 6 -- sys/msdk/msdk_d3d.c | 18 ---- sys/msdk/msdk_libva.c | 99 --------------------- 15 files changed, 339 insertions(+), 154 deletions(-) create mode 100644 sys/msdk/gstmsdkcontext.c create mode 100644 sys/msdk/gstmsdkcontext.h diff --git a/sys/msdk/Makefile.am b/sys/msdk/Makefile.am index 20bbbbb6a..104ee1e5b 100644 --- a/sys/msdk/Makefile.am +++ b/sys/msdk/Makefile.am @@ -1,6 +1,7 @@ plugin_LTLIBRARIES = libgstmsdk.la libgstmsdk_la_SOURCES = \ + gstmsdkcontext.c \ gstmsdkh264dec.c \ gstmsdkh264enc.c \ gstmsdkh265dec.c \ @@ -20,6 +21,7 @@ nodist_EXTRA_libgstmsdk_la_SOURCES = not_present.cxx noinst_HEADERS = \ msdk.h \ + gstmsdkcontext.h \ gstmsdkh264dec.h \ gstmsdkh264enc.h \ gstmsdkh265dec.h \ diff --git a/sys/msdk/gstmsdkcontext.c b/sys/msdk/gstmsdkcontext.c new file mode 100644 index 000000000..851d133a5 --- /dev/null +++ b/sys/msdk/gstmsdkcontext.c @@ -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 +#include +#include +#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 +} diff --git a/sys/msdk/gstmsdkcontext.h b/sys/msdk/gstmsdkcontext.h new file mode 100644 index 000000000..2f20ff9a5 --- /dev/null +++ b/sys/msdk/gstmsdkcontext.h @@ -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 +#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 */ diff --git a/sys/msdk/gstmsdkdec.c b/sys/msdk/gstmsdkdec.c index 619a5eae2..b336205e3 100644 --- a/sys/msdk/gstmsdkdec.c +++ b/sys/msdk/gstmsdkdec.c @@ -190,7 +190,7 @@ gst_msdkdec_close_decoder (GstMsdkDec * thiz) 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) { GST_WARNING_OBJECT (thiz, "Decoder close failed (%s)", msdk_status_to_string (status)); @@ -200,8 +200,8 @@ gst_msdkdec_close_decoder (GstMsdkDec * thiz) g_array_set_size (thiz->surfaces, 0); g_ptr_array_set_size (thiz->extra_params, 0); - msdk_close_context (thiz->context); - thiz->context = NULL; + if (thiz->context) + gst_object_replace ((GstObject **) & thiz->context, NULL); memset (&thiz->param, 0, sizeof (thiz->param)); } @@ -224,7 +224,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz) /* make sure that the decoder is closed */ gst_msdkdec_close_decoder (thiz); - thiz->context = msdk_open_context (thiz->hardware); + thiz->context = gst_msdk_context_new (thiz->hardware); if (!thiz->context) { GST_ERROR_OBJECT (thiz, "Context creation failed"); return FALSE; @@ -257,7 +257,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz) thiz->param.NumExtParam = thiz->extra_params->len; 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 */ status = MFXVideoDECODE_Query (session, &thiz->param, &thiz->param); if (status < MFX_ERR_NONE) { @@ -324,7 +324,7 @@ gst_msdkdec_init_decoder (GstMsdkDec * thiz) failed: GST_OBJECT_UNLOCK (thiz); - msdk_close_context (thiz->context); + gst_object_replace ((GstObject **) & thiz->context, NULL); thiz->context = NULL; return FALSE; } @@ -392,8 +392,8 @@ gst_msdkdec_finish_task (GstMsdkDec * thiz, MsdkDecTask * task) if (G_LIKELY (task->sync_point)) { status = - MFXVideoCORE_SyncOperation (msdk_context_get_session (thiz->context), - task->sync_point, 10000); + MFXVideoCORE_SyncOperation (gst_msdk_context_get_session + (thiz->context), task->sync_point, 10000); if (status != MFX_ERR_NONE) return GST_FLOW_ERROR; frame = gst_video_decoder_get_oldest_frame (decoder); @@ -426,10 +426,10 @@ static gboolean gst_msdkdec_close (GstVideoDecoder * decoder) { GstMsdkDec *thiz = GST_MSDKDEC (decoder); - if (thiz->context) { - msdk_close_context (thiz->context); - thiz->context = NULL; - } + + if (thiz->context) + gst_object_replace ((GstObject **) & thiz->context, NULL); + return TRUE; } @@ -493,7 +493,7 @@ gst_msdkdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame) bitstream.DataLength = map_info.size; bitstream.MaxLength = map_info.size; - session = msdk_context_get_session (thiz->context); + session = gst_msdk_context_get_session (thiz->context); for (;;) { task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task); flow = gst_msdkdec_finish_task (thiz, task); @@ -684,7 +684,7 @@ gst_msdkdec_drain (GstVideoDecoder * decoder) if (!thiz->context) return GST_FLOW_OK; - session = msdk_context_get_session (thiz->context); + session = gst_msdk_context_get_session (thiz->context); for (;;) { task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task); diff --git a/sys/msdk/gstmsdkdec.h b/sys/msdk/gstmsdkdec.h index 392096f57..517dc1563 100644 --- a/sys/msdk/gstmsdkdec.h +++ b/sys/msdk/gstmsdkdec.h @@ -35,6 +35,7 @@ #include #include #include "msdk.h" +#include "gstmsdkcontext.h" G_BEGIN_DECLS @@ -66,7 +67,7 @@ struct _GstMsdkDec GstVideoInfo pool_info; /* MFX context */ - MsdkContext *context; + GstMsdkContext *context; mfxVideoParam param; GPtrArray *extra_params; GArray *surfaces; diff --git a/sys/msdk/gstmsdkenc.c b/sys/msdk/gstmsdkenc.c index 5d4d361b5..aebd40550 100644 --- a/sys/msdk/gstmsdkenc.c +++ b/sys/msdk/gstmsdkenc.c @@ -231,14 +231,14 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) /* make sure that the encoder is closed */ gst_msdkenc_close_encoder (thiz); - thiz->context = msdk_open_context (thiz->hardware); + thiz->context = gst_msdk_context_new (thiz->hardware); if (!thiz->context) { GST_ERROR_OBJECT (thiz, "Context creation failed"); return FALSE; } GST_OBJECT_LOCK (thiz); - session = msdk_context_get_session (thiz->context); + session = gst_msdk_context_get_session (thiz->context); thiz->has_vpp = FALSE; if (info->finfo->format != GST_VIDEO_FORMAT_NV12) { @@ -477,8 +477,8 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) no_vpp: failed: GST_OBJECT_UNLOCK (thiz); - msdk_close_context (thiz->context); - thiz->context = NULL; + if (thiz->context) + gst_object_replace ((GstObject **) & thiz->context, NULL); return FALSE; } @@ -493,7 +493,7 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz) 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) { GST_WARNING_OBJECT (thiz, "Encoder close failed (%s)", 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 * and 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) { GST_WARNING_OBJECT (thiz, "VPP close failed (%s)", msdk_status_to_string (status)); @@ -538,8 +538,9 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz) thiz->vpp_surfaces = NULL; } - msdk_close_context (thiz->context); - thiz->context = NULL; + if (thiz->context) + gst_object_replace ((GstObject **) & thiz->context, NULL); + memset (&thiz->param, 0, sizeof (thiz->param)); thiz->num_extra_params = 0; } @@ -663,7 +664,7 @@ gst_msdkenc_finish_frame (GstMsdkEnc * thiz, MsdkEncTask * task, } /* 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); if (!discard && task->output_bitstream.DataLength) { 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); 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); @@ -895,7 +896,7 @@ gst_msdkenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame) surface->Data.TimeStamp = MFX_TIMESTAMP_UNKNOWN; } - session = msdk_context_get_session (thiz->context); + session = gst_msdk_context_get_session (thiz->context); for (;;) { status = MFXVideoVPP_RunFrameVPPAsync (session, vpp_surface, surface, NULL, diff --git a/sys/msdk/gstmsdkenc.h b/sys/msdk/gstmsdkenc.h index 600f24ef2..04be395bd 100644 --- a/sys/msdk/gstmsdkenc.h +++ b/sys/msdk/gstmsdkenc.h @@ -35,6 +35,7 @@ #include #include #include "msdk.h" +#include "gstmsdkcontext.h" G_BEGIN_DECLS @@ -69,7 +70,7 @@ struct _GstMsdkEnc GList *pending_frames; /* MFX context */ - MsdkContext *context; + GstMsdkContext *context; mfxVideoParam param; guint num_surfaces; mfxFrameSurface1 *surfaces; diff --git a/sys/msdk/gstmsdkh265dec.c b/sys/msdk/gstmsdkh265dec.c index fd1ae753f..e593a745d 100644 --- a/sys/msdk/gstmsdkh265dec.c +++ b/sys/msdk/gstmsdkh265dec.c @@ -65,7 +65,7 @@ gst_msdkh265dec_configure (GstMsdkDec * decoder) mfxStatus status; const mfxPluginUID *uid; - session = msdk_context_get_session (decoder->context); + session = gst_msdk_context_get_session (decoder->context); if (decoder->hardware) uid = &MFX_PLUGINID_HEVCD_HW; diff --git a/sys/msdk/gstmsdkh265enc.c b/sys/msdk/gstmsdkh265enc.c index f7d4620bf..525c3d64c 100644 --- a/sys/msdk/gstmsdkh265enc.c +++ b/sys/msdk/gstmsdkh265enc.c @@ -71,7 +71,7 @@ gst_msdkh265enc_configure (GstMsdkEnc * encoder) mfxStatus status; const mfxPluginUID *uid; - session = msdk_context_get_session (encoder->context); + session = gst_msdk_context_get_session (encoder->context); if (encoder->hardware) uid = &MFX_PLUGINID_HEVCE_HW; diff --git a/sys/msdk/gstmsdkvp8dec.c b/sys/msdk/gstmsdkvp8dec.c index 9f3df5d3e..1b5a1f07d 100644 --- a/sys/msdk/gstmsdkvp8dec.c +++ b/sys/msdk/gstmsdkvp8dec.c @@ -64,7 +64,7 @@ gst_msdkvp8dec_configure (GstMsdkDec * decoder) mfxStatus status; const mfxPluginUID *uid; - session = msdk_context_get_session (decoder->context); + session = gst_msdk_context_get_session (decoder->context); uid = &MFX_PLUGINID_VP8D_HW; diff --git a/sys/msdk/gstmsdkvp8enc.c b/sys/msdk/gstmsdkvp8enc.c index 9e269ad50..e42eb9d89 100644 --- a/sys/msdk/gstmsdkvp8enc.c +++ b/sys/msdk/gstmsdkvp8enc.c @@ -119,7 +119,7 @@ gst_msdkvp8enc_configure (GstMsdkEnc * encoder) mfxStatus status; 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); if (status < MFX_ERR_NONE) { GST_ERROR_OBJECT (thiz, "Media SDK Plugin load failed (%s)", diff --git a/sys/msdk/meson.build b/sys/msdk/meson.build index 338ae1d9b..041b1fa87 100644 --- a/sys/msdk/meson.build +++ b/sys/msdk/meson.build @@ -1,5 +1,6 @@ msdk_sources = [ 'gstmsdk.c', + 'gstmsdkcontext.c', 'gstmsdkdec.c', 'gstmsdkenc.c', 'gstmsdkh264dec.c', diff --git a/sys/msdk/msdk.h b/sys/msdk/msdk.h index d2e560211..0f574c05b 100644 --- a/sys/msdk/msdk.h +++ b/sys/msdk/msdk.h @@ -49,17 +49,11 @@ G_BEGIN_DECLS -typedef struct _MsdkContext MsdkContext; - mfxSession msdk_open_session (gboolean hardware); void msdk_close_session (mfxSession session); 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, guint size); void msdk_frame_to_surface (GstVideoFrame * frame, mfxFrameSurface1 * surface); diff --git a/sys/msdk/msdk_d3d.c b/sys/msdk/msdk_d3d.c index 372e15907..6ae4bbe55 100644 --- a/sys/msdk/msdk_d3d.c +++ b/sys/msdk/msdk_d3d.c @@ -30,21 +30,3 @@ */ #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; -} diff --git a/sys/msdk/msdk_libva.c b/sys/msdk/msdk_libva.c index 149e919bd..714e29fba 100644 --- a/sys/msdk/msdk_libva.c +++ b/sys/msdk/msdk_libva.c @@ -79,105 +79,6 @@ static const struct rt_map gst_msdk_rt_mfx_to_va[] = { {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 gst_msdk_get_mfx_status_from_va_status (VAStatus va_res) { -- cgit v1.2.1