Skip to content

Answer recorder ONVIF calls and publish a real sub stream - #62

Open
carbofos wants to merge 2 commits into
OpenIPC:masterfrom
carbofos:cursor/onvif-nvr-33d4
Open

carbofos wants to merge 2 commits into
OpenIPC:masterfrom
carbofos:cursor/onvif-nvr-33d4

Conversation

@carbofos

@carbofos carbofos commented Oct 19, 2026 •

Copy link
Copy Markdown

Recorders send ONVIF actions with a namespace prefix and a username token even when authentication is turned off. The camera treated the prefix as part of the action name and did not answer, so the recorder reported a bad username or password and never opened RTSP.

This accepts those calls, answers the device and media requests a recorder uses before it plays, and keeps the RTSP session when CSeq starts at zero. The main picture is stream=0, which is also used when the parameter is absent. stream=1 is a separate H.264 640×360 encoder with its own parameter sets. When that encoder does not match an open scaler channel, it opens one instead of stretching the main picture.

On FH8852 the H.264 constant-bitrate block does not place the frame rate where the driver reads it, and the bitrate target is ignored, so the picture stays at the worst quantizer. The requested bitrate is applied as a fixed quantizer: 38 at 1024 kbps, 36 at 2048, 34 at 4096, 32 at 8192, and never below 30. H.265 still uses the driver's constant-bitrate control, with the frame rate in the field the vendor layout uses. MJPEG was using the quality factor as a quantizer and emitting one frame every N seconds. Quality 1 is now quantizer 98 and quality 99 is quantizer 0, at the configured frame rate.

GC4653 is started from the 1920×1080 tables in the sensor library, format 0x203 at 25 fps and 0x204 at 30 fps. That is the resolution of the shipped tuning file. The 4 megapixel tables request an ISP buffer of about 21 MB once the full picture is enabled, and that allocation does not fit in the 35 MB zone on this board, so a request for 2560×1440 stays at 1080p.

The ISP helper was previously called with no sensor table, and before the ISP was initialized, so it never attached to GC4653. It is now called with the sensor operations after API_ISP_Init. Automatic white balance on this sensor still settles near 2.4× gain on red and blue, which is a magenta cast. For gc4653_mipi automatic white balance is disabled and the gains are held at 256.

The encoder can return an H.264 unit whose length runs past the mapping it handed to userspace. Copying that length faults inside memcpy, the process exits without stopping the watchdog, and the camera resets. A unit is copied only when its bytes, and the extra bytes memcpy reads beyond the length, lie inside a single mapping. Anything else is left out of the stream.

Recorders send a namespace prefix and a username token even when
authentication is disabled. Strip the prefix, ignore the token unless
authentication is on, and answer the device and media calls used before
the stream opens.

Keep the RTSP session when CSeq starts at zero or the client sends only
line feeds. The main picture is stream=0, which is also the default.
stream=1 is a separate H.264 640x360 encoder with its own parameter sets.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Support recorder ONVIF requests and a dedicated RTSP substream

🐞 Bug fix ✨ Enhancement 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Answer prefixed ONVIF actions and recorder discovery requests without rejecting tokens when
 authentication is disabled.
• Publish separate main and 640×360 H.264 substreams with matching ONVIF profiles and RTSP parameter
 sets.
• Preserve RTSP sessions for zero-based CSeq, LF-only requests, and parameter keepalives.
Diagram

sequenceDiagram
    actor Recorder
    participant HTTP as HTTP server
    participant ONVIF as ONVIF service
    participant Templates as SOAP templates
    participant Media as Media encoders
    participant RTSP as RTSP server
    participant RTP as RTP sender
    Recorder->>HTTP: Prefixed SOAP request
    HTTP->>ONVIF: Dispatch action
    ONVIF->>Templates: Build capabilities and profiles
    Templates-->>Recorder: Stream URI and profiles
    Media->>RTP: Main or sub H.264 frames
    Recorder->>RTSP: DESCRIBE SETUP PLAY
    RTSP->>RTP: Select stream slot
    RTP-->>Recorder: Selected RTP stream
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use a structured SOAP parser
  • ➕ Handles namespace prefixes and request fields without substring matching.
  • ➕ Makes token validation and future ONVIF actions easier to maintain.
  • ➖ Adds code or a dependency to an embedded application.
  • ➖ Requires a broader rewrite than this recorder-compatibility change.

