From 2e5929abfc5f26bca3bf813918e1732f38322116 Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Thu, 13 Jul 2023 16:16:44 +0200 Subject: [PATCH] v4l2videoenc: replace custom QUERY_CAPS handling with getcaps callback The videoencoder base class uses getcaps() to ask a subclass for the caps in its sink_query_default() implementation. Replace the custom handling of the QUERY_CAPS in the v4l2videoenc with an implementation of getcaps() that returns the caps that are supported by the v4l2videoenc to return these caps in the query. This getcaps() implementation also calls the provided proxy_getcaps(), which sends a caps query to downstream. This fixes the v4l2videoenc element to respect limits of downstream elements in a sink query. Part-of: --- .../sys/v4l2/gstv4l2videoenc.c | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c index 5c99a97563..8738cc1700 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c @@ -517,6 +517,26 @@ negotiate_profile_and_level (GstCapsFeatures * features, GstStructure * s, return failed; } +static GstCaps * +gst_v4l2_video_enc_sink_getcaps (GstVideoEncoder * encoder, GstCaps * filter) +{ + GstV4l2VideoEnc *self = GST_V4L2_VIDEO_ENC (encoder); + GstCaps *probed_caps = NULL; + GstCaps *caps; + + if (self->probed_sinkcaps) + probed_caps = gst_caps_ref (self->probed_sinkcaps); + + caps = gst_video_encoder_proxy_getcaps (encoder, probed_caps, filter); + + if (probed_caps) + gst_caps_unref (probed_caps); + + GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, caps); + + return caps; +} + static gboolean gst_v4l2_video_enc_negotiate (GstVideoEncoder * encoder) { @@ -1009,34 +1029,8 @@ static gboolean gst_v4l2_video_enc_sink_query (GstVideoEncoder * encoder, GstQuery * query) { gboolean ret = TRUE; - GstV4l2VideoEnc *self = GST_V4L2_VIDEO_ENC (encoder); switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_CAPS:{ - GstCaps *filter, *result = NULL; - GstPad *pad = GST_VIDEO_ENCODER_SINK_PAD (encoder); - - gst_query_parse_caps (query, &filter); - - if (self->probed_sinkcaps) - result = gst_caps_ref (self->probed_sinkcaps); - else - result = gst_pad_get_pad_template_caps (pad); - - if (filter) { - GstCaps *tmp = result; - result = - gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST); - gst_caps_unref (tmp); - } - - GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, result); - - gst_query_set_caps_result (query, result); - gst_caps_unref (result); - break; - } - default: ret = GST_VIDEO_ENCODER_CLASS (parent_class)->sink_query (encoder, query); break; @@ -1170,6 +1164,8 @@ gst_v4l2_video_enc_class_init (GstV4l2VideoEncClass * klass) video_encoder_class->flush = GST_DEBUG_FUNCPTR (gst_v4l2_video_enc_flush); video_encoder_class->set_format = GST_DEBUG_FUNCPTR (gst_v4l2_video_enc_set_format); + video_encoder_class->getcaps = + GST_DEBUG_FUNCPTR (gst_v4l2_video_enc_sink_getcaps); video_encoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_v4l2_video_enc_negotiate); video_encoder_class->decide_allocation =