v4l2codecs: h265: Minimize memory allocation

Be smarter when allocating sink and source memory pools to reduce the
memory footprint. Use gst_v4l2_decoder_get_render_delay() to know the
need number of buffers for downstream element.

Handle errors in case of memory allocation failures.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7544>
This commit is contained in:
Benjamin Gaignard 2024-09-17 14:48:03 +02:00 committed by GStreamer Marge Bot
parent edf64dc277
commit 0d0097b0b2

View file

@ -461,7 +461,7 @@ gst_v4l2_codec_h265_dec_decide_allocation (GstVideoDecoder * decoder,
{ {
GstV4l2CodecH265Dec *self = GST_V4L2_CODEC_H265_DEC (decoder); GstV4l2CodecH265Dec *self = GST_V4L2_CODEC_H265_DEC (decoder);
GstCaps *caps = NULL; GstCaps *caps = NULL;
guint min = 0; guint min = 0, num_bitstream;
if (self->streaming) if (self->streaming)
goto no_internal_changes; goto no_internal_changes;
@ -489,10 +489,26 @@ gst_v4l2_codec_h265_dec_decide_allocation (GstVideoDecoder * decoder,
min = MAX (2, min); min = MAX (2, min);
num_bitstream = 1 +
MAX (1, gst_v4l2_decoder_get_render_delay (self->decoder));
self->sink_allocator = gst_v4l2_codec_allocator_new (self->decoder, self->sink_allocator = gst_v4l2_codec_allocator_new (self->decoder,
GST_PAD_SINK, self->min_pool_size + 2); GST_PAD_SINK, num_bitstream);
if (!self->sink_allocator) {
GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT,
("Not enough memory to allocate sink buffers."), (NULL));
return FALSE;
}
self->src_allocator = gst_v4l2_codec_allocator_new (self->decoder, self->src_allocator = gst_v4l2_codec_allocator_new (self->decoder,
GST_PAD_SRC, self->min_pool_size + min + 1); GST_PAD_SRC, self->min_pool_size + min);
if (!self->src_allocator) {
GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT,
("Not enough memory to allocate source buffers."), (NULL));
g_clear_object (&self->sink_allocator);
return FALSE;
}
self->src_pool = gst_v4l2_codec_pool_new (self->src_allocator, &self->vinfo); self->src_pool = gst_v4l2_codec_pool_new (self->src_allocator, &self->vinfo);
no_internal_changes: no_internal_changes: