mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
d3d11: Don't find global default allocator
We were using global default allocator already. Pass null allocator object to *_alloc() methods then the method will use default allocator. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2843>
This commit is contained in:
parent
21e5c33797
commit
66d504ee58
7 changed files with 6 additions and 74 deletions
|
@ -218,7 +218,6 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
|
||||||
{
|
{
|
||||||
GstD3D11Memory *dmem;
|
GstD3D11Memory *dmem;
|
||||||
GstD3D11Device *device;
|
GstD3D11Device *device;
|
||||||
GstD3D11Allocator *alloc = NULL;
|
|
||||||
GstBuffer *staging_buffer = NULL;
|
GstBuffer *staging_buffer = NULL;
|
||||||
gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
|
gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
|
||||||
gsize offset[GST_VIDEO_MAX_PLANES] = { 0, };
|
gsize offset[GST_VIDEO_MAX_PLANES] = { 0, };
|
||||||
|
@ -245,12 +244,6 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc = (GstD3D11Allocator *) gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!alloc) {
|
|
||||||
GST_ERROR ("D3D11 allocator is not available");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
staging_buffer = gst_buffer_new ();
|
staging_buffer = gst_buffer_new ();
|
||||||
for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
|
for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
|
||||||
D3D11_TEXTURE2D_DESC staging_desc;
|
D3D11_TEXTURE2D_DESC staging_desc;
|
||||||
|
@ -263,7 +256,7 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
|
||||||
fill_staging_desc (&desc, &staging_desc);
|
fill_staging_desc (&desc, &staging_desc);
|
||||||
|
|
||||||
new_mem = (GstD3D11Memory *)
|
new_mem = (GstD3D11Memory *)
|
||||||
gst_d3d11_allocator_alloc (alloc, mem->device, &staging_desc);
|
gst_d3d11_allocator_alloc (nullptr, mem->device, &staging_desc);
|
||||||
if (!new_mem) {
|
if (!new_mem) {
|
||||||
GST_ERROR ("Failed to allocate memory");
|
GST_ERROR ("Failed to allocate memory");
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -295,14 +288,10 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
|
||||||
GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
|
GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
|
||||||
offset, stride);
|
offset, stride);
|
||||||
|
|
||||||
if (alloc)
|
|
||||||
gst_object_unref (alloc);
|
|
||||||
|
|
||||||
return staging_buffer;
|
return staging_buffer;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
gst_clear_buffer (&staging_buffer);
|
gst_clear_buffer (&staging_buffer);
|
||||||
gst_clear_object (&alloc);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,6 @@ gst_d3d11_window_dispose (GObject * object)
|
||||||
|
|
||||||
gst_clear_buffer (&self->cached_buffer);
|
gst_clear_buffer (&self->cached_buffer);
|
||||||
gst_clear_object (&self->device);
|
gst_clear_object (&self->device);
|
||||||
gst_clear_object (&self->allocator);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
@ -316,7 +315,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width,
|
||||||
size *= 4;
|
size *= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem = gst_d3d11_allocator_alloc_wrapped (self->allocator,
|
mem = gst_d3d11_allocator_alloc_wrapped (nullptr,
|
||||||
self->device, backbuffer.Get (), size, nullptr, nullptr);
|
self->device, backbuffer.Get (), size, nullptr, nullptr);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
GST_ERROR_OBJECT (self, "Couldn't allocate wrapped memory");
|
GST_ERROR_OBJECT (self, "Couldn't allocate wrapped memory");
|
||||||
|
@ -548,18 +547,6 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
|
||||||
const gchar *cll_str = nullptr;
|
const gchar *cll_str = nullptr;
|
||||||
const gchar *mdcv_str = nullptr;
|
const gchar *mdcv_str = nullptr;
|
||||||
|
|
||||||
if (!window->allocator) {
|
|
||||||
window->allocator =
|
|
||||||
(GstD3D11Allocator *) gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!window->allocator) {
|
|
||||||
GST_ERROR_OBJECT (window, "Allocator is unavailable");
|
|
||||||
if (config)
|
|
||||||
gst_structure_free (config);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Step 1: Clear old resources and objects */
|
/* Step 1: Clear old resources and objects */
|
||||||
gst_clear_buffer (&window->cached_buffer);
|
gst_clear_buffer (&window->cached_buffer);
|
||||||
gst_clear_object (&window->compositor);
|
gst_clear_object (&window->compositor);
|
||||||
|
|
|
@ -78,7 +78,6 @@ struct _GstD3D11Window
|
||||||
/*< protected >*/
|
/*< protected >*/
|
||||||
gboolean initialized;
|
gboolean initialized;
|
||||||
GstD3D11Device *device;
|
GstD3D11Device *device;
|
||||||
GstD3D11Allocator *allocator;
|
|
||||||
guintptr external_handle;
|
guintptr external_handle;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
|
|
|
@ -87,18 +87,6 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
|
||||||
guint display_width, guint display_height, GstCaps * caps,
|
guint display_width, guint display_height, GstCaps * caps,
|
||||||
GstStructure * config, GError ** error)
|
GstStructure * config, GError ** error)
|
||||||
{
|
{
|
||||||
if (!window->allocator) {
|
|
||||||
window->allocator =
|
|
||||||
(GstD3D11Allocator *) gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!window->allocator) {
|
|
||||||
GST_ERROR_OBJECT (window, "Allocator is unavailable");
|
|
||||||
if (config)
|
|
||||||
gst_structure_free (config);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_clear_object (&window->compositor);
|
gst_clear_object (&window->compositor);
|
||||||
gst_clear_object (&window->converter);
|
gst_clear_object (&window->converter);
|
||||||
|
|
||||||
|
@ -257,7 +245,7 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mem = gst_d3d11_allocator_alloc_wrapped (window->allocator,
|
mem = gst_d3d11_allocator_alloc_wrapped (nullptr,
|
||||||
device, texture.Get (), desc.Width * desc.Height * 4, nullptr, nullptr);
|
device, texture.Get (), desc.Width * desc.Height * 4, nullptr, nullptr);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
GST_ERROR_OBJECT (window, "Couldn't allocate memory");
|
GST_ERROR_OBJECT (window, "Couldn't allocate memory");
|
||||||
|
|
|
@ -132,7 +132,6 @@ gst_qsv_d3d11_allocator_alloc (GstQsvAllocator * allocator,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->Info.FourCC == MFX_FOURCC_P8) {
|
if (request->Info.FourCC == MFX_FOURCC_P8) {
|
||||||
GstD3D11Allocator *d3d11_alloc = nullptr;
|
|
||||||
D3D11_BUFFER_DESC desc;
|
D3D11_BUFFER_DESC desc;
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
GstMemory *mem;
|
GstMemory *mem;
|
||||||
|
@ -141,23 +140,13 @@ gst_qsv_d3d11_allocator_alloc (GstQsvAllocator * allocator,
|
||||||
gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
|
gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
|
||||||
guint size;
|
guint size;
|
||||||
|
|
||||||
d3d11_alloc =
|
|
||||||
(GstD3D11Allocator *) gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!d3d11_alloc) {
|
|
||||||
GST_ERROR_OBJECT (self, "D3D11 allocator is unavailable");
|
|
||||||
|
|
||||||
return MFX_ERR_MEMORY_ALLOC;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&desc, 0, sizeof (D3D11_BUFFER_DESC));
|
memset (&desc, 0, sizeof (D3D11_BUFFER_DESC));
|
||||||
|
|
||||||
desc.ByteWidth = request->Info.Width * request->Info.Height;
|
desc.ByteWidth = request->Info.Width * request->Info.Height;
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
|
||||||
mem = gst_d3d11_allocator_alloc_buffer (d3d11_alloc, self->device, &desc);
|
mem = gst_d3d11_allocator_alloc_buffer (nullptr, self->device, &desc);
|
||||||
gst_object_unref (d3d11_alloc);
|
|
||||||
|
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
GST_ERROR_OBJECT (self, "Failed to allocate buffer");
|
GST_ERROR_OBJECT (self, "Failed to allocate buffer");
|
||||||
return MFX_ERR_MEMORY_ALLOC;
|
return MFX_ERR_MEMORY_ALLOC;
|
||||||
|
|
|
@ -44,7 +44,6 @@ typedef struct
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
GstD3D11Device *d3d11_device;
|
GstD3D11Device *d3d11_device;
|
||||||
GstD3D11Allocator *d3d11_allocator;
|
|
||||||
|
|
||||||
ID3D11Device *device;
|
ID3D11Device *device;
|
||||||
ID3D11DeviceContext *context;
|
ID3D11DeviceContext *context;
|
||||||
|
@ -404,7 +403,7 @@ handle_window_resize (AppData * app_data)
|
||||||
|
|
||||||
backbuffer->GetDesc (&desc);
|
backbuffer->GetDesc (&desc);
|
||||||
|
|
||||||
mem = gst_d3d11_allocator_alloc_wrapped (app_data->d3d11_allocator,
|
mem = gst_d3d11_allocator_alloc_wrapped (nullptr,
|
||||||
app_data->d3d11_device, backbuffer.Get (),
|
app_data->d3d11_device, backbuffer.Get (),
|
||||||
/* This might not be correct CPU accessible (staging) texture size
|
/* This might not be correct CPU accessible (staging) texture size
|
||||||
* but it's fine since we don't use this memory for CPU access */
|
* but it's fine since we don't use this memory for CPU access */
|
||||||
|
@ -546,15 +545,6 @@ main (gint argc, gchar ** argv)
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gets d3d11 memory allocator which will be used to wrap swapchain
|
|
||||||
* backbuffer */
|
|
||||||
app_data.d3d11_allocator = (GstD3D11Allocator *)
|
|
||||||
gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!app_data.d3d11_allocator) {
|
|
||||||
gst_printerrln ("D3D11 allocator is unavailable");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Creates window and swapchain */
|
/* Creates window and swapchain */
|
||||||
app_data.hwnd = create_window ();
|
app_data.hwnd = create_window ();
|
||||||
if (!app_data.hwnd) {
|
if (!app_data.hwnd) {
|
||||||
|
@ -603,7 +593,6 @@ main (gint argc, gchar ** argv)
|
||||||
if (app_data.hwnd)
|
if (app_data.hwnd)
|
||||||
DestroyWindow (app_data.hwnd);
|
DestroyWindow (app_data.hwnd);
|
||||||
|
|
||||||
gst_clear_object (&app_data.d3d11_allocator);
|
|
||||||
gst_clear_object (&app_data.d3d11_device);
|
gst_clear_object (&app_data.d3d11_device);
|
||||||
gst_clear_object (&app_data.pipeline);
|
gst_clear_object (&app_data.pipeline);
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,6 @@ on_need_data (GstAppSrc * appsrc, guint length, gpointer user_data)
|
||||||
ComPtr < ID3D11RenderTargetView > rtv;
|
ComPtr < ID3D11RenderTargetView > rtv;
|
||||||
FLOAT clear_color[4] = { 1.0, 1.0, 1.0, 1.0 };
|
FLOAT clear_color[4] = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
GstMemory *mem;
|
GstMemory *mem;
|
||||||
GstD3D11Allocator *allocator;
|
|
||||||
GstD3D11Memory *dmem;
|
GstD3D11Memory *dmem;
|
||||||
MemoryUserData *memory_data;
|
MemoryUserData *memory_data;
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
|
@ -265,13 +264,6 @@ on_need_data (GstAppSrc * appsrc, guint length, gpointer user_data)
|
||||||
app_data->context->ClearRenderTargetView (rtv.Get (), clear_color);
|
app_data->context->ClearRenderTargetView (rtv.Get (), clear_color);
|
||||||
gst_d3d11_device_unlock (app_data->d3d11_device);
|
gst_d3d11_device_unlock (app_data->d3d11_device);
|
||||||
|
|
||||||
/* Find global default D3D11 allocator */
|
|
||||||
allocator = (GstD3D11Allocator *) gst_allocator_find (GST_D3D11_MEMORY_NAME);
|
|
||||||
if (!allocator) {
|
|
||||||
gst_printerrln ("D3D11 allocator is unavailable");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Demonstrating application-side texture pool.
|
/* Demonstrating application-side texture pool.
|
||||||
* GstD3D11BufferPool can be used instead */
|
* GstD3D11BufferPool can be used instead */
|
||||||
memory_data = g_new0 (MemoryUserData, 1);
|
memory_data = g_new0 (MemoryUserData, 1);
|
||||||
|
@ -282,10 +274,9 @@ on_need_data (GstAppSrc * appsrc, guint length, gpointer user_data)
|
||||||
/* gst_d3d11_allocator_alloc_wrapped() method does not take ownership of
|
/* gst_d3d11_allocator_alloc_wrapped() method does not take ownership of
|
||||||
* ID3D11Texture2D object, but in this example, we pass ownership via
|
* ID3D11Texture2D object, but in this example, we pass ownership via
|
||||||
* user data */
|
* user data */
|
||||||
mem = gst_d3d11_allocator_alloc_wrapped (allocator, app_data->d3d11_device,
|
mem = gst_d3d11_allocator_alloc_wrapped (nullptr, app_data->d3d11_device,
|
||||||
texture, app_data->mem_size, memory_data,
|
texture, app_data->mem_size, memory_data,
|
||||||
(GDestroyNotify) on_memory_freed);
|
(GDestroyNotify) on_memory_freed);
|
||||||
gst_object_unref (allocator);
|
|
||||||
|
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
gst_printerrln ("Couldn't allocate memory");
|
gst_printerrln ("Couldn't allocate memory");
|
||||||
|
|
Loading…
Reference in a new issue