Recommendation: Extending the existing embedded-template approach is reasonable for targeted recorder compatibility and keeps the deployment footprint small. A structured parser becomes preferable if ONVIF request handling grows further, particularly for write operations and token validation.

Files changed (29) +1241 / -194

Enhancement (24) +1109 / -79
capabilities.xmlAdvertise actual security and RTSP-over-TCP capabilities +3/-3

Advertise actual security and RTSP-over-TCP capabilities

• Makes UsernameToken support depend on authentication configuration, stops advertising HTTP Digest, and advertises RTP over RTSP/TCP.

res/onvif/capabilities.xml

devicecaps.xmlAdd device service capabilities response +12/-0

Add device service capabilities response

• Defines network, security, and system capabilities, including a configurable UsernameToken value.

res/onvif/devicecaps.xml

dns.xmlAdd DNS information response +10/-0

Add DNS information response

• Provides a GetDNS SOAP response reporting DHCP-derived DNS information.

res/onvif/dns.xml

encoder.xmlAdd reusable video encoder configuration fragment +26/-0

Add reusable video encoder configuration fragment

• Defines encoder details, rate control, codec-specific content, multicast settings, and session timeout for generated configuration responses.

res/onvif/encoder.xml

encoderoptions.xmlAdd H.264 encoder options response +36/-0

Add H.264 encoder options response

• Advertises main and substream resolutions alongside quality, GOP, frame-rate, and H.264 profile options.

res/onvif/encoderoptions.xml

encoders.xmlAdd encoder configurations envelope +8/-0

Add encoder configurations envelope

• Wraps generated encoder configuration fragments in a GetVideoEncoderConfigurations SOAP response.

res/onvif/encoders.xml

gateway.xmlAdd default gateway response +10/-0

Add default gateway response

• Defines a GetNetworkDefaultGateway response populated with the detected IPv4 gateway.

res/onvif/gateway.xml

hostname.xmlAdd hostname response +11/-0

Add hostname response

• Defines a GetHostname response populated with the camera hostname.

res/onvif/hostname.xml

mediacaps.xmlAdd media service capabilities response +11/-0

Add media service capabilities response

• Advertises two profiles and RTSP-over-TCP streaming in the media service capabilities.

res/onvif/mediacaps.xml

mediaprofile.xmlExpand media profile encoder details +11/-0

Expand media profile encoder details

• Adds codec-specific configuration, multicast settings, and session timeout to generated media profiles.

res/onvif/mediaprofile.xml

network.xmlAdd network interface response +24/-0

Add network interface response

• Reports interface name, MAC address, IPv4 address, and prefix length to ONVIF clients.

res/onvif/network.xml

profile.xmlAdd single-profile response envelope +8/-0

Add single-profile response envelope

• Wraps a selected profile in a GetProfile SOAP response.

res/onvif/profile.xml

protocols.xmlAdd network protocols response +17/-0

Add network protocols response

• Reports configured HTTP and RTSP ports and whether RTSP is enabled.

res/onvif/protocols.xml

scopes.xmlAdd discovery scopes response +23/-0

Add discovery scopes response

• Advertises streaming, video-encoder, device-name, and hardware scopes.

res/onvif/scopes.xml

services.xmlAdd ONVIF service directory response +23/-0

Add ONVIF service directory response

• Returns device and media service namespaces and network addresses for recorder discovery.

res/onvif/services.xml

settime.xmlAdd clock-setting acknowledgement +6/-0

Add clock-setting acknowledgement

• Defines the SOAP response for SetSystemDateAndTime.

res/onvif/settime.xml

sourceconfigs.xmlAdd video source configuration response +13/-0

Add video source configuration response

• Reports the video source token and configured source bounds.

res/onvif/sourceconfigs.xml

media.cCreate and route a dedicated H.264 sub-encoder +91/-8

Create and route a dedicated H.264 sub-encoder

• Starts a 640×360 H.264 sub-encoder alongside the main encoder and sends each channel to its corresponding RTSP slot. Keeps MP4 and UDP output on the main channel, recreates the substream with MP4, and requests IDR frames from every active video channel.

src/media.c

media.hDeclare substream settings and channel identities +9/-0

Declare substream settings and channel identities

• Defines substream resolution, frame rate, bitrate, and GOP constants and exposes main/sub channel tracking and sub-encoder startup.

