From 522f19e013904faa99380577804d5da992f30bd8 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 28 Apr 2022 09:19:57 -0400 Subject: [PATCH] v4l2videoenc: Setup crop rectangle if needed Hantro H1 and Rockchip VEPU2 drivers will pad the width/height to a multiple of 16. In order to obtain the right JPEG size, the image needs to be cropped using the S_SELECTION API. This support is added as best effort since older drivers may emulate this by looking at the capture queue width/height. Part-of: --- subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c | 2 -- subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c index 5c8a1126fd..b948e16cc6 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c @@ -3194,7 +3194,6 @@ gst_v4l2_object_reset_compose_region (GstV4l2Object * obj) struct v4l2_selection sel = { 0 }; GST_V4L2_CHECK_OPEN (obj); - GST_V4L2_CHECK_NOT_ACTIVE (obj); sel.type = obj->type; sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; @@ -4357,7 +4356,6 @@ gst_v4l2_object_set_crop (GstV4l2Object * obj, struct v4l2_rect * crop_rect) struct v4l2_crop crop = { 0 }; GST_V4L2_CHECK_OPEN (obj); - GST_V4L2_CHECK_NOT_ACTIVE (obj); sel.type = obj->type; sel.target = V4L2_SEL_TGT_CROP; diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c index 3c70dc04bc..62990c591a 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c @@ -342,6 +342,9 @@ gst_v4l2_video_enc_set_format (GstVideoEncoder * encoder, return FALSE; } + /* best effort */ + gst_v4l2_object_setup_padding (self->v4l2output); + self->input_state = gst_video_codec_state_ref (state); GST_DEBUG_OBJECT (self, "output caps: %" GST_PTR_FORMAT, state->caps); @@ -876,6 +879,9 @@ gst_v4l2_video_enc_decide_allocation (GstVideoEncoder * } gst_caps_unref (caps); + /* best effort */ + gst_v4l2_object_setup_padding (self->v4l2capture); + if (gst_v4l2_object_decide_allocation (self->v4l2capture, query)) { GstVideoEncoderClass *enc_class = GST_VIDEO_ENCODER_CLASS (parent_class); ret = enc_class->decide_allocation (encoder, query);