Skip to contentSkip to conversation

Add Rockchip VPU JPEG encoder

PATCH Superseded Ezequiel Garcia 4 participants 16 messages Sep 5, 2018 – Oct 15, 2018 8 messages not in the archive

Subsystems (5)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add Rockchip VPU JPEG encoder

This series adds support for JPEG encoding via the VPU block present in Rockchip platforms. Currently, support for RK3288 and RK3399 is included.

Please, see the previous versions of this cover letter for more information.

Compliance
==========

(Same results as v3)

v4l2-compliance SHA: d0f4ea7ddab6d0244c4fe1e960bb2aaeefb911b9, 64 bits

Compliance test for device /dev/video0:

Driver Info:

	Driver name      : rockchip-vpu
	Card type        : rockchip,rk3399-vpu-enc
	Bus info         : platform: rockchip-vpu
	Driver version   : 4.18.0
	Capabilities     : 0x84204000

Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : rockchip-vpu
	Model            : rockchip-vpu
	Serial           : 
	Bus info         : 
	Media version    : 4.18.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 4.18.0
Interface Info:
	ID               : 0x0300000c
	Type             : V4L Video
Entity Info:
	ID               : 0x00000001 (1)
	Name             : rockchip,rk3399-vpu-enc-source
	Function         : V4L2 I/O
	Pad 0x01000002   : Source
	  Link 0x02000008: to remote pad 0x1000005 of entity 'rockchip,rk3399-vpu-enc-proc': Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 2 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
test MMAP: OK
test USERPTR: OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device

Total: 48, Succeeded: 48, Failed: 0, Warnings: 0

v5:
- Make coefficients 2-byte wide, to support 8-bit and 16-bit precision coefficient. Also, add a 'precision' field, to allow the user to specifiy the coefficient precision.
- Minor style changes as requested by Hans.
- Get rid of all the unused leftover code.
- Move driver to staging. The driver will support video encoding, via the request API. So let's use staging until the controls are stabilized.
v4:
- Change luma and chroma array controls, with a compound control, as suggested by Paul.
v3:
- Refactor driver to allow a more elegant integration with other codec modes (h264 decoding, jpeg decoding, etc). Each variant can now be encoders, decoders or both.
- Register driver in the media controller framework,
in preparation for the Request API.
- Set values for JPEG quantization controls in the core, as suggested by Tomasz and Hans.
- Move pm_runtime_get/put to run/done, reducing power consumption. This was possible thanks to Miouyouyou, who pointed out the power domains missing [1].
- Use bulk clock API for simpler code.
v2:
- Add devicetree binding documentation and devicetree changes
- Add documentation to added pixel format and controls
- Address Hans' review comments
- Get rid of unused running_ctx field
- Fix wrong planar pixel format depths
- Other minor changes for v4l2-compliance
- Drop .crop support, we will add support for the
selector API later, if needed.

[1] https://github.com/Miouyouyou/RockMyy/blob/master/patches/kernel/v4.18/DTS/0026-ARM-DTSI-rk3288-Set-the-VPU-MMU-power-domains.patch

Ezequiel Garcia (4):
dt-bindings: Document the Rockchip VPU bindings
ARM: dts: rockchip: add VPU device node for RK3288
arm64: dts: rockchip: add VPU device node for RK3399
media: add Rockchip VPU JPEG encoder driver

Shunqian Zheng (2):
media: Add JPEG_RAW format
media: Add controls for JPEG quantization tables

 .../bindings/media/rockchip-vpu.txt           |  30 +
 .../media/uapi/v4l/extended-controls.rst      |  31 +
 .../media/uapi/v4l/pixfmt-compressed.rst      |   9 +
 .../media/videodev2.h.rst.exceptions          |   1 +
 MAINTAINERS                                   |   7 +
 arch/arm/boot/dts/rk3288.dtsi                 |  14 +-
 arch/arm64/boot/dts/rockchip/rk3399.dtsi      |  14 +-
 drivers/media/v4l2-core/v4l2-ctrls.c          |  10 +
 drivers/media/v4l2-core/v4l2-ioctl.c          |   1 +
 drivers/staging/media/Kconfig                 |   2 +
 drivers/staging/media/Makefile                |   1 +
 drivers/staging/media/rockchip/vpu/Makefile   |   9 +
 drivers/staging/media/rockchip/vpu/TODO       |   5 +
 .../media/rockchip/vpu/rk3288_vpu_hw.c        | 123 ++++
 .../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c     | 129 ++++
 .../media/rockchip/vpu/rk3288_vpu_regs.h      | 442 +++++++++++++
 .../media/rockchip/vpu/rk3399_vpu_hw.c        | 123 ++++
 .../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c     | 157 +++++
 .../media/rockchip/vpu/rk3399_vpu_regs.h      | 601 +++++++++++++++++
 .../staging/media/rockchip/vpu/rockchip_vpu.h | 296 +++++++++
 .../media/rockchip/vpu/rockchip_vpu_common.h  |  31 +
 .../media/rockchip/vpu/rockchip_vpu_drv.c     | 528 +++++++++++++++
 .../media/rockchip/vpu/rockchip_vpu_enc.c     | 604 ++++++++++++++++++
 .../media/rockchip/vpu/rockchip_vpu_hw.h      |  65 ++
 include/uapi/linux/v4l2-controls.h            |  12 +
 include/uapi/linux/videodev2.h                |   2 +
 26 files changed, 3245 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-vpu.txt
 create mode 100644 drivers/staging/media/rockchip/vpu/Makefile
 create mode 100644 drivers/staging/media/rockchip/vpu/TODO
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
Signature · 1 line
2.18.0

