Neutral native camera-worker supervision, independent of model results. More...
#include "imx500_pipe.h"#include "camera_capture.h"#include "path_utils.h"#include <errno.h>#include <fcntl.h>#include <limits.h>#include <poll.h>#include <signal.h>#include <spawn.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/wait.h>#include <time.h>#include <unistd.h>
Go to the source code of this file.
Macros | |
| #define | IMX500_STARTUP_TIMEOUT_MS 180000 |
| First-use RPK upload/warm-up needs more time than a warm still capture. | |
| #define | IMX500_SHOT_TIMEOUT_MS 15000 |
| Bound response waiting so an abandoned shot cannot block the owner indefinitely. | |
| #define | IMX500_RESPONSE_BYTES 16 |
| Fixed space for short protocol replies, never arbitrary child diagnostics. | |
| #define | IMX500_EXIT_GRACE_MS 2000 |
| #define | IMX500_KILL_GRACE_MS 1000 |
Functions | |
| static int64_t | milliseconds (void) |
| Read elapsed-time evidence unaffected by wall-clock corrections. | |
| static int | expect_response (struct imx500_pipe *pipe, const char *expected, int timeout) |
| Consume one exact line before an unchanged monotonic response deadline. | |
| static bool | reap_owned_camera (struct imx500_pipe *pipe, int timeout_ms) |
| Poll for exit of the camera child. | |
| void | imx500_pipe_stop (struct imx500_pipe *pipe) |
| Close the channel, allow an exit grace period, then kill/reap if needed. | |
| int | imx500_pipe_start (struct imx500_pipe *pipe) |
| Replace any owned worker and require its exact READY response. | |
| static bool | send_request (struct imx500_pipe *pipe, const char *request, size_t length) |
| Send one request before a single absolute deadline, including partial writes. | |
| int | imx500_pipe_analyze (struct imx500_pipe *pipe, const char *filename, unsigned number) |
| Submit one saved-picture request to a warm analysis worker without recapturing pixels. | |
| int | imx500_pipe_shoot (struct imx500_pipe *pipe, char *filename, size_t capacity, int number) |
| Request one saved photograph and qualify its acknowledgement/file. | |
Variables | |
| char ** | environ |
| Inherit the process environment; executable and model remain explicit argv. | |
Detailed Description
Neutral native camera-worker supervision, independent of model results.
Keep process transport separate from inference interpretation. The same READY/SHOT/OK exchange serves detector and LOOM owners without inventing object results for a feature-only capture.
Definition in file imx500_pipe.c.
Macro Definition Documentation
◆ IMX500_EXIT_GRACE_MS
| #define IMX500_EXIT_GRACE_MS 2000 |
Definition at line 48 of file imx500_pipe.c.
◆ IMX500_KILL_GRACE_MS
| #define IMX500_KILL_GRACE_MS 1000 |
Definition at line 49 of file imx500_pipe.c.
◆ IMX500_RESPONSE_BYTES
| #define IMX500_RESPONSE_BYTES 16 |
Fixed space for short protocol replies, never arbitrary child diagnostics.
Definition at line 47 of file imx500_pipe.c.
◆ IMX500_SHOT_TIMEOUT_MS
| #define IMX500_SHOT_TIMEOUT_MS 15000 |
Bound response waiting so an abandoned shot cannot block the owner indefinitely.
Definition at line 45 of file imx500_pipe.c.
◆ IMX500_STARTUP_TIMEOUT_MS
| #define IMX500_STARTUP_TIMEOUT_MS 180000 |
First-use RPK upload/warm-up needs more time than a warm still capture.
Definition at line 43 of file imx500_pipe.c.
Function Documentation
◆ expect_response()
|
static |
Consume one exact line before an unchanged monotonic response deadline.
- Parameters
-
[in,out] pipe State containing the nonblocking status descriptor. [in] expected Complete expected line, including its newline. [in] timeout Response allowance in milliseconds.
- Returns
- Zero for an exact line, otherwise -1.
Bytewise reads are cheap for these tiny replies and do not steal bytes belonging to a later exchange. EINTR retries retain the original deadline.
Definition at line 72 of file imx500_pipe.c.
◆ imx500_pipe_analyze()
| int imx500_pipe_analyze | ( | struct imx500_pipe * | pipe, |
| const char * | filename, | ||
| unsigned | number ) |
Submit one saved-picture request to a warm analysis worker without recapturing pixels.
- Parameters
-
pipe Running owner started with analyze=true and explicit settings. filename Immutable picture path, or a producer-owned private picture for private-image processing. number Positive increasing request number within this worker lifetime.
- Returns
- Zero for an exact successful reply, otherwise minus one after closing/reaping the failed worker.
A failed exchange is not retried, preventing a late reply from qualifying another picture.
Definition at line 239 of file imx500_pipe.c.
◆ imx500_pipe_shoot()
| int imx500_pipe_shoot | ( | struct imx500_pipe * | pipe, |
| char * | filename, | ||
| size_t | capacity, | ||
| int | number ) |
Request one saved photograph and qualify its acknowledgement/file.
- Parameters
-
[in,out] pipe Running worker owned by the calling backend. [out] filename Private .pending path; consume it only after successful return. [in] capacity Writable bytes in filename, including its terminator.[in] number Nonnegative photo number used in the backend's filename.
- Returns
- Zero for an exact OK response and a nonempty regular file, otherwise -1.
Absolute paths avoid dependence on the child's working directory. Newlines are rejected because the protocol is line-framed. A failed exchange closes/reaps the worker rather than pairing a late response with another shot. A later request starts a replacement worker only after the previous owner exits. The caller finishes metadata and calls usher_complete_photo before final-name publication.
- Warning
- This does not decode JPEG pixels, prove exposure timing, or establish valid inference. A failed shot is never automatically replayed.
Definition at line 251 of file imx500_pipe.c.
◆ imx500_pipe_start()
| int imx500_pipe_start | ( | struct imx500_pipe * | pipe | ) |
Replace any owned worker and require its exact READY response.
- Parameters
-
[in,out] pipe Initialized state with live command/model/directory strings.
- Returns
- Zero after readiness, otherwise -1 with newly acquired resources closed.
The child owns the camera. Readiness includes its model-specific warm-up, not just successful process creation. Existing owned work is stopped before spawning, preventing a second child from competing for the same sensor.
- Note
- No analysis sidecar or object/LOOM result is read by this interface.
Definition at line 149 of file imx500_pipe.c.
◆ imx500_pipe_stop()
| void imx500_pipe_stop | ( | struct imx500_pipe * | pipe | ) |
Close the channel, allow an exit grace period, then kill/reap if needed.
- Parameters
-
[in,out] pipe Initialized state; NULL is ignored.
Closing the command channel lets a healthy worker finish normally. Reaping keeps stale process state from being mistaken for an available camera. Monotonic grace periods bound polling; an unconfirmed exit retains PID ownership and prevents a replacement worker. Scheduling and kernel stalls are not preempted.
- Note
- Repeated stops are harmless once the PID and descriptor are cleared.
Definition at line 132 of file imx500_pipe.c.
◆ milliseconds()
|
static |
Read elapsed-time evidence unaffected by wall-clock corrections.
- Returns
- Monotonic milliseconds, or -1 if a deadline cannot be established.
Definition at line 56 of file imx500_pipe.c.
◆ reap_owned_camera()
|
static |
Poll for exit of the camera child.
- Parameters
-
[in,out] pipe Subprocess owner; clears the PID once ownership ends. timeout_ms Polling budget in milliseconds.
- Returns
- True when no child remains owned.
Leave the PID intact on timeout or hard wait errors so callers cannot launch another sensor owner while the previous child may be alive.
Definition at line 118 of file imx500_pipe.c.
◆ send_request()
|
static |
Send one request before a single absolute deadline, including partial writes.
Definition at line 215 of file imx500_pipe.c.
Variable Documentation
◆ environ
|
extern |
Inherit the process environment; executable and model remain explicit argv.