From 9c44b32c2114a81780fb00c5c9ad866ef58e828c Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 25 Mar 2022 21:03:02 +0900 Subject: [PATCH] qsv: Use pipeline's VA context Part-of: --- .../sys/qsv/gstqsvallocator_va.h | 2 +- .../gst-plugins-bad/sys/qsv/gstqsvdecoder.cpp | 31 +++++++++---------- .../gst-plugins-bad/sys/qsv/gstqsvencoder.cpp | 31 +++++++++---------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_va.h b/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_va.h index 8c6e6e076a..ba4bf919e9 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_va.h +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_va.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include "gstqsvallocator.h" G_BEGIN_DECLS diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvdecoder.cpp b/subprojects/gst-plugins-bad/sys/qsv/gstqsvdecoder.cpp index fe5ca56298..9faaa6f56f 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvdecoder.cpp +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvdecoder.cpp @@ -26,7 +26,6 @@ #include #ifdef G_OS_WIN32 -#include #include "gstqsvallocator_d3d11.h" #include @@ -35,7 +34,6 @@ using namespace Microsoft::WRL; /* *INDENT-ON* */ #else -#include #include "gstqsvallocator_va.h" #endif /* G_OS_WIN32 */ @@ -243,13 +241,16 @@ gst_qsv_decoder_finalize (GObject * object) static void gst_qsv_decoder_set_context (GstElement * element, GstContext * context) { -#ifdef G_OS_WIN32 GstQsvDecoder *self = GST_QSV_DECODER (element); GstQsvDecoderClass *klass = GST_QSV_DECODER_GET_CLASS (element); GstQsvDecoderPrivate *priv = self->priv; +#ifdef G_OS_WIN32 gst_d3d11_handle_set_context_for_adapter_luid (element, context, klass->adapter_luid, (GstD3D11Device **) & priv->device); +#else + gst_va_handle_set_context (element, context, klass->display_path, + (GstVaDisplay **) & priv->device); #endif GST_ELEMENT_CLASS (parent_class)->set_context (element, context); @@ -319,19 +320,14 @@ gst_qsv_decoder_open_platform_device (GstQsvDecoder * self) mfxStatus status; GstVaDisplay *display; - /* TODO: use GstVADisplay context sharing */ - if (!priv->device) { - display = gst_va_display_drm_new_from_path (klass->display_path); - if (!display) { - GST_ERROR_OBJECT (self, "VA display is unavailable"); - return FALSE; - } - - priv->device = GST_OBJECT (display); - } else { - display = GST_VA_DISPLAY (priv->device); + if (!gst_va_ensure_element_data (GST_ELEMENT (self), klass->display_path, + (GstVaDisplay **) & priv->device)) { + GST_ERROR_OBJECT (self, "VA display is unavailable"); + return FALSE; } + display = GST_VA_DISPLAY (priv->device); + priv->allocator = gst_qsv_va_allocator_new (display); status = MFXVideoCORE_SetHandle (priv->session, MFX_HANDLE_VA_DISPLAY, @@ -1270,14 +1266,15 @@ gst_qsv_decoder_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) static gboolean gst_qsv_decoder_handle_context_query (GstQsvDecoder * self, GstQuery * query) { -#ifdef G_OS_WIN32 GstQsvDecoderPrivate *priv = self->priv; +#ifdef G_OS_WIN32 return gst_d3d11_handle_context_query (GST_ELEMENT (self), query, (GstD3D11Device *) priv->device); +#else + return gst_va_handle_context_query (GST_ELEMENT (self), query, + (GstVaDisplay *) priv->device); #endif - - return FALSE; } static gboolean diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp index b31d3cb15c..6f1b18a559 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp @@ -27,7 +27,6 @@ #include #ifdef G_OS_WIN32 -#include #include "gstqsvallocator_d3d11.h" #include @@ -36,7 +35,6 @@ using namespace Microsoft::WRL; /* *INDENT-ON* */ #else -#include #include "gstqsvallocator_va.h" #endif /* G_OS_WIN32 */ @@ -294,13 +292,16 @@ gst_qsv_encoder_get_property (GObject * object, guint prop_id, GValue * value, static void gst_qsv_encoder_set_context (GstElement * element, GstContext * context) { -#ifdef G_OS_WIN32 GstQsvEncoder *self = GST_QSV_ENCODER (element); GstQsvEncoderClass *klass = GST_QSV_ENCODER_GET_CLASS (element); GstQsvEncoderPrivate *priv = self->priv; +#ifdef G_OS_WIN32 gst_d3d11_handle_set_context_for_adapter_luid (element, context, klass->adapter_luid, (GstD3D11Device **) & priv->device); +#else + gst_va_handle_set_context (element, context, klass->display_path, + (GstVaDisplay **) & priv->device); #endif GST_ELEMENT_CLASS (parent_class)->set_context (element, context); @@ -377,19 +378,14 @@ gst_qsv_encoder_open_platform_device (GstQsvEncoder * self) mfxStatus status; GstVaDisplay *display; - /* GstVADisplay context sharing is not public yet (VA plugin internal) */ - if (!priv->device) { - display = gst_va_display_drm_new_from_path (klass->display_path); - if (!display) { - GST_ERROR_OBJECT (self, "VA display is unavailable"); - return FALSE; - } - - priv->device = GST_OBJECT (display); - } else { - display = GST_VA_DISPLAY (priv->device); + if (!gst_va_ensure_element_data (GST_ELEMENT (self), klass->display_path, + (GstVaDisplay **) & priv->device)) { + GST_ERROR_OBJECT (self, "VA display is unavailable"); + return FALSE; } + display = GST_VA_DISPLAY (priv->device); + priv->allocator = gst_qsv_va_allocator_new (display); status = MFXVideoCORE_SetHandle (priv->session, MFX_HANDLE_VA_DISPLAY, @@ -1302,14 +1298,15 @@ gst_qsv_encoder_flush (GstVideoEncoder * encoder) static gboolean gst_qsv_encoder_handle_context_query (GstQsvEncoder * self, GstQuery * query) { -#ifdef G_OS_WIN32 GstQsvEncoderPrivate *priv = self->priv; +#ifdef G_OS_WIN32 return gst_d3d11_handle_context_query (GST_ELEMENT (self), query, (GstD3D11Device *) priv->device); +#else + return gst_va_handle_context_query (GST_ELEMENT (self), query, + (GstVaDisplay *) priv->device); #endif - - return FALSE; } static gboolean