Skip to content

Fix ONVIF driver crashes on continuous-only PTZ cameras#172

Open
cam-s-hunt wants to merge 1 commit intoopensensorhub:masterfrom
cam-s-hunt:fix/onvif-continuous-ptz-and-webcodecs
Open

Fix ONVIF driver crashes on continuous-only PTZ cameras#172
cam-s-hunt wants to merge 1 commit intoopensensorhub:masterfrom
cam-s-hunt:fix/onvif-continuous-ptz-and-webcodecs

Conversation

@cam-s-hunt
Copy link

Summary

Fixes four bugs in the ONVIF driver that cause crashes or failures when used with cameras that only support continuous PTZ (no absolute/relative), such as Reolink models.

  • Fix IllegalArgumentException on ptzPos access after removal: When a camera lacks absolute pan/tilt, the ptzPos component is removed from commandData. The subsequent zoom-removal code then crashes trying to access the already-removed item. Added a guard flag (absolutePtRemoved) to skip the nested removal.

  • Fix NullPointerException in execCommand when position is null: Some cameras return null from getStatus() or getPosition() rather than throwing an exception. Added null checks with a fallback to an empty PTZVector.

  • Fix NullPointerException on autoRemoteHost.clear() during init: GSON deserializes missing/null JSON fields as null, overriding Java field initializers. Added a null-check before clear(), initializing with new TreeSet<>() when null.

  • Enable H.264 extradata injection for WebCodecs compatibility: Calls mpegTsProcessor.setInjectVideoExtradata(true) so SPS/PPS NAL units are prepended before keyframes. Without this, browser-based viewers using the WebCodecs VideoDecoder API cannot decode the H.264 stream when joining mid-stream (they require a keyframe with SPS/PPS to initialize).

Test plan

  • Tested with Reolink RLC-823A (continuous-only PTZ, H.264)
  • Camera initializes without IllegalArgumentException
  • PTZ continuous move commands work correctly
  • H.264 video streams to OSH Viewer via WebCodecs without DataError
  • Audio stream initializes alongside video

…olink)

Four bugs fixed:

1. IllegalArgumentException when camera lacks absolute PTZ:
   When absolute pan/tilt is unsupported, ptzPos is removed from
   commandData. The zoom removal then crashes trying to access
   the already-removed ptzPos item. Added a guard flag to skip
   the nested removal when ptzPos was already removed.

2. NullPointerException in execCommand when getPosition() returns null:
   Some cameras return null from getStatus() or getPosition() instead
   of throwing. Added null checks with a fallback to empty PTZVector.

3. NullPointerException on autoRemoteHost.clear() during init:
   GSON deserializes missing/null JSON fields as null, overriding Java
   field defaults. Added null-check before clear(), initializing with
   new TreeSet<>() when null.

4. H.264 WebCodecs decoder failure for late-joining viewers:
   Enabled setInjectVideoExtradata(true) on MpegTsProcessor so SPS/PPS
   NAL units are prepended before keyframes. Without this, WebCodecs
   VideoDecoder cannot initialize when joining mid-stream.

Tested with Reolink RLC-823A (continuous PTZ only, H.264).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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