src/media.h

onvif.cNormalize SOAP actions and answer recorder ONVIF calls +642/-41

Normalize SOAP actions and answer recorder ONVIF calls

• Strips action namespace prefixes and adds device, media, and ancillary service responses used during recorder discovery and setup. Generates stream-specific profiles and RTSP URIs, reports network and encoder details, and handles clock-setting and synchronization requests.

src/onvif.c

onvif.hExpose expanded ONVIF response handlers +18/-2

Expose expanded ONVIF response handlers

• Declares the new response and dispatch functions and passes request SOAP into profile and stream URI handlers.

src/onvif.h

rtp.cSeparate RTP delivery and codec parameter sets by stream +27/-22

Separate RTP delivery and codec parameter sets by stream

• Stores VPS, SPS, PPS, and codec state per stream slot. Delivers video frames only to connections selecting that slot while retaining audio-track delivery.

src/rtsp/rtp.c

rtsp_server.hPass stream slot to RTP sender +1/-1

Pass stream slot to RTP sender

• Extends the H.26x RTP send interface with the main or substream slot.

src/rtsp/rtsp_server.h

server.cRoute expanded ONVIF actions and restart both encoders +69/-2

Route expanded ONVIF actions and restart both encoders

• Dispatches new ONVIF device and media actions, passes SOAP payloads to stream-aware handlers, and falls back to ancillary-service dispatch. Recreates the sub-encoder when MP4 video is reconfigured.

src/server.c

Bug fix (4) +131 / -114
systemtime.xmlCorrect system time schema and mode +18/-18

Correct system time schema and mode

• Moves time fields into the ONVIF schema namespace and reports manual rather than NTP time.

res/onvif/systemtime.xml

videosources.xmlSimplify video source response +8/-38

Simplify video source response

• Reports the source token, frame rate, and resolution directly in the media response, removing the former nested source and imaging fields.

res/onvif/videosources.xml

rtsp.cSupport recorder RTSP sessions and stream selection +97/-51

Support recorder RTSP sessions and stream selection

• Selects main or substream from the RTSP URI and uses that stream’s parameter sets in DESCRIBE. Accepts CSeq zero, responds to parameter keepalives, initializes nonzero session identifiers, and handles interleaved TCP playback.

src/rtsp/rtsp.c

rtsp.hTrack RTSP stream slots and tolerate LF-only headers +8/-7

Track RTSP stream slots and tolerate LF-only headers

• Adds a parameter method and per-connection stream selection, changes codec parameter storage to two slots, and recognizes blank request lines regardless of line ending.

src/rtsp/rtsp.h

Documentation (1) +1 / -1
config.mdClarify disabled ONVIF authentication +1/-1

Clarify disabled ONVIF authentication

• Documents that a request carrying a username token is still answered when ONVIF authentication is disabled.

doc/config.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (8) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Unauthenticated clients can change the clock 🐞 Bug ⛨ Security
Description
SetSystemDateAndTime now calls settimeofday() under the same authentication condition as
read-only ONVIF requests. When ONVIF is enabled with its default enable_auth: false, any client
that can reach the service can submit a timestamp and change the camera clock.
Code

src/onvif.c[R576-578]

+        time_t stamp = onvif_timegm(year, month, day, hour, min, sec);
+        struct timeval tv = { .tv_sec = stamp, .tv_usec = 0 };
+        if (stamp == (time_t)-1 || settimeofday(&tv, NULL) != 0)
Evidence
Authentication is conditional on onvif_enable_auth, which defaults to false; the new action is
dispatched to a handler that invokes settimeofday().

src/app_config.c[230-235]
src/server.c[621-638]
src/server.c[653-656]
src/onvif.c[562-586]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new clock-setting endpoint permits unauthenticated clock changes under the default ONVIF authentication setting.
## Fix Focus Areas
- src/server.c[628-638]
- src/server.c[653-656]
- src/onvif.c[575-586]
## Recommended Fix
Require authorization specifically for clock-changing requests, or decline the mutation when authentication is disabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Network changes falsely report success 🐞 Bug ≡ Correctness
Description
onvif_dispatch_extra() answers SetNetworkInterfaces with a fixed successful response without
reading or applying the requested configuration. A client that submits a new address receives
RebootNeeded=false, while the camera retains its previous interface settings.
Code

src/onvif.c[R970-971]

