v4l2codecs: Add support for render delay

This add support for render delay in the decoder helper.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
This commit is contained in:
Nicolas Dufresne 2021-01-29 09:41:22 -05:00 committed by GStreamer Merge Bot
parent 88b93416fe
commit 241a490084
2 changed files with 43 additions and 3 deletions

View file

@ -82,6 +82,7 @@ struct _GstV4l2Decoder
/* properties */ /* properties */
gchar *media_device; gchar *media_device;
gchar *video_device; gchar *video_device;
guint render_delay;
}; };
G_DEFINE_TYPE_WITH_CODE (GstV4l2Decoder, gst_v4l2_decoder, GST_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (GstV4l2Decoder, gst_v4l2_decoder, GST_TYPE_OBJECT,
@ -914,6 +915,38 @@ gst_v4l2_decoder_alloc_sub_request (GstV4l2Decoder * self,
return request; return request;
} }
/**
* gst_v4l2_decoder_set_render_delay:
* @self a #GstV4l2Decoder pointer
* @delay The expected render delay
*
* The decoder will adjust the number of allowed concurrent request in order
* to allow this delay. The same number of concurrent bitstream buffer will be
* used, so make sure to adjust the number of bitstream buffer.
*
* For per-slice decoder, this is the maximum number of pending slice, so the
* render backlog in frame may be less then the render delay.
*/
void
gst_v4l2_decoder_set_render_delay (GstV4l2Decoder * self, guint delay)
{
self->render_delay = delay;
}
/**
* gst_v4l2_decoder_get_render_delay:
* @self a #GstV4l2Decoder pointer
*
* This function is used to avoid storing the render delay in multiple places.
*
* Returns: The currently configured render delay.
*/
guint
gst_v4l2_decoder_get_render_delay (GstV4l2Decoder * self)
{
return self->render_delay;
}
GstV4l2Request * GstV4l2Request *
gst_v4l2_request_ref (GstV4l2Request * request) gst_v4l2_request_ref (GstV4l2Request * request)
{ {
@ -985,6 +1018,7 @@ gst_v4l2_request_queue (GstV4l2Request * request, guint flags)
{ {
GstV4l2Decoder *decoder = request->decoder; GstV4l2Decoder *decoder = request->decoder;
gint ret; gint ret;
guint max_pending;
GST_TRACE_OBJECT (decoder, "Queuing request %p.", request); GST_TRACE_OBJECT (decoder, "Queuing request %p.", request);
@ -1014,9 +1048,9 @@ gst_v4l2_request_queue (GstV4l2Request * request, guint flags)
gst_queue_array_push_tail (decoder->pending_requests, gst_queue_array_push_tail (decoder->pending_requests,
gst_v4l2_request_ref (request)); gst_v4l2_request_ref (request));
/* FIXME to support more then one pending requests, we need the request to max_pending = MAX (1, decoder->render_delay);
* be refcounted */
if (gst_queue_array_get_length (decoder->pending_requests) > 6) { if (gst_queue_array_get_length (decoder->pending_requests) > max_pending) {
GstV4l2Request *pending_req; GstV4l2Request *pending_req;
pending_req = gst_queue_array_peek_head (decoder->pending_requests); pending_req = gst_queue_array_peek_head (decoder->pending_requests);

View file

@ -108,6 +108,12 @@ GstV4l2Request *gst_v4l2_decoder_alloc_sub_request (GstV4l2Decoder * self,
GstV4l2Request * prev_request, GstV4l2Request * prev_request,
GstMemory *bitstream); GstMemory *bitstream);
void gst_v4l2_decoder_set_render_delay (GstV4l2Decoder * self,
guint delay);
guint gst_v4l2_decoder_get_render_delay (GstV4l2Decoder * self);
GstV4l2Request * gst_v4l2_request_ref (GstV4l2Request * request); GstV4l2Request * gst_v4l2_request_ref (GstV4l2Request * request);
void gst_v4l2_request_unref (GstV4l2Request * request); void gst_v4l2_request_unref (GstV4l2Request * request);