2023-09-10 14:34:26 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2023-10-13 12:40:45 +00:00
|
|
|
/**
|
|
|
|
* plugin-d3d12:
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2024-07-18 14:51:23 +00:00
|
|
|
#include "gstd3d12plugin-config.h"
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
#include <gst/gst.h>
|
2024-03-31 12:55:51 +00:00
|
|
|
#include <gst/d3d12/gstd3d12.h>
|
|
|
|
#include "gstd3d12pluginutils.h"
|
2023-12-29 12:22:41 +00:00
|
|
|
#include "gstd3d12convert.h"
|
2023-12-26 08:12:31 +00:00
|
|
|
#include "gstd3d12videosink.h"
|
2023-12-29 15:08:27 +00:00
|
|
|
#include "gstd3d12testsrc.h"
|
2023-12-30 15:29:10 +00:00
|
|
|
#include "gstd3d12compositor.h"
|
2024-01-01 16:05:23 +00:00
|
|
|
#include "gstd3d12screencapturedevice.h"
|
|
|
|
#include "gstd3d12screencapturesrc.h"
|
2024-01-24 17:17:36 +00:00
|
|
|
#include "gstd3d12mpeg2dec.h"
|
2023-09-10 14:34:26 +00:00
|
|
|
#include "gstd3d12h264dec.h"
|
2024-01-06 12:26:46 +00:00
|
|
|
#include "gstd3d12h264enc.h"
|
2023-09-15 14:52:34 +00:00
|
|
|
#include "gstd3d12h265dec.h"
|
2024-02-10 10:23:25 +00:00
|
|
|
#include "gstd3d12vp8dec.h"
|
2023-09-15 14:53:24 +00:00
|
|
|
#include "gstd3d12vp9dec.h"
|
2023-09-15 14:55:14 +00:00
|
|
|
#include "gstd3d12av1dec.h"
|
2024-03-22 10:48:50 +00:00
|
|
|
#include "gstd3d12ipcclient.h"
|
|
|
|
#include "gstd3d12ipcsrc.h"
|
|
|
|
#include "gstd3d12ipcsink.h"
|
2023-12-26 15:04:06 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <versionhelpers.h>
|
2023-09-10 14:34:26 +00:00
|
|
|
#include <wrl.h>
|
2024-03-31 12:55:51 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2023-09-10 14:34:26 +00:00
|
|
|
|
2024-06-29 14:02:21 +00:00
|
|
|
#ifdef HAVE_GST_D3D11
|
|
|
|
#include "gstd3d12memorycopy.h"
|
2024-07-18 16:14:20 +00:00
|
|
|
#include <gst/d3d11/gstd3d11.h>
|
|
|
|
#include <gst/d3d11/gstd3d11device-private.h>
|
|
|
|
#include <d3d11_4.h>
|
2024-06-29 14:02:21 +00:00
|
|
|
#else
|
|
|
|
#include "gstd3d12download.h"
|
|
|
|
#include "gstd3d12upload.h"
|
|
|
|
#endif
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
using namespace Microsoft::WRL;
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2024-02-04 14:25:19 +00:00
|
|
|
static void
|
|
|
|
plugin_deinit (gpointer data)
|
|
|
|
{
|
2024-03-22 10:48:50 +00:00
|
|
|
gst_d3d12_ipc_client_deinit ();
|
2024-02-04 14:25:19 +00:00
|
|
|
}
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2023-12-26 15:04:06 +00:00
|
|
|
if (!IsWindows8OrGreater ()) {
|
2024-03-31 12:55:51 +00:00
|
|
|
gst_plugin_add_status_warning (plugin,
|
|
|
|
N_("This plugin requires at least Windows 8 or newer."));
|
2023-12-26 15:04:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2024-06-17 15:33:37 +00:00
|
|
|
guint sink_rank = GST_RANK_NONE;
|
|
|
|
guint decoder_rank = GST_RANK_NONE;
|
|
|
|
bool have_video_device = false;
|
|
|
|
|
|
|
|
if (gst_d3d12_is_windows_10_or_greater ())
|
|
|
|
decoder_rank = GST_RANK_PRIMARY + 2;
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
/* Enumerate devices to register decoders per device and to get the highest
|
|
|
|
* feature level */
|
|
|
|
/* AMD seems to be supporting up to 12 cards, and 8 for NVIDIA */
|
|
|
|
for (guint i = 0; i < 12; i++) {
|
|
|
|
GstD3D12Device *device = nullptr;
|
|
|
|
ID3D12Device *device_handle;
|
|
|
|
ComPtr < ID3D12VideoDevice > video_device;
|
|
|
|
HRESULT hr;
|
2024-07-18 16:14:20 +00:00
|
|
|
gboolean d3d11_interop = FALSE;
|
2023-09-10 14:34:26 +00:00
|
|
|
|
|
|
|
device = gst_d3d12_device_new (i);
|
|
|
|
if (!device)
|
|
|
|
break;
|
|
|
|
|
|
|
|
device_handle = gst_d3d12_device_get_device_handle (device);
|
2023-12-14 12:07:10 +00:00
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
hr = device_handle->QueryInterface (IID_PPV_ARGS (&video_device));
|
|
|
|
if (FAILED (hr)) {
|
|
|
|
gst_object_unref (device);
|
|
|
|
continue;
|
|
|
|
}
|
2024-07-18 16:14:20 +00:00
|
|
|
#ifdef HAVE_GST_D3D11
|
|
|
|
gint64 luid;
|
|
|
|
g_object_get (device, "adapter-luid", &luid, nullptr);
|
|
|
|
auto device11 = gst_d3d11_device_new_for_adapter_luid (luid,
|
|
|
|
D3D11_CREATE_DEVICE_BGRA_SUPPORT);
|
|
|
|
if (device11 && gst_d3d11_device_d3d12_import_supported (device11)) {
|
|
|
|
auto device11_handle = gst_d3d11_device_get_device_handle (device11);
|
|
|
|
ComPtr < ID3D11Device5 > device11_5;
|
|
|
|
hr = device11_handle->QueryInterface (IID_PPV_ARGS (&device11_5));
|
|
|
|
if (SUCCEEDED (hr)) {
|
|
|
|
ComPtr < ID3D11DeviceContext > context11;
|
|
|
|
ComPtr < ID3D11DeviceContext4 > context11_4;
|
|
|
|
device11_5->GetImmediateContext (&context11);
|
|
|
|
hr = context11.As (&context11_4);
|
|
|
|
if (SUCCEEDED (hr))
|
|
|
|
d3d11_interop = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_clear_object (&device11);
|
|
|
|
#endif
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
|
2024-06-17 15:33:37 +00:00
|
|
|
have_video_device = true;
|
|
|
|
|
2024-01-24 17:17:36 +00:00
|
|
|
gst_d3d12_mpeg2_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2023-09-10 14:34:26 +00:00
|
|
|
gst_d3d12_h264_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2023-09-15 14:52:34 +00:00
|
|
|
gst_d3d12_h265_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2024-02-10 10:23:25 +00:00
|
|
|
gst_d3d12_vp8_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2023-09-15 14:53:24 +00:00
|
|
|
gst_d3d12_vp9_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2023-09-15 14:55:14 +00:00
|
|
|
gst_d3d12_av1_dec_register (plugin, device, video_device.Get (),
|
2024-07-18 16:14:20 +00:00
|
|
|
decoder_rank, d3d11_interop);
|
2023-09-10 14:34:26 +00:00
|
|
|
|
2024-01-06 12:26:46 +00:00
|
|
|
gst_d3d12_h264_enc_register (plugin, device, video_device.Get (),
|
|
|
|
GST_RANK_NONE);
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
gst_object_unref (device);
|
|
|
|
}
|
|
|
|
|
2024-06-17 15:33:37 +00:00
|
|
|
if (gst_d3d12_is_windows_10_or_greater () && have_video_device)
|
|
|
|
sink_rank = GST_RANK_PRIMARY + 1;
|
|
|
|
|
2023-12-29 12:22:41 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12convert", GST_RANK_NONE, GST_TYPE_D3D12_CONVERT);
|
2023-09-18 09:54:07 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12download", GST_RANK_NONE, GST_TYPE_D3D12_DOWNLOAD);
|
2023-12-23 16:05:21 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12upload", GST_RANK_NONE, GST_TYPE_D3D12_UPLOAD);
|
2023-12-26 08:12:31 +00:00
|
|
|
gst_element_register (plugin,
|
2024-06-17 15:33:37 +00:00
|
|
|
"d3d12videosink", sink_rank, GST_TYPE_D3D12_VIDEO_SINK);
|
2023-12-29 15:08:27 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12testsrc", GST_RANK_NONE, GST_TYPE_D3D12_TEST_SRC);
|
2023-12-30 15:29:10 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12compositor", GST_RANK_NONE, GST_TYPE_D3D12_COMPOSITOR);
|
2024-01-01 16:05:23 +00:00
|
|
|
gst_element_register (plugin, "d3d12screencapturesrc", GST_RANK_NONE,
|
|
|
|
GST_TYPE_D3D12_SCREEN_CAPTURE_SRC);
|
|
|
|
gst_device_provider_register (plugin,
|
|
|
|
"d3d12screencapturedeviceprovider", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_D3D12_SCREEN_CAPTURE_DEVICE_PROVIDER);
|
2024-03-22 10:48:50 +00:00
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12ipcsrc", GST_RANK_NONE, GST_TYPE_D3D12_IPC_SRC);
|
|
|
|
gst_element_register (plugin,
|
|
|
|
"d3d12ipcsink", GST_RANK_NONE, GST_TYPE_D3D12_IPC_SINK);
|
2023-09-18 09:54:07 +00:00
|
|
|
|
2024-02-04 14:25:19 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (plugin),
|
|
|
|
"plugin-d3d12-shutdown", (gpointer) "shutdown-data",
|
|
|
|
(GDestroyNotify) plugin_deinit);
|
|
|
|
|
2023-09-10 14:34:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
d3d12,
|
|
|
|
"Direct3D12 plugin",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|