Skip to contentSkip to conversation

Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

PATCH Applied Mirela Rabulea (OSS) 7 participants 24 messages Nov 12, 2020 – Dec 4, 2020

Subsystems (4)

v5 of 9 Applied Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

From: Mirela Rabulea <[email protected]>

This patch set adds the V4L2 driver for i.MX8QXP/QM JPEG encoder/decoder and it's dependencies.
The driver was tested on i.MX8QXP, using a unit test application and the v4l2-compliance tool, including the streaming tests for decoder & encoder.

The output of latest v4l2-compliance on i.MX8QXP, decoder & encoder:

root@imx8qxpmek:/unit_tests/JPEG# ./v4l2-compliance-master -d /dev/video0 -s
v4l2-compliance 1.21.0-4679, 64 bits, 64-bit time_t
v4l2-compliance SHA: 225c6c2a17be 2020-10-30 15:13:07

Compliance test for mxc-jpeg decode device /dev/video0:

Driver Info:

	Driver name      : mxc-jpeg decode
	Card type        : mxc-jpeg decoder
	Bus info         : platform:58400000.jpegdec
	Driver version   : 5.10.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
Detected JPEG Decoder

Required ioctls:
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

test invalid ioctls: 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 (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 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 test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported) test USERPTR (select): OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device

Total for mxc-jpeg decode device /dev/video0: 52, Succeeded: 52, Failed: 0, Warnings: 0

root@imx8qxpmek:/unit_tests/JPEG# ./v4l2-compliance-master -d /dev/video1 -s
v4l2-compliance 1.21.0-4679, 64 bits, 64-bit time_t
v4l2-compliance SHA: 225c6c2a17be 2020-10-30 15:13:07

Compliance test for mxc-jpeg decode device /dev/video1:

Driver Info:

	Driver name      : mxc-jpeg decode
	Card type        : mxc-jpeg decoder
	Bus info         : platform:58450000.jpegenc
	Driver version   : 5.10.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
Detected JPEG Encoder

Required ioctls:
test VIDIOC_QUERYCAP: OK

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

test invalid ioctls: 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 (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 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 (Not Supported)

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

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported) test USERPTR (select): OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device

Total for mxc-jpeg decode device /dev/video1: 52, Succeeded: 52, Failed: 0, Warnings: 0

Mirela Rabulea (10):
media: v4l: Add packed YUV444 24bpp pixel format
firmware: imx: scu-pd: Add power domains for imx-jpeg
media: dt-bindings: Add bindings for i.MX8QXP/QM JPEG driver
media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder
arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes Add maintainer for IMX jpeg v4l2 driver
media: Add parsing for APP14 data segment in jpeg helpers
media: Quit parsing stream if doesn't start with SOI
media: Avoid parsing quantization and huffman tables
media: imx-jpeg: Use v4l2 jpeg helpers in mxc-jpeg

 .../bindings/media/nxp,imx8-jpeg.yaml         |   84 +
 .../media/v4l/pixfmt-packed-yuv.rst           |   37 +-
 MAINTAINERS                                   |    8 +
 arch/arm64/boot/dts/freescale/imx8qxp-mek.dts |    8 +
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi    |   37 +
 drivers/firmware/imx/scu-pd.c                 |    6 +
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/imx-jpeg/Kconfig       |   11 +
 drivers/media/platform/imx-jpeg/Makefile      |    3 +
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c |  168 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h |  140 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg.c    | 2193 +++++++++++++++++
 drivers/media/platform/imx-jpeg/mxc-jpeg.h    |  180 ++
 drivers/media/v4l2-core/v4l2-ioctl.c          |    1 +
 drivers/media/v4l2-core/v4l2-jpeg.c           |   52 +-
 include/media/v4l2-jpeg.h                     |    6 +-
 include/uapi/linux/videodev2.h                |    1 +
 18 files changed, 2928 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
 create mode 100644 drivers/media/platform/imx-jpeg/Kconfig
 create mode 100644 drivers/media/platform/imx-jpeg/Makefile
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/10 media: v4l: Add packed YUV444 24bpp pixel format

From: Mirela Rabulea <[email protected]>

The added format is V4L2_PIX_FMT_YUV24, this is a packed YUV 4:4:4 format, with 8 bits for each component, 24 bits per sample.

This format is used by the i.MX 8QuadMax and i.MX 8DualXPlus/8QuadXPlus JPEG encoder/decoder.

---
Changes in v5:
Added <Reviewed-by>

 .../media/v4l/pixfmt-packed-yuv.rst           | 37 ++++++++++++++++++-
 drivers/media/v4l2-core/v4l2-ioctl.c          |  1 +
 include/uapi/linux/videodev2.h                |  1 +
 3 files changed, 38 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst +36 -1
index 84262208dd1c..7b340bf5695d 100644
@@ -10,7 +10,8 @@ Description
 ===========
 
 Similar to the packed RGB formats these formats store the Y, Cb and Cr
-component of each pixel in one 16 or 32 bit word.
+component of each pixel next to each other in memory. They occupy 16, 24 or 32
+bits per pixel.
 
 
 .. raw:: latex
@@ -150,6 +151,40 @@ component of each pixel in one 16 or 32 bit word.
 
       -  :cspan:`15`
 
+    * .. _V4L2-PIX-FMT-YUV24:
+
+      - ``V4L2_PIX_FMT_YUV24``
+      - 'YUV3'
+
+      - Y'\ :sub:`7`
+      - Y'\ :sub:`6`
+      - Y'\ :sub:`5`
+      - Y'\ :sub:`4`
+      - Y'\ :sub:`3`
+      - Y'\ :sub:`2`
+      - Y'\ :sub:`1`
+      - Y'\ :sub:`0`
+
+      - Cb\ :sub:`7`
+      - Cb\ :sub:`6`
+      - Cb\ :sub:`5`
+      - Cb\ :sub:`4`
+      - Cb\ :sub:`3`
+      - Cb\ :sub:`2`
+      - Cb\ :sub:`1`
+      - Cb\ :sub:`0`
+
+      - Cr\ :sub:`7`
+      - Cr\ :sub:`6`
+      - Cr\ :sub:`5`
+      - Cr\ :sub:`4`
+      - Cr\ :sub:`3`
+      - Cr\ :sub:`2`
+      - Cr\ :sub:`1`
+      - Cr\ :sub:`0`
+
+      -  :cspan:`7`
+
     * .. _V4L2-PIX-FMT-YUV32:
 
       - ``V4L2_PIX_FMT_YUV32``
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
index f0f6906a879d..366b76690432 100644
@@ -1304,6 +1304,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_YUV444:	descr = "16-bit A/XYUV 4-4-4-4"; break;
 	case V4L2_PIX_FMT_YUV555:	descr = "16-bit A/XYUV 1-5-5-5"; break;
 	case V4L2_PIX_FMT_YUV565:	descr = "16-bit YUV 5-6-5"; break;