A message that is not in the archive (sent off-list or not yet received): 20180905220011.16612-1-ezequiel-ZGY8ohtN/[email protected]

#2 lore raw

PATCH v5 1/6 dt-bindings: Document the Rockchip VPU bindings

Add devicetree binding documentation for Rockchip Video Processing Unit IP.

---
 .../bindings/media/rockchip-vpu.txt           | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-vpu.txt
Documentation/devicetree/bindings/media/rockchip-vpu.txt new file +30 -0
new file mode 100644
index 000000000000..5e0d421301ca
@@ -0,0 +1,30 @@
+device-tree bindings for rockchip VPU codec
+
+Rockchip (Video Processing Unit) present in various Rockchip platforms,
+such as RK3288 and RK3399.
+
+Required properties:
+- compatible: value should be one of the following
+		"rockchip,rk3288-vpu";
+		"rockchip,rk3399-vpu";
+- interrupts: encoding and decoding interrupt specifiers
+- interrupt-names: should be "vepu" and "vdpu"
+- clocks: phandle to VPU aclk, hclk clocks
+- clock-names: should be "aclk" and "hclk"
+- power-domains: phandle to power domain node
+- iommus: phandle to a iommu node
+
+Example:
+SoC-specific DT entry:
+	vpu: video-codec@ff9a0000 {
+		compatible = "rockchip,rk3288-vpu";
+		reg = <0x0 0xff9a0000 0x0 0x800>;
+		interrupts = <GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "vepu", "vdpu";
+		clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
+		clock-names = "aclk", "hclk";
+		power-domains = <&power RK3288_PD_VIDEO>;
+		iommus = <&vpu_mmu>;
+	};
+
Signature · 1 line
2.18.0
#3 lore raw

PATCH v5 2/6 ARM: dts: rockchip: add VPU device node for RK3288

In reply to a message not in the archive

Add the Video Processing Unit node for RK3288 SoC.

Fix the VPU IOMMU node, which was disabled and lacking its power domain property.

---
 arch/arm/boot/dts/rk3288.dtsi | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
arch/arm/boot/dts/rk3288.dtsi +13 -1
index 0840ffb3205c..40d203cdca09 100644
@@ -1223,6 +1223,18 @@
 		};
 	};
 
+	vpu: video-codec@ff9a0000 {
+		compatible = "rockchip,rk3288-vpu";
+		reg = <0x0 0xff9a0000 0x0 0x800>;
+		interrupts = <GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "vepu", "vdpu";
+		clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
+		clock-names = "aclk", "hclk";
+		power-domains = <&power RK3288_PD_VIDEO>;
+		iommus = <&vpu_mmu>;
+	};
+
 	vpu_mmu: iommu@ff9a0800 {
 		compatible = "rockchip,iommu";
 		reg = <0x0 0xff9a0800 0x0 0x100>;
@@ -1230,8 +1242,8 @@
 		interrupt-names = "vpu_mmu";
 		clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
 		clock-names = "aclk", "iface";
+		power-domains = <&power RK3288_PD_VIDEO>;
 		#iommu-cells = <0>;
-		status = "disabled";
 	};
 
 	hevc_mmu: iommu@ff9c0440 {
Signature · 1 line
2.18.0
#4 lore raw

PATCH v5 3/6 arm64: dts: rockchip: add VPU device node for RK3399

In reply to a message not in the archive

Add the Video Processing Unit node for the RK3399 SoC.

Also, fix the VPU IOMMU node, which was disabled and lacking its power domain property.

---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +13 -1
index c88e603396f6..5efb124e5c3a 100644
@@ -1198,6 +1198,18 @@
 		status = "disabled";
 	};
 