+        if (EQUALS(action, "GetRelayOutputs")) return onvif_static(response, respLen, onvif_relay);
+        if (EQUALS(action, "SetNetworkInterfaces")) return onvif_static(response, respLen, onvif_setnetif);
Evidence
The dispatch passes only a static success document to onvif_static(); it does not pass the request
body or invoke a network setter.

src/onvif.c[779-783]
src/onvif.c[966-973]
src/onvif.c[767-771]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`SetNetworkInterfaces` reports success without changing any network setting.
## Fix Focus Areas
- src/onvif.c[779-783]
- src/onvif.c[969-973]
## Recommended Fix
Implement and verify the requested interface update, or return an unsupported-operation SOAP fault rather than a success response.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Imaging changes falsely report success 🐞 Bug ≡ Correctness
Description
SetImagingSettings returns a static success document without parsing the request or updating
camera controls. A subsequent GetImagingSettings still returns the hard-coded values of 50, so a
client cannot tell from the setter response that its changes were discarded.
Code

src/onvif.c[R995-997]

+        if (EQUALS(action, "GetImagingSettings")) return onvif_static(response, respLen, onvif_image);
+        if (EQUALS(action, "GetOptions")) return onvif_static(response, respLen, onvif_imageopt);
+        if (EQUALS(action, "SetImagingSettings")) return onvif_static(response, respLen, onvif_imageset);
Evidence
The getter returns fixed settings, and the setter's dispatch returns a fixed document without using
soap or calling imaging controls.

src/onvif.c[837-858]
src/onvif.c[994-998]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`SetImagingSettings` acknowledges updates that it never applies.
## Fix Focus Areas
- src/onvif.c[837-858]
- src/onvif.c[994-998]
## Recommended Fix
Apply supported settings and report failures, or return an unsupported-operation SOAP fault instead of success.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Recorders receive stale substream settings 🐞 Bug ≡ Correctness
Description
media_mp4_disable() clears the new stream channel IDs but does not clear the RTSP parameter-set
caches for either slot. After the settings endpoint recreates an encoder with different parameters,
__retrieve_sprop() retains its old SPS and PPS, so a later DESCRIBE can advertise parameter sets
from the previous stream.
Code

src/media.c[R714-715]

+    media_main_ch = -1;
+    media_sub_ch = -1;
Evidence
Runtime configuration replaces both encoders; extraction populates parameter sets only when their
slot's cache is empty, and the caches are otherwise freed only at RTSP shutdown.

src/server.c[1229-1233]
src/media.c[711-731]
src/rtsp/rtp.c[364-396]
src/rtsp/rtsp.c[183-188]
src/rtsp/rtsp.c[913-918]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
RTSP parameter sets survive main and sub encoder replacement, leaving later SDP descriptions stale.
## Fix Focus Areas
- src/media.c[711-731]
- src/rtsp/rtp.c[364-428]
- src/rtsp/rtsp.c[913-918]
## Recommended Fix
Synchronize encoder replacement with RTSP access and invalidate the affected slot's cached parameter sets before advertising frames from the replacement encoder.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View review recommended (3)
5. Clock-setting failures appear successful 🐞 Bug ≡ Correctness
Description
onvif_respond_settime() only logs a failed settimeofday() call and then unconditionally
constructs SetSystemDateAndTimeResponse. If the process lacks permission to set time, or the
supplied date is invalid, the recorder receives success even though the camera clock was not
updated.
Code

src/onvif.c[R578-580]

+        if (stamp == (time_t)-1 || settimeofday(&tv, NULL) != 0)
+            HAL_WARNING("onvif", "Could not set the clock to %04d-%02d-%02d %02d:%02d:%02d\n",
+                year, month, day, hour, min, sec);
Evidence
The failure branch logs a warning but falls through to the fixed success template, which the server
sends to the caller.

src/onvif.c[547-558]
src/onvif.c[575-586]
res/onvif/settime.xml[1-6]
src/server.c[653-656]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The clock-setting handler acknowledges failed or invalid updates as successful.
## Fix Focus Areas
- src/onvif.c[562-586]
- src/server.c[653-656]
## Recommended Fix
Validate the timestamp fully and send an appropriate SOAP fault when validation or `settimeofday()` fails; emit success only after the update succeeds.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. A single audio query gets the wrong reply 🐞 Bug ≡ Correctness
Description
onvif_dispatch_extra() routes both audio-encoder configuration actions to the plural
GetAudioEncoderConfigurationsResponse document. A client requesting the singular
GetAudioEncoderConfiguration action therefore receives a response for a different operation
instead of a matching result or fault.
Code