+	case V4L2_PIX_FMT_YUV24:	descr = "24-bit YUV 4:4:4 8-8-8"; break;
 	case V4L2_PIX_FMT_YUV32:	descr = "32-bit A/XYUV 8-8-8-8"; break;
 	case V4L2_PIX_FMT_AYUV32:	descr = "32-bit AYUV 8-8-8-8"; break;
 	case V4L2_PIX_FMT_XYUV32:	descr = "32-bit XYUV 8-8-8-8"; break;
include/uapi/linux/videodev2.h +1 -0
index 927075fa9099..9973b5f76c76 100644
@@ -590,6 +590,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_YUV444  v4l2_fourcc('Y', '4', '4', '4') /* 16  xxxxyyyy uuuuvvvv */
 #define V4L2_PIX_FMT_YUV555  v4l2_fourcc('Y', 'U', 'V', 'O') /* 16  YUV-5-5-5     */
 #define V4L2_PIX_FMT_YUV565  v4l2_fourcc('Y', 'U', 'V', 'P') /* 16  YUV-5-6-5     */
+#define V4L2_PIX_FMT_YUV24   v4l2_fourcc('Y', 'U', 'V', '3') /* 24  YUV-8-8-8     */
 #define V4L2_PIX_FMT_YUV32   v4l2_fourcc('Y', 'U', 'V', '4') /* 32  YUV-8-8-8-8   */
 #define V4L2_PIX_FMT_AYUV32  v4l2_fourcc('A', 'Y', 'U', 'V') /* 32  AYUV-8-8-8-8  */
 #define V4L2_PIX_FMT_XYUV32  v4l2_fourcc('X', 'Y', 'U', 'V') /* 32  XYUV-8-8-8-8  */
Signature · 1 line
2.17.1
#2 lore raw

PATCH v5 2/10 firmware: imx: scu-pd: Add power domains for imx-jpeg

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

The power domains are for imx8qxp/imx8qm JPEG encoder & decoder. Each has 4 slots and a wrapper.

---
Changes in v5:
Added Acked-by

 drivers/firmware/imx/scu-pd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/firmware/imx/scu-pd.c +6 -0
index 946eea292b52..a614d8dd868e 100644
@@ -180,6 +180,12 @@ static const struct imx_sc_pd_range imx8qxp_scu_pd_ranges[] = {
 	{ "cm41-pid", IMX_SC_R_M4_1_PID0, 5, true, 0},
 	{ "cm41-mu-a1", IMX_SC_R_M4_1_MU_1A, 1, false, 0},
 	{ "cm41-lpuart", IMX_SC_R_M4_1_UART, 1, false, 0},
+
+	/* IMAGE SS */
+	{ "img-jpegdec-mp", IMX_SC_R_MJPEG_DEC_MP, 1, false, 0 },
+	{ "img-jpegdec-s0", IMX_SC_R_MJPEG_DEC_S0, 4, true, 0 },
+	{ "img-jpegenc-mp", IMX_SC_R_MJPEG_ENC_MP, 1, false, 0 },
+	{ "img-jpegenc-s0", IMX_SC_R_MJPEG_ENC_S0, 4, true, 0 },
 };
 
 static const struct imx_sc_pd_soc imx8qxp_scu_pd = {
Signature · 1 line
2.17.1
#4 lore raw

PATCH v5 3/10 media: dt-bindings: Add bindings for i.MX8QXP/QM JPEG driver

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add bindings documentation for i.MX8QXP/QM JPEG decoder & encoder driver.

---
Changes in v5:
changed compatible name to be SOC specific
changed fsl->nxp
rephrased a bit the interrupts description

 .../bindings/media/nxp,imx8-jpeg.yaml         | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml new file +84 -0
new file mode 100644
index 000000000000..5d13cbb5251b
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/nxp,imx8-jpeg.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: i.MX8QXP/QM JPEG decoder/encoder Device Tree Bindings
+
+maintainers:
+  - Mirela Rabulea <[email protected]>
+
+description: |-
+  The JPEG decoder/encoder present in iMX8QXP and iMX8QM SoCs is an
+  ISO/IEC 10918-1 JPEG standard compliant decoder/encoder, for Baseline
+  and Extended Sequential DCT modes.
+
+properties:
+  compatible:
+    items:
+      - enum:
+            # JPEG decoder
+          - nxp,imx8qxp-jpgdec
+            # JPEG encoder
+          - nxp,imx8qxp-jpgenc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description: |
+      There are 4 slots available in the IP, which the driver may use
+      If a certain slot is used, it should have an associated interrupt
+      The interrupt with index i is assumed to be for slot i
+    minItems: 1               # At least one slot is needed by the driver
+    maxItems: 4               # The IP has 4 slots available for use
+
+  power-domains:
+    description:
+      List of phandle and PM domain specifier as documented in
+      Documentation/devicetree/bindings/power/power_domain.txt
+    minItems: 2               # Wrapper and 1 slot
+    maxItems: 5               # Wrapper and 4 slots
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - power-domains
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/firmware/imx/rsrc.h>
+
+    jpegdec: jpegdec@58400000 {
+        compatible = "nxp,imx8qxp-jpgdec";
+        reg = <0x58400000 0x00050000 >;
+        interrupts = <GIC_SPI 309 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 312 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S0>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S1>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S2>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S3>;
+    };
+
+    jpegenc: jpegenc@58450000 {
+        compatible = "nxp,imx8qxp-jpgenc";
+        reg = <0x58450000 0x00050000 >;
+        interrupts = <GIC_SPI 305 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 307 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 308 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S0>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S1>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S2>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S3>;
+    };
+...
Signature · 1 line
2.17.1
maintainer Reviewed-by on v5 3/10
#5 lore raw

Re: [PATCH v5 03/10] media: dt-bindings: Add bindings for i.MX8QXP/QM JPEG driver

Quoted 11 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add bindings documentation for i.MX8QXP/QM JPEG decoder & encoder driver.

---
Changes in v5:
changed compatible name to be SOC specific
changed fsl->nxp
rephrased a bit the interrupts description

Quoted 4 lines
 .../bindings/media/nxp,imx8-jpeg.yaml         | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
#6 lore raw

PATCH v5 4/10 media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

V4L2 driver for the JPEG encoder/decoder from i.MX8QXP/i.MX8QM application processors.
The multi-planar buffers API is used.

Baseline and extended sequential jpeg decoding is supported. Progressive jpeg decoding is not supported by the IP. Supports encode and decode of various formats:

     YUV444, YUV422, YUV420, RGB, ARGB, Gray

YUV420 is the only multi-planar format supported. Minimum resolution is 64 x 64, maximum 8192 x 8192.
The alignment requirements for the resolution depend on the format, multiple of 16 resolutions should work for all formats.

v4l2-compliance tests are passing, including the
streaming tests, "v4l2-compliance -s"

---
Changes in v5:
Properly indented data blocks for encoder configuration stream
one tab to the right.
Remove fourcc_to_str, instead just print the format directly (%c%c%c%c)
Use the "debug" module parameter instead of "mxc_jpeg_tracing".
Change return type for get_byte function (end of jpeg stream was not properly detected, visible only with corrupted stream)
Use NULL instead of 0 for NULL pointers.
Add a check to exit jpeg parse if stream does not start with SOI (slow run on v4l2-compliance streaming tests otherwise, the same problem was fixed in jpeg helpers) Change compatible name to match patch 3
Fix colorspace information to sRGB for both output & capture (latest v4l2-compliance fail)
Squashed patch 7 (v4l2-compliance streaming test fix for decoder)

 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/imx-jpeg/Kconfig       |   10 +
 drivers/media/platform/imx-jpeg/Makefile      |    3 +
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c |  168 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h |  140 +
 drivers/media/platform/imx-jpeg/mxc-jpeg.c    | 2324 +++++++++++++++++
 drivers/media/platform/imx-jpeg/mxc-jpeg.h    |  184 ++
 8 files changed, 2832 insertions(+)
 create mode 100644 drivers/media/platform/imx-jpeg/Kconfig
 create mode 100644 drivers/media/platform/imx-jpeg/Makefile
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.h
drivers/media/platform/Kconfig +2 -0
index 7e152bbb4fa6..f5bf2fd2b48a 100644
@@ -206,6 +206,8 @@ config VIDEO_IMX_PXP
 	  The i.MX Pixel Pipeline is a memory-to-memory engine for scaling,
 	  color space conversion, and rotation.
 
+source "drivers/media/platform/imx-jpeg/Kconfig"
+
 config VIDEO_MEDIATEK_JPEG
 	tristate "Mediatek JPEG Codec driver"
 	depends on MTK_IOMMU_V1 || MTK_IOMMU || COMPILE_TEST
drivers/media/platform/Makefile +1 -0
index 62b6cdc8c730..71bbf36d182a 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_VIDEO_MX2_EMMAPRP)		+= mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA)		+= coda/
 
 obj-$(CONFIG_VIDEO_IMX_PXP)		+= imx-pxp.o
