Repository navigation
Infinity3: working HAL, verified on an Imou LOOC 2 (MSC316DC, OV2735) - #64
HeytalePazguato wants to merge 22 commits into
Conversation
Video, audio capture and playback, ISP exposure read-out, software OSD widgets and the property store the vendor library reads its scaler settings from. Verified on an Imou LOOC 2 (MSC316DC, OV2735).
Chrome 153 on Windows rejects several MPEG audio frames in one sample and the Shine MP3 bitstream altogether; browsers get Opus (libopus loaded at run time). Stale audio is dropped while no client is draining it.
The password '@System' checks Basic credentials against /etc/shadow (src/sysauth.c), so the camera's own login is used and no password is kept in the config.
Night when the exposure index is high and the picture dark; back to day by briefly switching the IR LEDs off and measuring again. Adds a white lamp pin.
Refuses to record onto the root filesystem, removes its own oldest segments below a free-space reserve, cuts segments on keyframes, takes fragments from the live muxer (so clips carry audio), retries continuous mode when the card shows up later.
Sub-stream on a second RTSP port, talk-back (/api/speak), lamp, time zone, clip list and download with byte ranges, Media Source live player, sub-stream and recording settings, system-account web login, start/stop fixes for /api/record, web port bind retry.
OpenIPC now builds infinity3 on musl, with glibc-compat for the vendor libraries: - open libmi_isp.so before libmi.so (musl binds their mutual symbols that way; glibc needed both preloaded) - hand the mi.* settings to OpenIPC's libat.so as well, which keeps them in the process instead of the bionic property area - with GLIBC_COMPAT defined, leave out the empty backtrace, __ctype_b_loc and pthread cancel stand-ins: the shim and musl have working ones, and the executable's own definitions would be found first Verified on the Imou LOOC 2 on OpenIPC firmware master (musl): 1080p H.264 + Opus, snapshot, sub-stream, RTSP on both ports.
The JPEG, MJPEG and MP4 channel configs were built on the stack and only partly filled, so frame rate, GOP, profile and quality limits held whatever was there. HALs that read those fields got garbage: on Infinity3 the snapshot encoder was created at a random frame rate (198-230 fps) and its port never came up, so every snapshot failed. The sub-stream config was already cleared this way.
MI_VENC_SetColor2Grey() leaves the bottom of a 1080p frame in colour and the MJPEG encoder rejects it, so night snapshots stayed pink. Use MI_ISP_SetColorToGray() with the full attribute from I3_isp_api.xml (manual mode), which turns every channel gray; keep the encoder call as a fallback.
MI_VENC_CreateChn hands rate control mode 1 to _MI_VENC_SetVbr and 2 to _MI_VENC_SetCbr; 0 means none. The HAL passed 0 for CBR, so the H.264 encoder ignored the bitrate and sat at QP 48 (about 600 kbps at 1080p, visibly blocky). Measured on the LOOC 2 after the fix: CBR 2048 -> 2.1 Mbit/s at QP 33-36, VBR 2048 -> 2.1 Mbit/s, CBR 4096 -> 4.2 Mbit/s. While a channel is being restarted, MI_VENC_GetStreamTimeOut fails at once instead of waiting; back off 10 ms so the stream thread does not spin (65000 vendor log lines per restart before, about 100 after).
Each probe switches the IR lamps off for a moment, which blanks the picture. Daylight is caught from the exposure falling below the darkest level seen under the lamps, or the picture getting brighter than the auto-exposure aims for; the timed probes now start after ten minutes and back off to about once an hour.
/api/record?start&duration=N records for N seconds; repeating the call moves the end, so an NVR or home automation event can keep a clip going without having to send the stop. A plain start still records until stop, and the response reports the seconds left in stop_in.
PR Summary by QodoEnable end-to-end Infinity3 camera streaming, audio, and recording
AI Description
Diagram
High-Level Assessment
Files changed (24)
|
Code Review by Qodo
1.
|
The /tmp/http.log request trace was debugging left over from the Infinity3 bring-up. Clips are opened with O_NOFOLLOW so a link in the recording directory cannot serve a file from elsewhere, and the clip list skips links and names that would need JSON escaping. An explicit stop now also ends continuous mode, which otherwise restarted the recording, and a timed recording is limited to a day.
…o thread Start and stop are serialized with their remounts, so a late stop cannot remount the card read-only under a new recording. A failed start remounts it read-only at once, and after a write or rotation failure on the encoder thread the next tick does. The free-space cleanup runs from the tick instead of under the recorder and muxer locks, and only removes names in the exact <stem>_YYYYMMDD-HHMMSS[-N]<ext> form it creates.
The HTTP and RTSP threads both check logins: the cache and crypt() are now under a lock. The last good credential is kept for five minutes and only while /etc/shadow is unchanged, so a password change takes effect. Instead of sleeping half a second in the caller's server loop after a failure, new credentials are refused for a second without checking.
…upted probe With exposure_day left at 0 the daylight probe never ran. A probe cut short by manual mode or a settings change now turns the IR lamps back on instead of leaving them off in night mode.
…t failure The still and MJPEG encoders use the configured qfactor (fixed for the channel's life). media_sub_enable returned success after a failed channel, encoder or bind step.
The reports it sent to the camera's request trace went with the trace.
The snapshot channel is an MJPEG encoder: MI_VENC_SetMjpegParam changes its quality, and the vendor only accepts that while the channel is stopped, so it is set between snapshots, before the bind. Tested at qfactor 20/50/80/95 (17/25/64/170 KB at 1280x720).
# Conflicts: # src/night.c
Since a903df9 the exported mmap takes a 32-bit offset. On infinity3 the vendor libraries' mmap calls are renamed to the glibc-compat shim's mm32, which calls mmap with musl's 64-bit off_t. With -rdynamic the exported mmap overrides musl's for the shim as well, reads the offset from the wrong argument slot, and the first vendor mapping faults with SIGBUS during MI_VI init. GLIBC_COMPAT builds already bridge the 32-bit callers through mm32, so leave mmap to musl there.
The Infinity3 HAL was marked work in progress; this makes it work end to end on real hardware: an Imou LOOC 2 (IPC-C26EP-V2, MSC316DC, OV2735 MIPI, 128 MB), running OpenIPC with the vendor libmi.
What works on the camera:
Commits (each builds on its own with the armhf glibc toolchain):
auth_pass: "@system", src/sysauth.c)exposure_night/exposure_day)/api/record?start&duration=Nrecords for N seconds and repeating it moves the end, so an NVR or home automation event can trigger clips on the card without sending the stop;stop_inin the responseTested on the LOOC 2 on top of 251d329, with the camera's glibc image and booted from OpenIPC firmware master (musl, kernel and rootfs built from HeytalePazguato/firmware branch infinity3-imou-looc2): live MP4 1080p + Opus, snapshots, RTSP 554/555 over TCP and UDP, continuous recording (15 s segments, H.264 + Opus) and recording to a real exFAT card, day/night switching with the IR lamp (gray streams and snapshots at night, colour back in day mode), 401 without login on web and RTSP.
Not tested: other Infinity3 chips (MSC313E, MSC316DM) and sensors other than OV2735.