qsv: Use pipeline's VA context

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2030>
This commit is contained in:
Seungha Yang 2022-03-25 21:03:02 +09:00
parent c24d8838f5
commit 9c44b32c21
3 changed files with 29 additions and 35 deletions

View file

@ -20,7 +20,7 @@
#pragma once #pragma once
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/va/gstvadisplay.h> #include <gst/va/gstva.h>
#include "gstqsvallocator.h" #include "gstqsvallocator.h"
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -26,7 +26,6 @@
#include <string.h> #include <string.h>
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#include <gst/d3d11/gstd3d11.h>
#include "gstqsvallocator_d3d11.h" #include "gstqsvallocator_d3d11.h"
#include <wrl.h> #include <wrl.h>
@ -35,7 +34,6 @@
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
/* *INDENT-ON* */ /* *INDENT-ON* */
#else #else
#include <gst/va/gstvadisplay_drm.h>
#include "gstqsvallocator_va.h" #include "gstqsvallocator_va.h"
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */
@ -243,13 +241,16 @@ gst_qsv_decoder_finalize (GObject * object)
static void static void
gst_qsv_decoder_set_context (GstElement * element, GstContext * context) gst_qsv_decoder_set_context (GstElement * element, GstContext * context)
{ {
#ifdef G_OS_WIN32
GstQsvDecoder *self = GST_QSV_DECODER (element); GstQsvDecoder *self = GST_QSV_DECODER (element);
GstQsvDecoderClass *klass = GST_QSV_DECODER_GET_CLASS (element); GstQsvDecoderClass *klass = GST_QSV_DECODER_GET_CLASS (element);
GstQsvDecoderPrivate *priv = self->priv; GstQsvDecoderPrivate *priv = self->priv;
#ifdef G_OS_WIN32
gst_d3d11_handle_set_context_for_adapter_luid (element, gst_d3d11_handle_set_context_for_adapter_luid (element,
context, klass->adapter_luid, (GstD3D11Device **) & priv->device); context, klass->adapter_luid, (GstD3D11Device **) & priv->device);
#else
gst_va_handle_set_context (element, context, klass->display_path,
(GstVaDisplay **) & priv->device);
#endif #endif
GST_ELEMENT_CLASS (parent_class)->set_context (element, context); GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
@ -319,19 +320,14 @@ gst_qsv_decoder_open_platform_device (GstQsvDecoder * self)
mfxStatus status; mfxStatus status;
GstVaDisplay *display; GstVaDisplay *display;
/* TODO: use GstVADisplay context sharing */ if (!gst_va_ensure_element_data (GST_ELEMENT (self), klass->display_path,
if (!priv->device) { (GstVaDisplay **) & priv->device)) {
display = gst_va_display_drm_new_from_path (klass->display_path); GST_ERROR_OBJECT (self, "VA display is unavailable");
if (!display) { return FALSE;
GST_ERROR_OBJECT (self, "VA display is unavailable");
return FALSE;
}
priv->device = GST_OBJECT (display);
} else {
display = GST_VA_DISPLAY (priv->device);
} }
display = GST_VA_DISPLAY (priv->device);
priv->allocator = gst_qsv_va_allocator_new (display); priv->allocator = gst_qsv_va_allocator_new (display);
status = MFXVideoCORE_SetHandle (priv->session, MFX_HANDLE_VA_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 static gboolean
gst_qsv_decoder_handle_context_query (GstQsvDecoder * self, GstQuery * query) gst_qsv_decoder_handle_context_query (GstQsvDecoder * self, GstQuery * query)
{ {
#ifdef G_OS_WIN32
GstQsvDecoderPrivate *priv = self->priv; GstQsvDecoderPrivate *priv = self->priv;
#ifdef G_OS_WIN32
return gst_d3d11_handle_context_query (GST_ELEMENT (self), query, return gst_d3d11_handle_context_query (GST_ELEMENT (self), query,
(GstD3D11Device *) priv->device); (GstD3D11Device *) priv->device);
#else
return gst_va_handle_context_query (GST_ELEMENT (self), query,
(GstVaDisplay *) priv->device);
#endif #endif
return FALSE;
} }
static gboolean static gboolean

View file

@ -27,7 +27,6 @@
#include <string> #include <string>
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#include <gst/d3d11/gstd3d11.h>
#include "gstqsvallocator_d3d11.h" #include "gstqsvallocator_d3d11.h"
#include <wrl.h> #include <wrl.h>
@ -36,7 +35,6 @@
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
/* *INDENT-ON* */ /* *INDENT-ON* */
#else #else
#include <gst/va/gstvadisplay_drm.h>
#include "gstqsvallocator_va.h" #include "gstqsvallocator_va.h"
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */
@ -294,13 +292,16 @@ gst_qsv_encoder_get_property (GObject * object, guint prop_id, GValue * value,
static void static void
gst_qsv_encoder_set_context (GstElement * element, GstContext * context) gst_qsv_encoder_set_context (GstElement * element, GstContext * context)
{ {
#ifdef G_OS_WIN32
GstQsvEncoder *self = GST_QSV_ENCODER (element); GstQsvEncoder *self = GST_QSV_ENCODER (element);
GstQsvEncoderClass *klass = GST_QSV_ENCODER_GET_CLASS (element); GstQsvEncoderClass *klass = GST_QSV_ENCODER_GET_CLASS (element);
GstQsvEncoderPrivate *priv = self->priv; GstQsvEncoderPrivate *priv = self->priv;
#ifdef G_OS_WIN32
gst_d3d11_handle_set_context_for_adapter_luid (element, gst_d3d11_handle_set_context_for_adapter_luid (element,
context, klass->adapter_luid, (GstD3D11Device **) & priv->device); context, klass->adapter_luid, (GstD3D11Device **) & priv->device);
#else
gst_va_handle_set_context (element, context, klass->display_path,
(GstVaDisplay **) & priv->device);
#endif #endif
GST_ELEMENT_CLASS (parent_class)->set_context (element, context); GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
@ -377,19 +378,14 @@ gst_qsv_encoder_open_platform_device (GstQsvEncoder * self)
mfxStatus status; mfxStatus status;
GstVaDisplay *display; GstVaDisplay *display;
/* GstVADisplay context sharing is not public yet (VA plugin internal) */ if (!gst_va_ensure_element_data (GST_ELEMENT (self), klass->display_path,
if (!priv->device) { (GstVaDisplay **) & priv->device)) {
display = gst_va_display_drm_new_from_path (klass->display_path); GST_ERROR_OBJECT (self, "VA display is unavailable");
if (!display) { return FALSE;
GST_ERROR_OBJECT (self, "VA display is unavailable");
return FALSE;
}
priv->device = GST_OBJECT (display);
} else {
display = GST_VA_DISPLAY (priv->device);
} }
display = GST_VA_DISPLAY (priv->device);
priv->allocator = gst_qsv_va_allocator_new (display); priv->allocator = gst_qsv_va_allocator_new (display);
status = MFXVideoCORE_SetHandle (priv->session, MFX_HANDLE_VA_DISPLAY, status = MFXVideoCORE_SetHandle (priv->session, MFX_HANDLE_VA_DISPLAY,
@ -1302,14 +1298,15 @@ gst_qsv_encoder_flush (GstVideoEncoder * encoder)
static gboolean static gboolean
gst_qsv_encoder_handle_context_query (GstQsvEncoder * self, GstQuery * query) gst_qsv_encoder_handle_context_query (GstQsvEncoder * self, GstQuery * query)
{ {
#ifdef G_OS_WIN32
GstQsvEncoderPrivate *priv = self->priv; GstQsvEncoderPrivate *priv = self->priv;
#ifdef G_OS_WIN32
return gst_d3d11_handle_context_query (GST_ELEMENT (self), query, return gst_d3d11_handle_context_query (GST_ELEMENT (self), query,
(GstD3D11Device *) priv->device); (GstD3D11Device *) priv->device);
#else
return gst_va_handle_context_query (GST_ELEMENT (self), query,
(GstVaDisplay *) priv->device);
#endif #endif
return FALSE;
} }
static gboolean static gboolean