mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
v4l2codecs: pool: Create new buffer when pool is empty
This simply create an empty GstBuffer when the pool is empty. This way it's up to the allocator to grow or wait if we ran out of memory.
This commit is contained in:
parent
ee26c9c9a1
commit
bc0a8ff40d
1 changed files with 19 additions and 9 deletions
|
@ -33,22 +33,37 @@ struct _GstV4l2CodecPool
|
|||
|
||||
G_DEFINE_TYPE (GstV4l2CodecPool, gst_v4l2_codec_pool, GST_TYPE_BUFFER_POOL);
|
||||
|
||||
static GstBuffer *
|
||||
gst_v4l2_codec_pool_create_empty_buffer (void)
|
||||
{
|
||||
GstVideoMeta *vmeta;
|
||||
GstBuffer *buffer = gst_buffer_new ();
|
||||
|
||||
vmeta = gst_buffer_add_video_meta (buffer, 0, GST_VIDEO_FORMAT_NV12, 1, 1);
|
||||
GST_META_FLAG_SET (vmeta, GST_META_FLAG_POOLED);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_v4l2_codec_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
||||
GstBufferPoolAcquireParams * params)
|
||||
{
|
||||
GstV4l2CodecPool *self = GST_V4L2_CODEC_POOL (pool);
|
||||
GstBuffer *buf = gst_atomic_queue_pop (self->queue);
|
||||
GstBuffer *buf;
|
||||
GstVideoMeta *vmeta;
|
||||
|
||||
/* A GstVideoInfo must be set before buffer can be acquired */
|
||||
g_return_val_if_fail (self->vinfo, GST_FLOW_ERROR);
|
||||
|
||||
buf = gst_atomic_queue_pop (self->queue);
|
||||
if (!buf)
|
||||
return GST_FLOW_ERROR;
|
||||
buf = gst_v4l2_codec_pool_create_empty_buffer ();
|
||||
|
||||
if (!gst_v4l2_codec_allocator_prepare_buffer (self->allocator, buf))
|
||||
if (!gst_v4l2_codec_allocator_prepare_buffer (self->allocator, buf)) {
|
||||
gst_atomic_queue_push (self->queue, buf);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
vmeta = gst_buffer_get_video_meta (buf);
|
||||
vmeta->format = GST_VIDEO_INFO_FORMAT (self->vinfo);
|
||||
|
@ -130,12 +145,7 @@ gst_v4l2_codec_pool_new (GstV4l2CodecAllocator * allocator,
|
|||
|
||||
pool_size = gst_v4l2_codec_allocator_get_pool_size (allocator);
|
||||
for (gsize i = 0; i < pool_size; i++) {
|
||||
GstVideoMeta *vmeta;
|
||||
GstBuffer *buffer = gst_buffer_new ();
|
||||
|
||||
vmeta = gst_buffer_add_video_meta (buffer, 0, GST_VIDEO_FORMAT_NV12, 1, 1);
|
||||
GST_META_FLAG_SET (vmeta, GST_META_FLAG_POOLED);
|
||||
|
||||
GstBuffer *buffer = gst_v4l2_codec_pool_create_empty_buffer ();
|
||||
gst_atomic_queue_push (pool->queue, buffer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue