[libcamera-devel,v5,0/2] Fix a format mismatch within the RkISP1 pipeline
mbox series

Message ID 20210227180126.37591-1-sebastian.fricke@posteo.net
Headers show
Series
  • Fix a format mismatch within the RkISP1 pipeline
Related show

Message

Sebastian Fricke Feb. 27, 2021, 6:01 p.m. UTC
This patch-set fixes a format mismatch, that occurs when a sensor format
is used that is greater than the maximum resolution for the Image
Signal Processor. Within the validate method, which is called during the
configuration generation, we request the sensor format.

We have to check for one special case, that can lead to an oversized sensor
resolution. The getFormat method takes the smallest sensor resolution,
where the width and height are greater or equal to the input size parameter.

Example for a problematic case:
Sensor resolutions:
- 2112x1568
- 4224x3136
Stream configuration size:
- 1920x1920

In this case, the requested resolution for the stream is smaller than the
ISP maximum, but the only viable alternative has a height that is
smaller than the requested height, so getFormat will pick the oversized
resolution.

We resolve this issue by making sure, that the stream configuration
resolution is smaller than the maximum viable sensor resolution before
requesting the best-fit sensor format.

Additionally, the ISP subdevice has to be shared with the CameraData
class, so that we can access that device within a method of the
RkISP1CameraConfiguration class.

v1: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015113.html
v2: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015136.html
v3: https://patchwork.libcamera.org/patch/10660/
v4: https://patchwork.libcamera.org/patch/11180/

Changelog:

Changes since v4:
* Completely rework the design of the fix, adjust the sensor resolution
  during the validate() method, in order to have a correct sensor format
  within configure()
* Share the ISP subdevice between the PipelineHandler and the CameraData
  class, so that the CameraConfiguration class has access to this device

Changes since v3:

* Introduce a helper method for finding the correct sensor format:
  `findBestFitFormat`
* Besides checking for a valid format resolution also check for a
  matching media bus code
* Return -EINVAL on an error instead of -1
* Add documentation for the `findBestFitFormat` method

Changes since v2:

* Replace the act of attempting to set the ISP format before negotiating
  the actual format for both the ISP input pad and the sensor in order
  to get the maximum frame size. With a logic that involves enumerating
  the maximum size directly from the subdevice and using that size for
  the negotiation process.
* Improve the log messages

Changes since v1:

* Change snake_case variable names to camelCase
* Use the request comment style
* Correct the scope of the newly implemented variables
* Correct the subject of the debug log for the ISP format configuration
* Update the comment above the ISP format configuration
* Check if the original format is not equal to the configured ISP format
  instead of checking if it is greater, this denies a false positive
  where the height exceeds the maximum while the width is smaller.
  If the configured format does not exceed the maximum resolution of the
  ISP, it will stay untouched so the inequality always means that we
  have to reconfigure the format.
* Adjust the comparison of the ISP format size with the available sensor
  formats, to detect a false-positive were the width is smaller while
  the height exceeds the maximum
* Use the standard function `max`

-----

The following tests were all able to create a working camera pipeline:
1. Without stream configuration
2. With a normal stream configuration
3. With a stream configuration that exceeds the maximum of the ISP
4. With a very small resolution stream configuration
5. With a configuration that is closer to the upper than to the lower
resolution

-----

1. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3

[9:26:53.975708264] [7581] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12
[9:26:53.976907882] [7581]  INFO Camera camera.cpp:890 configuring streams: (0) 1920x1920-NV12
...
[9:26:53.978132875] [7582] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10
[9:26:53.978232332] [7582] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10
[9:26:53.978358332] [7582] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568
[9:26:53.978441748] [7582] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:26:53.978548789] [7582] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:26:53.978680621] [7582] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:26:53.978763454] [7582] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 1920x1920-YUYV8_2X8
[9:26:53.978840454] [7582] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 1920x1920-YUYV8_1_5X8

2. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=900,height=600,pixelformat=NV12,role=video

[9:27:40.379117478] [7586] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12
[9:27:40.380064806] [7586]  INFO Camera camera.cpp:890 configuring streams: (0) 900x600-NV12
...
[9:27:40.381540047] [7587] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10
[9:27:40.381681796] [7587] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10
[9:27:40.381864670] [7587] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568
[9:27:40.381985419] [7587] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:27:40.382142335] [7587] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:27:40.382334251] [7587] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:27:40.382452667] [7587] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 900x600-YUYV8_2X8
[9:27:40.382564666] [7587] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 900x600-YUYV8_1_5X8

3. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=4500,height=3500,pixelformat=NV12,role=video

[9:28:21.358328098] [7589] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12
[9:28:21.358584180] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12
[9:28:21.358701137] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 1920x1920-NV12
[9:28:21.358801470] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12
Camera configuration adjusted
[9:28:21.359524799] [7589]  INFO Camera camera.cpp:890 configuring streams: (0) 4416x3312-NV12
...
[9:28:21.360212587] [7590] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10
[9:28:21.360255753] [7590] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10
[9:28:21.360309419] [7590] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568
[9:28:21.360340336] [7590] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:28:21.360378252] [7590] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:28:21.360430169] [7590] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:28:21.360459918] [7590] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 4416x3312-YUYV8_2X8
[9:28:21.360487918] [7590] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 4416x3312-YUYV8_1_5X8

4. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=40,height=30,pixelformat=NV12,role=video

[9:29:21.653077053] [7592] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12
[9:29:21.653987340] [7592]  INFO Camera camera.cpp:890 configuring streams: (0) 40x30-NV12
...
[9:29:21.655460873] [7593] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10
[9:29:21.655601455] [7593] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10
[9:29:21.655780829] [7593] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568
[9:29:21.655901578] [7593] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:29:21.656136077] [7593] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:29:21.656356576] [7593] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:29:21.656487533] [7593] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 40x30-YUYV8_2X8
[9:29:21.656608574] [7593] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 40x30-YUYV8_1_5X8

5. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=3450,height=2456,pixelformat=NV12,role=video

[9:30:08.027510441] [7595] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12
[9:30:08.028457768] [7595]  INFO Camera camera.cpp:890 configuring streams: (0) 3450x2456-NV12
...
[9:30:08.029969509] [7596] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10
[9:30:08.030114758] [7596] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10
[9:30:08.030296174] [7596] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568
[9:30:08.030422465] [7596] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:30:08.030582881] [7596] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:30:08.030776546] [7596] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568
[9:30:08.030899629] [7596] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 3450x2456-YUYV8_2X8
[9:30:08.031016586] [7596] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 3450x2456-YUYV8_1_5X8

Sebastian Fricke (2):
  pipeline: rkisp1: Share the ISP subdevice
  pipeline: rkisp1: Fix sensor ISP format mismatch

 src/libcamera/pipeline/rkisp1/rkisp1.cpp | 40 +++++++++++++++++++++---
 1 file changed, 35 insertions(+), 5 deletions(-)