+obj-$(CONFIG_VIDEO_IMX8_JPEG)		+= imx-jpeg/
 
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)	+= m2m-deinterlace.o
 
drivers/media/platform/imx-jpeg/Kconfig new file +10 -0
new file mode 100644
index 000000000000..7cc89e5eff90
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+config VIDEO_IMX8_JPEG
+	tristate "IMX8 JPEG Encoder/Decoder"
+	depends on VIDEO_DEV && VIDEO_V4L2
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_MEM2MEM_DEV
+	default m
+	help
+	  This is a video4linux2 driver for the i.MX8 QXP/QM integrated
+	  JPEG encoder/decoder.
drivers/media/platform/imx-jpeg/Makefile new file +3 -0
new file mode 100644
index 000000000000..bf19c82e61b4
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+mxc-jpeg-encdec-objs := mxc-jpeg-hw.o mxc-jpeg.o
+obj-$(CONFIG_VIDEO_IMX8_JPEG) += mxc-jpeg-encdec.o
drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c new file +168 -0

168 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h new file +140 -0

140 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.c new file +2324 -0

2,324 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.h new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v5 5/10 arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add jpeg decoder/encoder nodes, for now on imx8qxp only. The same should work on imx8qm, but it was not tested.

---
 arch/arm64/boot/dts/freescale/imx8qxp-mek.dts |  8 ++++
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi    | 37 +++++++++++++++++++
 2 files changed, 45 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp-mek.dts +8 -0
index 46437d3c7a04..a0ad9789e9b8 100644
@@ -270,3 +270,11 @@
 		>;
 	};
 };
+
+&jpegdec {
+	status = "okay";
+};
+
+&jpegenc {
+	status = "okay";
+};
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +37 -0
index e46faac1fe71..1d9a16388fa8 100644
@@ -629,4 +629,41 @@
 			};
 		};
 	};
+
+	img_subsys: bus@58000000 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges = <0x58000000 0x0 0x58000000 0x1000000>;
+
+		jpegdec: jpegdec@58400000 {
+			compatible = "nxp,imx8qxp-jpgdec";
+			reg = <0x58400000 0x00050000 >;
+			interrupts = <GIC_SPI 309 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 312 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+					<&pd IMX_SC_R_MJPEG_DEC_S0>,
+					<&pd IMX_SC_R_MJPEG_DEC_S1>,
+					<&pd IMX_SC_R_MJPEG_DEC_S2>,
+					<&pd IMX_SC_R_MJPEG_DEC_S3>;
+			status = "disabled";
+		};
+
+		jpegenc: jpegenc@58450000 {
+			compatible = "nxp,imx8qxp-jpgenc";
+			reg = <0x58450000 0x00050000 >;
+			interrupts = <GIC_SPI 305 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 307 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 308 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+					<&pd IMX_SC_R_MJPEG_ENC_S0>,
+					<&pd IMX_SC_R_MJPEG_ENC_S1>,
+					<&pd IMX_SC_R_MJPEG_ENC_S2>,
+					<&pd IMX_SC_R_MJPEG_ENC_S3>;
+			status = "disabled";
+		};
+	};
 };
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH v5 05/10] arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes

Hi Mirela,

Quoted 5 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add jpeg decoder/encoder nodes, for now on imx8qxp only. The same should work on imx8qm, but it was not tested.

Does imx8qm need changes in the dt bindings?

Unless you are aware of reasons preventing us from enabling it on imx8qm, then we could go for imx8qm as well (reusing imx8qxp- compatible).

Quoted 12 lines
---
 arch/arm64/boot/dts/freescale/imx8qxp-mek.dts |  8 ++++
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi    | 37 +++++++++++++++++++
 2 files changed, 45 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp-mek.dts +0 -0
index 46437d3c7a04..a0ad9789e9b8 100644
@@ -270,3 +270,11 @@
 		>;

arch/arm64/boot/dts/freescale/imx8qxp-mek.dts line 280

Quoted 10 lines
arch/arm64/boot/dts/freescale/imx8qxp-mek.dts +8 -0
 	};
 };
+
+&jpegdec {
+	status = "okay";
+};
+
+&jpegenc {
+	status = "okay";
+};

Please drop this. See below.

Quoted 18 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +10 -0
index e46faac1fe71..1d9a16388fa8 100644
@@ -629,4 +629,41 @@
 			};
 		};
 	};
+
+	img_subsys: bus@58000000 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges = <0x58000000 0x0 0x58000000 0x1000000>;
+
+		jpegdec: jpegdec@58400000 {
+			compatible = "nxp,imx8qxp-jpgdec";
+			reg = <0x58400000 0x00050000 >;

arch/arm64/boot/dts/freescale/imx8qxp.dtsi line 651

Quoted 10 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +10 -0
+			interrupts = <GIC_SPI 309 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 312 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+					<&pd IMX_SC_R_MJPEG_DEC_S0>,
+					<&pd IMX_SC_R_MJPEG_DEC_S1>,
+					<&pd IMX_SC_R_MJPEG_DEC_S2>,
+					<&pd IMX_SC_R_MJPEG_DEC_S3>;
+			status = "disabled";

Pure memory-to-memory are typically not enabled per-board, but just per-platform.

So you can drop the disabled status here.

Thanks,
Ezequiel

Quoted 18 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +17 -0
+		};
+
+		jpegenc: jpegenc@58450000 {
+			compatible = "nxp,imx8qxp-jpgenc";
+			reg = <0x58450000 0x00050000 >;
+			interrupts = <GIC_SPI 305 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 307 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 308 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+					<&pd IMX_SC_R_MJPEG_ENC_S0>,
+					<&pd IMX_SC_R_MJPEG_ENC_S1>,
+					<&pd IMX_SC_R_MJPEG_ENC_S2>,
+					<&pd IMX_SC_R_MJPEG_ENC_S3>;
+			status = "disabled";
+		};
+	};
 };
#9 lore raw

Re: [EXT] Re: [PATCH v5 05/10] arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes

Hi Ezequiel,

Quoted 10 lines · Ezequiel Garcia

Hi Mirela,

Quoted 5 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add jpeg decoder/encoder nodes, for now on imx8qxp only. The same should work on imx8qm, but it was not tested.

Quoted 5 lines

Does imx8qm need changes in the dt bindings?

Unless you are aware of reasons preventing us from enabling it on imx8qm, then we could go for imx8qm as well (reusing imx8qxp- compatible).

I think it will be possible to reuse the same compatile for 8qm, too. There is no dts for 8qm upstream for now, I understand Aisheng has something started on that. We'll see how it goes.

Quoted 19 lines
Quoted 19 lines
---
 arch/arm64/boot/dts/freescale/imx8qxp-mek.dts |  8 ++++
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi    | 37
+++++++++++++++++++
 2 files changed, 45 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp-mek.dts +2 -0
index 46437d3c7a04..a0ad9789e9b8 100644
@@ -270,3 +270,11 @@
              >;
      };
 };
+
+&jpegdec {
Quoted 8 lines

arch/arm64/boot/dts/freescale/imx8qxp-mek.dts line 280

Quoted 6 lines
arch/arm64/boot/dts/freescale/imx8qxp-mek.dts +6 -0
+     status = "okay";
+};
+
+&jpegenc {
+     status = "okay";
+};

Please drop this. See below.

Done for the next version.

Quoted 38 lines
Quoted 28 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +12 -0
index e46faac1fe71..1d9a16388fa8 100644
@@ -629,4 +629,41 @@
                      };
              };
      };
+
+     img_subsys: bus@58000000 {
+             compatible = "simple-bus";
+             #address-cells = <1>;
+             #size-cells = <1>;
+             ranges = <0x58000000 0x0 0x58000000 0x1000000>;
+
+             jpegdec: jpegdec@58400000 {
+                     compatible = "nxp,imx8qxp-jpgdec";
+                     reg = <0x58400000 0x00050000 >;
+                     interrupts = <GIC_SPI 309
 IRQ_TYPE_LEVEL_HIGH>,
+                                  <GIC_SPI 310

IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 311
IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 312
IRQ_TYPE_LEVEL_HIGH>;

arch/arm64/boot/dts/freescale/imx8qxp.dtsi line 651

Quoted 6 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +6 -0
+                     power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+                                     <&pd IMX_SC_R_MJPEG_DEC_S0>,
+                                     <&pd IMX_SC_R_MJPEG_DEC_S1>,
+                                     <&pd IMX_SC_R_MJPEG_DEC_S2>,
+                                     <&pd IMX_SC_R_MJPEG_DEC_S3>;
+                     status = "disabled";

Pure memory-to-memory are typically not enabled per-board, but just per-platform.

Quoted 1 line

So you can drop the disabled status here.

Done for the next version.

Thanks,
Mirela

Quoted 28 lines

Thanks,
Ezequiel

Quoted 22 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +6 -0
+             };
+
+             jpegenc: jpegenc@58450000 {
+                     compatible = "nxp,imx8qxp-jpgenc";
+                     reg = <0x58450000 0x00050000 >;
+                     interrupts = <GIC_SPI 305

IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 306
IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 307
IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 308
IRQ_TYPE_LEVEL_HIGH>;

arch/arm64/boot/dts/freescale/imx8qxp.dtsi +8 -0
+                     power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+                                     <&pd IMX_SC_R_MJPEG_ENC_S0>,
+                                     <&pd IMX_SC_R_MJPEG_ENC_S1>,
+                                     <&pd IMX_SC_R_MJPEG_ENC_S2>,
+                                     <&pd IMX_SC_R_MJPEG_ENC_S3>;
+                     status = "disabled";
+             };
+     };
 };
#10 lore raw

PATCH v5 6/10 Add maintainer for IMX jpeg v4l2 driver

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

The driver is located in drivers/media/platform/imx-jpeg, and it applies to the JPEG decoder from i.MX QXP and QM.

---
Changes in v5:
move to NXP section in maintainers file

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index f1f088a29bc2..f4c9b53d9077 100644
@@ -12692,6 +12692,14 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Supported
 F:	drivers/nfc/nxp-nci
 
+NXP i.MX 8QXP/8QM JPEG V4L2 DRIVER
+M:	Mirela Rabulea <[email protected]>
+R:	NXP Linux Team <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/imx8-jpeg.yaml
+F:	drivers/media/platform/imx-jpeg
+
 OBJAGG
 M:	Jiri Pirko <[email protected]>
 L:	[email protected]
Signature · 1 line
2.17.1
#11 lore raw

PATCH v5 7/10 media: Add parsing for APP14 data segment in jpeg helpers

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding. 2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

---
Changes in v5:
This was patch 8 in previous version
Replaced a struct for app14 data with just an int, since the transform flag is the only meaningfull information from this segment

 drivers/media/v4l2-core/v4l2-jpeg.c | 39 +++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           |  6 +++--
 2 files changed, 41 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +37 -2
index 8947fd95c6f1..3181ce544f79 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP	0xffde	/* hierarchical progression */
 #define EXP	0xffdf	/* expand reference */
 #define APP0	0xffe0	/* application data */
+#define APP14	0xffee	/* application data for colour encoding */
 #define APP15	0xffef
 #define JPG0	0xfff0	/* extensions */
 #define JPG13	0xfffd
@@ -444,8 +445,37 @@ static int jpeg_skip_segment(struct jpeg_stream *stream)
 	return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+	int ret;
+	int Lp;
+	int skip;
+	int tf;
+
+	Lp = jpeg_get_word_be(stream);
+	if (Lp < 0)
+		return Lp;
+
+	/* get to Ap12 */
+	ret = jpeg_skip(stream, 11);
+	if (ret < 0)
+		return -EINVAL;
+
+	tf = jpeg_get_byte(stream);
+	if (tf < 0)
+		return tf;
+
+	skip = Lp - 2 - 11;
+	ret = jpeg_skip(stream, skip);
+	if (ret < 0)
+		return -EINVAL;
+	else
+		return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
  * @buf: address of the JPEG buffer, should start with a SOI marker
  * @len: length of the JPEG buffer
  * @out: returns marker segment positions and optionally parsed headers
