GstMemoryMapFunction parent_map;
+ GMutex buffer_lock;
GCond buffer_cond;
GstVideoInfo info;
gst_atomic_queue_unref (self->available_mems);
gst_clear_object (&self->display);
+ g_mutex_clear (&self->buffer_lock);
g_cond_clear (&self->buffer_cond);
G_OBJECT_CLASS (dmabuf_parent_class)->finalize (object);
gst_va_dmabuf_allocator_init (GstVaDmabufAllocator * self)
{
self->available_mems = gst_atomic_queue_new (2);
+ g_mutex_init (&self->buffer_lock);
g_cond_init (&self->buffer_cond);
self->parent_map = GST_ALLOCATOR (self)->mem_map;
GstMemory *mem = GST_MEMORY_CAST (mini_object);
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (mem->allocator);
- GST_OBJECT_LOCK (self);
-
GST_LOG ("releasing %p", mem);
+
+ g_mutex_lock (&self->buffer_lock);
gst_atomic_queue_push (self->available_mems, gst_memory_ref (mem));
g_cond_signal (&self->buffer_cond);
-
- GST_OBJECT_UNLOCK (self);
+ g_mutex_unlock (&self->buffer_lock);
/* Keep last in case we are holding on the last allocator ref */
gst_object_unref (mem->allocator);
return gst_va_dmabuf_allocator_setup_buffer_full (allocator, buffer, NULL);
}
-gboolean
-gst_va_dmabuf_allocator_prepare_buffer (GstAllocator * allocator,
+static VASurfaceID
+gst_va_dmabuf_allocator_prepare_buffer_unlocked (GstVaDmabufAllocator * self,
GstBuffer * buffer)
{
- GstMemory *pmem, *mem[GST_VIDEO_MAX_PLANES] = { 0, };
- GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
- VASurfaceID surface, psurface;
+ GstMemory *mem[GST_VIDEO_MAX_PLANES] = { 0, };
+ VASurfaceID surface;
gint j, idx = 1;
- GST_OBJECT_LOCK (self);
-
- /* if available mems, use them */
- while (gst_atomic_queue_length (self->available_mems) == 0 && !self->flushing)
- g_cond_wait (&self->buffer_cond, GST_OBJECT_GET_LOCK (self));
-
- if (self->flushing) {
- GST_OBJECT_UNLOCK (self);
- return FALSE;
- }
-
mem[0] = gst_atomic_queue_pop (self->available_mems);
+ if (!mem[0])
+ return VA_INVALID_ID;
+
surface = gst_va_memory_get_surface (mem[0]);
+ while (surface != VA_INVALID_ID) {
+ GstMemory *pmem;
+ VASurfaceID psurface;
- do {
pmem = gst_atomic_queue_peek (self->available_mems);
if (!pmem)
break;
break;
mem[idx++] = gst_atomic_queue_pop (self->available_mems);
- } while (TRUE);
-
- GST_OBJECT_UNLOCK (self);
+ };
/* append them in reverse order */
for (j = idx - 1; j >= 0; j--) {
gst_buffer_append_memory (buffer, mem[j]);
}
- GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface, buffer);
+ return surface;
+}
- return TRUE;
+gboolean
+gst_va_dmabuf_allocator_prepare_buffer (GstAllocator * allocator,
+ GstBuffer * buffer)
+{
+ GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
+ VASurfaceID surface;
+
+ g_mutex_lock (&self->buffer_lock);
+ surface = gst_va_dmabuf_allocator_prepare_buffer_unlocked (self, buffer);
+ g_mutex_unlock (&self->buffer_lock);
+
+ if (surface != VA_INVALID_ID) {
+ GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface,
+ buffer);
+ }
+
+ return (surface != VA_INVALID_ID);
+}
+
+gboolean
+gst_va_dmabuf_allocator_wait_for_memory (GstAllocator * allocator,
+ GstBuffer * buffer)
+{
+ GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
+ VASurfaceID surface;
+
+ g_mutex_lock (&self->buffer_lock);
+ while (gst_atomic_queue_length (self->available_mems) == 0 && !self->flushing)
+ g_cond_wait (&self->buffer_cond, &self->buffer_lock);
+
+ if (self->flushing) {
+ g_mutex_unlock (&self->buffer_lock);
+ return FALSE;
+ }
+
+ surface = gst_va_dmabuf_allocator_prepare_buffer_unlocked (self, buffer);
+ g_mutex_unlock (&self->buffer_lock);
+
+ if (surface != VA_INVALID_ID) {
+ GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface,
+ buffer);
+ }
+
+ return (surface != VA_INVALID_ID);
}
void
{
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
- GST_OBJECT_LOCK (self);
+ g_mutex_lock (&self->buffer_lock);
self->flushing = TRUE;
_available_mems_flush (self->display, self->available_mems,
&self->surface_count);
self->flushing = FALSE;
g_cond_broadcast (&self->buffer_cond);
- GST_OBJECT_UNLOCK (self);
+ g_mutex_unlock (&self->buffer_lock);
}
static gboolean
guint32 fourcc;
guint32 rt_format;
+ GMutex buffer_lock;
GCond buffer_cond;
GstVideoInfo info;
gst_atomic_queue_unref (self->available_mems);
gst_clear_object (&self->display);
g_clear_pointer (&self->surface_formats, g_array_unref);
+ g_mutex_clear (&self->buffer_lock);
g_cond_clear (&self->buffer_cond);
G_OBJECT_CLASS (gst_va_allocator_parent_class)->finalize (object);
self->use_derived = TRUE;
+ g_mutex_init (&self->buffer_lock);
g_cond_init (&self->buffer_cond);
GST_OBJECT_FLAG_SET (self, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
GstMemory *mem = GST_MEMORY_CAST (mini_object);
GstVaAllocator *self = GST_VA_ALLOCATOR (mem->allocator);
- GST_OBJECT_LOCK (self);
-
GST_LOG ("releasing %p", mem);
+
+ g_mutex_lock (&self->buffer_lock);
gst_atomic_queue_push (self->available_mems, gst_memory_ref (mem));
g_cond_signal (&self->buffer_cond);
-
- GST_OBJECT_UNLOCK (self);
+ g_mutex_unlock (&self->buffer_lock);
/* Keep last in case we are holding on the last allocator ref */
gst_object_unref (mem->allocator);
return GST_ALLOCATOR (self);
}
+static VASurfaceID
+gst_va_allocator_prepare_buffer_unlocked (GstVaAllocator * self,
+ GstBuffer * buffer)
+{
+ GstMemory *mem;
+ VASurfaceID surface;
+
+ mem = gst_atomic_queue_pop (self->available_mems);
+ if (!mem)
+ return VA_INVALID_ID;
+
+ gst_object_ref (mem->allocator);
+ surface = gst_va_memory_get_surface (mem);
+ gst_buffer_append_memory (buffer, mem);
+
+ return surface;
+}
+
gboolean
gst_va_allocator_prepare_buffer (GstAllocator * allocator, GstBuffer * buffer)
{
- GstMemory *mem;
GstVaAllocator *self = GST_VA_ALLOCATOR (allocator);
VASurfaceID surface;
- GST_OBJECT_LOCK (self);
+ g_mutex_lock (&self->buffer_lock);
+ surface = gst_va_allocator_prepare_buffer_unlocked (self, buffer);
+ g_mutex_unlock (&self->buffer_lock);
- if (self->flushing) {
- GST_OBJECT_UNLOCK (self);
- return FALSE;
+ if (surface != VA_INVALID_ID) {
+ GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface,
+ buffer);
}
- /* if available mems, use them */
- while (gst_atomic_queue_length (self->available_mems) == 0)
- g_cond_wait (&self->buffer_cond, GST_OBJECT_GET_LOCK (self));
+ return (surface != VA_INVALID_ID);
+}
- mem = gst_atomic_queue_pop (self->available_mems);
- GST_OBJECT_UNLOCK (self);
+gboolean
+gst_va_allocator_wait_for_memory (GstAllocator * allocator, GstBuffer * buffer)
+{
+ GstVaAllocator *self = GST_VA_ALLOCATOR (allocator);
+ VASurfaceID surface;
- gst_object_ref (mem->allocator);
- surface = gst_va_memory_get_surface (mem);
- gst_buffer_append_memory (buffer, mem);
+ g_mutex_lock (&self->buffer_lock);
+ while (gst_atomic_queue_length (self->available_mems) == 0 && !self->flushing)
+ g_cond_wait (&self->buffer_cond, &self->buffer_lock);
+
+ if (self->flushing) {
+ g_mutex_unlock (&self->buffer_lock);
+ return FALSE;
+ }
- GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface, buffer);
+ surface = gst_va_allocator_prepare_buffer_unlocked (self, buffer);
+ g_mutex_unlock (&self->buffer_lock);
- return TRUE;
+ if (surface != VA_INVALID_ID) {
+ GST_TRACE_OBJECT (self, "Prepared surface %#x in buffer %p", surface,
+ buffer);
+ }
+
+ return (surface != VA_INVALID_ID);
}
void
{
GstVaAllocator *self = GST_VA_ALLOCATOR (allocator);
- GST_OBJECT_LOCK (self);
+ g_mutex_lock (&self->buffer_lock);
self->flushing = TRUE;
_available_mems_flush (self->display, self->available_mems,
&self->surface_count);
self->flushing = FALSE;
g_cond_broadcast (&self->buffer_cond);
- GST_OBJECT_UNLOCK (self);
+ g_mutex_unlock (&self->buffer_lock);
}
static gboolean