media: hantro: Implement V4L2_CID_JPEG_ACTIVE_MARKER control
authorChen-Yu Tsai <wenst@chromium.org>
Fri, 7 Jan 2022 09:34:53 +0000 (10:34 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 28 Jan 2022 12:25:58 +0000 (13:25 +0100)
The Hantro JPEG encoder driver adds various segments to the JPEG header.
While it would be quite complicated to make these segments selectable
to userspace, given that the driver has to fill in various fields in
these segments, and also take care of alignment, it would be nice if
the driver could signal to userspace what segments are included.

Implement the V4L2_CID_JPEG_ACTIVE_MARKER control, and make it read
only so that it always returns the set of segments that the driver adds.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/hantro/hantro_drv.c

index 6a51f39..b376b9d 100644 (file)
@@ -332,6 +332,11 @@ static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
        .s_ctrl = hantro_hevc_s_ctrl,
 };
 
+#define HANTRO_JPEG_ACTIVE_MARKERS     (V4L2_JPEG_ACTIVE_MARKER_APP0 | \
+                                        V4L2_JPEG_ACTIVE_MARKER_COM | \
+                                        V4L2_JPEG_ACTIVE_MARKER_DQT | \
+                                        V4L2_JPEG_ACTIVE_MARKER_DHT)
+
 static const struct hantro_ctrl controls[] = {
        {
                .codec = HANTRO_JPEG_ENCODER,
@@ -344,6 +349,22 @@ static const struct hantro_ctrl controls[] = {
                        .ops = &hantro_jpeg_ctrl_ops,
                },
        }, {
+               .codec = HANTRO_JPEG_ENCODER,
+               .cfg = {
+                       .id = V4L2_CID_JPEG_ACTIVE_MARKER,
+                       .max = HANTRO_JPEG_ACTIVE_MARKERS,
+                       .def = HANTRO_JPEG_ACTIVE_MARKERS,
+                       /*
+                        * Changing the set of active markers/segments also
+                        * messes up the alignment of the JPEG header, which
+                        * is needed to allow the hardware to write directly
+                        * to the output buffer. Implementing this introduces
+                        * a lot of complexity for little gain, as the markers
+                        * enabled is already the minimum required set.
+                        */
+                       .flags = V4L2_CTRL_FLAG_READ_ONLY,
+               },
+       }, {
                .codec = HANTRO_MPEG2_DECODER,
                .cfg = {
                        .id = V4L2_CID_STATELESS_MPEG2_SEQUENCE,