d3d11: Don't find global default allocator
authorSeungha Yang <seungha@centricular.com>
Fri, 5 Aug 2022 13:34:06 +0000 (22:34 +0900)
committerSeungha Yang <seungha@centricular.com>
Sat, 6 Aug 2022 14:55:18 +0000 (23:55 +0900)
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>

subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp
subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.cpp
subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.h
subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_dummy.cpp
subprojects/gst-plugins-bad/sys/qsv/gstqsvallocator_d3d11.cpp
subprojects/gst-plugins-bad/tests/examples/d3d11/d3d11converter.cpp
subprojects/gst-plugins-bad/tests/examples/d3d11/d3d11videosink-appsrc.cpp

index f86a41e..c262e7e 100644 (file)
@@ -218,7 +218,6 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
 {
   GstD3D11Memory *dmem;
   GstD3D11Device *device;
-  GstD3D11Allocator *alloc = NULL;
   GstBuffer *staging_buffer = NULL;
   gint stride[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;
   }
 
-  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 ();
   for (i = 0; i < gst_buffer_n_memory (buffer); i++) {
     D3D11_TEXTURE2D_DESC staging_desc;
@@ -263,7 +256,7 @@ gst_d3d11_allocate_staging_buffer_for (GstBuffer * buffer,
     fill_staging_desc (&desc, &staging_desc);
 
     new_mem = (GstD3D11Memory *)
-        gst_d3d11_allocator_alloc (alloc, mem->device, &staging_desc);
+        gst_d3d11_allocator_alloc (nullptr, mem->device, &staging_desc);
     if (!new_mem) {
       GST_ERROR ("Failed to allocate memory");
       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),
       offset, stride);
 
-  if (alloc)
-    gst_object_unref (alloc);
-
   return staging_buffer;
 
 error:
   gst_clear_buffer (&staging_buffer);
-  gst_clear_object (&alloc);
 
   return NULL;
 }
index 0825c30..cf99a01 100644 (file)
@@ -263,7 +263,6 @@ gst_d3d11_window_dispose (GObject * object)
 
   gst_clear_buffer (&self->cached_buffer);
   gst_clear_object (&self->device);
-  gst_clear_object (&self->allocator);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -316,7 +315,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width,
     size *= 4;
   }
 
-  mem = gst_d3d11_allocator_alloc_wrapped (self->allocator,
+  mem = gst_d3d11_allocator_alloc_wrapped (nullptr,
       self->device, backbuffer.Get (), size, nullptr, nullptr);
   if (!mem) {
     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 *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 */
   gst_clear_buffer (&window->cached_buffer);
   gst_clear_object (&window->compositor);
index bc5181f..eb787aa 100644 (file)
@@ -78,7 +78,6 @@ struct _GstD3D11Window
   /*< protected >*/
   gboolean initialized;
   GstD3D11Device *device;
-  GstD3D11Allocator *allocator;
   guintptr external_handle;
 
   /* properties */
index 32a5e69..32ab87b 100644 (file)
@@ -87,18 +87,6 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window,
     guint display_width, guint display_height, GstCaps * caps,
     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->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);
   if (!mem) {
     GST_ERROR_OBJECT (window, "Couldn't allocate memory");
index 388f6a1..d48784a 100644 (file)
@@ -132,7 +132,6 @@ gst_qsv_d3d11_allocator_alloc (GstQsvAllocator * allocator,
   }
 
   if (request->Info.FourCC == MFX_FOURCC_P8) {
-    GstD3D11Allocator *d3d11_alloc = nullptr;
     D3D11_BUFFER_DESC desc;
     GstVideoInfo info;
     GstMemory *mem;
@@ -141,23 +140,13 @@ gst_qsv_d3d11_allocator_alloc (GstQsvAllocator * allocator,
     gint stride[GST_VIDEO_MAX_PLANES] = { 0, };
     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));
 
     desc.ByteWidth = request->Info.Width * request->Info.Height;
     desc.Usage = D3D11_USAGE_STAGING;
     desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 
-    mem = gst_d3d11_allocator_alloc_buffer (d3d11_alloc, self->device, &desc);
-    gst_object_unref (d3d11_alloc);
-
+    mem = gst_d3d11_allocator_alloc_buffer (nullptr, self->device, &desc);
     if (!mem) {
       GST_ERROR_OBJECT (self, "Failed to allocate buffer");
       return MFX_ERR_MEMORY_ALLOC;
index b5a540c..ea50d8a 100644 (file)
@@ -44,7 +44,6 @@ typedef struct
   GMainLoop *loop;
   GstElement *pipeline;
   GstD3D11Device *d3d11_device;
-  GstD3D11Allocator *d3d11_allocator;
 
   ID3D11Device *device;
   ID3D11DeviceContext *context;
@@ -404,7 +403,7 @@ handle_window_resize (AppData * app_data)
 
   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 (),
       /* This might not be correct CPU accessible (staging) texture size
        * 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);
   }
 
-  /* 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 */
   app_data.hwnd = create_window ();
   if (!app_data.hwnd) {
@@ -603,7 +593,6 @@ main (gint argc, gchar ** argv)
   if (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.pipeline);
 
index 54fce35..39a40b9 100644 (file)
@@ -221,7 +221,6 @@ on_need_data (GstAppSrc * appsrc, guint length, gpointer user_data)
   ComPtr < ID3D11RenderTargetView > rtv;
   FLOAT clear_color[4] = { 1.0, 1.0, 1.0, 1.0 };
   GstMemory *mem;
-  GstD3D11Allocator *allocator;
   GstD3D11Memory *dmem;
   MemoryUserData *memory_data;
   GstBuffer *buffer;
@@ -265,13 +264,6 @@ on_need_data (GstAppSrc * appsrc, guint length, gpointer user_data)
   app_data->context->ClearRenderTargetView (rtv.Get (), clear_color);
   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.
    * GstD3D11BufferPool can be used instead */
   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
    * ID3D11Texture2D object, but in this example, we pass ownership via
    * 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,
       (GDestroyNotify) on_memory_freed);
-  gst_object_unref (allocator);
 
   if (!mem) {
     gst_printerrln ("Couldn't allocate memory");