fix a stale channel state, truncated audio settings and an RTCP send to fd 0 - #41
Conversation
…to fd 0 Four independent defects, found while bringing up a new platform but none of them platform-specific. media: a failed channel, encoder or bind left chnState[index].enable true, so the video thread kept polling a channel that was never created. server: audio bitrate, gain and srate were parsed into a short. 48000 does not fit, so setting a 48 kHz sample rate over the API silently stored -17536. server: a POST with no Content-Type dereferenced NULL in STARTS_WITH. rtcp: __rtcp_send_sr() sent on con->trans[track_id].server_port_rtp without checking the track was ever SETUP. An audio track a client never set up has fd 0, so the report went to stdin.
PR Summary by QodoFix media state, audio parsing, POST handling, and RTCP transport
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
media: clearing chnState[index].enable before HAL_ERROR returned made things worse, not better. media_mjpeg_disable() and media_mp4_disable() skip slots whose enable is already clear, so a failure after the channel or encoder had been created stranded them in the HAL, and take_next_free_channel() would then hand the same index out again. Roll back stage by stage instead: release the encoder and channel that were created, then clear the slot. rtcp: the new transport guard indexed con->trans[track_id] ahead of the bounds assertion that follows it, so an out-of-range track read out of bounds before the assertion could reject it. Moved below the assertion and expressed through the t pointer it already sets up. server: widening the audio settings from short to int stopped them being truncated but still stored whatever strtol() returned, including trailing garbage, saturated overflow and negatives - and audio_bitrate and audio_srate are unsigned, so a negative wrapped rather than being rejected. They are now accepted only as a complete number inside the same ranges the config loader enforces: bitrate 32-320, gain -60-30, srate 8000-96000.
Adds src/hal/fh: a HAL for the Fullhan FH8852/FH8856 V100 generation (ARM1176 softfloat, kernel 3.0.8, SDK V1.2.0 "OSDRV" libraries libdsp/ libisp/libispcore/libvmm/libmipi/libadvapi/libacw_mpi). The SDK ships as binary-only shared objects without headers; the interface was recovered from the libraries and a vendor application that statically links the same SDK, and verified on an Asecam/Vatilon PB1 (FH8856 + GC4653). - fh_sys/fh_vpss/fh_venc/fh_isp/fh_aud: dlopen wrappers for the MPI subset - fh_snr_gc4653: userspace GC4653 driver (the ISP calls back into a sensor op table; registers go over /dev/i2c-0) - H.264 and H.265 over RTSP, MJPEG, JPEG snapshots, audio capture, OSD via the VPU graphic plane (ARGB1555 at sensor resolution) - anti-flicker via the AE flicker command; SmartIR image-gain day/night detection wired into night mode (no external light sensor needed) - the VPU exposes two scaler channels (main + one sub); the JPEG snapshot is taken from the MJPEG sub-stream when MJPEG is enabled, mirroring the vendor - fh_compat: getifaddrs() over SIOCGIFCONF; gpio.c resolves GPIO<n> vs gpio<n> sysfs node naming (fh kernels use uppercase) - server: do not crash on an OSD POST without a Content-Type header - platform detection via /proc/driver/chip; built only for ARMv6 targets Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Epx86cKNLr14TY4B41nq89 Includes the fixes from the upstream review of the three PRs this branch is split into (OpenIPC/divinus OpenIPC#41, OpenIPC#42, OpenIPC#43): stage-aware rollback on media init failure, the RTCP bounds check before indexing, validated audio API ranges, interleaved flush for audio-only sessions, a latched RTSP audio codec, exact 8 kHz G.711 resampling, bounded config parsing for rtsp.audio_codec and night_mode.lamp, JSON escaping in the new endpoints, OSD clipping and bitmap scaling, per-region OSD opacity, and checked snapshot reallocations.
Adds src/hal/fh: a HAL for the Fullhan FH8852/FH8856 V100 generation (ARM1176 softfloat, kernel 3.0.8, SDK V1.2.0 "OSDRV" libraries libdsp/ libisp/libispcore/libvmm/libmipi/libadvapi/libacw_mpi). The SDK ships as binary-only shared objects without headers; the interface was recovered from the libraries and a vendor application that statically links the same SDK, and verified on an Asecam/Vatilon PB1 (FH8856 + GC4653). - fh_sys/fh_vpss/fh_venc/fh_isp/fh_aud: dlopen wrappers for the MPI subset - fh_snr_gc4653: userspace GC4653 driver (the ISP calls back into a sensor op table; registers go over /dev/i2c-0) - H.264 and H.265 over RTSP, MJPEG, JPEG snapshots, audio capture, OSD via the VPU graphic plane (ARGB1555 at sensor resolution) - anti-flicker via the AE flicker command; SmartIR image-gain day/night detection wired into night mode (no external light sensor needed) - the VPU exposes two scaler channels (main + one sub); the JPEG snapshot is taken from the MJPEG sub-stream when MJPEG is enabled, mirroring the vendor - fh_compat: getifaddrs() over SIOCGIFCONF; gpio.c resolves GPIO<n> vs gpio<n> sysfs node naming (fh kernels use uppercase) - server: do not crash on an OSD POST without a Content-Type header - platform detection via /proc/driver/chip; built only for ARMv6 targets Claude-Session: https://claude.ai/code/session_01Epx86cKNLr14TY4B41nq89 Includes the fixes from the upstream review of the three PRs this branch is split into (OpenIPC/divinus OpenIPC#41, OpenIPC#42, OpenIPC#43): stage-aware rollback on media init failure, the RTCP bounds check before indexing, validated audio API ranges, interleaved flush for audio-only sessions, a latched RTSP audio codec, exact 8 kHz G.711 resampling, bounded config parsing for rtsp.audio_codec and night_mode.lamp, JSON escaping in the new endpoints, OSD clipping and bitmap scaling, per-region OSD opacity, and checked snapshot reallocations.
|
Thank you very much for the fixes! The stale channel state and RTCP-to-stdin issues were good catches, I refined a few things on top, mainly moving the ranged-value parser to hal/tools so it can be reused by other modules. Apologies for the delay in reviewing this, I’ll make sure to get to the other two PRs you opened promptly as well. |
Four independent defects, found while bringing up a new platform but none of them platform-specific. Split out of a larger branch so they can be reviewed on their own.
media— a failedcreate_channel,video_createorbind_channelreturned throughHAL_ERRORleavingchnState[index].enabletrue, so the video thread kept polling a channel that was never created.server— audiobitrate,gainandsratewere parsed into ashort. 48000 does not fit, soPOST /api/audio?srate=48000silently stored −17536.server— a POST with noContent-Typeheader dereferenced NULL insideSTARTS_WITH.rtcp—__rtcp_send_sr()sent oncon->trans[track_id].server_port_rtpwithout checking the track had ever been SETUP. A client that sets up video only leaves the audio track at fd 0, so the sender report went to stdin.Testing
Built for
fh8856v100_lite(ARMv6). Runs as part of the combined branch this was split from, on three Fullhan FH8856 cameras. This branch on its own is build-tested, not separately run on hardware.Two follow-ups are prepared on top of this: RTSP interleaved-send/timestamp work, and a Fullhan FH8852/FH8856 HAL.