mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
v4l2codecs: allocator: Add method to wait for more buffers
This add function to wait for buffers to get back into the pool along with a set_flushing() method to allow unblocking this wait.
This commit is contained in:
parent
bc0a8ff40d
commit
f69283819a
2 changed files with 48 additions and 0 deletions
|
@ -45,6 +45,9 @@ struct _GstV4l2CodecAllocator
|
||||||
gint pool_size;
|
gint pool_size;
|
||||||
gboolean detached;
|
gboolean detached;
|
||||||
|
|
||||||
|
GCond buffer_cond;
|
||||||
|
gboolean flushing;
|
||||||
|
|
||||||
GstV4l2Decoder *decoder;
|
GstV4l2Decoder *decoder;
|
||||||
GstPadDirection direction;
|
GstPadDirection direction;
|
||||||
};
|
};
|
||||||
|
@ -152,6 +155,7 @@ gst_v4l2_codec_allocator_release (GstMiniObject * mini_object)
|
||||||
if (gst_v4l2_codec_buffer_release_mem (buf)) {
|
if (gst_v4l2_codec_buffer_release_mem (buf)) {
|
||||||
GST_DEBUG_OBJECT (self, "Placing back buffer %i into pool", buf->index);
|
GST_DEBUG_OBJECT (self, "Placing back buffer %i into pool", buf->index);
|
||||||
g_queue_push_tail (&self->pool, buf);
|
g_queue_push_tail (&self->pool, buf);
|
||||||
|
g_cond_signal (&self->buffer_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_OBJECT_UNLOCK (self);
|
GST_OBJECT_UNLOCK (self);
|
||||||
|
@ -196,6 +200,7 @@ failed:
|
||||||
static void
|
static void
|
||||||
gst_v4l2_codec_allocator_init (GstV4l2CodecAllocator * self)
|
gst_v4l2_codec_allocator_init (GstV4l2CodecAllocator * self)
|
||||||
{
|
{
|
||||||
|
g_cond_init (&self->buffer_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -220,6 +225,8 @@ gst_v4l2_codec_allocator_finalize (GObject * object)
|
||||||
if (!self->detached)
|
if (!self->detached)
|
||||||
gst_v4l2_decoder_request_buffers (self->decoder, self->direction, 0);
|
gst_v4l2_decoder_request_buffers (self->decoder, self->direction, 0);
|
||||||
|
|
||||||
|
g_cond_clear (&self->buffer_cond);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_v4l2_codec_allocator_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_v4l2_codec_allocator_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,6 +280,27 @@ gst_v4l2_codec_allocator_alloc (GstV4l2CodecAllocator * self)
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_v4l2_codec_allocator_create_buffer (GstV4l2CodecAllocator * self)
|
||||||
|
{
|
||||||
|
/* TODO implement */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_v4l2_codec_allocator_wait_for_buffer (GstV4l2CodecAllocator * self)
|
||||||
|
{
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (self);
|
||||||
|
while (self->pool.length == 0 && !self->flushing)
|
||||||
|
g_cond_wait (&self->buffer_cond, GST_OBJECT_GET_LOCK (self));
|
||||||
|
ret = !self->flushing;
|
||||||
|
GST_OBJECT_UNLOCK (self);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_v4l2_codec_allocator_prepare_buffer (GstV4l2CodecAllocator * self,
|
gst_v4l2_codec_allocator_prepare_buffer (GstV4l2CodecAllocator * self,
|
||||||
GstBuffer * gstbuf)
|
GstBuffer * gstbuf)
|
||||||
|
@ -324,6 +352,17 @@ gst_v4l2_codec_allocator_detach (GstV4l2CodecAllocator * self)
|
||||||
GST_OBJECT_UNLOCK (self);
|
GST_OBJECT_UNLOCK (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_v4l2_codec_allocator_set_flushing (GstV4l2CodecAllocator * self,
|
||||||
|
gboolean flushing)
|
||||||
|
{
|
||||||
|
GST_OBJECT_LOCK (self);
|
||||||
|
self->flushing = flushing;
|
||||||
|
if (flushing)
|
||||||
|
g_cond_broadcast (&self->buffer_cond);
|
||||||
|
GST_OBJECT_UNLOCK (self);
|
||||||
|
}
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
gst_v4l2_codec_memory_get_index (GstMemory * mem)
|
gst_v4l2_codec_memory_get_index (GstMemory * mem)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,12 @@ GstV4l2CodecAllocator *gst_v4l2_codec_allocator_new (GstV4l2Decoder * decoder,
|
||||||
|
|
||||||
GstMemory *gst_v4l2_codec_allocator_alloc (GstV4l2CodecAllocator * allocator);
|
GstMemory *gst_v4l2_codec_allocator_alloc (GstV4l2CodecAllocator * allocator);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gboolean gst_v4l2_codec_allocator_create_buffer (GstV4l2CodecAllocator * self);
|
||||||
|
|
||||||
|
gboolean gst_v4l2_codec_allocator_wait_for_buffer (GstV4l2CodecAllocator * self);
|
||||||
|
|
||||||
gboolean gst_v4l2_codec_allocator_prepare_buffer (GstV4l2CodecAllocator * allocator,
|
gboolean gst_v4l2_codec_allocator_prepare_buffer (GstV4l2CodecAllocator * allocator,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
|
|
||||||
|
@ -45,6 +51,9 @@ guint gst_v4l2_codec_allocator_get_pool_size (GstV4l2CodecAllo
|
||||||
|
|
||||||
void gst_v4l2_codec_allocator_detach (GstV4l2CodecAllocator * self);
|
void gst_v4l2_codec_allocator_detach (GstV4l2CodecAllocator * self);
|
||||||
|
|
||||||
|
void gst_v4l2_codec_allocator_set_flushing (GstV4l2CodecAllocator * self,
|
||||||
|
gboolean flushing);
|
||||||
|
|
||||||
guint32 gst_v4l2_codec_memory_get_index (GstMemory * mem);
|
guint32 gst_v4l2_codec_memory_get_index (GstMemory * mem);
|
||||||
|
|
||||||
#endif /* _GST_V4L2_CODECS_ALLOCATOR_H_ */
|
#endif /* _GST_V4L2_CODECS_ALLOCATOR_H_ */
|
||||||
|
|
Loading…
Reference in a new issue