@@ -476,6 +506,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	if (marker != SOI)
 		return -EINVAL;
 
+	/* init value to signal if this marker is not present */
+	out->app14_tf = -EINVAL;
+
 	/* loop through marker segments */
 	while ((marker = jpeg_next_marker(&stream)) >= 0) {
 		switch (marker) {
@@ -519,7 +552,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 			ret = jpeg_parse_restart_interval(&stream,
 							&out->restart_interval);
 			break;
-
+		case APP14:
+			out->app14_tf = jpeg_parse_app14_data(&stream);
+			break;
 		case SOS:
 			ret = jpeg_reference_segment(&stream, &out->sos);
 			if (ret < 0)
include/media/v4l2-jpeg.h +4 -2
index ddba2a56c321..008e0476d928 100644
@@ -100,10 +100,11 @@ struct v4l2_jpeg_scan_header {
  *                  order, optional
  * @restart_interval: number of MCU per restart interval, Ri
  * @ecs_offset: buffer offset in bytes to the entropy coded segment
+ * @app14_tf: transform flag from app14 data
  *
  * When this structure is passed to v4l2_jpeg_parse_header, the optional scan,
- * quantization_tables, and huffman_tables pointers must be initialized to NULL
- * or point at valid memory.
+ * quantization_tables and huffman_tables pointers must be initialized
+ * to NULL or point at valid memory.
  */
 struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference sof;
@@ -119,6 +120,7 @@ struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference *huffman_tables;
 	u16 restart_interval;
 	size_t ecs_offset;
+	int app14_tf;
 };
 
 int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out);
Signature · 1 line
2.17.1
maintainer
#12 lore raw

Re: [PATCH v5 07/10] media: Add parsing for APP14 data segment in jpeg helpers

Hi Philipp,
any thoughts on the jpeg helpers related patches from this patch set (7,8,9,10)?

Thanks,
Mirela

Quoted 139 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which
may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding.
2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

---
Changes in v5:
This was patch 8 in previous version
Replaced a struct for app14 data with just an int, since the transform flag is the only meaningfull information from this segment

 drivers/media/v4l2-core/v4l2-jpeg.c | 39
+++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           |  6 +++--
 2 files changed, 41 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -0
index 8947fd95c6f1..3181ce544f79 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP	0xffde	/* hierarchical progression */
 #define EXP	0xffdf	/* expand reference */
 #define APP0	0xffe0	/* application data */
+#define APP14	0xffee	/* application data for colour

encoding */
#define APP15 0xffef
#define JPG0 0xfff0 /* extensions */
#define JPG13 0xfffd

drivers/media/v4l2-core/v4l2-jpeg.c +29 -1
@@ -444,8 +445,37 @@ static int jpeg_skip_segment(struct jpeg_stream
 *stream)
 	return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+	int ret;
+	int Lp;
+	int skip;
+	int tf;
+
+	Lp = jpeg_get_word_be(stream);
+	if (Lp < 0)
+		return Lp;
+
+	/* get to Ap12 */
+	ret = jpeg_skip(stream, 11);
+	if (ret < 0)
+		return -EINVAL;
+
+	tf = jpeg_get_byte(stream);
+	if (tf < 0)
+		return tf;
+
+	skip = Lp - 2 - 11;
+	ret = jpeg_skip(stream, skip);
+	if (ret < 0)
+		return -EINVAL;
+	else
+		return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse

headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
* @buf: address of the JPEG buffer, should start with a SOI marker
* @len: length of the JPEG buffer
* @out: returns marker segment positions and optionally parsed
headers

drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
@@ -476,6 +506,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len,
 struct v4l2_jpeg_header *out)
 	if (marker != SOI)
 		return -EINVAL;
 
