tests: d3d11: Add buffer pool test
authorSeungha Yang <seungha@centricular.com>
Wed, 28 Feb 2024 17:30:38 +0000 (02:30 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 29 Feb 2024 11:57:50 +0000 (11:57 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6240>

subprojects/gst-plugins-bad/tests/check/libs/d3d11memory.c

index 7a746f5b41bda9428732a4f6c24749c51337f428..36a12ab5a37038adef1dcb2e6e8ff744bb14de8f 100644 (file)
@@ -102,6 +102,62 @@ GST_START_TEST (test_free_active_allocator)
 
 GST_END_TEST;
 
+GST_START_TEST (test_free_buffer_after_deactivate)
+{
+  GstVideoInfo info;
+  gboolean ret;
+  GstFlowReturn flow_ret;
+  GstBufferPool *pool;
+  GstStructure *config;
+  GstCaps *caps;
+  GstBuffer *buffers[2];
+  gboolean alloc_finalized = FALSE;
+
+  gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 320, 240);
+
+  caps = gst_video_info_to_caps (&info);
+  fail_unless (caps);
+
+  pool = gst_d3d11_buffer_pool_new (device);
+  fail_unless (pool);
+
+  g_object_set_qdata_full (G_OBJECT (pool), memory_tester_quark,
+      &alloc_finalized, (GDestroyNotify) allocator_finalize_cb);
+
+  config = gst_buffer_pool_get_config (pool);
+  fail_unless (config);
+
+  gst_buffer_pool_config_set_params (config, caps, info.size, 0, 0);
+  gst_caps_unref (caps);
+
+  ret = gst_buffer_pool_set_config (pool, config);
+  fail_unless (ret);
+
+  ret = gst_buffer_pool_set_active (pool, TRUE);
+  fail_unless (ret);
+
+  flow_ret = gst_buffer_pool_acquire_buffer (pool, &buffers[0], NULL);
+  fail_unless (flow_ret == GST_FLOW_OK);
+
+  flow_ret = gst_buffer_pool_acquire_buffer (pool, &buffers[1], NULL);
+  fail_unless (flow_ret == GST_FLOW_OK);
+
+  ret = gst_buffer_pool_set_active (pool, FALSE);
+  fail_unless (ret);
+  fail_if (alloc_finalized);
+
+  gst_object_unref (pool);
+  fail_if (alloc_finalized);
+
+  gst_buffer_unref (buffers[0]);
+  fail_if (alloc_finalized);
+
+  gst_buffer_unref (buffers[1]);
+  fail_unless (alloc_finalized);
+}
+
+GST_END_TEST;
+
 typedef struct
 {
   GMutex lock;
@@ -225,6 +281,7 @@ d3d11memory_suite (void)
     return s;
 
   tcase_add_test (tc_chain, test_free_active_allocator);
+  tcase_add_test (tc_chain, test_free_buffer_after_deactivate);
   tcase_add_test (tc_chain, test_unblock_on_stop);
 
   return s;