mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 23:28:16 +00:00
va: pool: simplify the logic
Instead of removing memories from buffers at reset_buffer()/release_buffer() the bufferpool operation is kept as originally designed, still the allocator pool is used too. Thus, this patch restores the buffer size configuration while removing release_buffer(), reset_buffer() and acquire_buffer() vmethods overloads. Then, when the bufferpool base class decides to discard a buffer, the VA surface-based memory is returned to the allocator pool when its last reference is freed, and later reused if a new buffer is allocated again. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2013>
This commit is contained in:
parent
8deec238cb
commit
1ee9b202a6
1 changed files with 2 additions and 78 deletions
|
@ -180,11 +180,8 @@ gst_va_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|||
}
|
||||
}
|
||||
|
||||
/* with pooled allocators bufferpool->release_buffer() is cheated
|
||||
* because the memories are removed from the buffer at
|
||||
* reset_buffer(), then buffer is an empty holder with size 0 while
|
||||
* releasing. */
|
||||
gst_buffer_pool_config_set_params (config, caps, 0, min_buffers, max_buffers);
|
||||
gst_buffer_pool_config_set_params (config, caps,
|
||||
GST_VIDEO_INFO_SIZE (&alloc_info), min_buffers, max_buffers);
|
||||
|
||||
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
||||
|
||||
|
@ -273,76 +270,6 @@ no_memory:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_va_pool_reset_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
||||
{
|
||||
/* Clears all the memories and only pool the GstBuffer objects */
|
||||
gst_buffer_remove_all_memory (buffer);
|
||||
|
||||
GST_BUFFER_POOL_CLASS (parent_class)->reset_buffer (pool, buffer);
|
||||
|
||||
GST_BUFFER_FLAGS (buffer) = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_va_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
||||
{
|
||||
GstVaPool *vpool = GST_VA_POOL (pool);
|
||||
|
||||
/* Clears all the memories and only pool the GstBuffer objects */
|
||||
if (G_UNLIKELY (vpool->starting)) {
|
||||
gst_buffer_remove_all_memory (buffer);
|
||||
GST_BUFFER_FLAGS (buffer) = 0;
|
||||
}
|
||||
|
||||
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (pool, buffer);
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_va_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
||||
GstBufferPoolAcquireParams * params)
|
||||
{
|
||||
GstFlowReturn ret;
|
||||
GstVaPool *vpool = GST_VA_POOL (pool);
|
||||
|
||||
ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (pool, buffer,
|
||||
params);
|
||||
if (ret != GST_FLOW_OK)
|
||||
return ret;
|
||||
|
||||
/* if buffer is new, return it */
|
||||
if (gst_buffer_n_memory (*buffer) > 0)
|
||||
return GST_FLOW_OK;
|
||||
|
||||
if (GST_IS_VA_DMABUF_ALLOCATOR (vpool->allocator)) {
|
||||
if (gst_va_dmabuf_allocator_prepare_buffer (vpool->allocator, *buffer))
|
||||
return GST_FLOW_OK;
|
||||
|
||||
if (params && (params->flags & GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT))
|
||||
return GST_FLOW_EOS;
|
||||
if (!gst_va_dmabuf_allocator_wait_for_memory (vpool->allocator, *buffer))
|
||||
goto flushing;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
} else if (GST_IS_VA_ALLOCATOR (vpool->allocator)) {
|
||||
if (gst_va_allocator_prepare_buffer (vpool->allocator, *buffer))
|
||||
return GST_FLOW_OK;
|
||||
|
||||
if (params && (params->flags & GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT))
|
||||
return GST_FLOW_EOS;
|
||||
if (!gst_va_allocator_wait_for_memory (vpool->allocator, *buffer))
|
||||
goto flushing;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
return GST_FLOW_ERROR;
|
||||
|
||||
flushing:
|
||||
gst_buffer_replace (buffer, NULL);
|
||||
return GST_FLOW_FLUSHING;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_va_pool_flush_start (GstBufferPool * pool)
|
||||
{
|
||||
|
@ -390,9 +317,6 @@ gst_va_pool_class_init (GstVaPoolClass * klass)
|
|||
gstbufferpool_class->get_options = gst_va_pool_get_options;
|
||||
gstbufferpool_class->set_config = gst_va_pool_set_config;
|
||||
gstbufferpool_class->alloc_buffer = gst_va_pool_alloc;
|
||||
gstbufferpool_class->reset_buffer = gst_va_pool_reset_buffer;
|
||||
gstbufferpool_class->release_buffer = gst_va_pool_release_buffer;
|
||||
gstbufferpool_class->acquire_buffer = gst_va_pool_acquire_buffer;
|
||||
gstbufferpool_class->flush_start = gst_va_pool_flush_start;
|
||||
gstbufferpool_class->start = gst_va_pool_start;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue