d3d11memory, d3d12memory: Fix outstanding memory count tracing
authorSeungha Yang <seungha@centricular.com>
Wed, 28 Feb 2024 17:41:42 +0000 (02:41 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 29 Feb 2024 11:57:50 +0000 (11:57 +0000)
Gets being released memory back to queue even if allocator is flushing
in order to count the number of outstanding memory objects.
Also, clear queue if there's no outstanding memory object and
allocator is flushing

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6240>

subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11bufferpool.cpp
subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12memory.cpp

index fbf1e8dc93dfff6c6bf37e7960521ae8667976a0..d5a86b64c2057e0de2a01f639709d4215b3a04c9 100644 (file)
@@ -243,9 +243,9 @@ gst_d3d11_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
 
     pool_alloc = GST_D3D11_POOL_ALLOCATOR (alloc);
     flow_ret = gst_d3d11_pool_allocator_acquire_memory (pool_alloc, &mem);
+    gst_d3d11_allocator_set_active (alloc, FALSE);
     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;
     }
@@ -254,7 +254,6 @@ gst_d3d11_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
             &stride) || stride < 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);
 
index 7c39236c767c62f3b36673e1590bd398636b23f4..d443ff1eab6439171946501d63707d0681f395b3 100644 (file)
@@ -2208,6 +2208,8 @@ gst_d3d11_pool_allocator_release_memory (GstD3D11PoolAllocator * self,
   /* keep it around in our queue */
   priv->queue.push (mem);
   priv->outstanding--;
+  if (priv->outstanding == 0 && priv->flushing)
+    gst_d3d11_pool_allocator_stop (self);
   WakeAllConditionVariable (&priv->cond);
   ReleaseSRWLockExclusive (&priv->lock);
 
@@ -2232,13 +2234,6 @@ gst_d3d11_memory_release (GstMiniObject * object)
   priv = alloc->priv;
 
   AcquireSRWLockExclusive (&priv->lock);
-  /* if flushing, free this memory */
-  if (alloc->priv->flushing) {
-    ReleaseSRWLockExclusive (&priv->lock);
-    GST_LOG_OBJECT (alloc, "allocator is flushing, free %p", mem);
-    return TRUE;
-  }
-
   /* return the memory to the allocator */
   gst_memory_ref (mem);
   gst_d3d11_pool_allocator_release_memory (alloc, mem);
index 6af65b476f2b890487468c149518a63c7365d562..ad9c4efcedea2501b3d430f6c3c977361ae5bec4 100644 (file)
@@ -1100,6 +1100,8 @@ gst_d3d12_pool_allocator_release_memory (GstD3D12PoolAllocator * self,
   /* keep it around in our queue */
   priv->queue.push (mem);
   priv->outstanding--;
+  if (priv->outstanding == 0 && priv->flushing)
+    gst_d3d12_pool_allocator_stop (self);
   priv->cond.notify_all ();
   priv->lock.unlock ();
 
@@ -1124,13 +1126,6 @@ gst_d3d12_memory_release (GstMiniObject * mini_object)
   priv = alloc->priv;
 
   priv->lock.lock ();
-  /* if flushing, free this memory */
-  if (alloc->priv->flushing) {
-    priv->lock.unlock ();
-    GST_LOG_OBJECT (alloc, "allocator is flushing, free %p", mem);
-    return TRUE;
-  }
-
   /* return the memory to the allocator */
   gst_memory_ref (mem);
   gst_d3d12_pool_allocator_release_memory (alloc, mem);