diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11.h index c64fc15b03..f92bdb3926 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11.h @@ -33,6 +33,5 @@ #include #include #include -#include #endif /* __GST_D3D11_H__ */ diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.cpp deleted file mode 100644 index cc8d2314d9..0000000000 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.cpp +++ /dev/null @@ -1,421 +0,0 @@ -/* GStreamer - * Copyright (C) 2022 Seungha Yang - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstd3d11stagingbufferpool.h" -#include "gstd3d11memory.h" -#include "gstd3d11device.h" -#include "gstd3d11utils.h" -#include "gstd3d11_private.h" - -#include - -GST_DEBUG_CATEGORY_STATIC (gst_d3d11_staging_buffer_pool_debug); -#define GST_CAT_DEFAULT gst_d3d11_staging_buffer_pool_debug - -struct _GstD3D11StagingBufferPoolPrivate -{ - GstVideoInfo info; - - D3D11_TEXTURE2D_DESC desc[GST_VIDEO_MAX_PLANES]; - GstD3D11Allocator *alloc[GST_VIDEO_MAX_PLANES]; - gint stride[GST_VIDEO_MAX_PLANES]; - gsize offset[GST_VIDEO_MAX_PLANES]; -}; - -#define gst_d3d11_staging_buffer_pool_parent_class parent_class -G_DEFINE_TYPE_WITH_PRIVATE (GstD3D11StagingBufferPool, - gst_d3d11_staging_buffer_pool, GST_TYPE_BUFFER_POOL); - -static void gst_d3d11_staging_buffer_pool_dispose (GObject * object); -static const gchar **gst_d3d11_staging_buffer_pool_get_options (GstBufferPool * - pool); -static gboolean gst_d3d11_staging_buffer_pool_set_config (GstBufferPool * pool, - GstStructure * config); -static GstFlowReturn gst_d3d11_staging_buffer_pool_alloc_buffer (GstBufferPool * - pool, GstBuffer ** buffer, GstBufferPoolAcquireParams * params); -static gboolean gst_d3d11_staging_buffer_pool_start (GstBufferPool * pool); -static gboolean gst_d3d11_staging_buffer_pool_stop (GstBufferPool * pool); - -static void -gst_d3d11_staging_buffer_pool_class_init (GstD3D11StagingBufferPoolClass * - klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstBufferPoolClass *bufferpool_class = GST_BUFFER_POOL_CLASS (klass); - - gobject_class->dispose = gst_d3d11_staging_buffer_pool_dispose; - - bufferpool_class->get_options = gst_d3d11_staging_buffer_pool_get_options; - bufferpool_class->set_config = gst_d3d11_staging_buffer_pool_set_config; - bufferpool_class->alloc_buffer = gst_d3d11_staging_buffer_pool_alloc_buffer; - bufferpool_class->start = gst_d3d11_staging_buffer_pool_start; - bufferpool_class->stop = gst_d3d11_staging_buffer_pool_stop; - - GST_DEBUG_CATEGORY_INIT (gst_d3d11_staging_buffer_pool_debug, - "d3d11stagingbufferpool", 0, "d3d11stagingbufferpool object"); -} - -static void -gst_d3d11_staging_buffer_pool_init (GstD3D11StagingBufferPool * self) -{ - self->priv = (GstD3D11StagingBufferPoolPrivate *) - gst_d3d11_staging_buffer_pool_get_instance_private (self); -} - -static void -gst_d3d11_staging_buffer_pool_clear_allocator (GstD3D11StagingBufferPool * self) -{ - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - - for (guint i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { - if (priv->alloc[i]) { - gst_d3d11_allocator_set_active (priv->alloc[i], FALSE); - gst_clear_object (&priv->alloc[i]); - } - } -} - -static void -gst_d3d11_staging_buffer_pool_dispose (GObject * object) -{ - GstD3D11StagingBufferPool *self = GST_D3D11_STAGING_BUFFER_POOL (object); - - gst_clear_object (&self->device); - gst_d3d11_staging_buffer_pool_clear_allocator (self); - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static const gchar ** -gst_d3d11_staging_buffer_pool_get_options (GstBufferPool * pool) -{ - /* NOTE: d3d11 memory does not support alignment */ - static const gchar *options[] = - { GST_BUFFER_POOL_OPTION_VIDEO_META, nullptr }; - - return options; -} - -static gboolean -gst_d3d11_staging_buffer_pool_set_config (GstBufferPool * pool, - GstStructure * config) -{ - GstD3D11StagingBufferPool *self = GST_D3D11_STAGING_BUFFER_POOL (pool); - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - GstVideoInfo info; - GstCaps *caps = nullptr; - guint min_buffers, max_buffers; - D3D11_TEXTURE2D_DESC *desc; - GstD3D11Format format; - gsize offset = 0; - - if (!gst_buffer_pool_config_get_params (config, &caps, nullptr, &min_buffers, - &max_buffers)) - goto wrong_config; - - if (caps == nullptr) - goto no_caps; - - /* now parse the caps from the config */ - if (!gst_video_info_from_caps (&info, caps)) - goto wrong_caps; - - if (!gst_d3d11_device_get_format (self->device, GST_VIDEO_INFO_FORMAT (&info), - &format)) { - goto wrong_caps; - } - - GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height, - caps); - - gst_d3d11_staging_buffer_pool_clear_allocator (self); - - memset (priv->stride, 0, sizeof (priv->stride)); - memset (priv->offset, 0, sizeof (priv->offset)); - memset (priv->desc, 0, sizeof (priv->desc)); - - if (format.dxgi_format == DXGI_FORMAT_UNKNOWN) { - for (guint i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) { - desc = &priv->desc[i]; - - desc->Width = GST_VIDEO_INFO_COMP_WIDTH (&info, i); - desc->Height = GST_VIDEO_INFO_COMP_HEIGHT (&info, i); - desc->MipLevels = 1; - desc->ArraySize = 1; - desc->Format = format.resource_format[i]; - desc->SampleDesc.Count = 1; - desc->Usage = D3D11_USAGE_STAGING; - desc->CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } - } else { - guint width, height; - guint align; - - desc = &priv->desc[0]; - - width = GST_VIDEO_INFO_WIDTH (&info); - height = GST_VIDEO_INFO_HEIGHT (&info); - - align = gst_d3d11_dxgi_format_get_alignment (format.dxgi_format); - - /* resolution of semi-planar formats must be multiple of 2 */ - if (align != 0) { - width = GST_ROUND_UP_N (width, align); - height = GST_ROUND_UP_N (height, align); - } - - desc->Width = width; - desc->Height = height; - desc->MipLevels = 1; - desc->ArraySize = 1; - desc->Format = format.dxgi_format; - desc->SampleDesc.Count = 1; - desc->Usage = D3D11_USAGE_STAGING; - desc->CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } - - offset = 0; - for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++) { - GstD3D11Allocator *alloc; - GstD3D11PoolAllocator *pool_alloc; - GstFlowReturn flow_ret; - GstMemory *mem = nullptr; - guint stride = 0; - - if (priv->desc[i].Format == DXGI_FORMAT_UNKNOWN) - break; - - alloc = - (GstD3D11Allocator *) gst_d3d11_pool_allocator_new (self->device, - &priv->desc[i]); - if (!gst_d3d11_allocator_set_active (alloc, TRUE)) { - GST_ERROR_OBJECT (self, "Failed to activate allocator"); - gst_object_unref (alloc); - return FALSE; - } - - pool_alloc = GST_D3D11_POOL_ALLOCATOR (alloc); - flow_ret = gst_d3d11_pool_allocator_acquire_memory (pool_alloc, &mem); - if (flow_ret != GST_FLOW_OK) { - GST_ERROR_OBJECT (self, "Failed to allocate initial memory"); - gst_d3d11_allocator_set_active (alloc, FALSE); - gst_object_unref (alloc); - return FALSE; - } - - if (!gst_d3d11_memory_get_resource_stride (GST_D3D11_MEMORY_CAST (mem), - &stride) || stride < priv->desc[i].Width) { - GST_ERROR_OBJECT (self, "Failed to calculate stride"); - - gst_d3d11_allocator_set_active (alloc, FALSE); - gst_object_unref (alloc); - gst_memory_unref (mem); - - return FALSE; - } - - priv->stride[i] = stride; - priv->offset[i] = offset; - offset += mem->size; - - priv->alloc[i] = alloc; - - gst_memory_unref (mem); - } - - /* single texture semi-planar formats */ - if (format.dxgi_format != DXGI_FORMAT_UNKNOWN && - GST_VIDEO_INFO_N_PLANES (&info) == 2) { - priv->stride[1] = priv->stride[0]; - priv->offset[1] = priv->stride[0] * priv->desc[0].Height; - } - - gst_buffer_pool_config_set_params (config, - caps, offset, min_buffers, max_buffers); - - priv->info = info; - - return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config); - - /* ERRORS */ -wrong_config: - { - GST_WARNING_OBJECT (pool, "invalid config"); - return FALSE; - } -no_caps: - { - GST_WARNING_OBJECT (pool, "no caps in config"); - return FALSE; - } -wrong_caps: - { - GST_WARNING_OBJECT (pool, - "failed getting geometry from caps %" GST_PTR_FORMAT, caps); - return FALSE; - } -} - -static GstFlowReturn -gst_d3d11_staging_buffer_pool_fill_buffer (GstD3D11StagingBufferPool * self, - GstBuffer * buf) -{ - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - GstFlowReturn ret = GST_FLOW_OK; - - for (guint i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { - GstMemory *mem = nullptr; - GstD3D11PoolAllocator *alloc = GST_D3D11_POOL_ALLOCATOR (priv->alloc[i]); - - if (!alloc) - break; - - ret = gst_d3d11_pool_allocator_acquire_memory (alloc, &mem); - if (ret != GST_FLOW_OK) { - GST_WARNING_OBJECT (self, "Failed to acquire memory, ret %s", - gst_flow_get_name (ret)); - return ret; - } - - gst_buffer_append_memory (buf, mem); - } - - return GST_FLOW_OK; -} - -static GstFlowReturn -gst_d3d11_staging_buffer_pool_alloc_buffer (GstBufferPool * pool, - GstBuffer ** buffer, GstBufferPoolAcquireParams * params) -{ - GstD3D11StagingBufferPool *self = GST_D3D11_STAGING_BUFFER_POOL (pool); - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - GstVideoInfo *info = &priv->info; - GstBuffer *buf; - GstFlowReturn ret = GST_FLOW_OK; - - buf = gst_buffer_new (); - ret = gst_d3d11_staging_buffer_pool_fill_buffer (self, buf); - if (ret != GST_FLOW_OK) { - gst_buffer_unref (buf); - return ret; - } - - gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE, - GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info), - GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info), - priv->offset, priv->stride); - - *buffer = buf; - - return GST_FLOW_OK; -} - -static gboolean -gst_d3d11_staging_buffer_pool_start (GstBufferPool * pool) -{ - GstD3D11StagingBufferPool *self = GST_D3D11_STAGING_BUFFER_POOL (pool); - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - gboolean ret; - - GST_DEBUG_OBJECT (self, "Start"); - - for (guint i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { - GstD3D11Allocator *alloc = priv->alloc[i]; - - if (!alloc) - break; - - if (!gst_d3d11_allocator_set_active (alloc, TRUE)) { - GST_ERROR_OBJECT (self, "Failed to activate allocator"); - return FALSE; - } - } - - ret = GST_BUFFER_POOL_CLASS (parent_class)->start (pool); - if (!ret) { - GST_ERROR_OBJECT (self, "Failed to start"); - - for (guint i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { - GstD3D11Allocator *alloc = priv->alloc[i]; - - if (!alloc) - break; - - gst_d3d11_allocator_set_active (alloc, FALSE); - } - - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_d3d11_staging_buffer_pool_stop (GstBufferPool * pool) -{ - GstD3D11StagingBufferPool *self = GST_D3D11_STAGING_BUFFER_POOL (pool); - GstD3D11StagingBufferPoolPrivate *priv = self->priv; - - GST_DEBUG_OBJECT (self, "Stop"); - - for (guint i = 0; i < G_N_ELEMENTS (priv->alloc); i++) { - GstD3D11Allocator *alloc = priv->alloc[i]; - - if (!alloc) - break; - - if (!gst_d3d11_allocator_set_active (alloc, FALSE)) { - GST_ERROR_OBJECT (self, "Failed to deactivate allocator"); - return FALSE; - } - } - - return GST_BUFFER_POOL_CLASS (parent_class)->stop (pool); -} - -/** - * gst_d3d11_staging_buffer_pool_new: - * @device: a #GstD3D11Device to use - * - * Returns: a #GstBufferPool that allocates buffers with #GstD3D11Memory - * which hold Direct3D11 staging texture allocated with D3D11_USAGE_STAGING - * flag, instead of D3D11_USAGE_DEFAULT. The staging texture can be used for - * optimized resource upload/download. - * - * Since: 1.22 - */ -GstBufferPool * -gst_d3d11_staging_buffer_pool_new (GstD3D11Device * device) -{ - GstD3D11StagingBufferPool *pool; - - g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), nullptr); - - pool = (GstD3D11StagingBufferPool *) - g_object_new (GST_TYPE_D3D11_STAGING_BUFFER_POOL, nullptr); - gst_object_ref_sink (pool); - - pool->device = (GstD3D11Device *) gst_object_ref (device); - - return GST_BUFFER_POOL_CAST (pool); -} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.h deleted file mode 100644 index 3bcd2d0f29..0000000000 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11stagingbufferpool.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GStreamer - * Copyright (C) 2022 Seungha Yang - * - * 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. - */ - -#pragma once - -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_D3D11_STAGING_BUFFER_POOL (gst_d3d11_staging_buffer_pool_get_type()) -#define GST_D3D11_STAGING_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_D3D11_STAGING_BUFFER_POOL, GstD3D11StagingBufferPool)) -#define GST_D3D11_STAGING_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS((klass), GST_TYPE_D3D11_STAGING_BUFFER_POOL, GstD3D11StagingBufferPoolClass)) -#define GST_IS_D3D11_STAGING_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_D3D11_STAGING_BUFFER_POOL)) -#define GST_IS_D3D11_STAGING_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_STAGING_BUFFER_POOL)) -#define GST_D3D11_STAGING_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_STAGING_BUFFER_POOL, GstD3D11StagingBufferPoolClass)) - -struct _GstD3D11StagingBufferPool -{ - GstBufferPool parent; - - GstD3D11Device *device; - - /*< private >*/ - GstD3D11StagingBufferPoolPrivate *priv; - - gpointer _gst_reserved[GST_PADDING]; -}; - -struct _GstD3D11StagingBufferPoolClass -{ - GstBufferPoolClass bufferpool_class; - - /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; -}; - -GST_D3D11_API -GType gst_d3d11_staging_buffer_pool_get_type (void); - -GST_D3D11_API -GstBufferPool * gst_d3d11_staging_buffer_pool_new (GstD3D11Device * device); - -G_END_DECLS - diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build index 92c5ba7bc4..b1e9a2d52e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build @@ -3,7 +3,6 @@ d3d11_sources = [ 'gstd3d11device.cpp', 'gstd3d11format.cpp', 'gstd3d11memory.cpp', - 'gstd3d11stagingbufferpool.cpp', 'gstd3d11utils.cpp', ] diff --git a/subprojects/gst-plugins-bad/sys/amfcodec/gstamfencoder.cpp b/subprojects/gst-plugins-bad/sys/amfcodec/gstamfencoder.cpp index 4cebd8022c..9ce5b4b859 100644 --- a/subprojects/gst-plugins-bad/sys/amfcodec/gstamfencoder.cpp +++ b/subprojects/gst-plugins-bad/sys/amfcodec/gstamfencoder.cpp @@ -360,7 +360,7 @@ gst_amf_encoder_try_output (GstAmfEncoder * self, gboolean do_wait) ret = gst_amf_encoder_process_output (self, buffer.GetPtr ()); if (ret != GST_FLOW_OK) { GST_INFO_OBJECT (self, "Process output returned %s", - gst_flow_get_name (ret)); + gst_flow_get_name (ret)); } } else if (result == AMF_REPEAT || result == AMF_OK) { GST_TRACE_OBJECT (self, "Output is not ready, do_wait %d", do_wait); @@ -374,7 +374,7 @@ gst_amf_encoder_try_output (GstAmfEncoder * self, gboolean do_wait) ret = GST_VIDEO_ENCODER_FLOW_NEED_DATA; } else { GST_ERROR_OBJECT (self, "query output returned %" GST_AMF_RESULT_FORMAT, - GST_AMF_RESULT_ARGS (result)); + GST_AMF_RESULT_ARGS (result)); ret = GST_FLOW_ERROR; } } while (ret == GST_FLOW_OK); @@ -1014,6 +1014,8 @@ gst_amf_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) guint size; GstStructure *config; GstCapsFeatures *features; + gboolean is_d3d11 = FALSE; + guint min_buffers = 0; gst_query_parse_allocation (query, &caps, nullptr); if (!caps) { @@ -1031,18 +1033,24 @@ gst_amf_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) { GST_DEBUG_OBJECT (self, "upstream support d3d11 memory"); pool = gst_d3d11_buffer_pool_new (device); + is_d3d11 = TRUE; + + /* XXX: AMF API does not provide information about internal queue size, + * use hardcoded value 16 */ + min_buffers = 16; } else { - pool = gst_d3d11_staging_buffer_pool_new (device); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); + if (!is_d3d11) { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); + } size = GST_VIDEO_INFO_SIZE (&info); - - /* XXX: AMF API does not provide information about internal queue size, - * use hardcoded value 16 */ - gst_buffer_pool_config_set_params (config, caps, size, 16, 0); + gst_buffer_pool_config_set_params (config, caps, size, min_buffers, 0); if (!gst_buffer_pool_set_config (pool, config)) { GST_WARNING_OBJECT (self, "Failed to set pool config"); @@ -1057,7 +1065,7 @@ gst_amf_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) gst_buffer_pool_config_get_params (config, nullptr, &size, nullptr, nullptr); gst_structure_free (config); - gst_query_add_allocation_pool (query, pool, size, 16, 0); + gst_query_add_allocation_pool (query, pool, size, min_buffers, 0); gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, nullptr); gst_object_unref (pool); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp index 0e89ca526b..5ef48d0a3b 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp @@ -1807,7 +1807,7 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * agg, pool = gst_d3d11_buffer_pool_new (self->device); is_d3d11 = TRUE; } else { - pool = gst_d3d11_staging_buffer_pool_new (self->device); + pool = gst_video_buffer_pool_new (); } if (!pool) { @@ -1829,6 +1829,9 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * agg, gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params); gst_d3d11_allocation_params_free (d3d11_params); + } else { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); } gst_buffer_pool_config_set_params (config, caps, (guint) size, 0, 0); @@ -1866,7 +1869,6 @@ gst_d3d11_compositor_decide_allocation (GstAggregator * agg, GstQuery * query) GstVideoInfo info; GstStructure *config; gboolean use_d3d11_pool; - gboolean has_videometa; gst_query_parse_allocation (query, &caps, nullptr); @@ -1880,8 +1882,6 @@ gst_d3d11_compositor_decide_allocation (GstAggregator * agg, GstQuery * query) return FALSE; } - has_videometa = gst_query_find_allocation_meta (query, - GST_VIDEO_META_API_TYPE, nullptr); use_d3d11_pool = self->downstream_supports_d3d11; n = gst_query_get_n_allocation_pools (query); @@ -1889,22 +1889,17 @@ gst_d3d11_compositor_decide_allocation (GstAggregator * agg, GstQuery * query) gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); /* create our own pool */ - if (pool) { - if (use_d3d11_pool) { - if (!GST_IS_D3D11_BUFFER_POOL (pool)) { - GST_DEBUG_OBJECT (self, - "Downstream pool is not d3d11, will create new one"); - gst_clear_object (&pool); - } else { - GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); - if (dpool->device != self->device) { - GST_DEBUG_OBJECT (self, "Different device, will create new one"); - gst_clear_object (&pool); - } - } - } else if (has_videometa) { - /* We will use d3d11 staging buffer pool */ + if (pool && use_d3d11_pool) { + if (!GST_IS_D3D11_BUFFER_POOL (pool)) { + GST_DEBUG_OBJECT (self, + "Downstream pool is not d3d11, will create new one"); gst_clear_object (&pool); + } else { + GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); + if (dpool->device != self->device) { + GST_DEBUG_OBJECT (self, "Different device, will create new one"); + gst_clear_object (&pool); + } } } @@ -1913,8 +1908,6 @@ gst_d3d11_compositor_decide_allocation (GstAggregator * agg, GstQuery * query) if (!pool) { if (use_d3d11_pool) pool = gst_d3d11_buffer_pool_new (self->device); - else if (has_videometa) - pool = gst_d3d11_staging_buffer_pool_new (self->device); else pool = gst_video_buffer_pool_new (); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp index 3826d2586b..d5e4c259b0 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp @@ -1722,7 +1722,6 @@ gst_d3d11_decoder_decide_allocation (GstD3D11Decoder * decoder, GstStructure *config; GstD3D11AllocationParams *d3d11_params; gboolean use_d3d11_pool; - gboolean has_videometa; g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE); g_return_val_if_fail (GST_IS_VIDEO_DECODER (videodec), FALSE); @@ -1740,8 +1739,6 @@ gst_d3d11_decoder_decide_allocation (GstD3D11Decoder * decoder, return FALSE; } - has_videometa = gst_query_find_allocation_meta (query, - GST_VIDEO_META_API_TYPE, nullptr); use_d3d11_pool = decoder->downstream_supports_d3d11; if (use_d3d11_pool) { decoder->use_crop_meta = @@ -1759,30 +1756,23 @@ gst_d3d11_decoder_decide_allocation (GstD3D11Decoder * decoder, gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); /* create our own pool */ - if (pool) { - if (use_d3d11_pool) { - if (!GST_IS_D3D11_BUFFER_POOL (pool)) { - GST_DEBUG_OBJECT (videodec, - "Downstream pool is not d3d11, will create new one"); - gst_clear_object (&pool); - } else { - GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); - if (dpool->device != decoder->device) { - GST_DEBUG_OBJECT (videodec, "Different device, will create new one"); - gst_clear_object (&pool); - } - } - } else if (has_videometa) { - /* We will use d3d11 staging buffer pool */ + if (pool && use_d3d11_pool) { + if (!GST_IS_D3D11_BUFFER_POOL (pool)) { + GST_DEBUG_OBJECT (videodec, + "Downstream pool is not d3d11, will create new one"); gst_clear_object (&pool); + } else { + GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); + if (dpool->device != decoder->device) { + GST_DEBUG_OBJECT (videodec, "Different device, will create new one"); + gst_clear_object (&pool); + } } } if (!pool) { if (use_d3d11_pool) pool = gst_d3d11_buffer_pool_new (decoder->device); - else if (has_videometa) - pool = gst_d3d11_staging_buffer_pool_new (decoder->device); else pool = gst_video_buffer_pool_new (); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11download.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11download.cpp index 20a7bcb4de..31da780f1c 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11download.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11download.cpp @@ -189,6 +189,7 @@ gst_d3d11_download_propose_allocation (GstBaseTransform * trans, GstBufferPool *pool; GstCaps *caps; guint size; + gboolean is_d3d11 = FALSE; if (!GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans, decide_query, query)) @@ -216,14 +217,19 @@ gst_d3d11_download_propose_allocation (GstBaseTransform * trans, GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) { GST_DEBUG_OBJECT (filter, "upstream support d3d11 memory"); pool = gst_d3d11_buffer_pool_new (filter->device); + is_d3d11 = TRUE; } else { - pool = gst_d3d11_staging_buffer_pool_new (filter->device); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); + if (!is_d3d11) { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); + } size = GST_VIDEO_INFO_SIZE (&info); gst_buffer_pool_config_set_params (config, caps, size, 0, 0); @@ -261,12 +267,10 @@ static gboolean gst_d3d11_download_decide_allocation (GstBaseTransform * trans, GstQuery * query) { - GstD3D11BaseFilter *filter = GST_D3D11_BASE_FILTER (trans); GstBufferPool *pool = NULL; GstStructure *config; guint min, max, size; gboolean update_pool; - gboolean has_videometa; GstCaps *outcaps = NULL; gst_query_parse_allocation (query, &outcaps, NULL); @@ -287,14 +291,8 @@ gst_d3d11_download_decide_allocation (GstBaseTransform * trans, update_pool = FALSE; } - has_videometa = gst_query_find_allocation_meta (query, - GST_VIDEO_META_API_TYPE, nullptr); - if (!pool) { - if (has_videometa) - pool = gst_d3d11_staging_buffer_pool_new (filter->device); - else - pool = gst_video_buffer_pool_new (); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp index f5b0d7c7b3..4b4477c946 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp @@ -476,7 +476,6 @@ gst_d3d11_screen_capture_src_decide_allocation (GstBaseSrc * bsrc, guint min, max, size; gboolean update_pool; GstVideoInfo vinfo; - gboolean has_videometa; if (self->pool) { gst_buffer_pool_set_active (self->pool, FALSE); @@ -485,9 +484,6 @@ gst_d3d11_screen_capture_src_decide_allocation (GstBaseSrc * bsrc, gst_query_parse_allocation (query, &caps, NULL); - has_videometa = gst_query_find_allocation_meta (query, - GST_VIDEO_META_API_TYPE, nullptr); - if (!caps) { GST_ERROR_OBJECT (self, "No output caps"); return FALSE; @@ -505,26 +501,19 @@ gst_d3d11_screen_capture_src_decide_allocation (GstBaseSrc * bsrc, update_pool = FALSE; } - if (pool) { - if (self->downstream_supports_d3d11) { - if (!GST_IS_D3D11_BUFFER_POOL (pool)) { - gst_clear_object (&pool); - } else { - GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); - if (dpool->device != self->device) - gst_clear_object (&pool); - } - } else if (has_videometa) { - /* We will use staging buffer pool for better performance */ + if (pool && self->downstream_supports_d3d11) { + if (!GST_IS_D3D11_BUFFER_POOL (pool)) { gst_clear_object (&pool); + } else { + GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); + if (dpool->device != self->device) + gst_clear_object (&pool); } } if (!pool) { if (self->downstream_supports_d3d11) pool = gst_d3d11_buffer_pool_new (self->device); - else if (has_videometa) - pool = gst_d3d11_staging_buffer_pool_new (self->device); else pool = gst_video_buffer_pool_new (); } diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp index 0ae5cc1bd0..935438234c 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp @@ -1433,13 +1433,9 @@ gst_d3d11_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query) guint min, max, size; gboolean update_pool; GstVideoInfo vinfo; - gboolean has_videometa; gst_query_parse_allocation (query, &caps, nullptr); - has_videometa = gst_query_find_allocation_meta (query, - GST_VIDEO_META_API_TYPE, nullptr); - if (!caps) { GST_ERROR_OBJECT (self, "No output caps"); return FALSE; @@ -1457,26 +1453,19 @@ gst_d3d11_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query) update_pool = FALSE; } - if (pool) { - if (self->downstream_supports_d3d11) { - if (!GST_IS_D3D11_BUFFER_POOL (pool)) { - gst_clear_object (&pool); - } else { - GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); - if (dpool->device != self->device) - gst_clear_object (&pool); - } - } else if (has_videometa) { - /* We will use staging buffer pool for better performance */ + if (pool && self->downstream_supports_d3d11) { + if (!GST_IS_D3D11_BUFFER_POOL (pool)) { gst_clear_object (&pool); + } else { + GstD3D11BufferPool *dpool = GST_D3D11_BUFFER_POOL (pool); + if (dpool->device != self->device) + gst_clear_object (&pool); } } if (!pool) { if (self->downstream_supports_d3d11) pool = gst_d3d11_buffer_pool_new (self->device); - else if (has_videometa) - pool = gst_d3d11_staging_buffer_pool_new (self->device); else pool = gst_video_buffer_pool_new (); } diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11upload.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11upload.cpp index 05b0b3bcef..42505ca1bb 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11upload.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11upload.cpp @@ -222,6 +222,7 @@ gst_d3d11_upload_propose_allocation (GstBaseTransform * trans, GstBufferPool *pool; GstCaps *caps; guint size; + gboolean is_d3d11 = FALSE; if (!GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans, decide_query, query)) @@ -248,14 +249,19 @@ gst_d3d11_upload_propose_allocation (GstBaseTransform * trans, GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) { GST_DEBUG_OBJECT (filter, "upstream support d3d11 memory"); pool = gst_d3d11_buffer_pool_new (filter->device); + is_d3d11 = TRUE; } else { - pool = gst_d3d11_staging_buffer_pool_new (filter->device); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); + if (!is_d3d11) { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); + } size = GST_VIDEO_INFO_SIZE (&info); gst_buffer_pool_config_set_params (config, caps, size, 0, 0); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11videosink.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11videosink.cpp index 7bdc29ef79..2a8a97a5d0 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11videosink.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11videosink.cpp @@ -881,7 +881,7 @@ gst_d3d11_video_sink_propose_allocation (GstBaseSink * sink, GstQuery * query) if (need_pool) { GstCapsFeatures *features; GstStructure *config; - gboolean is_d3d11 = false; + gboolean is_d3d11 = FALSE; features = gst_caps_get_features (caps, 0); if (features @@ -889,14 +889,18 @@ gst_d3d11_video_sink_propose_allocation (GstBaseSink * sink, GstQuery * query) GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY)) { GST_DEBUG_OBJECT (self, "upstream support d3d11 memory"); pool = gst_d3d11_buffer_pool_new (self->device); - is_d3d11 = true; + is_d3d11 = TRUE; } else { - pool = gst_d3d11_staging_buffer_pool_new (self->device); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); + if (!is_d3d11) { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); + } size = GST_VIDEO_INFO_SIZE (&info); if (is_d3d11) { diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_d3d11.cpp b/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_d3d11.cpp index 0a784e7179..33be0fa1ed 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_d3d11.cpp +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_d3d11.cpp @@ -451,6 +451,7 @@ gst_qsv_d3d11_allocator_download (GstQsvAllocator * allocator, const GstVideoInfo * info, gboolean force_copy, GstQsvFrame * frame, GstBufferPool * pool) { + GstD3D11BufferPool *d3d11_pool; GstBuffer *src_buf, *dst_buf; GstMemory *mem; GstD3D11Memory *dmem; @@ -469,30 +470,19 @@ gst_qsv_d3d11_allocator_download (GstQsvAllocator * allocator, return nullptr; } - if (!GST_IS_D3D11_BUFFER_POOL (pool) && - !GST_IS_D3D11_STAGING_BUFFER_POOL (pool)) { + if (!GST_IS_D3D11_BUFFER_POOL (pool)) { GST_TRACE_OBJECT (allocator, "Output is not d3d11 memory"); goto fallback; } dmem = GST_D3D11_MEMORY_CAST (mem); - /* both pool and qsvframe should hold the same d3d11 device already */ - if (GST_IS_D3D11_BUFFER_POOL (pool)) { - GstD3D11BufferPool *d3d11_pool = GST_D3D11_BUFFER_POOL (pool); - - if (d3d11_pool->device != dmem->device) { - GST_WARNING_OBJECT (allocator, "Pool holds different device"); - goto fallback; - } - } else { - GstD3D11StagingBufferPool *d3d11_pool = - GST_D3D11_STAGING_BUFFER_POOL (pool); - - if (d3d11_pool->device != dmem->device) { - GST_WARNING_OBJECT (allocator, "Staging pool holds different device"); - goto fallback; - } + /* both pool and qsvframe should hold the same d3d11 device already, + * but checking again */ + d3d11_pool = GST_D3D11_BUFFER_POOL (pool); + if (d3d11_pool->device != dmem->device) { + GST_WARNING_OBJECT (allocator, "Pool holds different device"); + goto fallback; } ret = gst_buffer_pool_acquire_buffer (pool, &dst_buf, nullptr); diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp index 88bbf89d66..093b0f582b 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp @@ -1466,7 +1466,7 @@ gst_qsv_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) pool = gst_d3d11_buffer_pool_new (device); is_d3d11 = TRUE; } else { - pool = gst_d3d11_staging_buffer_pool_new (device); + pool = gst_video_buffer_pool_new (); } config = gst_buffer_pool_get_config (pool); @@ -1492,6 +1492,9 @@ gst_qsv_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) gst_d3d11_allocation_params_alignment (d3d11_params, &align); gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params); gst_d3d11_allocation_params_free (d3d11_params); + } else { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT); } size = GST_VIDEO_INFO_SIZE (&info);