Skip to content

perf(camera): 30 fps viewfinder and the IMX766 gain model on the Jolla - #113

Open
patrickjquinn wants to merge 2 commits into
fix/jolla-camera-selectionfrom
feat/jolla-camera-quality
Open

patrickjquinn wants to merge 2 commits into
fix/jolla-camera-selectionfrom
feat/jolla-camera-quality

Conversation

@patrickjquinn

Copy link
Copy Markdown
Owner

Stacked on #106 (camera selection). Part one of the Jolla Phone camera quality work; the kernel half (IMX766 binned mode, IMX766 gain range, CAMSV cacheable buffers, linux-mt6858 r27) is a separate PR on the r26 series.

What was wrong

  • The GPU debayer already ran in the app's sandbox (EGL surfaceless on the Mali-G610, panfrost). The slow part was the software ISP's CPU statistics. They read every 4096x3072 frame from CAMSV's coherent buffers, which the CPU maps uncached: 127 ms every fourth frame.
  • In a dim room the AGC stretched frames to 66 ms, so the viewfinder dropped to 15 fps.
  • The IMX766's analogue gain is 16384 / (16384 - code), as in MediaTek's gain2reg(). Both our libcamera helper and the kernel driver assumed 1024 / (1024 - code), and the driver capped the code at 960, which is 1.06x. The AGC thought it was running at 16x while the sensor stayed near 1x. Measured on the phone: the raw levels were identical when libcamera asked for 1x, 4x and 16x, while exposure time scaled them as expected. That is the grey, dark image.

Changes

  • libcamera r6:
    • 0037 samples at most 128 line pairs for the statistics.
    • 0038 asks for cacheable MMAP buffers (V4L2_MEMORY_FLAG_NON_COHERENT). It takes effect with linux-mt6858 r27; until then the driver ignores it.
    • 0039 fixes the IMX766 gain model.
  • Camera app: the viewfinder and the photo's frames request a 33.3 ms frame duration (FrameDurationLimits), so they hold 30 fps and dim scenes take gain instead.

Measured on the Jolla (IMX766, app viewfinder 1400x1050)

before (r5 libcamera, old app) after
CPU statistics (every 4th frame) 127.6 ms 16.7 ms
GPU debayer + statistics, mean per frame 37.5 ms 12.2 ms
viewfinder, with the 30 fps cap 23.6 fps 30.0 fps, 0 frames lost over 360
viewfinder, old app in a dim room 15 fps (66 ms frames) 30 fps
photo: shutter to frame 576 ms 298 ms
photo: JPEG written 195 ms 186-203 ms

Fps was measured from frame timestamps in the app, with a temporary counter that is not in this PR.

Not in this PR

  • Per-sensor tuning (CCM). It waits on a ColorChecker capture.
  • The IPA change that keeps the AGC across a binned viewfinder mode and the full-resolution still mode. It waits on the r27 boot.

The software ISP's exposure control lengthens the frames to 66 ms in a
dim room, so the viewfinder fell to 15 fps. Ask for a 33.3 ms frame
duration for the viewfinder and the photo's frames: the exposure stays
within one frame and a dim scene takes more gain instead.

On the Jolla Phone's IMX766 with the libcamera from this branch, the
viewfinder (1400x1050) ran at 30.0 fps with no frame lost over 360
frames, measured in the app.
…ixel sensor (r6)

- 0037: sample at most 128 line pairs for the statistics. On the Jolla
  Phone the statistics read each 4096x3072 frame from uncached CAMSV
  memory in 127 ms, every fourth frame; now 17 ms. The Camera app's
  viewfinder went from 23.6 fps to 30.0 fps, with no frame lost, and
  the GPU debayer plus statistics from 37.5 to 12.2 ms a frame.
- 0038: ask for cacheable MMAP buffers (V4L2_MEMORY_FLAG_NON_COHERENT);
  drivers that don't allow cache hints ignore it. CAMSV allows them
  from linux-mt6858 r27.
- 0039: the IMX766's analogue gain is 16384 / (16384 - code), as in
  MediaTek's driver; with the 1024-based model the AGC believed it
  ran 16x while the sensor stayed near 1x (raw levels measured on the
  phone at 1x, 4x and 16x were the same), so frames came out grey and
  dark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant