mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
d3d11: Add a helper method for d3d11buffferpool setup
Remove duplicated code for d3d11buffferpool setup. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1892>
This commit is contained in:
parent
ac04681b6f
commit
f1e3e5276a
5 changed files with 91 additions and 121 deletions
|
@ -799,8 +799,8 @@ static gboolean
|
|||
gst_d3d11_compositor_configure_fallback_pool (GstD3D11Compositor * self,
|
||||
GstVideoInfo * info, gint bind_flags, GstBufferPool ** pool)
|
||||
{
|
||||
GstStructure *config;
|
||||
GstD3D11AllocationParams *d3d11_params;
|
||||
GstBufferPool *new_pool;
|
||||
GstCaps *caps;
|
||||
|
||||
if (*pool) {
|
||||
|
@ -814,28 +814,21 @@ gst_d3d11_compositor_configure_fallback_pool (GstD3D11Compositor * self,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
*pool = gst_d3d11_buffer_pool_new (self->device);
|
||||
config = gst_buffer_pool_get_config (*pool);
|
||||
gst_buffer_pool_config_set_params (config,
|
||||
caps, GST_VIDEO_INFO_SIZE (info), 0, 0);
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device,
|
||||
info, 0, bind_flags);
|
||||
|
||||
new_pool = gst_d3d11_buffer_pool_new_with_options (self->device,
|
||||
caps, d3d11_params, 0, 0);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
|
||||
if (!d3d11_params) {
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device,
|
||||
info, 0, bind_flags);
|
||||
} else {
|
||||
gint i;
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++)
|
||||
d3d11_params->desc[i].BindFlags |= bind_flags;
|
||||
}
|
||||
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params);
|
||||
gst_d3d11_allocation_params_free (d3d11_params);
|
||||
|
||||
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
gst_buffer_pool_set_config (*pool, config);
|
||||
gst_buffer_pool_set_active (*pool, TRUE);
|
||||
if (!new_pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to configure fallback pool");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gst_buffer_pool_set_active (new_pool, TRUE);
|
||||
*pool = new_pool;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1742,35 +1735,19 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * aggregator,
|
|||
return FALSE;
|
||||
|
||||
if (gst_query_get_n_allocation_pools (query) == 0) {
|
||||
GstStructure *config;
|
||||
GstD3D11AllocationParams *d3d11_params;
|
||||
gint i;
|
||||
|
||||
pool = gst_d3d11_buffer_pool_new (self->device);
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0,
|
||||
D3D11_BIND_SHADER_RESOURCE);
|
||||
|
||||
gst_buffer_pool_config_add_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
|
||||
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
|
||||
if (!d3d11_params) {
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0,
|
||||
D3D11_BIND_SHADER_RESOURCE);
|
||||
} else {
|
||||
/* Set bind flag */
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
|
||||
d3d11_params->desc[i].BindFlags |= D3D11_BIND_SHADER_RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params);
|
||||
pool = gst_d3d11_buffer_pool_new_with_options (self->device,
|
||||
caps, d3d11_params, 0, 0);
|
||||
gst_d3d11_allocation_params_free (d3d11_params);
|
||||
|
||||
size = GST_VIDEO_INFO_SIZE (&info);
|
||||
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
||||
|
||||
if (!gst_buffer_pool_set_config (pool, config))
|
||||
goto config_failed;
|
||||
if (!pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create buffer pool");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* d3d11 buffer pool might update buffer size by self */
|
||||
size = GST_D3D11_BUFFER_POOL (pool)->buffer_size;
|
||||
|
@ -1782,14 +1759,6 @@ gst_d3d11_compositor_propose_allocation (GstAggregator * aggregator,
|
|||
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
config_failed:
|
||||
{
|
||||
GST_ERROR_OBJECT (self, "failed to set config");
|
||||
gst_object_unref (pool);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -376,7 +376,6 @@ gst_d3d11_decoder_prepare_output_view_pool (GstD3D11Decoder * self,
|
|||
GstD3D11DecoderPrivate *priv = self->priv;
|
||||
GstD3D11AllocationParams *alloc_params = NULL;
|
||||
GstBufferPool *pool = NULL;
|
||||
GstStructure *config = NULL;
|
||||
GstCaps *caps = NULL;
|
||||
GstVideoAlignment align;
|
||||
GstD3D11AllocationFlags alloc_flags = 0;
|
||||
|
@ -410,29 +409,19 @@ gst_d3d11_decoder_prepare_output_view_pool (GstD3D11Decoder * self,
|
|||
goto error;
|
||||
}
|
||||
|
||||
pool = gst_d3d11_buffer_pool_new (priv->device);
|
||||
if (!pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create buffer pool");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Setup buffer pool */
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
caps = gst_video_info_to_caps (info);
|
||||
if (!caps) {
|
||||
GST_ERROR_OBJECT (self, "Couldn't convert video info to caps");
|
||||
goto error;
|
||||
}
|
||||
|
||||
gst_buffer_pool_config_set_params (config, caps, GST_VIDEO_INFO_SIZE (info),
|
||||
0, pool_size);
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, alloc_params);
|
||||
gst_caps_unref (caps);
|
||||
gst_d3d11_allocation_params_free (alloc_params);
|
||||
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
pool = gst_d3d11_buffer_pool_new_with_options (priv->device,
|
||||
caps, alloc_params, 0, pool_size);
|
||||
gst_clear_caps (&caps);
|
||||
g_clear_pointer (&alloc_params, gst_d3d11_allocation_params_free);
|
||||
|
||||
if (!gst_buffer_pool_set_config (pool, config)) {
|
||||
GST_ERROR_OBJECT (self, "Invalid pool config");
|
||||
if (!pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create buffer pool");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "gstd3d11utils.h"
|
||||
#include "gstd3d11device.h"
|
||||
#include "gstd3d11memory.h"
|
||||
#include "gstd3d11bufferpool.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <versionhelpers.h>
|
||||
|
@ -668,3 +668,38 @@ gst_d3d11_buffer_copy_into (GstBuffer * dst, GstBuffer * src)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GstBufferPool *
|
||||
gst_d3d11_buffer_pool_new_with_options (GstD3D11Device * device,
|
||||
GstCaps * caps, GstD3D11AllocationParams * alloc_params,
|
||||
guint min_buffers, guint max_buffers)
|
||||
{
|
||||
GstBufferPool *pool;
|
||||
GstStructure *config;
|
||||
GstVideoInfo info;
|
||||
|
||||
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
|
||||
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
|
||||
g_return_val_if_fail (alloc_params != NULL, NULL);
|
||||
|
||||
if (!gst_video_info_from_caps (&info, caps)) {
|
||||
GST_ERROR_OBJECT (device, "invalid caps");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pool = gst_d3d11_buffer_pool_new (device);
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_set_params (config,
|
||||
caps, GST_VIDEO_INFO_SIZE (&info), min_buffers, max_buffers);
|
||||
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, alloc_params);
|
||||
|
||||
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
if (!gst_buffer_pool_set_config (pool, config)) {
|
||||
GST_ERROR_OBJECT (pool, "Couldn't set config");
|
||||
gst_object_unref (pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <gst/video/video.h>
|
||||
|
||||
#include "gstd3d11_fwd.h"
|
||||
#include "gstd3d11memory.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -67,6 +68,13 @@ GstBuffer * gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
|
|||
gboolean gst_d3d11_buffer_copy_into (GstBuffer * dst,
|
||||
GstBuffer * src);
|
||||
|
||||
GstBufferPool * gst_d3d11_buffer_pool_new_with_options (GstD3D11Device * device,
|
||||
GstCaps * caps,
|
||||
GstD3D11AllocationParams * alloc_params,
|
||||
guint min_buffers,
|
||||
guint max_buffers);
|
||||
|
||||
|
||||
gboolean _gst_d3d11_result (HRESULT hr,
|
||||
GstD3D11Device * device,
|
||||
GstDebugCategory * cat,
|
||||
|
|
|
@ -367,8 +367,6 @@ gst_d3d11_video_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
|
|||
gint display_par_n = 1, display_par_d = 1; /* display's PAR */
|
||||
guint num, den;
|
||||
GError *error = NULL;
|
||||
GstStructure *config;
|
||||
gint i;
|
||||
|
||||
GST_DEBUG_OBJECT (self, "set caps %" GST_PTR_FORMAT, caps);
|
||||
|
||||
|
@ -462,14 +460,9 @@ gst_d3d11_video_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
|
|||
|
||||
if (self->fallback_pool) {
|
||||
gst_buffer_pool_set_active (self->fallback_pool, FALSE);
|
||||
gst_object_unref (self->fallback_pool);
|
||||
gst_clear_object (&self->fallback_pool);
|
||||
}
|
||||
|
||||
self->fallback_pool = gst_d3d11_buffer_pool_new (self->device);
|
||||
config = gst_buffer_pool_get_config (self->fallback_pool);
|
||||
gst_buffer_pool_config_set_params (config,
|
||||
caps, GST_VIDEO_INFO_SIZE (&self->info), 0, 2);
|
||||
|
||||
{
|
||||
GstD3D11AllocationParams *d3d11_params;
|
||||
gint bind_flags = D3D11_BIND_SHADER_RESOURCE;
|
||||
|
@ -488,23 +481,18 @@ gst_d3d11_video_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
|
|||
bind_flags |= D3D11_BIND_RENDER_TARGET;
|
||||
}
|
||||
|
||||
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
|
||||
if (!d3d11_params) {
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device,
|
||||
&self->info, 0, bind_flags);
|
||||
} else {
|
||||
/* Set bind flag */
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&self->info); i++) {
|
||||
d3d11_params->desc[i].BindFlags |= bind_flags;
|
||||
}
|
||||
}
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device,
|
||||
&self->info, 0, bind_flags);
|
||||
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params);
|
||||
self->fallback_pool = gst_d3d11_buffer_pool_new_with_options (self->device,
|
||||
caps, d3d11_params, 0, 2);
|
||||
gst_d3d11_allocation_params_free (d3d11_params);
|
||||
}
|
||||
|
||||
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
gst_buffer_pool_set_config (self->fallback_pool, config);
|
||||
if (!self->fallback_pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to configure fallback pool");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
@ -685,7 +673,6 @@ static gboolean
|
|||
gst_d3d11_video_sink_propose_allocation (GstBaseSink * sink, GstQuery * query)
|
||||
{
|
||||
GstD3D11VideoSink *self = GST_D3D11_VIDEO_SINK (sink);
|
||||
GstStructure *config;
|
||||
GstCaps *caps;
|
||||
GstBufferPool *pool = NULL;
|
||||
GstVideoInfo info;
|
||||
|
@ -707,39 +694,26 @@ gst_d3d11_video_sink_propose_allocation (GstBaseSink * sink, GstQuery * query)
|
|||
size = info.size;
|
||||
|
||||
if (need_pool) {
|
||||
gint i;
|
||||
GstD3D11AllocationParams *d3d11_params;
|
||||
|
||||
GST_DEBUG_OBJECT (self, "create new pool");
|
||||
|
||||
pool = gst_d3d11_buffer_pool_new (self->device);
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_set_params (config, caps, size, 2,
|
||||
DXGI_MAX_SWAP_CHAIN_BUFFERS);
|
||||
|
||||
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
|
||||
if (!d3d11_params) {
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0,
|
||||
D3D11_BIND_SHADER_RESOURCE);
|
||||
} else {
|
||||
/* Set bind flag */
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
|
||||
d3d11_params->desc[i].BindFlags |= D3D11_BIND_SHADER_RESOURCE;
|
||||
}
|
||||
}
|
||||
|
||||
gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params);
|
||||
d3d11_params = gst_d3d11_allocation_params_new (self->device, &info, 0,
|
||||
D3D11_BIND_SHADER_RESOURCE);
|
||||
pool = gst_d3d11_buffer_pool_new_with_options (self->device, caps,
|
||||
d3d11_params, 0, 2);
|
||||
gst_d3d11_allocation_params_free (d3d11_params);
|
||||
gst_buffer_pool_config_add_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
|
||||
if (!gst_buffer_pool_set_config (pool, config)) {
|
||||
g_object_unref (pool);
|
||||
goto config_failed;
|
||||
if (!pool) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create buffer pool");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size = GST_D3D11_BUFFER_POOL (pool)->buffer_size;
|
||||
}
|
||||
|
||||
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
||||
/* We don't need more than two buffers */
|
||||
gst_query_add_allocation_pool (query, pool, size, 0, 2);
|
||||
if (pool)
|
||||
g_object_unref (pool);
|
||||
|
||||
|
@ -760,11 +734,6 @@ invalid_caps:
|
|||
GST_WARNING_OBJECT (self, "invalid caps specified");
|
||||
return FALSE;
|
||||
}
|
||||
config_failed:
|
||||
{
|
||||
GST_WARNING_OBJECT (self, "failed setting config");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue