From 99ebbf72ef01b5155c7e2bfa40c0beaaaabfcf52 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 29 Jan 2021 09:43:07 -0500 Subject: [PATCH] v4l2codecs: h264: Enable 1 frame delay on non-live When doing non-live decoding, enable 1 frame of delay. This will ensure that we queue the next decoding job before we actually wait for the previous to complete. This improves throughput notably on RK3399. Part-of: --- sys/v4l2codecs/gstv4l2codech264dec.c | 27 +++++++++++++++++++++++++-- sys/v4l2codecs/gstv4l2decoder.c | 4 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index ca3662d3d0..d8cab64f3f 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -323,7 +323,7 @@ gst_v4l2_codec_h264_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) { GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder); - guint min = 0; + guint min = 0, num_bitstream; self->has_videometa = gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); @@ -336,8 +336,11 @@ gst_v4l2_codec_h264_dec_decide_allocation (GstVideoDecoder * decoder, 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, - GST_PAD_SINK, 2); + GST_PAD_SINK, num_bitstream); self->src_allocator = gst_v4l2_codec_allocator_new (self->decoder, GST_PAD_SRC, self->min_pool_size + min + 4); self->src_pool = gst_v4l2_codec_pool_new (self->src_allocator, &self->vinfo); @@ -1066,6 +1069,24 @@ gst_v4l2_codec_h264_dec_end_picture (GstH264Decoder * decoder, return gst_v4l2_codec_h264_dec_submit_bitstream (self, picture, 0); } +static guint +gst_v4l2_codec_h264_dec_get_preferred_output_delay (GstH264Decoder * decoder, + gboolean live) +{ + GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder); + guint delay; + + if (live) + delay = 0; + else + /* Just one for now, perhaps we can make this configurable in the future. */ + delay = 1; + + gst_v4l2_decoder_set_render_delay (self->decoder, delay); + + return delay; +} + static void gst_v4l2_codec_h264_dec_set_flushing (GstV4l2CodecH264Dec * self, gboolean flushing) @@ -1222,6 +1243,8 @@ gst_v4l2_codec_h264_dec_subclass_init (GstV4l2CodecH264DecClass * klass, GST_DEBUG_FUNCPTR (gst_v4l2_codec_h264_dec_decode_slice); h264decoder_class->end_picture = GST_DEBUG_FUNCPTR (gst_v4l2_codec_h264_dec_end_picture); + h264decoder_class->get_preferred_output_delay = + GST_DEBUG_FUNCPTR (gst_v4l2_codec_h264_dec_get_preferred_output_delay); klass->device = device; gst_v4l2_decoder_install_properties (gobject_class, PROP_LAST, device); diff --git a/sys/v4l2codecs/gstv4l2decoder.c b/sys/v4l2codecs/gstv4l2decoder.c index c145d65714..da0300e478 100644 --- a/sys/v4l2codecs/gstv4l2decoder.c +++ b/sys/v4l2codecs/gstv4l2decoder.c @@ -915,7 +915,7 @@ gst_v4l2_decoder_alloc_sub_request (GstV4l2Decoder * self, return request; } -/** +/* * gst_v4l2_decoder_set_render_delay: * @self a #GstV4l2Decoder pointer * @delay The expected render delay @@ -933,7 +933,7 @@ gst_v4l2_decoder_set_render_delay (GstV4l2Decoder * self, guint delay) self->render_delay = delay; } -/** +/* * gst_v4l2_decoder_get_render_delay: * @self a #GstV4l2Decoder pointer *