+	/* init value to signal if this marker is not present */
+	out->app14_tf = -EINVAL;
+
 	/* loop through marker segments */
 	while ((marker = jpeg_next_marker(&stream)) >= 0) {
drivers/media/v4l2-core/v4l2-jpeg.c +3 -1
 		switch (marker) {
@@ -519,7 +552,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len,
 struct v4l2_jpeg_header *out)
 			ret = jpeg_parse_restart_interval(&stream,
 							&out-
 >restart_interval);
 			break;
-
+		case APP14:
+			out->app14_tf = jpeg_parse_app14_data(&stream);
+			break;
 		case SOS:

ret = jpeg_reference_segment(&stream, &out-

Quoted 1 line

sos);

drivers/media/v4l2-core/v4l2-jpeg.c +0 -0
 			if (ret < 0)
include/media/v4l2-jpeg.h +1 -1
index ddba2a56c321..008e0476d928 100644
@@ -100,10 +100,11 @@ struct v4l2_jpeg_scan_header {
  *                  order, optional
  * @restart_interval: number of MCU per restart interval, Ri
  * @ecs_offset: buffer offset in bytes to the entropy coded segment
+ * @app14_tf: transform flag from app14 data
  *
  * When this structure is passed to v4l2_jpeg_parse_header, the
 optional scan,
- * quantization_tables, and huffman_tables pointers must be

initialized to NULL
- * or point at valid memory.
+ * quantization_tables and huffman_tables pointers must be initialized
+ * to NULL or point at valid memory.
*/
struct v4l2_jpeg_header {

include/media/v4l2-jpeg.h +1 -0
 	struct v4l2_jpeg_reference sof;
@@ -119,6 +120,7 @@ struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference *huffman_tables;
 	u16 restart_interval;
 	size_t ecs_offset;
+	int app14_tf;
 };
 
 int v4l2_jpeg_parse_header(void *buf, size_t len, struct

v4l2_jpeg_header *out);

#13 lore raw

Re: [PATCH v5 07/10] media: Add parsing for APP14 data segment in jpeg helpers

In reply to Mirela Rabulea (OSS)

Hi Mirela,

Quoted 13 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding. 2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

Quoted 6 lines

---
Changes in v5:
This was patch 8 in previous version
Replaced a struct for app14 data with just an int, since the transform flag is the only meaningfull information from this segment

Could we turn this into an enum for the transform flag, and include the above spec reference in its kerneldoc comment? I think this would be better than checking for (app14_tf == <magic_number>) in the drivers.

Quoted 17 lines
 drivers/media/v4l2-core/v4l2-jpeg.c | 39 +++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           |  6 +++--
 2 files changed, 41 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -0
index 8947fd95c6f1..3181ce544f79 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP	0xffde	/* hierarchical progression */
 #define EXP	0xffdf	/* expand reference */
 #define APP0	0xffe0	/* application data */
+#define APP14	0xffee	/* application data for colour encoding */
 #define APP15	0xffef
 #define JPG0	0xfff0	/* extensions */
 #define JPG13	0xfffd

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_skip_segment(struct jpeg_stream *stream) · line 452

Quoted 8 lines
drivers/media/v4l2-core/v4l2-jpeg.c +5 -0
@@ -444,8 +445,37 @@ static int jpeg_skip_segment(struct jpeg_stream *stream)
 	return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+	int ret;
+	int Lp;

Let's keep variables lower case.

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_skip_segment(struct jpeg_stream *stream) · line 458

Quoted 6 lines
drivers/media/v4l2-core/v4l2-jpeg.c +6 -0
+	int skip;
+	int tf;
+
+	Lp = jpeg_get_word_be(stream);
+	if (Lp < 0)
+		return Lp;

Should we check that Ap1 to 6 are actually "Adobe\0"?

Quoted 49 lines
drivers/media/v4l2-core/v4l2-jpeg.c +24 -2
+	/* get to Ap12 */
+	ret = jpeg_skip(stream, 11);
+	if (ret < 0)
+		return -EINVAL;
+
+	tf = jpeg_get_byte(stream);
+	if (tf < 0)
+		return tf;
+
+	skip = Lp - 2 - 11;
+	ret = jpeg_skip(stream, skip);
+	if (ret < 0)
+		return -EINVAL;
+	else
+		return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
  * @buf: address of the JPEG buffer, should start with a SOI marker
  * @len: length of the JPEG buffer
  * @out: returns marker segment positions and optionally parsed headers
@@ -476,6 +506,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	if (marker != SOI)
 		return -EINVAL;
 
+	/* init value to signal if this marker is not present */
+	out->app14_tf = -EINVAL;
+
 	/* loop through marker segments */
 	while ((marker = jpeg_next_marker(&stream)) >= 0) {
 		switch (marker) {
@@ -519,7 +552,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 			ret = jpeg_parse_restart_interval(&stream,
 							&out->restart_interval);
 			break;
-
+		case APP14:
+			out->app14_tf = jpeg_parse_app14_data(&stream);
+			break;
 		case SOS:
 			ret = jpeg_reference_segment(&stream, &out->sos);
 			if (ret < 0)
include/media/v4l2-jpeg.h +0 -0
index ddba2a56c321..008e0476d928 100644

include/media/v4l2-jpeg.h struct v4l2_jpeg_scan_header { · line 107

Quoted 10 lines
include/media/v4l2-jpeg.h +3 -2
@@ -100,10 +100,11 @@ struct v4l2_jpeg_scan_header {
  *                  order, optional
  * @restart_interval: number of MCU per restart interval, Ri
  * @ecs_offset: buffer offset in bytes to the entropy coded segment
+ * @app14_tf: transform flag from app14 data
  *
  * When this structure is passed to v4l2_jpeg_parse_header, the optional scan,
- * quantization_tables, and huffman_tables pointers must be initialized to NULL
- * or point at valid memory.
+ * quantization_tables and huffman_tables pointers must be initialized
+ * to NULL or point at valid memory.

Unnecessary, unrelated change? I'd drop this.

include/media/v4l2-jpeg.h struct v4l2_jpeg_header { · line 126

Quoted 11 lines
include/media/v4l2-jpeg.h +1 -0
  */
 struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference sof;
@@ -119,6 +120,7 @@ struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference *huffman_tables;
 	u16 restart_interval;
 	size_t ecs_offset;
+	int app14_tf;
 };
 
 int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out);

regards
Philipp

#14 lore raw

Re: [EXT] Re: [PATCH v5 07/10] media: Add parsing for APP14 data segment in jpeg helpers

Hi Phipipp,

Quoted 28 lines · Philipp Zabel

Hi Mirela,

Quoted 16 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which
may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding.
2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

Quoted 7 lines

---
Changes in v5:
This was patch 8 in previous version
Replaced a struct for app14 data with just an int, since the transform flag is the only meaningfull information from this segment

Quoted 4 lines

Could we turn this into an enum for the transform flag, and include the
above spec reference in its kerneldoc comment? I think this would be better than checking for (app14_tf == <magic_number>) in the drivers.

Appreciate your feedback, for all patches, I'll address it in v6. Where would be a better place for this enum, v4l2-jpeg.h, or maybe include/uapi/linux/v4l2-controls.h?

Thanks,
Mirela

Quoted 132 lines
Quoted 21 lines
 drivers/media/v4l2-core/v4l2-jpeg.c | 39
+++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           |  6 +++--
 2 files changed, 41 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +1 -0
index 8947fd95c6f1..3181ce544f79 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP  0xffde  /* hierarchical progression */
 #define EXP  0xffdf  /* expand reference */
 #define APP0 0xffe0  /* application data */
+#define APP14        0xffee  /* application data for colour

encoding */

 #define APP15        0xffef
 #define JPG0 0xfff0  /* extensions */
 #define JPG13        0xfffd

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_skip_segment(struct · line 453

Quoted 9 lines
drivers/media/v4l2-core/v4l2-jpeg.c +5 -0
@@ -444,8 +445,37 @@ static int jpeg_skip_segment(struct
 jpeg_stream *stream)
      return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+     int ret;
+     int Lp;

Let's keep variables lower case.

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_skip_segment(struct jpeg_stream *stream) · line 458

Quoted 6 lines
drivers/media/v4l2-core/v4l2-jpeg.c +6 -0
+     int skip;
+     int tf;
+
+     Lp = jpeg_get_word_be(stream);
+     if (Lp < 0)
+             return Lp;

Should we check that Ap1 to 6 are actually "Adobe\0"?

Quoted 64 lines
drivers/media/v4l2-core/v4l2-jpeg.c +17 -1
+     /* get to Ap12 */
+     ret = jpeg_skip(stream, 11);
+     if (ret < 0)
+             return -EINVAL;
+
+     tf = jpeg_get_byte(stream);
+     if (tf < 0)
+             return tf;
+
+     skip = Lp - 2 - 11;
+     ret = jpeg_skip(stream, skip);
+     if (ret < 0)
+             return -EINVAL;
+     else
+             return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse

headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
* @buf: address of the JPEG buffer, should start with a SOI
marker
* @len: length of the JPEG buffer
* @out: returns marker segment positions and optionally parsed
headers

drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
@@ -476,6 +506,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t
 len, struct v4l2_jpeg_header *out)
      if (marker != SOI)
              return -EINVAL;
 
+     /* init value to signal if this marker is not present */
+     out->app14_tf = -EINVAL;
+
      /* loop through marker segments */
      while ((marker = jpeg_next_marker(&stream)) >= 0) {
              switch (marker) {
drivers/media/v4l2-core/v4l2-jpeg.c +3 -1
@@ -519,7 +552,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t
 len, struct v4l2_jpeg_header *out)
                      ret = jpeg_parse_restart_interval(&stream,
                                                      &out-
 >restart_interval);
                      break;
-
+             case APP14:
+                     out->app14_tf =
 jpeg_parse_app14_data(&stream);
+                     break;

case SOS:
ret = jpeg_reference_segment(&stream, &out-

Quoted 1 line

sos);

                      if (ret < 0)
include/media/v4l2-jpeg.h +0 -0
index ddba2a56c321..008e0476d928 100644
@@ -100,10 +100,11 @@ struct v4l2_jpeg_scan_header {
  *                  order, optional
  * @restart_interval: number of MCU per restart interval, Ri
  * @ecs_offset: buffer offset in bytes to the entropy coded

segment
+ * @app14_tf: transform flag from app14 data
*

Quoted 8 lines

* When this structure is passed to v4l2_jpeg_parse_header, the
optional scan,
- * quantization_tables, and huffman_tables pointers must be initialized to NULL
- * or point at valid memory.
+ * quantization_tables and huffman_tables pointers must be initialized
+ * to NULL or point at valid memory.

Unnecessary, unrelated change? I'd drop this.

Quoted 11 lines

*/

 struct v4l2_jpeg_header {
      struct v4l2_jpeg_reference sof;
include/media/v4l2-jpeg.h +1 -0
@@ -119,6 +120,7 @@ struct v4l2_jpeg_header {
      struct v4l2_jpeg_reference *huffman_tables;
      u16 restart_interval;
      size_t ecs_offset;
+     int app14_tf;
 };
 
 int v4l2_jpeg_parse_header(void *buf, size_t len, struct
Quoted 1 line

v4l2_jpeg_header *out);

regards
Philipp

#15 lore raw

Re: [EXT] Re: [PATCH v5 07/10] media: Add parsing for APP14 data segment in jpeg helpers

Quoted 30 lines · Mirela Rabulea (OSS)

Hi Phipipp,

Quoted 27 lines · Philipp Zabel

Hi Mirela,

Quoted 23 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which
may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding.
2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

---
Changes in v5:
This was patch 8 in previous version
Replaced a struct for app14 data with just an int, since the transform flag is the only meaningfull information from this segment

Quoted 8 lines
Quoted 4 lines

Could we turn this into an enum for the transform flag, and include the
above spec reference in its kerneldoc comment? I think this would be better than checking for (app14_tf == <magic_number>) in the drivers.

Appreciate your feedback, for all patches, I'll address it in v6. Where would be a better place for this enum, v4l2-jpeg.h, or maybe include/uapi/linux/v4l2-controls.h?

v4l2-jpeg.h seems like the right place to me.

regards
Philipp

#16 lore raw

PATCH v5 8/10 media: Quit parsing stream if doesn't start with SOI

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

In the case we get an invalid stream, such as from v4l2-compliance streaming test, jpeg_next_marker will end up parsing the entire stream. The standard describes the high level syntax of a jpeg as starting with SOI, ending with EOI, so return error if the very first 2 bytes are not SOI.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +2 -5
index 3181ce544f79..d77e04083d57 100644
@@ -499,11 +499,8 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	out->num_dht = 0;
 	out->num_dqt = 0;
 
-	/* the first marker must be SOI */
-	marker = jpeg_next_marker(&stream);
-	if (marker < 0)
-		return marker;
-	if (marker != SOI)
+	/* the first bytes must be SOI, B.2.1 High-level syntax */
+	if (jpeg_get_word_be(&stream) != SOI)
 		return -EINVAL;
 
 	/* init value to signal if this marker is not present */
Signature · 1 line
2.17.1
Reviewed-by on v5 8/10
#17 lore raw

Re: [PATCH v5 08/10] media: Quit parsing stream if doesn't start with SOI

Quoted 21 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

In the case we get an invalid stream, such as from v4l2-compliance streaming test, jpeg_next_marker will end up parsing the entire stream. The standard describes the high level syntax of a jpeg as starting with SOI, ending with EOI, so return error if the very first 2 bytes are not SOI.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +0 -0
index 3181ce544f79..d77e04083d57 100644
@@ -499,11 +499,8 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	out->num_dht = 0;
 	out->num_dqt = 0;
 

drivers/media/v4l2-core/v4l2-jpeg.c int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out) · line 506

Quoted 10 lines
drivers/media/v4l2-core/v4l2-jpeg.c +2 -5
-	/* the first marker must be SOI */
-	marker = jpeg_next_marker(&stream);
-	if (marker < 0)
-		return marker;
-	if (marker != SOI)
+	/* the first bytes must be SOI, B.2.1 High-level syntax */
+	if (jpeg_get_word_be(&stream) != SOI)
 		return -EINVAL;
 
 	/* init value to signal if this marker is not present */

Yes, shorter, potentially faster code, and it adheres to the specification more strictly.

regards
Philipp

#18 lore raw

PATCH v5 9/10 media: Avoid parsing quantization and huffman tables

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so do not parse if not requested, save some time.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +6 -0
index d77e04083d57..7576cd0ce6b9 100644
@@ -307,6 +307,9 @@ static int jpeg_parse_quantization_tables(struct jpeg_stream *stream,
 {
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+
 	if (len < 0)
 		return len;
 	/* Lq = 2 + n * 65 (for baseline DCT), n >= 1 */
@@ -361,6 +364,9 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
 	int mt;
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+
 	if (len < 0)
 		return len;
 	/* Table B.5 - Huffman table specification parameter sizes and values */
Signature · 1 line
2.17.1
#19 lore raw

Re: [PATCH v5 09/10] media: Avoid parsing quantization and huffman tables

Quoted 15 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so do not parse if not requested, save some time.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +0 -0
index d77e04083d57..7576cd0ce6b9 100644

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_parse_quantization_tables(struct jpeg_stream *stream, · line 312

Quoted 6 lines
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
@@ -307,6 +307,9 @@ static int jpeg_parse_quantization_tables(struct jpeg_stream *stream,
 {
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+

It feels more natural to check for a non-NULL out->quantization_tables or non-NULL out->huffman_tables pointer in v4l2_jpeg_parse_header() rather than in these low-level functions. It's weird to have this check here.

Regards,

Hans

Quoted 14 lines
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
 	if (len < 0)
 		return len;
 	/* Lq = 2 + n * 65 (for baseline DCT), n >= 1 */
@@ -361,6 +364,9 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
 	int mt;
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+
 	if (len < 0)
 		return len;
 	/* Table B.5 - Huffman table specification parameter sizes and values */
#20 lore raw

Re: [PATCH v5 09/10] media: Avoid parsing quantization and huffman tables

Quoted 19 lines · Hans Verkuil
Quoted 18 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so do not parse if not requested, save some time.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +0 -0
index d77e04083d57..7576cd0ce6b9 100644
@@ -307,6 +307,9 @@ static int jpeg_parse_quantization_tables(struct jpeg_stream *stream,
 {
 	int len = jpeg_get_word_be(stream);
 
Quoted 7 lines

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_parse_quantization_tables(struct jpeg_stream *stream, · line 312

Quoted 3 lines
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
+	if (!tables)
+		return 0;
+

It feels more natural to check for a non-NULL out->quantization_tables or non-NULL out->huffman_tables pointer in v4l2_jpeg_parse_header() rather than in these low-level functions. It's weird to have this check here.

Ah, now I get it.

Yes, if you want to skip the entire DQT for performance reasons, it is probably better to just call jpeg_skip_segment() instead of jpeg_parse_quantization_table(). Otherwise the next jpeg_next_marker has to scan the whole quantization table for segment markers.

regards
Philipp

#21 lore raw

Re: [PATCH v5 09/10] media: Avoid parsing quantization and huffman tables

In reply to Mirela Rabulea (OSS)

Hi Mirela,

Quoted 25 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so do not parse if not requested, save some time.

---
 drivers/media/v4l2-core/v4l2-jpeg.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
index d77e04083d57..7576cd0ce6b9 100644
@@ -307,6 +307,9 @@ static int jpeg_parse_quantization_tables(struct jpeg_stream *stream,
 {
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+
 	if (len < 0)
 		return len;
 	/* Lq = 2 + n * 65 (for baseline DCT), n >= 1 */

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_parse_huffman_tables(struct jpeg_stream *stream, · line 372

Quoted 9 lines
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
@@ -361,6 +364,9 @@ static int jpeg_parse_huffman_tables(struct jpeg_stream *stream,
 	int mt;
 	int len = jpeg_get_word_be(stream);
 
+	if (!tables)
+		return 0;
+
 	if (len < 0)
 		return len;
 	/* Table B.5 - Huffman table specification parameter sizes and values */

I don't understand this. jpeg_parse_quantization_tables() is only called if v4l2_jpeg_parse_header() finds a DQT marker. The entire quantization table-specification parameter block is optional, but when a DQT marker is present, IIUC the block must contain at least one table (see B.2.4.1, specifically figure B.6).

regards
Philipp

#22 lore raw

PATCH v5 10/10 media: imx-jpeg: Use v4l2 jpeg helpers in mxc-jpeg

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Use v4l2_jpeg_parse_header in mxc_jpeg_parse, remove the old parsing way, which was duplicated in other jpeg drivers.

---
Changes in v5:
This was patch 11 in previous version
Change triggered by patch 7 (app14 data change struct -> int)

 drivers/media/platform/imx-jpeg/Kconfig    |   1 +
 drivers/media/platform/imx-jpeg/mxc-jpeg.c | 267 ++++++---------------
 drivers/media/platform/imx-jpeg/mxc-jpeg.h |  26 +-
 3 files changed, 80 insertions(+), 214 deletions(-)
drivers/media/platform/imx-jpeg/Kconfig +1 -0
index 7cc89e5eff90..d875f7c88cda 100644
@@ -4,6 +4,7 @@ config VIDEO_IMX8_JPEG
 	depends on VIDEO_DEV && VIDEO_V4L2
 	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_MEM2MEM_DEV
+	select V4L2_JPEG_HELPER
 	default m
 	help
 	  This is a video4linux2 driver for the i.MX8 QXP/QM integrated
drivers/media/platform/imx-jpeg/mxc-jpeg.c +68 -199

390 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.h +11 -15
index ef1670dafeb4..313b09f831a4 100644
@@ -42,6 +42,8 @@ enum mxc_jpeg_mode {
  * struct jpeg_fmt - driver's internal color format data
  * @name:	format description
  * @fourcc:	fourcc code, 0 if not applicable
+ * @subsampling subsampling of jpeg components
+ * @nc:		number of color components
  * @depth:	number of bits per pixel
  * @colplanes:	number of color planes (1 for packed formats)
  * @h_align:	horizontal alignment order (align to 2^h_align)
@@ -49,13 +51,15 @@ enum mxc_jpeg_mode {
  * @flags:	flags describing format applicability
  */
 struct mxc_jpeg_fmt {
-	char	*name;
-	u32	fourcc;
-	int	depth;
-	int	colplanes;
-	int	h_align;
-	int	v_align;
-	u32	flags;
+	char					*name;
+	u32					fourcc;
+	enum v4l2_jpeg_chroma_subsampling	subsampling;
+	int					nc;
+	int					depth;
+	int					colplanes;
+	int					h_align;
+	int					v_align;
+	u32					flags;
 };
 
 struct mxc_jpeg_desc {
@@ -117,14 +121,6 @@ struct mxc_jpeg_dev {
 	struct device_link		**pd_link;
 };
 
-/* JPEG marker identifiers */
-#define SOF0				0xC0
-#define SOF1				0xC1
-#define SOF2				0xC2
-#define SOS				0xDA
-#define DHT				0xC4
-#define APP14				0xEE
-
 /**
  * struct mxc_jpeg_sof_comp - JPEG Start Of Frame component fields
  * @id:				component id
Signature · 1 line
2.17.1
#23 lore raw

Re: [PATCH v5 10/10] media: imx-jpeg: Use v4l2 jpeg helpers in mxc-jpeg

Quoted 32 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Use v4l2_jpeg_parse_header in mxc_jpeg_parse, remove the old parsing way, which was duplicated in other jpeg drivers.

---
Changes in v5:
This was patch 11 in previous version
Change triggered by patch 7 (app14 data change struct -> int)

 drivers/media/platform/imx-jpeg/Kconfig    |   1 +
 drivers/media/platform/imx-jpeg/mxc-jpeg.c | 267 ++++++---------------
 drivers/media/platform/imx-jpeg/mxc-jpeg.h |  26 +-
 3 files changed, 80 insertions(+), 214 deletions(-)
drivers/media/platform/imx-jpeg/Kconfig +1 -0
index 7cc89e5eff90..d875f7c88cda 100644
@@ -4,6 +4,7 @@ config VIDEO_IMX8_JPEG
 	depends on VIDEO_DEV && VIDEO_V4L2
 	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_MEM2MEM_DEV
+	select V4L2_JPEG_HELPER
 	default m
 	help
 	  This is a video4linux2 driver for the i.MX8 QXP/QM integrated
drivers/media/platform/imx-jpeg/mxc-jpeg.c +0 -0
index 8f297803f2c3..d3b7581ce46e 100644

[...]

drivers/media/platform/imx-jpeg/mxc-jpeg.c static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, · line 1321

Quoted 12 lines
drivers/media/platform/imx-jpeg/mxc-jpeg.c +2 -6
@@ -1448,12 +1317,11 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx,
 	 * encoded with 3 components have RGB colorspace, see Recommendation
 	 * ITU-T T.872 chapter 6.5.3 APP14 marker segment for colour encoding
 	 */
-	if (img_fmt == MXC_JPEG_YUV444 && app14 && app14_transform == 0)
-		img_fmt = MXC_JPEG_RGB;
-
-	if (mxc_jpeg_imgfmt_to_fourcc(img_fmt, &fourcc)) {
-		dev_err(dev, "Fourcc not found for %d", img_fmt);
-		return -EINVAL;
+	if (fourcc == V4L2_PIX_FMT_YUV24 || fourcc == V4L2_PIX_FMT_RGB24) {
+		if (header.app14_tf == 0)

This is what I meant in patch 7, I think it would be more clear to have an enum value that says "RGB color coding" than to rely on the reader to know what the value 0 means.

drivers/media/platform/imx-jpeg/mxc-jpeg.c static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, · line 1327

Quoted 7 lines
drivers/media/platform/imx-jpeg/mxc-jpeg.c +3 -0
+			fourcc = V4L2_PIX_FMT_RGB24;
+		else
+			fourcc = V4L2_PIX_FMT_YUV24;
 	}
 
 	/*

Otherwise this patch looks fine to me.

regards
Philipp