src/onvif.c[R984-986]

+        if (EQUALS(action, "GetAudioEncoderConfigurations") ||
+            EQUALS(action, "GetAudioEncoderConfiguration"))
+            return onvif_static(response, respLen, onvif_audioenc);
Evidence
The shared dispatch target contains only a plural response element, although one of the accepted
actions is singular.

src/onvif.c[814-817]
src/onvif.c[984-986]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The singular audio-encoder query is answered using the plural operation's response element.
## Fix Focus Areas
- src/onvif.c[814-817]
- src/onvif.c[984-986]
## Recommended Fix
Return an operation-matching singular response or a SOAP fault for the singular query; keep the plural response for the plural query.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Crafted RTSP request writes past track table 🐞 Bug ⛨ Security
Description
The request-line parsers store client-supplied trackID= and track= values in con->track_id
without checking them against the two-element trans array. Before authentication, a client can
send SETUP rtsp://cam/trackID=2, causing both __method_setup and Transport-header parsing to
index past that array.
Code

src/rtsp/rtsp.c[R456-457]

+                if (strstr(buf, "trackID="))
+                    STR_KEY_NUM(buf, "trackID=", con->track_id);
Evidence
The trackID= parser writes directly to con->track_id without a range check, and the existing
track= parser has the same gap. SETUP uses that value to index p->trans at lines 287–308, while
Transport-header parsing indexes con->trans at lines 484–497; both arrays have two entries, so a
client-supplied value of 2 or greater is out of bounds before authentication.

src/rtsp/rtsp.c[437-461]
src/rtsp/rtsp.c[285-310]
src/rtsp/rtsp.c[480-500]
src/rtsp/rtsp.c[451-457]
src/rtsp/rtsp.c[282-309]
src/rtsp/rtsp.c[483-501]
src/rtsp/rtsp.h[102-109]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
An RTSP client can set `con->track_id` through `trackID=` or `track=`, and an unchecked value is used to index the two-element transport array during SETUP and Transport-header parsing.
## Fix Focus Areas
- src/rtsp/rtsp.c[282-309]
- src/rtsp/rtsp.c[437-458]
## Recommended Fix
Validate `con->track_id` against the size of `trans` immediately after both request-line `STR_KEY_NUM` calls, before any transport access. Reject invalid SETUP requests with 400 Bad Request, or reset an out-of-range value to 0.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

8. MJPEG-only camera returns an empty profile 🐞 Bug ≡ Correctness
Description
onvif_respond_profile sets which = 1 unless the SOAP body contains stream=1, but the MJPEG
branch of onvif_fill_profiles only adds a profile when which != 1. The fallback
onvif_fill_profiles(profile, 1) repeats the same empty case, so with mp4 disabled and mjpeg
enabled, any GetProfile request without stream=1 gets a GetProfileResponse with no profile in
it.
Code

src/onvif.c[R688-692]

