From 2c14a7253bc37f455346fba631c255a970002a56 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sun, 20 Jun 2021 18:48:21 +0900 Subject: [PATCH] libs: d3d11: Port to C++ In general, C++ COM APIs are slightly less verbose and more readable than C APIs. And C++ supports some helper methods (smart pointer and C++ only macros for example) which are not allowed for C. Part-of: --- gst-libs/gst/d3d11/gstd3d11_private.h | 7 + ...d11bufferpool.c => gstd3d11bufferpool.cpp} | 12 +- .../{gstd3d11device.c => gstd3d11device.cpp} | 232 ++++++++---------- .../{gstd3d11format.c => gstd3d11format.cpp} | 0 .../{gstd3d11memory.c => gstd3d11memory.cpp} | 162 ++++++------ .../{gstd3d11utils.c => gstd3d11utils.cpp} | 4 +- gst-libs/gst/d3d11/meson.build | 30 ++- 7 files changed, 211 insertions(+), 236 deletions(-) rename gst-libs/gst/d3d11/{gstd3d11bufferpool.c => gstd3d11bufferpool.cpp} (97%) rename gst-libs/gst/d3d11/{gstd3d11device.c => gstd3d11device.cpp} (86%) rename gst-libs/gst/d3d11/{gstd3d11format.c => gstd3d11format.cpp} (100%) rename gst-libs/gst/d3d11/{gstd3d11memory.c => gstd3d11memory.cpp} (92%) rename gst-libs/gst/d3d11/{gstd3d11utils.c => gstd3d11utils.cpp} (99%) diff --git a/gst-libs/gst/d3d11/gstd3d11_private.h b/gst-libs/gst/d3d11/gstd3d11_private.h index 7fccf2b59d..cb0392b3c8 100644 --- a/gst-libs/gst/d3d11/gstd3d11_private.h +++ b/gst-libs/gst/d3d11/gstd3d11_private.h @@ -36,6 +36,13 @@ void gst_d3d11_device_dxgi_debug (GstD3D11Device * device, const gchar * function, gint line); +#define GST_D3D11_CLEAR_COM(obj) G_STMT_START { \ + if (obj) { \ + (obj)->Release (); \ + (obj) = NULL; \ + } \ + } G_STMT_END + G_END_DECLS #endif /* __GST_D3D11_PRIVATE_H__ */ diff --git a/gst-libs/gst/d3d11/gstd3d11bufferpool.c b/gst-libs/gst/d3d11/gstd3d11bufferpool.cpp similarity index 97% rename from gst-libs/gst/d3d11/gstd3d11bufferpool.c rename to gst-libs/gst/d3d11/gstd3d11bufferpool.cpp index f4b2874c71..903fb17fd5 100644 --- a/gst-libs/gst/d3d11/gstd3d11bufferpool.c +++ b/gst-libs/gst/d3d11/gstd3d11bufferpool.cpp @@ -94,7 +94,8 @@ gst_d3d11_buffer_pool_class_init (GstD3D11BufferPoolClass * klass) static void gst_d3d11_buffer_pool_init (GstD3D11BufferPool * self) { - self->priv = gst_d3d11_buffer_pool_get_instance_private (self); + self->priv = (GstD3D11BufferPoolPrivate *) + gst_d3d11_buffer_pool_get_instance_private (self); } static void @@ -173,7 +174,8 @@ gst_d3d11_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) if (!priv->d3d11_params) { /* allocate memory with resource format by default */ priv->d3d11_params = - gst_d3d11_allocation_params_new (self->device, &info, 0, 0); + gst_d3d11_allocation_params_new (self->device, + &info, (GstD3D11AllocationFlags) 0, 0); } desc = priv->d3d11_params->desc; @@ -336,7 +338,7 @@ gst_d3d11_buffer_pool_fill_buffer (GstD3D11BufferPool * self, GstBuffer * buf) { GstD3D11BufferPoolPrivate *priv = self->priv; GstFlowReturn ret = GST_FLOW_OK; - gint i; + guint i; for (i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { GstMemory *mem = NULL; @@ -512,10 +514,10 @@ gst_d3d11_buffer_pool_new (GstD3D11Device * device) g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); - pool = g_object_new (GST_TYPE_D3D11_BUFFER_POOL, NULL); + pool = (GstD3D11BufferPool *) g_object_new (GST_TYPE_D3D11_BUFFER_POOL, NULL); gst_object_ref_sink (pool); - pool->device = gst_object_ref (device); + pool->device = (GstD3D11Device *) gst_object_ref (device); return GST_BUFFER_POOL_CAST (pool); } diff --git a/gst-libs/gst/d3d11/gstd3d11device.c b/gst-libs/gst/d3d11/gstd3d11device.cpp similarity index 86% rename from gst-libs/gst/d3d11/gstd3d11device.c rename to gst-libs/gst/d3d11/gstd3d11device.cpp index 526836f493..41d48bf98d 100644 --- a/gst-libs/gst/d3d11/gstd3d11device.c +++ b/gst-libs/gst/d3d11/gstd3d11device.cpp @@ -28,6 +28,7 @@ #include "gstd3d11_private.h" #include "gstd3d11memory.h" #include +#include #include #include @@ -47,6 +48,10 @@ * and gst_d3d11_device_unlock() */ +/* *INDENT-OFF* */ +using namespace Microsoft::WRL; +/* *INDENT-ON* */ + #if HAVE_D3D11SDKLAYERS_H #include static GModule *d3d11_debug_module = NULL; @@ -203,23 +208,24 @@ gst_d3d11_device_d3d11_debug (GstD3D11Device * device, SIZE_T msg_len = 0; HRESULT hr; UINT64 num_msg, i; + ID3D11InfoQueue *info_queue = priv->d3d11_info_queue; - if (!priv->d3d11_info_queue) + if (!info_queue) return; - num_msg = ID3D11InfoQueue_GetNumStoredMessages (priv->d3d11_info_queue); + num_msg = info_queue->GetNumStoredMessages (); for (i = 0; i < num_msg; i++) { GstDebugLevel level; - hr = ID3D11InfoQueue_GetMessage (priv->d3d11_info_queue, i, NULL, &msg_len); + hr = info_queue->GetMessage (i, NULL, &msg_len); if (FAILED (hr) || msg_len == 0) { return; } msg = (D3D11_MESSAGE *) g_alloca (msg_len); - hr = ID3D11InfoQueue_GetMessage (priv->d3d11_info_queue, i, msg, &msg_len); + hr = info_queue->GetMessage (i, msg, &msg_len); level = d3d11_message_severity_to_gst (msg->Severity); if (msg->Category == D3D11_MESSAGE_CATEGORY_STATE_CREATION && @@ -233,7 +239,7 @@ gst_d3d11_device_d3d11_debug (GstD3D11Device * device, G_OBJECT (device), "D3D11InfoQueue: %s", msg->pDescription); } - ID3D11InfoQueue_ClearStoredMessages (priv->d3d11_info_queue); + info_queue->ClearStoredMessages (); return; } @@ -317,33 +323,31 @@ gst_d3d11_device_dxgi_debug (GstD3D11Device * device, SIZE_T msg_len = 0; HRESULT hr; UINT64 num_msg, i; + IDXGIInfoQueue *info_queue = priv->dxgi_info_queue; - if (!priv->dxgi_info_queue) + if (!info_queue) return; - num_msg = IDXGIInfoQueue_GetNumStoredMessages (priv->dxgi_info_queue, - DXGI_DEBUG_ALL); + num_msg = info_queue->GetNumStoredMessages (DXGI_DEBUG_ALL); for (i = 0; i < num_msg; i++) { GstDebugLevel level; - hr = IDXGIInfoQueue_GetMessage (priv->dxgi_info_queue, - DXGI_DEBUG_ALL, i, NULL, &msg_len); + hr = info_queue->GetMessage (DXGI_DEBUG_ALL, i, NULL, &msg_len); if (FAILED (hr) || msg_len == 0) { return; } msg = (DXGI_INFO_QUEUE_MESSAGE *) g_alloca (msg_len); - hr = IDXGIInfoQueue_GetMessage (priv->dxgi_info_queue, - DXGI_DEBUG_ALL, i, msg, &msg_len); + hr = info_queue->GetMessage (DXGI_DEBUG_ALL, i, msg, &msg_len); level = dxgi_info_queue_message_severity_to_gst (msg->Severity); gst_debug_log (gst_d3d11_debug_layer_debug, level, file, function, line, G_OBJECT (device), "DXGIInfoQueue: %s", msg->pDescription); } - IDXGIInfoQueue_ClearStoredMessages (priv->dxgi_info_queue, DXGI_DEBUG_ALL); + info_queue->ClearStoredMessages (DXGI_DEBUG_ALL); return; } @@ -361,6 +365,11 @@ static void gst_d3d11_device_class_init (GstD3D11DeviceClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamFlags rw_construct_only_flags = + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + GParamFlags readable_flags = + (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); gobject_class->set_property = gst_d3d11_device_set_property; gobject_class->get_property = gst_d3d11_device_get_property; @@ -371,44 +380,38 @@ gst_d3d11_device_class_init (GstD3D11DeviceClass * klass) g_object_class_install_property (gobject_class, PROP_ADAPTER, g_param_spec_uint ("adapter", "Adapter", "DXGI Adapter index for creating device", - 0, G_MAXUINT32, DEFAULT_ADAPTER, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + 0, G_MAXUINT32, DEFAULT_ADAPTER, rw_construct_only_flags)); g_object_class_install_property (gobject_class, PROP_DEVICE_ID, g_param_spec_uint ("device-id", "Device Id", - "DXGI Device ID", 0, G_MAXUINT32, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + "DXGI Device ID", 0, G_MAXUINT32, 0, readable_flags)); g_object_class_install_property (gobject_class, PROP_VENDOR_ID, g_param_spec_uint ("vendor-id", "Vendor Id", - "DXGI Vendor ID", 0, G_MAXUINT32, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + "DXGI Vendor ID", 0, G_MAXUINT32, 0, readable_flags)); g_object_class_install_property (gobject_class, PROP_HARDWARE, g_param_spec_boolean ("hardware", "Hardware", - "Whether hardware device or not", TRUE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + "Whether hardware device or not", TRUE, readable_flags)); g_object_class_install_property (gobject_class, PROP_DESCRIPTION, g_param_spec_string ("description", "Description", - "Human readable device description", NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + "Human readable device description", NULL, readable_flags)); g_object_class_install_property (gobject_class, PROP_ALLOW_TEARING, g_param_spec_boolean ("allow-tearing", "Allow tearing", "Whether dxgi device supports allow-tearing feature or not", FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + readable_flags)); g_object_class_install_property (gobject_class, PROP_CREATE_FLAGS, g_param_spec_uint ("create-flags", "Create flags", "D3D11_CREATE_DEVICE_FLAG flags used for D3D11CreateDevice", - 0, G_MAXUINT32, DEFAULT_CREATE_FLAGS, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + 0, G_MAXUINT32, DEFAULT_CREATE_FLAGS, rw_construct_only_flags)); g_object_class_install_property (gobject_class, PROP_ADAPTER_LUID, g_param_spec_int64 ("adapter-luid", "Adapter LUID", "DXGI Adapter LUID (Locally Unique Identifier) of created device", - 0, G_MAXINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + 0, G_MAXINT64, 0, readable_flags)); gst_d3d11_memory_init_once (); } @@ -418,7 +421,8 @@ gst_d3d11_device_init (GstD3D11Device * self) { GstD3D11DevicePrivate *priv; - priv = gst_d3d11_device_get_instance_private (self); + priv = (GstD3D11DevicePrivate *) + gst_d3d11_device_get_instance_private (self); priv->adapter = DEFAULT_ADAPTER; g_rec_mutex_init (&priv->extern_lock); @@ -447,6 +451,19 @@ is_windows_8_or_greater (void) return ret; } +inline D3D11_FORMAT_SUPPORT +operator | (D3D11_FORMAT_SUPPORT lhs, D3D11_FORMAT_SUPPORT rhs) +{ + return static_cast < D3D11_FORMAT_SUPPORT > (static_cast < UINT > + (lhs) | static_cast < UINT > (rhs)); +} + +inline D3D11_FORMAT_SUPPORT +operator |= (D3D11_FORMAT_SUPPORT lhs, D3D11_FORMAT_SUPPORT rhs) +{ + return lhs | rhs; +} + static gboolean can_support_format (GstD3D11Device * self, DXGI_FORMAT format, D3D11_FORMAT_SUPPORT extra_flags) @@ -465,7 +482,7 @@ can_support_format (GstD3D11Device * self, DXGI_FORMAT format, return FALSE; } - hr = ID3D11Device_CheckFormatSupport (handle, format, &supported); + hr = handle->CheckFormatSupport (format, &supported); if (FAILED (hr)) { GST_DEBUG_OBJECT (self, "DXGI format %d is not supported by device", (guint) format); @@ -648,8 +665,8 @@ gst_d3d11_device_constructed (GObject * object) { GstD3D11Device *self = GST_D3D11_DEVICE (object); GstD3D11DevicePrivate *priv = self->priv; - IDXGIAdapter1 *adapter = NULL; - IDXGIFactory1 *factory = NULL; + ComPtr < IDXGIAdapter1 > adapter; + ComPtr < IDXGIFactory1 > factory; HRESULT hr; UINT d3d11_flags = priv->create_flags; @@ -676,16 +693,15 @@ gst_d3d11_device_constructed (GObject * object) GST_CAT_INFO_OBJECT (gst_d3d11_debug_layer_debug, self, "dxgi debug library was loaded"); - hr = gst_d3d11_device_dxgi_get_device_interface (&IID_IDXGIDebug, - (void **) &debug); + hr = gst_d3d11_device_dxgi_get_device_interface (IID_PPV_ARGS (&debug)); if (SUCCEEDED (hr)) { GST_CAT_INFO_OBJECT (gst_d3d11_debug_layer_debug, self, "IDXGIDebug interface available"); priv->dxgi_debug = debug; - hr = gst_d3d11_device_dxgi_get_device_interface (&IID_IDXGIInfoQueue, - (void **) &info_queue); + hr = gst_d3d11_device_dxgi_get_device_interface (IID_PPV_ARGS + (&info_queue)); if (SUCCEEDED (hr)) { GST_CAT_INFO_OBJECT (gst_d3d11_debug_layer_debug, self, "IDXGIInfoQueue interface available"); @@ -699,41 +715,33 @@ gst_d3d11_device_constructed (GObject * object) } #endif -#if (GST_D3D11_DXGI_HEADER_VERSION >= 5) - hr = CreateDXGIFactory1 (&IID_IDXGIFactory5, (void **) &factory); + hr = CreateDXGIFactory1 (IID_PPV_ARGS (&factory)); if (!gst_d3d11_result (hr, NULL)) { - GST_INFO_OBJECT (self, "IDXGIFactory5 was unavailable"); - factory = NULL; - } else { + GST_ERROR_OBJECT (self, "cannot create dxgi factory, hr: 0x%x", (guint) hr); + goto out; + } +#if (GST_D3D11_DXGI_HEADER_VERSION >= 5) + { + ComPtr < IDXGIFactory5 > factory5; BOOL allow_tearing; - hr = IDXGIFactory5_CheckFeatureSupport ((IDXGIFactory5 *) factory, - DXGI_FEATURE_PRESENT_ALLOW_TEARING, (void *) &allow_tearing, - sizeof (allow_tearing)); + hr = factory.As (&factory5); + if (SUCCEEDED (hr)) { + hr = factory5->CheckFeatureSupport (DXGI_FEATURE_PRESENT_ALLOW_TEARING, + (void *) &allow_tearing, sizeof (allow_tearing)); - priv->allow_tearing = SUCCEEDED (hr) && allow_tearing; - - hr = S_OK; + priv->allow_tearing = SUCCEEDED (hr) && allow_tearing; + } } #endif - if (!factory) { - hr = CreateDXGIFactory1 (&IID_IDXGIFactory1, (void **) &factory); - } - - if (!gst_d3d11_result (hr, NULL)) { - GST_ERROR_OBJECT (self, "cannot create dxgi factory, hr: 0x%x", (guint) hr); - goto error; - } - - if (IDXGIFactory1_EnumAdapters1 (factory, priv->adapter, - &adapter) == DXGI_ERROR_NOT_FOUND) { + if (factory->EnumAdapters1 (priv->adapter, &adapter) == DXGI_ERROR_NOT_FOUND) { GST_DEBUG_OBJECT (self, "No adapter for index %d", priv->adapter); - goto error; + goto out; } else { DXGI_ADAPTER_DESC1 desc; - hr = IDXGIAdapter1_GetDesc1 (adapter, &desc); + hr = adapter->GetDesc1 (&desc); if (SUCCEEDED (hr)) { gchar *description = NULL; gboolean is_hardware = FALSE; @@ -746,7 +754,8 @@ gst_d3d11_device_constructed (GObject * object) adapter_luid = (((gint64) desc.AdapterLuid.HighPart) << 32) | ((gint64) desc.AdapterLuid.LowPart); - description = g_utf16_to_utf8 (desc.Description, -1, NULL, NULL, NULL); + description = g_utf16_to_utf8 ((gunichar2 *) desc.Description, + -1, NULL, NULL, NULL); GST_DEBUG_OBJECT (self, "adapter index %d: D3D11 device vendor-id: 0x%04x, device-id: 0x%04x, " "Flags: 0x%x, adapter-luid: %" G_GINT64_FORMAT ", %s", @@ -776,13 +785,13 @@ gst_d3d11_device_constructed (GObject * object) } #endif - hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN, + hr = D3D11CreateDevice (adapter.Get (), D3D_DRIVER_TYPE_UNKNOWN, NULL, d3d11_flags, feature_levels, G_N_ELEMENTS (feature_levels), D3D11_SDK_VERSION, &priv->device, &selected_level, &priv->device_context); if (FAILED (hr)) { /* Retry if the system could not recognize D3D_FEATURE_LEVEL_11_1 */ - hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN, + hr = D3D11CreateDevice (adapter.Get (), D3D_DRIVER_TYPE_UNKNOWN, NULL, d3d11_flags, &feature_levels[1], G_N_ELEMENTS (feature_levels) - 1, D3D11_SDK_VERSION, &priv->device, &selected_level, &priv->device_context); @@ -796,14 +805,14 @@ gst_d3d11_device_constructed (GObject * object) d3d11_flags &= ~D3D11_CREATE_DEVICE_DEBUG; - hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN, + hr = D3D11CreateDevice (adapter.Get (), D3D_DRIVER_TYPE_UNKNOWN, NULL, d3d11_flags, feature_levels, G_N_ELEMENTS (feature_levels), D3D11_SDK_VERSION, &priv->device, &selected_level, &priv->device_context); if (FAILED (hr)) { /* Retry if the system could not recognize D3D_FEATURE_LEVEL_11_1 */ - hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN, + hr = D3D11CreateDevice (adapter.Get (), D3D_DRIVER_TYPE_UNKNOWN, NULL, d3d11_flags, &feature_levels[1], G_N_ELEMENTS (feature_levels) - 1, D3D11_SDK_VERSION, &priv->device, &selected_level, &priv->device_context); @@ -816,26 +825,24 @@ gst_d3d11_device_constructed (GObject * object) GST_INFO_OBJECT (self, "cannot create d3d11 device for adapter index %d with flags 0x%x, " "hr: 0x%x", priv->adapter, d3d11_flags, (guint) hr); - goto error; + goto out; } - priv->factory = factory; + priv->factory = factory.Detach (); #if HAVE_D3D11SDKLAYERS_H if ((d3d11_flags & D3D11_CREATE_DEVICE_DEBUG) == D3D11_CREATE_DEVICE_DEBUG) { ID3D11Debug *debug; ID3D11InfoQueue *info_queue; - hr = ID3D11Device_QueryInterface (priv->device, - &IID_ID3D11Debug, (void **) &debug); + hr = priv->device->QueryInterface (IID_PPV_ARGS (&debug)); if (SUCCEEDED (hr)) { GST_CAT_INFO_OBJECT (gst_d3d11_debug_layer_debug, self, "D3D11Debug interface available"); priv->d3d11_debug = debug; - hr = ID3D11Device_QueryInterface (priv->device, - &IID_ID3D11InfoQueue, (void **) &info_queue); + hr = priv->device->QueryInterface (IID_PPV_ARGS (&info_queue)); if (SUCCEEDED (hr)) { GST_CAT_INFO_OBJECT (gst_d3d11_debug_layer_debug, self, "ID3D11InfoQueue interface available"); @@ -849,20 +856,9 @@ gst_d3d11_device_constructed (GObject * object) * might be added by us */ priv->create_flags = d3d11_flags; - IDXGIAdapter1_Release (adapter); gst_d3d11_device_setup_format_table (self); - G_OBJECT_CLASS (parent_class)->constructed (object); - - return; - -error: - if (factory) - IDXGIFactory1_Release (factory); - - if (adapter) - IDXGIAdapter1_Release (adapter); - +out: G_OBJECT_CLASS (parent_class)->constructed (object); return; @@ -934,60 +930,35 @@ 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; - } - - if (priv->device_context) { - ID3D11DeviceContext_Release (priv->device_context); - priv->device_context = NULL; - } - - if (priv->factory) { - IDXGIFactory1_Release (priv->factory); - priv->factory = NULL; - } + GST_D3D11_CLEAR_COM (priv->video_device); + GST_D3D11_CLEAR_COM (priv->video_context); + GST_D3D11_CLEAR_COM (priv->device); + GST_D3D11_CLEAR_COM (priv->device_context); + GST_D3D11_CLEAR_COM (priv->factory); #if HAVE_D3D11SDKLAYERS_H if (priv->d3d11_debug) { - ID3D11Debug_ReportLiveDeviceObjects (priv->d3d11_debug, - (D3D11_RLDO_FLAGS) GST_D3D11_RLDO_FLAGS); - ID3D11Debug_Release (priv->d3d11_debug); - priv->d3d11_debug = NULL; + priv->d3d11_debug->ReportLiveDeviceObjects ((D3D11_RLDO_FLAGS) + GST_D3D11_RLDO_FLAGS); } + GST_D3D11_CLEAR_COM (priv->d3d11_debug); - if (priv->d3d11_info_queue) { + if (priv->d3d11_info_queue) gst_d3d11_device_d3d11_debug (self, __FILE__, GST_FUNCTION, __LINE__); - ID3D11InfoQueue_Release (priv->d3d11_info_queue); - priv->d3d11_info_queue = NULL; - } + GST_D3D11_CLEAR_COM (priv->d3d11_info_queue); #endif #if HAVE_DXGIDEBUG_H if (priv->dxgi_debug) { - IDXGIDebug_ReportLiveObjects (priv->dxgi_debug, DXGI_DEBUG_ALL, + priv->dxgi_debug->ReportLiveObjects (DXGI_DEBUG_ALL, (DXGI_DEBUG_RLO_FLAGS) GST_D3D11_RLDO_FLAGS); - IDXGIDebug_Release (priv->dxgi_debug); - priv->dxgi_debug = NULL; } + GST_D3D11_CLEAR_COM (priv->dxgi_debug); - if (priv->dxgi_info_queue) { + if (priv->dxgi_info_queue) gst_d3d11_device_dxgi_debug (self, __FILE__, GST_FUNCTION, __LINE__); - IDXGIInfoQueue_Release (priv->dxgi_info_queue); - priv->dxgi_info_queue = NULL; - } + GST_D3D11_CLEAR_COM (priv->dxgi_info_queue); #endif G_OBJECT_CLASS (parent_class)->dispose (object); @@ -1024,7 +995,8 @@ gst_d3d11_device_new (guint adapter, guint flags) GstD3D11Device *device = NULL; GstD3D11DevicePrivate *priv; - device = g_object_new (GST_TYPE_D3D11_DEVICE, "adapter", adapter, + device = (GstD3D11Device *) + g_object_new (GST_TYPE_D3D11_DEVICE, "adapter", adapter, "create-flags", flags, NULL); priv = device->priv; @@ -1120,10 +1092,11 @@ gst_d3d11_device_get_video_device_handle (GstD3D11Device * device) g_mutex_lock (&priv->resource_lock); if (!priv->video_device) { HRESULT hr; + ID3D11VideoDevice *video_device = NULL; - hr = ID3D11Device_QueryInterface (priv->device, &IID_ID3D11VideoDevice, - (void **) &priv->video_device); - gst_d3d11_result (hr, device); + hr = priv->device->QueryInterface (IID_PPV_ARGS (&video_device)); + if (gst_d3d11_result (hr, device)) + priv->video_device = video_device; } g_mutex_unlock (&priv->resource_lock); @@ -1153,10 +1126,11 @@ gst_d3d11_device_get_video_context_handle (GstD3D11Device * device) g_mutex_lock (&priv->resource_lock); if (!priv->video_context) { HRESULT hr; + ID3D11VideoContext *video_context = NULL; - hr = ID3D11DeviceContext_QueryInterface (priv->device_context, - &IID_ID3D11VideoContext, (void **) &priv->video_context); - gst_d3d11_result (hr, device); + hr = priv->device_context->QueryInterface (IID_PPV_ARGS (&video_context)); + if (gst_d3d11_result (hr, device)) + priv->video_context = video_context; } g_mutex_unlock (&priv->resource_lock); @@ -1224,7 +1198,7 @@ gst_d3d11_device_format_from_gst (GstD3D11Device * device, GstVideoFormat format) { GstD3D11DevicePrivate *priv; - gint i; + guint i; g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); diff --git a/gst-libs/gst/d3d11/gstd3d11format.c b/gst-libs/gst/d3d11/gstd3d11format.cpp similarity index 100% rename from gst-libs/gst/d3d11/gstd3d11format.c rename to gst-libs/gst/d3d11/gstd3d11format.cpp diff --git a/gst-libs/gst/d3d11/gstd3d11memory.c b/gst-libs/gst/d3d11/gstd3d11memory.cpp similarity index 92% rename from gst-libs/gst/d3d11/gstd3d11memory.c rename to gst-libs/gst/d3d11/gstd3d11memory.cpp index 8627d0930f..77d26fce76 100644 --- a/gst-libs/gst/d3d11/gstd3d11memory.c +++ b/gst-libs/gst/d3d11/gstd3d11memory.cpp @@ -26,6 +26,7 @@ #include "gstd3d11memory.h" #include "gstd3d11device.h" #include "gstd3d11utils.h" +#include "gstd3d11_private.h" GST_DEBUG_CATEGORY_STATIC (gst_d3d11_allocator_debug); #define GST_CAT_DEFAULT gst_d3d11_allocator_debug @@ -61,7 +62,7 @@ gst_d3d11_allocation_params_new (GstD3D11Device * device, GstVideoInfo * info, { GstD3D11AllocationParams *ret; const GstD3D11Format *d3d11_format; - gint i; + guint i; g_return_val_if_fail (info != NULL, NULL); @@ -139,7 +140,7 @@ gboolean gst_d3d11_allocation_params_alignment (GstD3D11AllocationParams * params, GstVideoAlignment * align) { - gint i; + guint i; guint padding_width, padding_height; GstVideoInfo *info; GstVideoInfo new_info; @@ -304,7 +305,7 @@ gst_d3d11_allocate_staging_texture (GstD3D11Device * device, desc.Usage = D3D11_USAGE_STAGING; desc.CPUAccessFlags = (D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE); - hr = ID3D11Device_CreateTexture2D (device_handle, &desc, NULL, &texture); + hr = device_handle->CreateTexture2D (&desc, NULL, &texture); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (device, "Failed to create texture"); return NULL; @@ -323,8 +324,7 @@ gst_d3d11_memory_map_cpu_access (GstD3D11Memory * dmem, D3D11_MAP map_type) ID3D11DeviceContext *device_context = gst_d3d11_device_get_device_context_handle (dmem->device); - hr = ID3D11DeviceContext_Map (device_context, - staging, 0, map_type, 0, &priv->map); + hr = device_context->Map (staging, 0, map_type, 0, &priv->map); if (!gst_d3d11_result (hr, dmem->device)) { GST_ERROR_OBJECT (GST_MEMORY_CAST (dmem)->allocator, @@ -347,9 +347,8 @@ gst_d3d11_memory_upload (GstD3D11Memory * dmem) return; device_context = gst_d3d11_device_get_device_context_handle (dmem->device); - ID3D11DeviceContext_CopySubresourceRegion (device_context, - (ID3D11Resource *) priv->texture, priv->subresource_index, 0, 0, 0, - (ID3D11Resource *) priv->staging, 0, NULL); + device_context->CopySubresourceRegion (priv->texture, priv->subresource_index, + 0, 0, 0, priv->staging, 0, NULL); } /* Must be called with d3d11 device lock */ @@ -364,9 +363,8 @@ gst_d3d11_memory_download (GstD3D11Memory * dmem) return; device_context = gst_d3d11_device_get_device_context_handle (dmem->device); - ID3D11DeviceContext_CopySubresourceRegion (device_context, - (ID3D11Resource *) priv->staging, 0, 0, 0, 0, - (ID3D11Resource *) priv->texture, priv->subresource_index, NULL); + device_context->CopySubresourceRegion (priv->staging, 0, 0, 0, 0, + priv->texture, priv->subresource_index, NULL); } static gpointer @@ -442,7 +440,7 @@ gst_d3d11_memory_unmap_cpu_access (GstD3D11Memory * dmem) ID3D11DeviceContext *device_context = gst_d3d11_device_get_device_context_handle (dmem->device); - ID3D11DeviceContext_Unmap (device_context, staging, 0); + device_context->Unmap (staging, 0); } static void @@ -561,7 +559,8 @@ gst_d3d11_memory_init_once (void) GST_DEBUG_CATEGORY_INIT (gst_d3d11_allocator_debug, "d3d11allocator", 0, "Direct3D11 Texture Allocator"); - _d3d11_memory_allocator = g_object_new (GST_TYPE_D3D11_ALLOCATOR, NULL); + _d3d11_memory_allocator = + (GstAllocator *) g_object_new (GST_TYPE_D3D11_ALLOCATOR, NULL); gst_object_ref_sink (_d3d11_memory_allocator); gst_allocator_register (GST_D3D11_MEMORY_NAME, _d3d11_memory_allocator); @@ -640,13 +639,15 @@ static gboolean create_shader_resource_views (GstD3D11Memory * mem) { GstD3D11MemoryPrivate *priv = mem->priv; - gint i; + guint i; HRESULT hr; guint num_views = 0; ID3D11Device *device_handle; - D3D11_SHADER_RESOURCE_VIEW_DESC resource_desc = { 0, }; + D3D11_SHADER_RESOURCE_VIEW_DESC resource_desc; DXGI_FORMAT formats[GST_VIDEO_MAX_PLANES] = { DXGI_FORMAT_UNKNOWN, }; + memset (&resource_desc, 0, sizeof (D3D11_SHADER_RESOURCE_VIEW_DESC)); + device_handle = gst_d3d11_device_get_device_handle (mem->device); switch (priv->desc.Format) { @@ -699,9 +700,8 @@ create_shader_resource_views (GstD3D11Memory * mem) for (i = 0; i < num_views; i++) { resource_desc.Format = formats[i]; - hr = ID3D11Device_CreateShaderResourceView (device_handle, - (ID3D11Resource *) priv->texture, &resource_desc, - &priv->shader_resource_view[i]); + hr = device_handle->CreateShaderResourceView (priv->texture, + &resource_desc, &priv->shader_resource_view[i]); if (!gst_d3d11_result (hr, mem->device)) { GST_ERROR_OBJECT (GST_MEMORY_CAST (mem)->allocator, @@ -718,11 +718,8 @@ create_shader_resource_views (GstD3D11Memory * mem) return FALSE; error: - for (i = 0; i < num_views; i++) { - if (priv->shader_resource_view[i]) - ID3D11ShaderResourceView_Release (priv->shader_resource_view[i]); - priv->shader_resource_view[i] = NULL; - } + for (i = 0; i < num_views; i++) + GST_D3D11_CLEAR_COM (priv->shader_resource_view[i]); priv->num_shader_resource_views = 0; @@ -810,13 +807,15 @@ static gboolean create_render_target_views (GstD3D11Memory * mem) { GstD3D11MemoryPrivate *priv = mem->priv; - gint i; + guint i; HRESULT hr; guint num_views = 0; ID3D11Device *device_handle; - D3D11_RENDER_TARGET_VIEW_DESC render_desc = { 0, }; + D3D11_RENDER_TARGET_VIEW_DESC render_desc; DXGI_FORMAT formats[GST_VIDEO_MAX_PLANES] = { DXGI_FORMAT_UNKNOWN, }; + memset (&render_desc, 0, sizeof (D3D11_RENDER_TARGET_VIEW_DESC)); + device_handle = gst_d3d11_device_get_device_handle (mem->device); switch (priv->desc.Format) { @@ -858,8 +857,7 @@ create_render_target_views (GstD3D11Memory * mem) for (i = 0; i < num_views; i++) { render_desc.Format = formats[i]; - hr = ID3D11Device_CreateRenderTargetView (device_handle, - (ID3D11Resource *) priv->texture, &render_desc, + hr = device_handle->CreateRenderTargetView (priv->texture, &render_desc, &priv->render_target_view[i]); if (!gst_d3d11_result (hr, mem->device)) { GST_ERROR_OBJECT (GST_MEMORY_CAST (mem)->allocator, @@ -876,11 +874,8 @@ create_render_target_views (GstD3D11Memory * mem) return FALSE; error: - for (i = 0; i < num_views; i++) { - if (priv->render_target_view[i]) - ID3D11RenderTargetView_Release (priv->render_target_view[i]); - priv->render_target_view[i] = NULL; - } + for (i = 0; i < num_views; i++) + GST_D3D11_CLEAR_COM (priv->render_target_view[i]); priv->num_render_target_views = 0; @@ -984,16 +979,14 @@ gst_d3d11_memory_ensure_decoder_output_view (GstD3D11Memory * mem, GST_D3D11_MEMORY_LOCK (mem); if (dmem_priv->decoder_output_view) { - ID3D11VideoDecoderOutputView_GetDesc (dmem_priv->decoder_output_view, - &desc); - if (IsEqualGUID (&desc.DecodeProfile, decoder_profile)) { + dmem_priv->decoder_output_view->GetDesc (&desc); + if (IsEqualGUID (desc.DecodeProfile, *decoder_profile)) { goto succeeded; } else { /* Shouldn't happen, but try again anyway */ GST_WARNING_OBJECT (allocator, "Existing view has different decoder profile"); - ID3D11VideoDecoderOutputView_Release (dmem_priv->decoder_output_view); - dmem_priv->decoder_output_view = NULL; + GST_D3D11_CLEAR_COM (dmem_priv->decoder_output_view); } } @@ -1004,8 +997,7 @@ gst_d3d11_memory_ensure_decoder_output_view (GstD3D11Memory * mem, desc.ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D; desc.Texture2D.ArraySlice = dmem_priv->subresource_index; - hr = ID3D11VideoDevice_CreateVideoDecoderOutputView (video_device, - (ID3D11Resource *) dmem_priv->texture, &desc, + hr = video_device->CreateVideoDecoderOutputView (dmem_priv->texture, &desc, &dmem_priv->decoder_output_view); if (!gst_d3d11_result (hr, mem->device)) { GST_ERROR_OBJECT (allocator, @@ -1091,9 +1083,8 @@ gst_d3d11_memory_ensure_processor_input_view (GstD3D11Memory * mem, desc.Texture2D.MipSlice = 0; desc.Texture2D.ArraySlice = dmem_priv->subresource_index; - hr = ID3D11VideoDevice_CreateVideoProcessorInputView (video_device, - (ID3D11Resource *) dmem_priv->texture, enumerator, &desc, - &dmem_priv->processor_input_view); + hr = video_device->CreateVideoProcessorInputView (dmem_priv->texture, + enumerator, &desc, &dmem_priv->processor_input_view); if (!gst_d3d11_result (hr, mem->device)) { GST_ERROR_OBJECT (allocator, "Could not create processor input view, hr: 0x%x", (guint) hr); @@ -1144,10 +1135,12 @@ gst_d3d11_memory_ensure_processor_output_view (GstD3D11Memory * mem, { GstD3D11MemoryPrivate *priv = mem->priv; GstD3D11Allocator *allocator; - D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC desc = { 0, }; + D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC desc; HRESULT hr; gboolean ret; + memset (&desc, 0, sizeof (D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC)); + allocator = GST_D3D11_ALLOCATOR (GST_MEMORY_CAST (mem)->allocator); if (!(priv->desc.BindFlags & D3D11_BIND_RENDER_TARGET)) { @@ -1170,9 +1163,8 @@ gst_d3d11_memory_ensure_processor_output_view (GstD3D11Memory * mem, desc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D; desc.Texture2D.MipSlice = 0; - hr = ID3D11VideoDevice_CreateVideoProcessorOutputView (video_device, - (ID3D11Resource *) priv->texture, enumerator, &desc, - &priv->processor_output_view); + hr = video_device->CreateVideoProcessorOutputView (priv->texture, + enumerator, &desc, &priv->processor_output_view); if (!gst_d3d11_result (hr, mem->device)) { GST_ERROR_OBJECT (allocator, "Could not create processor input view, hr: 0x%x", (guint) hr); @@ -1262,13 +1254,14 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) UINT supported_flags = 0; /* non-zero offset or different size is not supported */ - if (offset != 0 || (size != -1 && size != mem->size)) { + if (offset != 0 || (size != -1 && (gsize) size != mem->size)) { GST_DEBUG_OBJECT (alloc, "Different size/offset, try fallback copy"); return priv->fallback_copy (mem, offset, size); } gst_d3d11_device_lock (device); - if (!gst_memory_map (mem, &info, GST_MAP_READ | GST_MAP_D3D11)) { + if (!gst_memory_map (mem, &info, + (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) { gst_d3d11_device_unlock (device); GST_WARNING_OBJECT (alloc, "Failed to map memory, try fallback copy"); @@ -1276,7 +1269,7 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) return priv->fallback_copy (mem, offset, size); } - ID3D11Texture2D_GetDesc (dmem->priv->texture, &src_desc); + dmem->priv->texture->GetDesc (&src_desc); dst_desc.Width = src_desc.Width; dst_desc.Height = src_desc.Height; dst_desc.MipLevels = 1; @@ -1286,8 +1279,7 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) dst_desc.Usage = D3D11_USAGE_DEFAULT; /* If supported, use bind flags for SRV/RTV */ - hr = ID3D11Device_CheckFormatSupport (device_handle, - src_desc.Format, &supported_flags); + hr = device_handle->CheckFormatSupport (src_desc.Format, &supported_flags); if (gst_d3d11_result (hr, device)) { if ((supported_flags & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) == D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) { @@ -1312,10 +1304,8 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) } copy_dmem = GST_D3D11_MEMORY_CAST (copy); - ID3D11DeviceContext_CopySubresourceRegion (device_context, - (ID3D11Resource *) copy_dmem->priv->texture, 0, 0, 0, 0, - (ID3D11Resource *) dmem->priv->texture, dmem->priv->subresource_index, - NULL); + device_context->CopySubresourceRegion (copy_dmem->priv->texture, 0, 0, 0, 0, + dmem->priv->texture, dmem->priv->subresource_index, NULL); copy->maxsize = copy->size = mem->maxsize; gst_memory_unmap (mem, &info); gst_d3d11_device_unlock (device); @@ -1333,7 +1323,8 @@ gst_d3d11_allocator_init (GstD3D11Allocator * allocator) GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); GstD3D11AllocatorPrivate *priv; - priv = allocator->priv = gst_d3d11_allocator_get_instance_private (allocator); + priv = allocator->priv = (GstD3D11AllocatorPrivate *) + gst_d3d11_allocator_get_instance_private (allocator); alloc->mem_type = GST_D3D11_MEMORY_NAME; alloc->mem_map_full = gst_d3d11_memory_map_full; @@ -1364,27 +1355,15 @@ gst_d3d11_allocator_free (GstAllocator * allocator, GstMemory * mem) GST_LOG_OBJECT (allocator, "Free memory %p", mem); for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) { - if (dmem_priv->render_target_view[i]) - ID3D11RenderTargetView_Release (dmem_priv->render_target_view[i]); - - if (dmem_priv->shader_resource_view[i]) - ID3D11ShaderResourceView_Release (dmem_priv->shader_resource_view[i]); + GST_D3D11_CLEAR_COM (dmem_priv->render_target_view[i]); + GST_D3D11_CLEAR_COM (dmem_priv->shader_resource_view[i]); } - if (dmem_priv->decoder_output_view) - ID3D11VideoDecoderOutputView_Release (dmem_priv->decoder_output_view); - - if (dmem_priv->processor_input_view) - ID3D11VideoProcessorInputView_Release (dmem_priv->processor_input_view); - - if (dmem_priv->processor_output_view) - ID3D11VideoProcessorOutputView_Release (dmem_priv->processor_output_view); - - if (dmem_priv->texture) - ID3D11Texture2D_Release (dmem_priv->texture); - - if (dmem_priv->staging) - ID3D11Texture2D_Release (dmem_priv->staging); + GST_D3D11_CLEAR_COM (dmem_priv->decoder_output_view); + GST_D3D11_CLEAR_COM (dmem_priv->processor_input_view); + GST_D3D11_CLEAR_COM (dmem_priv->processor_output_view); + GST_D3D11_CLEAR_COM (dmem_priv->texture); + GST_D3D11_CLEAR_COM (dmem_priv->staging); gst_clear_object (&dmem->device); g_mutex_clear (&dmem_priv->lock); @@ -1403,16 +1382,16 @@ gst_d3d11_allocator_alloc_wrapped (GstD3D11Allocator * self, mem->priv = g_new0 (GstD3D11MemoryPrivate, 1); gst_memory_init (GST_MEMORY_CAST (mem), - 0, GST_ALLOCATOR_CAST (self), NULL, 0, 0, 0, 0); + (GstMemoryFlags) 0, GST_ALLOCATOR_CAST (self), NULL, 0, 0, 0, 0); g_mutex_init (&mem->priv->lock); mem->priv->texture = texture; mem->priv->desc = *desc; - mem->device = gst_object_ref (device); + mem->device = (GstD3D11Device *) gst_object_ref (device); /* This is staging texture as well */ if (desc->Usage == D3D11_USAGE_STAGING) { mem->priv->staging = texture; - ID3D11Texture2D_AddRef (texture); + texture->AddRef (); } return GST_MEMORY_CAST (mem); @@ -1428,7 +1407,7 @@ gst_d3d11_allocator_alloc_internal (GstD3D11Allocator * self, device_handle = gst_d3d11_device_get_device_handle (device); - hr = ID3D11Device_CreateTexture2D (device_handle, desc, NULL, &texture); + hr = device_handle->CreateTexture2D (desc, NULL, &texture); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create texture"); return NULL; @@ -1549,7 +1528,7 @@ gst_d3d11_pool_allocator_init (GstD3D11PoolAllocator * allocator) { GstD3D11PoolAllocatorPrivate *priv; - priv = allocator->priv = + priv = allocator->priv = (GstD3D11PoolAllocatorPrivate *) gst_d3d11_pool_allocator_get_instance_private (allocator); g_rec_mutex_init (&priv->lock); @@ -1588,8 +1567,7 @@ gst_d3d11_pool_allocator_finalize (GObject * object) gst_poll_free (priv->poll); g_rec_mutex_clear (&priv->lock); - if (priv->texture) - ID3D11Texture2D_Release (priv->texture); + GST_D3D11_CLEAR_COM (priv->texture); G_OBJECT_CLASS (pool_alloc_parent_class)->finalize (object); } @@ -1614,8 +1592,7 @@ gst_d3d11_pool_allocator_start (GstD3D11PoolAllocator * self) device_handle = gst_d3d11_device_get_device_handle (self->device); if (!priv->texture) { - hr = ID3D11Device_CreateTexture2D (device_handle, &priv->desc, NULL, - &priv->texture); + hr = device_handle->CreateTexture2D (&priv->desc, NULL, &priv->texture); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to allocate texture"); return FALSE; @@ -1626,7 +1603,7 @@ gst_d3d11_pool_allocator_start (GstD3D11PoolAllocator * self) for (i = 0; i < priv->desc.ArraySize; i++) { GstMemory *mem; - ID3D11Texture2D_AddRef (priv->texture); + priv->texture->AddRef (); mem = gst_d3d11_allocator_alloc_wrapped (GST_D3D11_ALLOCATOR_CAST (_d3d11_memory_allocator), self->device, &priv->desc, priv->texture); @@ -1775,7 +1752,7 @@ gst_d3d11_pool_allocator_clear_queue (GstD3D11PoolAllocator * self) GST_LOG_OBJECT (self, "Clearing queue"); /* clear the pool */ - while ((memory = gst_atomic_queue_pop (priv->queue))) { + while ((memory = (GstMemory *) gst_atomic_queue_pop (priv->queue))) { while (!gst_poll_read_control (priv->poll)) { if (errno == EWOULDBLOCK) { /* We put the memory into the queue but did not finish writing control @@ -1840,7 +1817,7 @@ gst_d3d11_pool_allocator_release_memory (GstD3D11PoolAllocator * self, GST_LOG_OBJECT (self, "Released memory %p", mem); GST_MINI_OBJECT_CAST (mem)->dispose = NULL; - mem->allocator = gst_object_ref (_d3d11_memory_allocator); + mem->allocator = (GstAllocator *) gst_object_ref (_d3d11_memory_allocator); gst_object_unref (self); /* keep it around in our queue */ @@ -1928,7 +1905,7 @@ gst_d3d11_pool_allocator_acquire_memory_internal (GstD3D11PoolAllocator * self, goto flushing; /* try to get a memory from the queue */ - *memory = gst_atomic_queue_pop (priv->queue); + *memory = (GstMemory *) gst_atomic_queue_pop (priv->queue); if (G_LIKELY (*memory)) { while (!gst_poll_read_control (priv->poll)) { if (errno == EWOULDBLOCK) { @@ -2018,10 +1995,11 @@ gst_d3d11_pool_allocator_new (GstD3D11Device * device, gst_d3d11_memory_init_once (); - self = g_object_new (GST_TYPE_D3D11_POOL_ALLOCATOR, NULL); + self = (GstD3D11PoolAllocator *) + g_object_new (GST_TYPE_D3D11_POOL_ALLOCATOR, NULL); gst_object_ref_sink (self); - self->device = gst_object_ref (device); + self->device = (GstD3D11Device *) gst_object_ref (device); self->priv->desc = *desc; return self; @@ -2047,7 +2025,7 @@ gst_d3d11_pool_allocator_acquire_memory (GstD3D11PoolAllocator * allocator, g_return_val_if_fail (GST_IS_D3D11_POOL_ALLOCATOR (allocator), GST_FLOW_ERROR); - g_return_val_if_fail (memory != NULL, FALSE); + g_return_val_if_fail (memory != NULL, GST_FLOW_ERROR); priv = allocator->priv; @@ -2060,7 +2038,7 @@ gst_d3d11_pool_allocator_acquire_memory (GstD3D11PoolAllocator * allocator, GstMemory *mem = *memory; /* Replace default allocator with ours */ gst_object_unref (mem->allocator); - mem->allocator = gst_object_ref (allocator); + mem->allocator = (GstAllocator *) gst_object_ref (allocator); GST_MINI_OBJECT_CAST (mem)->dispose = gst_d3d11_memory_release; } else { dec_outstanding (allocator); diff --git a/gst-libs/gst/d3d11/gstd3d11utils.c b/gst-libs/gst/d3d11/gstd3d11utils.cpp similarity index 99% rename from gst-libs/gst/d3d11/gstd3d11utils.c rename to gst-libs/gst/d3d11/gstd3d11utils.cpp index 2680b65fe4..e0d2aef64a 100644 --- a/gst-libs/gst/d3d11/gstd3d11utils.c +++ b/gst-libs/gst/d3d11/gstd3d11utils.cpp @@ -204,8 +204,8 @@ gst_d3d11_handle_context_query (GstElement * element, GstQuery * query, static gboolean pad_query (const GValue * item, GValue * value, gpointer user_data) { - GstPad *pad = g_value_get_object (item); - GstQuery *query = user_data; + GstPad *pad = (GstPad *) g_value_get_object (item); + GstQuery *query = (GstQuery *) user_data; gboolean res; res = gst_pad_peer_query (pad, query); diff --git a/gst-libs/gst/d3d11/meson.build b/gst-libs/gst/d3d11/meson.build index b699082d5f..4a844ef757 100644 --- a/gst-libs/gst/d3d11/meson.build +++ b/gst-libs/gst/d3d11/meson.build @@ -1,9 +1,9 @@ d3d11_sources = [ - 'gstd3d11bufferpool.c', - 'gstd3d11device.c', - 'gstd3d11format.c', - 'gstd3d11memory.c', - 'gstd3d11utils.c', + 'gstd3d11bufferpool.cpp', + 'gstd3d11device.cpp', + 'gstd3d11format.cpp', + 'gstd3d11memory.cpp', + 'gstd3d11utils.cpp', ] dxgi_headers = [ @@ -33,9 +33,12 @@ endif have_d3d11 = false extra_c_args = [ '-DCOBJMACROS', +] +extra_comm_args = [ '-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_D3D11' ] + have_dxgi_header = false have_d3d11_header = false have_d3d11sdk_h = false @@ -162,11 +165,21 @@ endif # don't need to be defined in gstd3d11config.h since it's gstd3d11device internal if have_d3d11sdk_h - extra_c_args += ['-DHAVE_D3D11SDKLAYERS_H'] + extra_comm_args += ['-DHAVE_D3D11SDKLAYERS_H'] endif if have_dxgidebug_h - extra_c_args += ['-DHAVE_DXGIDEBUG_H'] + extra_comm_args += ['-DHAVE_DXGIDEBUG_H'] +endif + +# MinGW 32bits compiler seems to be complaining about redundant-decls +# when ComPtr is in use. Let's just disable the warning +if cc.get_id() != 'msvc' + extra_args = cc.get_supported_arguments([ + '-Wno-redundant-decls', + ]) + + extra_comm_args += extra_args endif configure_file( @@ -176,7 +189,8 @@ configure_file( gstd3d11 = library('gstd3d11-' + api_version, d3d11_sources, - c_args : gst_plugins_bad_args + extra_c_args, + c_args : gst_plugins_bad_args + extra_c_args + extra_comm_args, + cpp_args : gst_plugins_bad_args + extra_comm_args, include_directories : [configinc, libsinc], version : libversion, soversion : soversion,