v4l2videoenc: Setup crop rectangle if needed
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 28 Apr 2022 13:19:57 +0000 (09:19 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 7 May 2022 11:35:14 +0000 (11:35 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2329>

subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c
subprojects/gst-plugins-good/sys/v4l2/gstv4l2videoenc.c

index 5c8a112..b948e16 100644 (file)
@@ -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;
index 3c70dc0..62990c5 100644 (file)
@@ -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);