+    int which = (soap && strstr(soap, "stream=1")) ? 2 : 1;
+    if (!response || !respLen) return;
+    onvif_fill_profiles(profile, which);
+    if (!profile[0])
+        onvif_fill_profiles(profile, 1);
Evidence
With mp4 disabled, onvif_fill_profiles returns an empty string for which=1 (line 373 needs `which
!= 1). The fallback at line 692 passes which=1 again instead of 0, so profile` stays empty.

src/onvif.c[353-379]
src/onvif.c[684-701]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The GetProfile fallback calls `onvif_fill_profiles(profile, 1)`, the same filter that just returned nothing, so MJPEG-only configs return an empty profile.
## Fix Focus Areas
- src/onvif.c[688-692]
## Recommended Fix
Change the fallback to `onvif_fill_profiles(profile, 0)`, which returns all profiles. The Profiles→Profile rename then applies to the first profile only.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can import rules and skills only from the repositories your team follows

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/onvif.c
Comment on lines +576 to +578
time_t stamp = onvif_timegm(year, month, day, hour, min, sec);
struct timeval tv = { .tv_sec = stamp, .tv_usec = 0 };
if (stamp == (time_t)-1 || settimeofday(&tv, NULL) != 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Unauthenticated clients can change the clock 🐞 Bug ⛨ Security

SetSystemDateAndTime now calls settimeofday() under the same authentication condition as
read-only ONVIF requests. When ONVIF is enabled with its default enable_auth: false, any client
that can reach the service can submit a timestamp and change the camera clock.
Agent Prompt
## Issue description
The new clock-setting endpoint permits unauthenticated clock changes under the default ONVIF authentication setting.
## Fix Focus Areas
- src/server.c[628-638]
- src/server.c[653-656]
- src/onvif.c[575-586]
## Recommended Fix
Require authorization specifically for clock-changing requests, or decline the mutation when authentication is disabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/onvif.c
Comment on lines +970 to +971
if (EQUALS(action, "GetRelayOutputs")) return onvif_static(response, respLen, onvif_relay);
if (EQUALS(action, "SetNetworkInterfaces")) return onvif_static(response, respLen, onvif_setnetif);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Network changes falsely report success 🐞 Bug ≡ Correctness

onvif_dispatch_extra() answers SetNetworkInterfaces with a fixed successful response without
reading or applying the requested configuration. A client that submits a new address receives
RebootNeeded=false, while the camera retains its previous interface settings.
Agent Prompt
## Issue description
`SetNetworkInterfaces` reports success without changing any network setting.
## Fix Focus Areas
- src/onvif.c[779-783]
- src/onvif.c[969-973]
## Recommended Fix
Implement and verify the requested interface update, or return an unsupported-operation SOAP fault rather than a success response.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/onvif.c
Comment on lines +995 to +997
if (EQUALS(action, "GetImagingSettings")) return onvif_static(response, respLen, onvif_image);
if (EQUALS(action, "GetOptions")) return onvif_static(response, respLen, onvif_imageopt);
if (EQUALS(action, "SetImagingSettings")) return onvif_static(response, respLen, onvif_imageset);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

3. Imaging changes falsely report success 🐞 Bug ≡ Correctness

SetImagingSettings returns a static success document without parsing the request or updating
camera controls. A subsequent GetImagingSettings still returns the hard-coded values of 50, so a
client cannot tell from the setter response that its changes were discarded.
Agent Prompt
## Issue description
`SetImagingSettings` acknowledges updates that it never applies.
## Fix Focus Areas
- src/onvif.c[837-858]
- src/onvif.c[994-998]
## Recommended Fix
Apply supported settings and report failures, or return an unsupported-operation SOAP fault instead of success.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/media.c
Comment on lines +714 to +715
media_main_ch = -1;
media_sub_ch = -1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Recorders receive stale substream settings 🐞 Bug ≡ Correctness

media_mp4_disable() clears the new stream channel IDs but does not clear the RTSP parameter-set
caches for either slot. After the settings endpoint recreates an encoder with different parameters,
__retrieve_sprop() retains its old SPS and PPS, so a later DESCRIBE can advertise parameter sets
from the previous stream.
Agent Prompt
## Issue description
RTSP parameter sets survive main and sub encoder replacement, leaving later SDP descriptions stale.
## Fix Focus Areas
- src/media.c[711-731]
- src/rtsp/rtp.c[364-428]
- src/rtsp/rtsp.c[913-918]
## Recommended Fix
Synchronize encoder replacement with RTSP access and invalidate the affected slot's cached parameter sets before advertising frames from the replacement encoder.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/onvif.c
Comment on lines +578 to +580
if (stamp == (time_t)-1 || settimeofday(&tv, NULL) != 0)
HAL_WARNING("onvif", "Could not set the clock to %04d-%02d-%02d %02d:%02d:%02d\n",
year, month, day, hour, min, sec);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

5. Clock-setting failures appear successful 🐞 Bug ≡ Correctness

onvif_respond_settime() only logs a failed settimeofday() call and then unconditionally
constructs SetSystemDateAndTimeResponse. If the process lacks permission to set time, or the
supplied date is invalid, the recorder receives success even though the camera clock was not
updated.
Agent Prompt
## Issue description
The clock-setting handler acknowledges failed or invalid updates as successful.
## Fix Focus Areas
- src/onvif.c[562-586]
- src/server.c[653-656]
## Recommended Fix
Validate the timestamp fully and send an appropriate SOAP fault when validation or `settimeofday()` fails; emit success only after the update succeeds.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/onvif.c
Comment on lines +984 to +986
if (EQUALS(action, "GetAudioEncoderConfigurations") ||
EQUALS(action, "GetAudioEncoderConfiguration"))
return onvif_static(response, respLen, onvif_audioenc);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

6. A single audio query gets the wrong reply 🐞 Bug ≡ Correctness

onvif_dispatch_extra() routes both audio-encoder configuration actions to the plural
GetAudioEncoderConfigurationsResponse document. A client requesting the singular
GetAudioEncoderConfiguration action therefore receives a response for a different operation
instead of a matching result or fault.
Agent Prompt
## Issue description
The singular audio-encoder query is answered using the plural operation's response element.
## Fix Focus Areas
- src/onvif.c[814-817]
- src/onvif.c[984-986]
## Recommended Fix
Return an operation-matching singular response or a SOAP fault for the singular query; keep the plural response for the plural query.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/rtsp/rtsp.c
Comment on lines +456 to +457
if (strstr(buf, "trackID="))
STR_KEY_NUM(buf, "trackID=", con->track_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

7. Crafted rtsp request writes past track table 🐞 Bug ⛨ Security

The request-line parsers store client-supplied trackID= and track= values in con->track_id
without checking them against the two-element trans array. Before authentication, a client can
send SETUP rtsp://cam/trackID=2, causing both __method_setup and Transport-header parsing to
index past that array.
Agent Prompt
## Issue description
An RTSP client can set `con->track_id` through `trackID=` or `track=`, and an unchecked value is used to index the two-element transport array during SETUP and Transport-header parsing.

## Fix Focus Areas
- src/rtsp/rtsp.c[282-309]
- src/rtsp/rtsp.c[437-458]

## Recommended Fix
Validate `con->track_id` against the size of `trans` immediately after both request-line `STR_KEY_NUM` calls, before any transport access. Reject invalid SETUP requests with 400 Bad Request, or reset an out-of-range value to 0.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/onvif.c
Comment on lines +688 to +692
int which = (soap && strstr(soap, "stream=1")) ? 2 : 1;
if (!response || !respLen) return;
onvif_fill_profiles(profile, which);
if (!profile[0])
onvif_fill_profiles(profile, 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informational

8. Mjpeg-only camera returns an empty profile 🐞 Bug ≡ Correctness

onvif_respond_profile sets which = 1 unless the SOAP body contains stream=1, but the MJPEG
branch of onvif_fill_profiles only adds a profile when which != 1. The fallback
onvif_fill_profiles(profile, 1) repeats the same empty case, so with mp4 disabled and mjpeg
enabled, any GetProfile request without stream=1 gets a GetProfileResponse with no profile in
it.
Agent Prompt
## Issue description
The GetProfile fallback calls `onvif_fill_profiles(profile, 1)`, the same filter that just returned nothing, so MJPEG-only configs return an empty profile.

## Fix Focus Areas
- src/onvif.c[688-692]

## Recommended Fix
Change the fallback to `onvif_fill_profiles(profile, 0)`, which returns all profiles. The Profiles→Profile rename then applies to the first profile only.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

The H.264 constant-bitrate block does not put the frame rate where the
driver reads it, and the bitrate target is ignored, so the picture stays
at the worst quantizer. Apply the requested bitrate as a fixed quantizer:
38 at 1024 kbps, 36 at 2048, 34 at 4096, 32 at 8192, never below 30.
H.265 still uses constant bitrate, with the frame rate in the vendor
layout. MJPEG was treating the quality factor as a quantizer and emitting
one frame every N seconds. Quality 1 is now quantizer 98 and quality 99
is quantizer 0, at the configured frame rate.

GC4653 starts from the 1920x1080 tables, 0x203 at 25 fps and 0x204 at 30.
That matches the shipped IQ file. The 4MP tables ask for an ISP buffer
that does not fit beside the encoder in the 35 MB zone, so a larger
request stays at 1080p. The ISP helper is called with the sensor
operations after the ISP is up. Automatic white balance on this sensor
still locks about 2.4x gain on red and blue, so gc4653_mipi holds unity
gains.

A reported NAL that runs past the userspace mapping faults in memcpy and
the process exits with the watchdog still armed. Copy a NAL only when
its bytes, plus the extra bytes memcpy reads, sit inside one mapping.

A second encoder that does not match an open VPSS channel opens its own
channel instead of scaling the main picture.
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