summaryrefslogtreecommitdiff
path: root/gst-libs/gst/d3d11
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-03-13 22:47:55 +0900
committerSeungha Yang <seungha@centricular.com>2021-03-14 14:44:55 +0900
commit615f52f2f7898925622ec30b581c83dd7a31920e (patch)
treeda2e96b097a0bee5ea9ccd8335847a130330e39b /gst-libs/gst/d3d11
parentb08310f748d9797c15c4369edd31f7f142d6f45b (diff)
downloadgstreamer-plugins-bad-615f52f2f7898925622ec30b581c83dd7a31920e.tar.gz
d3d11device: Hold ID3D11VideoDevice and ID3D11VideoContext object
... instead of QueryInterface-ing per elements. Note that ID3D11VideoDevice and ID3D11VideoContext objects might not be available if device doesn't support video interface. So GstD3D11Device object will create those objects only when requested. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2079>
Diffstat (limited to 'gst-libs/gst/d3d11')
-rw-r--r--gst-libs/gst/d3d11/gstd3d11device.c82
-rw-r--r--gst-libs/gst/d3d11/gstd3d11device.h6
2 files changed, 88 insertions, 0 deletions
diff --git a/gst-libs/gst/d3d11/gstd3d11device.c b/gst-libs/gst/d3d11/gstd3d11device.c
index df075246b..fd40ead5e 100644
--- a/gst-libs/gst/d3d11/gstd3d11device.c
+++ b/gst-libs/gst/d3d11/gstd3d11device.c
@@ -103,10 +103,14 @@ struct _GstD3D11DevicePrivate
ID3D11Device *device;
ID3D11DeviceContext *device_context;
+ ID3D11VideoDevice *video_device;
+ ID3D11VideoContext *video_context;
+
IDXGIFactory1 *factory;
GstD3D11Format format_table[GST_D3D11_N_FORMATS];
GRecMutex extern_lock;
+ GMutex resource_lock;
#if HAVE_D3D11SDKLAYERS_H
ID3D11Debug *d3d11_debug;
@@ -409,6 +413,7 @@ gst_d3d11_device_init (GstD3D11Device * self)
priv->adapter = DEFAULT_ADAPTER;
g_rec_mutex_init (&priv->extern_lock);
+ g_mutex_init (&priv->resource_lock);
self->priv = priv;
}
@@ -894,6 +899,16 @@ gst_d3d11_device_dispose (GObject * object)
GST_LOG_OBJECT (self, "dispose");
+ if (priv->video_device) {
+ ID3D11VideoDevice_Release (priv->video_device);
+ priv->video_device = NULL;
+ }
+
+ if (priv->video_context) {
+ ID3D11VideoContext_Release (priv->video_context);
+ priv->video_context = NULL;
+ }
+
if (priv->device) {
ID3D11Device_Release (priv->device);
priv->device = NULL;
@@ -952,6 +967,7 @@ gst_d3d11_device_finalize (GObject * object)
GST_LOG_OBJECT (self, "finalize");
g_rec_mutex_clear (&priv->extern_lock);
+ g_mutex_clear (&priv->resource_lock);
g_free (priv->description);
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -1047,6 +1063,72 @@ gst_d3d11_device_get_dxgi_factory_handle (GstD3D11Device * device)
}
/**
+ * gst_d3d11_device_get_video_device_handle:
+ * @device: a #GstD3D11Device
+ *
+ * Used for various D3D11 APIs directly. Caller must not destroy returned device
+ * object.
+ *
+ * Returns: (nullable) (transfer none) : the ID3D11VideoDevice handle or %NULL
+ * if ID3D11VideoDevice is unavailable.
+ *
+ * Since: 1.20
+ */
+ID3D11VideoDevice *
+gst_d3d11_device_get_video_device_handle (GstD3D11Device * device)
+{
+ GstD3D11DevicePrivate *priv;
+
+ g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
+
+ priv = device->priv;
+ g_mutex_lock (&priv->resource_lock);
+ if (!priv->video_device) {
+ HRESULT hr;
+
+ hr = ID3D11Device_QueryInterface (priv->device, &IID_ID3D11VideoDevice,
+ (void **) &priv->video_device);
+ gst_d3d11_result (hr, device);
+ }
+ g_mutex_unlock (&priv->resource_lock);
+
+ return priv->video_device;
+}
+
+/**
+ * gst_d3d11_device_get_video_context_handle:
+ * @device: a #GstD3D11Device
+ *
+ * Used for various D3D11 APIs directly. Caller must not destroy returned device
+ * object.
+ *
+ * Returns: (nullable) (transfer none): the ID3D11VideoContext handle or %NULL
+ * if ID3D11VideoContext is unavailable.
+ *
+ * Since: 1.20
+ */
+ID3D11VideoContext *
+gst_d3d11_device_get_video_context_handle (GstD3D11Device * device)
+{
+ GstD3D11DevicePrivate *priv;
+
+ g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
+
+ priv = device->priv;
+ g_mutex_lock (&priv->resource_lock);
+ if (!priv->video_context) {
+ HRESULT hr;
+
+ hr = ID3D11DeviceContext_QueryInterface (priv->device_context,
+ &IID_ID3D11VideoContext, (void **) &priv->video_context);
+ gst_d3d11_result (hr, device);
+ }
+ g_mutex_unlock (&priv->resource_lock);
+
+ return priv->video_context;
+}
+
+/**
* gst_d3d11_device_lock:
* @device: a #GstD3D11Device
*
diff --git a/gst-libs/gst/d3d11/gstd3d11device.h b/gst-libs/gst/d3d11/gstd3d11device.h
index d63d4bfe3..fd5d77d3f 100644
--- a/gst-libs/gst/d3d11/gstd3d11device.h
+++ b/gst-libs/gst/d3d11/gstd3d11device.h
@@ -72,6 +72,12 @@ GST_D3D11_API
IDXGIFactory1 * gst_d3d11_device_get_dxgi_factory_handle (GstD3D11Device * device);
GST_D3D11_API
+ID3D11VideoDevice * gst_d3d11_device_get_video_device_handle (GstD3D11Device * device);
+
+GST_D3D11_API
+ID3D11VideoContext * gst_d3d11_device_get_video_context_handle (GstD3D11Device * device);
+
+GST_D3D11_API
void gst_d3d11_device_lock (GstD3D11Device * device);
GST_D3D11_API