va: allocator: refactor flush methods for both allocators
Since the logic is the same, it can be generalized in a single common function. Also the methods run the common function with a lock and signal the buffers' conditional. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1626>
This commit is contained in:
parent
37fa6df57d
commit
dcc4557dd6
@ -360,6 +360,27 @@ gst_va_buffer_surface_new (VASurfaceID surface, GstVideoFormat format,
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_available_mems_flush (GstVaDisplay * display, GstAtomicQueue * available_mems)
|
||||||
|
{
|
||||||
|
GstMemory *mem;
|
||||||
|
GstVaBufferSurface *buf;
|
||||||
|
|
||||||
|
while ((mem = gst_atomic_queue_pop (available_mems))) {
|
||||||
|
/* destroy the surface */
|
||||||
|
buf = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
|
||||||
|
gst_va_buffer_surface_quark ());
|
||||||
|
if (buf && g_atomic_int_dec_and_test (&buf->ref_count)) {
|
||||||
|
GST_LOG ("Destroying surface %#x", buf->surface);
|
||||||
|
_destroy_surfaces (display, &buf->surface, 1);
|
||||||
|
g_slice_free (GstVaBufferSurface, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_MINI_OBJECT_CAST (mem)->dispose = NULL;
|
||||||
|
gst_memory_unref (mem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*=========================== GstVaDmabufAllocator ===========================*/
|
/*=========================== GstVaDmabufAllocator ===========================*/
|
||||||
|
|
||||||
struct _GstVaDmabufAllocator
|
struct _GstVaDmabufAllocator
|
||||||
@ -418,7 +439,7 @@ gst_va_dmabuf_allocator_dispose (GObject * object)
|
|||||||
{
|
{
|
||||||
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (object);
|
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (object);
|
||||||
|
|
||||||
gst_va_dmabuf_allocator_flush (GST_ALLOCATOR (object));
|
_available_mems_flush (self->display, self->available_mems);
|
||||||
gst_atomic_queue_unref (self->available_mems);
|
gst_atomic_queue_unref (self->available_mems);
|
||||||
|
|
||||||
gst_clear_object (&self->display);
|
gst_clear_object (&self->display);
|
||||||
@ -628,23 +649,12 @@ gst_va_dmabuf_allocator_prepare_buffer (GstAllocator * allocator,
|
|||||||
void
|
void
|
||||||
gst_va_dmabuf_allocator_flush (GstAllocator * allocator)
|
gst_va_dmabuf_allocator_flush (GstAllocator * allocator)
|
||||||
{
|
{
|
||||||
GstMemory *mem;
|
|
||||||
GstVaBufferSurface *buf;
|
|
||||||
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
|
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
|
||||||
|
|
||||||
while ((mem = gst_atomic_queue_pop (self->available_mems))) {
|
GST_OBJECT_LOCK (self);
|
||||||
/* destroy the surface */
|
_available_mems_flush (self->display, self->available_mems);
|
||||||
buf = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
|
g_cond_signal (&self->buffer_cond);
|
||||||
gst_va_buffer_surface_quark ());
|
GST_OBJECT_UNLOCK (self);
|
||||||
if (buf && g_atomic_int_dec_and_test (&buf->ref_count)) {
|
|
||||||
GST_LOG_OBJECT (self, "Destroying surface %#x", buf->surface);
|
|
||||||
_destroy_surfaces (self->display, &buf->surface, 1);
|
|
||||||
g_slice_free (GstVaBufferSurface, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_MINI_OBJECT_CAST (mem)->dispose = NULL;
|
|
||||||
gst_memory_unref (mem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -790,7 +800,7 @@ gst_va_allocator_dispose (GObject * object)
|
|||||||
{
|
{
|
||||||
GstVaAllocator *self = GST_VA_ALLOCATOR (object);
|
GstVaAllocator *self = GST_VA_ALLOCATOR (object);
|
||||||
|
|
||||||
gst_va_allocator_flush (GST_ALLOCATOR (object));
|
_available_mems_flush (self->display, self->available_mems);
|
||||||
gst_atomic_queue_unref (self->available_mems);
|
gst_atomic_queue_unref (self->available_mems);
|
||||||
|
|
||||||
gst_clear_object (&self->display);
|
gst_clear_object (&self->display);
|
||||||
@ -1185,23 +1195,12 @@ gst_va_allocator_prepare_buffer (GstAllocator * allocator, GstBuffer * buffer)
|
|||||||
void
|
void
|
||||||
gst_va_allocator_flush (GstAllocator * allocator)
|
gst_va_allocator_flush (GstAllocator * allocator)
|
||||||
{
|
{
|
||||||
GstMemory *mem;
|
|
||||||
GstVaBufferSurface *buf;
|
|
||||||
GstVaAllocator *self = GST_VA_ALLOCATOR (allocator);
|
GstVaAllocator *self = GST_VA_ALLOCATOR (allocator);
|
||||||
|
|
||||||
while ((mem = gst_atomic_queue_pop (self->available_mems))) {
|
GST_OBJECT_LOCK (self);
|
||||||
/* destroy the surface */
|
_available_mems_flush (self->display, self->available_mems);
|
||||||
buf = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
|
g_cond_signal (&self->buffer_cond);
|
||||||
gst_va_buffer_surface_quark ());
|
GST_OBJECT_UNLOCK (self);
|
||||||
if (buf && g_atomic_int_dec_and_test (&buf->ref_count)) {
|
|
||||||
GST_LOG_OBJECT (self, "Destroying surface %#x", buf->surface);
|
|
||||||
_destroy_surfaces (self->display, &buf->surface, 1);
|
|
||||||
g_slice_free (GstVaBufferSurface, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_MINI_OBJECT_CAST (mem)->dispose = NULL;
|
|
||||||
gst_memory_unref (mem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user