+	vpu: video-codec@ff650000 {
+		compatible = "rockchip,rk3399-vpu";
+		reg = <0x0 0xff650000 0x0 0x800>;
+		interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH 0>,
+			     <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH 0>;
+		interrupt-names = "vepu", "vdpu";
+		clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
+		clock-names = "aclk", "hclk";
+		power-domains = <&power RK3399_PD_VCODEC>;
+		iommus = <&vpu_mmu>;
+	};
+
 	vpu_mmu: iommu@ff650800 {
 		compatible = "rockchip,iommu";
 		reg = <0x0 0xff650800 0x0 0x40>;
@@ -1205,8 +1217,8 @@
 		interrupt-names = "vpu_mmu";
 		clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
 		clock-names = "aclk", "iface";
+		power-domains = <&power RK3399_PD_VCODEC>;
 		#iommu-cells = <0>;
-		status = "disabled";
 	};
 
 	vdec_mmu: iommu@ff660480 {
Signature · 1 line
2.18.0
#5 lore raw

PATCH v5 4/6 media: Add JPEG_RAW format

In reply to a message not in the archive

From: Shunqian Zheng <[email protected]>

Add V4L2_PIX_FMT_JPEG_RAW format that does not contain JPEG header in the output frame.

---
 Documentation/media/uapi/v4l/pixfmt-compressed.rst | 9 +++++++++
 drivers/media/v4l2-core/v4l2-ioctl.c               | 1 +
 include/uapi/linux/videodev2.h                     | 1 +
 3 files changed, 11 insertions(+)
Documentation/media/uapi/v4l/pixfmt-compressed.rst +9 -0
index d04b18adac33..39222091a87c 100644
@@ -23,6 +23,15 @@ Compressed Formats
       - 'JPEG'
       - TBD. See also :ref:`VIDIOC_G_JPEGCOMP <VIDIOC_G_JPEGCOMP>`,
 	:ref:`VIDIOC_S_JPEGCOMP <VIDIOC_G_JPEGCOMP>`.
+    * .. _V4L2-PIX-FMT-JPEG-RAW:
+
+      - ``V4L2_PIX_FMT_JPEG_RAW``
+      - 'Raw JPEG'
+      - Raw JPEG bitstream, containing a compressed payload. This format
+        contains an image scan, i.e. without any metadata or headers.
+        The user is expected to set the needed metadata such as
+        quantization and entropy encoding tables, via ``V4L2_CID_JPEG``
+        controls, see :ref:`jpeg-control-id`.
     * .. _V4L2-PIX-FMT-MPEG:
 
       - ``V4L2_PIX_FMT_MPEG``
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
index 54afc9c7ee6e..0dcd95f4bdf1 100644
@@ -1301,6 +1301,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 		/* Max description length mask:	descr = "0123456789012345678901234567890" */
 		case V4L2_PIX_FMT_MJPEG:	descr = "Motion-JPEG"; break;
 		case V4L2_PIX_FMT_JPEG:		descr = "JFIF JPEG"; break;
+		case V4L2_PIX_FMT_JPEG_RAW:	descr = "Raw JPEG"; break;
 		case V4L2_PIX_FMT_DV:		descr = "1394"; break;
 		case V4L2_PIX_FMT_MPEG:		descr = "MPEG-1/2/4"; break;
 		case V4L2_PIX_FMT_H264:		descr = "H.264"; break;
include/uapi/linux/videodev2.h +1 -0
index 622f0479d668..f9f3ae5b489e 100644
@@ -627,6 +627,7 @@ struct v4l2_pix_format {
 /* compressed formats */
 #define V4L2_PIX_FMT_MJPEG    v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   */
 #define V4L2_PIX_FMT_JPEG     v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG     */
+#define V4L2_PIX_FMT_JPEG_RAW v4l2_fourcc('J', 'P', 'G', 'R') /* JFIF JPEG RAW without headers */
 #define V4L2_PIX_FMT_DV       v4l2_fourcc('d', 'v', 's', 'd') /* 1394          */
 #define V4L2_PIX_FMT_MPEG     v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
 #define V4L2_PIX_FMT_H264     v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
Signature · 1 line
2.18.0
#6 lore raw

PATCH v5 5/6 media: Add controls for JPEG quantization tables

In reply to a message not in the archive

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +31 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.
+
+    * - __u16
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u16
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.
 
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +12 -0
index e4ee10ee917d..856b3325052f 100644
@@ -987,6 +987,18 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	/* ITU-T.81 specifies two quantization coefficient precisions:
+	 * 8-bit for baseline profile,
+	 * 8-bit or 16-bit for extended profile.
+	 *
+	 * User shall set "precision" to 0 for 8-bit and 1 for 16-bit.
+	 */
+	__u8	precision;
+	__u16	luma_quantization_matrix[64];
+	__u16	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +1 -0
index f9f3ae5b489e..8ace47cb1003 100644
@@ -1637,6 +1637,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 1 line
2.18.0

A message that is not in the archive (sent off-list or not yet received): 20180905220011.16612-6-ezequiel-ZGY8ohtN/[email protected]

#8 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Quoted 37 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +13 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.

So does specifying 1 here switch the HW encoder to use extended profile? What if the HW only supports baseline? The rockchip driver doesn't appear to check the precision field at all...

I think this needs a bit more thought.

I am not at all sure that this is the right place for the precision field. This is really about JPEG profiles, so I would kind of expect a JPEG PROFILE control (just like other codec profiles), or possibly a new pixelformat for extended profiles.

And based on that the driver would interpret these matrix values as 8 or 16 bits.

Regards,

Hans

Quoted 101 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+    * - __u16
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u16
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.
 
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +12 -0
index e4ee10ee917d..856b3325052f 100644
@@ -987,6 +987,18 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	/* ITU-T.81 specifies two quantization coefficient precisions:
+	 * 8-bit for baseline profile,
+	 * 8-bit or 16-bit for extended profile.
+	 *
+	 * User shall set "precision" to 0 for 8-bit and 1 for 16-bit.
+	 */
+	__u8	precision;
+	__u16	luma_quantization_matrix[64];
+	__u16	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +1 -0
index f9f3ae5b489e..8ace47cb1003 100644
@@ -1637,6 +1637,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */

A message that is not in the archive (sent off-list or not yet received): 718d8a73-008a-a610-d090-91cc54a992ad-qWit8jRvyhVmR6Xm/[email protected]

#10 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Hi Hans,

Thanks for the review.

Quoted 44 lines · Hans Verkuil
Quoted 43 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +19 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
Quoted 9 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 4 lines
Documentation/media/uapi/v4l/extended-controls.rst +4 -0
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.

So does specifying 1 here switch the HW encoder to use extended profile? What if the HW only supports baseline? The rockchip driver doesn't appear to check the precision field at all...

The driver is missing to check that, when the user sets this control.

Quoted 10 lines

I think this needs a bit more thought.

I am not at all sure that this is the right place for the precision field. This is really about JPEG profiles, so I would kind of expect a JPEG PROFILE control (just like other codec profiles), or possibly a new pixelformat for extended profiles.

And based on that the driver would interpret these matrix values as 8 or 16 bits.

Right, the JPEG profile control is definitely needed. I haven't add it because it wouldn't be used, since this VPU can only do baseline.

However, the problem is that some JPEGs in the wild have with 8-bit data and 16-bit quantization coefficients, as per [1] and [2]:

[1] https://github.com/martinhath/jpeg-rust/issues/1
[2] https://github.com/libjpeg-turbo/libjpeg-turbo/pull/90

So, in order to support decoding of these images, I've added the precision field to the quantization control. The user would be able to set a baseline or extended profile thru a (future) profile control, and if 16-bit tables are found, and if the hardware supports them, the driver would be able to support them.

Another option, which might be even better, is have explicit baseline and extended quantization tables controls, e.g.: V4L2_CID_JPEG_QUANT and V4L2_CID_JPEG_EXT_QUANT.

Thanks,
Ezequiel

A message that is not in the archive (sent off-list or not yet received): 710d4e77de63b46e6ffd440c9c98ca9af133117f.camel-ZGY8ohtN/[email protected]

#12 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Hi,

Quoted 68 lines · Ezequiel Garcia

Hi Hans,

Thanks for the review.

Quoted 44 lines · Hans Verkuil
Quoted 43 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +19 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
Quoted 9 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 4 lines
Documentation/media/uapi/v4l/extended-controls.rst +4 -0
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.

So does specifying 1 here switch the HW encoder to use extended profile? What if the HW only supports baseline? The rockchip driver doesn't appear to check the precision field at all...

The driver is missing to check that, when the user sets this control.

Quoted 7 lines

I think this needs a bit more thought.

I am not at all sure that this is the right place for the precision field. This is really about JPEG profiles, so I would kind of expect a JPEG PROFILE control (just like other codec profiles), or possibly a new pixelformat for extended profiles.

Quoted 6 lines
Quoted 3 lines

And based on that the driver would interpret these matrix values as 8 or 16 bits.

Right, the JPEG profile control is definitely needed. I haven't add it because it wouldn't be used, since this VPU can only do baseline.

Well, I suppose it would still be relevant that you add it for the encoder and only report baseline there.

Quoted 12 lines

However, the problem is that some JPEGs in the wild have with 8-bit data and 16-bit quantization coefficients, as per [1] and [2]:

[1] https://github.com/martinhath/jpeg-rust/issues/1
[2] https://github.com/libjpeg-turbo/libjpeg-turbo/pull/90

So, in order to support decoding of these images, I've added the precision field to the quantization control. The user would be able to set a baseline or extended profile thru a (future) profile control, and if 16-bit tables are found, and if the hardware supports them, the driver would be able to support them.

Quoted 3 lines

Another option, which might be even better, is have explicit baseline and extended quantization tables controls, e.g.: V4L2_CID_JPEG_QUANT and V4L2_CID_JPEG_EXT_QUANT.

I think this makes more sense than a common structure with an indication bit on how to interpret the data.

However, it seems problematic that userspace can't figure out whether 16-bit quant tables are supported with a baseline profile and just has to try and see.

Hans, do you think this is an acceptable approach or should we rather stick to the standard here, at the cost of not supporting these pictures that were encoded with this common abuse of the standard?

Cheers,

Paul

Signature · 5 lines
Developer of free digital technology and hardware support.

Website: https://www.paulk.fr/
Coding blog: https://code.paulk.fr/
Git repositories: https://git.paulk.fr/ https://git.code.paulk.fr/

A message that is not in the archive (sent off-list or not yet received): 928a021c1e402f99eadd20e00aa5ec0cc218edbd.camel-W9ppeneeCTY@public.gmane.org

#14 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Quoted 101 lines · Paul Kocialkowski

Hi,

Quoted 68 lines · Ezequiel Garcia

Hi Hans,

Thanks for the review.

Quoted 44 lines · Hans Verkuil
Quoted 43 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +19 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
Quoted 9 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 4 lines
Documentation/media/uapi/v4l/extended-controls.rst +4 -0
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.

So does specifying 1 here switch the HW encoder to use extended profile? What if the HW only supports baseline? The rockchip driver doesn't appear to check the precision field at all...

The driver is missing to check that, when the user sets this control.

Quoted 7 lines

I think this needs a bit more thought.

I am not at all sure that this is the right place for the precision field. This is really about JPEG profiles, so I would kind of expect a JPEG PROFILE control (just like other codec profiles), or possibly a new pixelformat for extended profiles.

Quoted 6 lines
Quoted 3 lines

And based on that the driver would interpret these matrix values as 8 or 16 bits.

Right, the JPEG profile control is definitely needed. I haven't add it because it wouldn't be used, since this VPU can only do baseline.

Well, I suppose it would still be relevant that you add it for the encoder and only report baseline there.

Quoted 12 lines

However, the problem is that some JPEGs in the wild have with 8-bit data and 16-bit quantization coefficients, as per [1] and [2]:

[1] https://github.com/martinhath/jpeg-rust/issues/1
[2] https://github.com/libjpeg-turbo/libjpeg-turbo/pull/90

So, in order to support decoding of these images, I've added the precision field to the quantization control. The user would be able to set a baseline or extended profile thru a (future) profile control, and if 16-bit tables are found, and if the hardware supports them, the driver would be able to support them.

Quoted 3 lines

Another option, which might be even better, is have explicit baseline and extended quantization tables controls, e.g.: V4L2_CID_JPEG_QUANT and V4L2_CID_JPEG_EXT_QUANT.

I think this makes more sense than a common structure with an indication bit on how to interpret the data.

Quoted 7 lines

However, it seems problematic that userspace can't figure out whether 16-bit quant tables are supported with a baseline profile and just has to try and see.

Hans, do you think this is an acceptable approach or should we rather stick to the standard here, at the cost of not supporting these pictures that were encoded with this common abuse of the standard?

Perhaps we just need a control called V4L2_CID_JPEG_QUANT_PRECISION, where drivers can set the min/max (e.g. min = 8, max = 16, step = 8) to the range they support and user space can select the precision it wants, if the hardware gives a choice?

Best regards,
Tomasz

#15 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

In reply to a message not in the archive

Hi,

Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..1335d27d30f3 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3357

Quoted 4 lines
Documentation/media/uapi/v4l/extended-controls.rst +1 -0
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:

I just had a look at how the Allwinner VPU handles JPEG decoding and it seems to require the following information (in addition to quantization):

* Horizontal and vertical sampling factors for each Y/U/V component:

The number of components and sampling factors are coded separately in the bitstream, but it's probably easier to use the already-existing V4L2_CID_JPEG_CHROMA_SUBSAMPLING control for specifying that.

However, this is potentially very much related to the destination format. If we decide that this format should match the format resulting from decompression, we don't need to specify it through an external control. On the other hand, it's possible that the VPU has format conversion block integrated in its pipeline so it would also make sense to consider the destination format as independent.

* Custom Huffman tables (DC and AC), both for luma and chroma

It seems that there is a default table when no Huffman table is provided in the bitstream (I'm not too sure how standard that is, just started learning about JPEG). We probably need a specific control for that.

* Reset interval

That's extracted from the bitstream as well and there's a V4L2_CID_JPEG_RESTART_INTERVAL control already.

In addition to these points, I see that among all the JPEG profiles, some have to do with arithmetic coding which will probably require a specific control on its own (not sure how it should look at this point though).

What do you think?

Cheers,

Paul

Quoted 122 lines
Documentation/media/uapi/v4l/extended-controls.rst +30 -0
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.
+
+    * - __u16
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u16
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.
 
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +12 -0
index e4ee10ee917d..856b3325052f 100644
@@ -987,6 +987,18 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	/* ITU-T.81 specifies two quantization coefficient precisions:
+	 * 8-bit for baseline profile,
+	 * 8-bit or 16-bit for extended profile.
+	 *
+	 * User shall set "precision" to 0 for 8-bit and 1 for 16-bit.
+	 */
+	__u8	precision;
+	__u16	luma_quantization_matrix[64];
+	__u16	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +1 -0
index f9f3ae5b489e..8ace47cb1003 100644
@@ -1637,6 +1637,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 5 lines
Developer of free digital technology and hardware support.

Website: https://www.paulk.fr/
Coding blog: https://code.paulk.fr/
Git repositories: https://git.paulk.fr/ https://git.code.paulk.fr/

A message that is not in the archive (sent off-list or not yet received): e7126e89d8984eb93216ec75c83ce1fc5afc437d.camel-W9ppeneeCTY@public.gmane.org

#17 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Hi,

Quoted 56 lines · Paul Kocialkowski

Hi,

Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..1335d27d30f3 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3357

Quoted 4 lines
Documentation/media/uapi/v4l/extended-controls.rst +1 -0
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:

I just had a look at how the Allwinner VPU handles JPEG decoding and it seems to require the following information (in addition to quantization):

* Horizontal and vertical sampling factors for each Y/U/V component:

The number of components and sampling factors are coded separately in the bitstream, but it's probably easier to use the already-existing V4L2_CID_JPEG_CHROMA_SUBSAMPLING control for specifying that.

However, this is potentially very much related to the destination format. If we decide that this format should match the format resulting from decompression, we don't need to specify it through an external control. On the other hand, it's possible that the VPU has format conversion block integrated in its pipeline so it would also make sense to consider the destination format as independent.

* Custom Huffman tables (DC and AC), both for luma and chroma

It seems that there is a default table when no Huffman table is provided in the bitstream (I'm not too sure how standard that is, just started learning about JPEG). We probably need a specific control for that.

* Reset interval

That's extracted from the bitstream as well and there's a V4L2_CID_JPEG_RESTART_INTERVAL control already.

Quoted 6 lines

In addition to these points, I see that among all the JPEG profiles, some have to do with arithmetic coding which will probably require a specific control on its own (not sure how it should look at this point though).

What do you think?

For clarification: these are required for decoding, not for encoding.

For encoding, it seems that the Allwinner hardware only requires quantization tables.

Cheers,

Paul

Quoted 122 lines
Quoted 122 lines
Documentation/media/uapi/v4l/extended-controls.rst +30 -0
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The :ref:`itu-t81`
+    specification allows 8-bit quantization coefficients for
+    baseline profile images, and 8-bit or 16-bit for extended profile
+    images. Supporting or not 16-bit precision coefficients is driver-specific.
+    Coefficients must be set in JPEG zigzag scan order.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``precision``
+      - Specifies the coefficient precision. User shall set 0
+        for 8-bit, and 1 for 16-bit.
+
+    * - __u16
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u16
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.
 
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +12 -0
index e4ee10ee917d..856b3325052f 100644
@@ -987,6 +987,18 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	/* ITU-T.81 specifies two quantization coefficient precisions:
+	 * 8-bit for baseline profile,
+	 * 8-bit or 16-bit for extended profile.
+	 *
+	 * User shall set "precision" to 0 for 8-bit and 1 for 16-bit.
+	 */
+	__u8	precision;
+	__u16	luma_quantization_matrix[64];
+	__u16	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +1 -0
index f9f3ae5b489e..8ace47cb1003 100644
@@ -1637,6 +1637,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 5 lines
Developer of free digital technology and hardware support.

Website: https://www.paulk.fr/
Coding blog: https://code.paulk.fr/
Git repositories: https://git.paulk.fr/ https://git.code.paulk.fr/
#18 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

In reply to a message not in the archive
Quoted 27 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
Quoted 5 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3357

Quoted 1 line
Documentation/media/uapi/v4l/extended-controls.rst +1 -0
+.. _jpeg-quant-tables-control:

I just had a look at how the Allwinner VPU handles JPEG decoding and it seems to require the following information (in addition to quantization):

I assume the hardware doesn't have the ability to parse those from the stream and so they need to be parsed by user space and given to the driver?

Quoted 7 lines

* Horizontal and vertical sampling factors for each Y/U/V component:

The number of components and sampling factors are coded separately in the bitstream, but it's probably easier to use the already-existing V4L2_CID_JPEG_CHROMA_SUBSAMPLING control for specifying that.

Quoted 6 lines

However, this is potentially very much related to the destination format. If we decide that this format should match the format resulting from decompression, we don't need to specify it through an external control. On the other hand, it's possible that the VPU has format conversion block integrated in its pipeline so it would also make sense to consider the destination format as independent.

+1 for keeping it separate.

Quoted 6 lines

* Custom Huffman tables (DC and AC), both for luma and chroma

It seems that there is a default table when no Huffman table is provided in the bitstream (I'm not too sure how standard that is, just started learning about JPEG). We probably need a specific control for that.

What happens if there is one in the bitstream? Would the hardware pick it automatically?

I think it might make sense to just have a general control for Huffman table, which would be always provided by the user space, regardless of whether it's parsed from the stream or default, so that drivers don't have to care and could just always use it.

Best regards,
Tomasz

A message that is not in the archive (sent off-list or not yet received): CAAFQd5Bir0uMsaJPHdgQDvcYHpxZ4sUSn10OPpRXcnn-THUx2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#20 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Hi,

Quoted 33 lines · Tomasz Figa
Quoted 26 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
Quoted 5 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3357

Quoted 1 line
Documentation/media/uapi/v4l/extended-controls.rst +1 -0
+.. _jpeg-quant-tables-control:

I just had a look at how the Allwinner VPU handles JPEG decoding and it seems to require the following information (in addition to quantization):

Quoted 3 lines

I assume the hardware doesn't have the ability to parse those from the stream and so they need to be parsed by user space and given to the driver?

That's correct, we are also dealing with a stateless decoder here. It's actually the same hardware engine that's used for MPEG2 decoding, only configured differently.

So we will need to introduce a pixfmt for compressed JPEG data without headers, reuse JPEG controls that apply and perhaps introduce new ones too if needed.

I am also wondering about how MJPEG support should fit into this. As far as I understood, it shouldn't be very different from JPEG so we might want to have common controls for both.

Quoted 6 lines
Quoted 6 lines

* Horizontal and vertical sampling factors for each Y/U/V component:

The number of components and sampling factors are coded separately in the bitstream, but it's probably easier to use the already-existing V4L2_CID_JPEG_CHROMA_SUBSAMPLING control for specifying that.

Quoted 8 lines
Quoted 6 lines

However, this is potentially very much related to the destination format. If we decide that this format should match the format resulting from decompression, we don't need to specify it through an external control. On the other hand, it's possible that the VPU has format conversion block integrated in its pipeline so it would also make sense to consider the destination format as independent.

+1 for keeping it separate.

Just like for the stateless decoding API, it would make sense to expect userspace to set those before enumerating CAPTURE formats in order to determine what the hardware can output.

Quoted 8 lines
Quoted 5 lines

* Custom Huffman tables (DC and AC), both for luma and chroma

It seems that there is a default table when no Huffman table is provided in the bitstream (I'm not too sure how standard that is, just started learning about JPEG). We probably need a specific control for that.

What happens if there is one in the bitstream? Would the hardware pick it automatically?

In our case, this part of the bitstream wouldn't be sent to the hardware anyway.

Quoted 4 lines

I think it might make sense to just have a general control for Huffman table, which would be always provided by the user space, regardless of whether it's parsed from the stream or default, so that drivers don't have to care and could just always use it.

For MPEG-2 support (and probably also H.265), we have considered the quantization tables optional and kept a default value in the driver. That's because said tables are not supported in all profiles, so they are de-facto optional. I think it's fair to consider that userspace does not need to implement more than what is needed for decoding. This makes our interface closer to the data obtained from the bitstream.

However, having one copy of the default table per driver is far from optimal. I would suggest moving it to common v4l2 functions instead, but keeping it in kernel space.

What do you think?

Cheers,

Paul

Signature · 5 lines
Developer of free digital technology and hardware support.

Website: https://www.paulk.fr/
Coding blog: https://code.paulk.fr/
Git repositories: https://git.paulk.fr/ https://git.code.paulk.fr/

_______________________________________________
Linux-rockchip mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

A message that is not in the archive (sent off-list or not yet received): 2878c8fa36f6e775079f53ba79518a53e1ea6bc5.camel-W9ppeneeCTY@public.gmane.org

#22 lore raw

Re: [PATCH v5 5/6] media: Add controls for JPEG quantization tables

Quoted 44 lines · Paul Kocialkowski

Hi,

Quoted 33 lines · Tomasz Figa
Quoted 26 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 31 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++
 include/uapi/linux/v4l2-controls.h            | 12 +++++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 55 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..1335d27d30f3 100644
@@ -3354,7 +3354,38 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
Quoted 5 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3357

Quoted 1 line
Documentation/media/uapi/v4l/extended-controls.rst +1 -0
+.. _jpeg-quant-tables-control:

I just had a look at how the Allwinner VPU handles JPEG decoding and it seems to require the following information (in addition to quantization):

Quoted 3 lines

I assume the hardware doesn't have the ability to parse those from the stream and so they need to be parsed by user space and given to the driver?

That's correct, we are also dealing with a stateless decoder here. It's actually the same hardware engine that's used for MPEG2 decoding, only configured differently.

Quoted 8 lines

So we will need to introduce a pixfmt for compressed JPEG data without headers, reuse JPEG controls that apply and perhaps introduce new ones too if needed.

I am also wondering about how MJPEG support should fit into this. As far as I understood, it shouldn't be very different from JPEG so we might want to have common controls for both.

We've recently discussed this and we were proposing to just drop MJPEG and stick to JPEG. The reason is that MJPEG is not clearly defined. Note that others treat MJPEG and JPEG as aliases.

See "Re: [RFC] V4L2_PIX_FMT_MJPEG vs V4L2_PIX_FMT_JPEG".

Also, I'll be adding support for spec-compliant JPEG frames in rockchip JPEG encoder. This will allow to use the driver with already available userspace. IOW, we don't absolutely need a new pixelformat for encoders.

Decoders, on the other side, would be a different story, as parsing headers in the kernel can raise some safety concerns.

Regards,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#23 lore raw

PATCH v5 6/6 media: add Rockchip VPU JPEG encoder driver

In reply to a message not in the archive

Add a mem2mem driver for the VPU available on Rockchip SoCs. Currently only JPEG encoding is supported, for RK3399 and RK3288 platforms.

---
 MAINTAINERS                                   |   7 +
 drivers/staging/media/Kconfig                 |   2 +
 drivers/staging/media/Makefile                |   1 +
 drivers/staging/media/rockchip/vpu/Makefile   |   9 +
 drivers/staging/media/rockchip/vpu/TODO       |   5 +
 .../media/rockchip/vpu/rk3288_vpu_hw.c        | 123 ++++
 .../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c     | 129 ++++
 .../media/rockchip/vpu/rk3288_vpu_regs.h      | 442 +++++++++++++
 .../media/rockchip/vpu/rk3399_vpu_hw.c        | 123 ++++
 .../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c     | 157 +++++
 .../media/rockchip/vpu/rk3399_vpu_regs.h      | 601 +++++++++++++++++
 .../staging/media/rockchip/vpu/rockchip_vpu.h | 296 +++++++++
 .../media/rockchip/vpu/rockchip_vpu_common.h  |  31 +
 .../media/rockchip/vpu/rockchip_vpu_drv.c     | 528 +++++++++++++++
 .../media/rockchip/vpu/rockchip_vpu_enc.c     | 604 ++++++++++++++++++
 .../media/rockchip/vpu/rockchip_vpu_hw.h      |  65 ++
 16 files changed, 3123 insertions(+)
 create mode 100644 drivers/staging/media/rockchip/vpu/Makefile
 create mode 100644 drivers/staging/media/rockchip/vpu/TODO
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
MAINTAINERS +7 -0
index a5b256b25905..7612029cd960 100644
@@ -12452,6 +12452,13 @@ S:	Maintained
 F:	drivers/media/platform/rockchip/rga/
 F:	Documentation/devicetree/bindings/media/rockchip-rga.txt
 
+ROCKCHIP VPU CODEC DRIVER
+M:	Ezequiel Garcia <ezequiel-ZGY8ohtN/[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/staging/media/platform/rockchip/vpu/
+F:	Documentation/devicetree/bindings/media/rockchip-vpu.txt
+
 ROCKER DRIVER
 M:	Jiri Pirko <[email protected]>
 L:	[email protected]
drivers/staging/media/Kconfig +2 -0
index db5cf67047ad..c7091dc3897a 100644
@@ -31,6 +31,8 @@ source "drivers/staging/media/mt9t031/Kconfig"
 
 source "drivers/staging/media/omap4iss/Kconfig"
 
+source "drivers/staging/media/rockchip/vpu/Kconfig"
+
 source "drivers/staging/media/tegra-vde/Kconfig"
 
 source "drivers/staging/media/zoran/Kconfig"
drivers/staging/media/Makefile +1 -0
index 503fbe47fa58..236aa1061534 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_VIDEO_DM365_VPFE)	+= davinci_vpfe/
 obj-$(CONFIG_VIDEO_OMAP4)	+= omap4iss/
 obj-$(CONFIG_TEGRA_VDE)		+= tegra-vde/
 obj-$(CONFIG_VIDEO_ZORAN)	+= zoran/
+obj-$(CONFIG_VIDEO_ROCKCHIP_VPU) += rockchip/vpu/
drivers/staging/media/rockchip/vpu/Makefile new file +9 -0
new file mode 100644
index 000000000000..2fb99adfbdb9
@@ -0,0 +1,9 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_VPU) += rockchip-vpu.o
+
+rockchip-vpu-y += \
+		rockchip_vpu_drv.o \
+		rockchip_vpu_enc.o \
+		rk3288_vpu_hw.o \
+		rk3288_vpu_hw_jpeg_enc.o \
+		rk3399_vpu_hw.o \
+		rk3399_vpu_hw_jpeg_enc.o
drivers/staging/media/rockchip/vpu/TODO new file +5 -0
new file mode 100644
index 000000000000..99bd1add7628
@@ -0,0 +1,5 @@
+This driver is in staging until the V4L controls stabilize.
+
+Given the V4L controls are part of the uABI, it's better
+to have the driver in staging, so users are aware of this
+driver having an unstable interface.
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c new file +123 -0

123 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c new file +129 -0

129 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h new file +442 -0

442 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c new file +123 -0

123 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c new file +157 -0

157 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h new file +601 -0

601 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rockchip_vpu.h new file +296 -0

296 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h new file +31 -0
new file mode 100644
index 000000000000..1a1c67fb47bb
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Rockchip VPU codec driver
+ *
+ * Copyright (C) 2018 Rockchip Electronics Co., Ltd.
+ *	Alpha Lin <[email protected]>
+ *	Jeffy Chen <[email protected]>
+ *
+ * Copyright (C) 2018 Google, Inc.
+ *	Tomasz Figa <[email protected]>
+ *
+ * Based on s5p-mfc driver by Samsung Electronics Co., Ltd.
+ * Copyright (C) 2011 Samsung Electronics Co., Ltd.
+ */
+
+#ifndef ROCKCHIP_VPU_COMMON_H_
+#define ROCKCHIP_VPU_COMMON_H_
+
+#include "rockchip_vpu.h"
+
+extern const struct v4l2_ioctl_ops rockchip_vpu_enc_ioctl_ops;
+extern const struct vb2_ops rockchip_vpu_enc_queue_ops;
+
+void *rockchip_vpu_find_control_data(struct rockchip_vpu_ctx *ctx,
+				unsigned int id);
+void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu,
+				struct rockchip_vpu_ctx *ctx);
+void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu,
+				struct rockchip_vpu_ctx *ctx);
+
+#endif /* ROCKCHIP_VPU_COMMON_H_ */
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c new file +528 -0

528 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c new file +604 -0

531 lines not on this page · raw message

drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h new file +65 -0

65 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.18.0

Part of the diff is not shown here. View the raw message.