Loading...
Searching...
No Matches
spotter_cam_pipe.c
Go to the documentation of this file.
81static struct imx500_pipe spotter_capture = IMX500_PIPE_INITIALIZER; /**< Exclusive native-detector process state. */
86static const char *photo_directory = USHER_SPOTTERCAM_PHOTO_DIR; /**< Borrowed configured photo directory. */
95 uint64_t sequence, sensor_timestamp_ns; /**< Sensor timestamp paired with that producer sequence. */
108static struct object_detection_result last_detection; /**< Current shot only; cleared on capture/binding failure. */
140 if (filename_length < 4 || filename_length >= PATH_MAX || strcmp(filename + filename_length - 4, ".jpg") != 0) {
168 const char *const names[] = {"schema", "sequence", "sensor_timestamp_ns", "image_width", "image_height", "count"};
187 if ((fields->hashes_seen & (1U << index)) || strlen(value) != 64 || strspn(value, "0123456789abcdef") != 64) return false;
189 char *destination = index == 0 ? fields->model_hash : index == 1 ? fields->descriptor_hash : fields->image_hash;
190 for (size_t character = 0; character < SHA256_HEX_SIZE; ++character) destination[character] = value[character];
197 for (size_t index = 0; index < (size_t)(suffix - key - 10); ++index) index_text[index] = key[10 + index];
199 if (!ini_uint(index_text, &object_index) || object_index >= OBJECT_MAX_DETECTIONS) return false;
200 const char *const object_names[] = {"name", "confidence", "x", "y", "width", "height", "center_x", "center_y"};
275 *result = (struct object_detection_result) {.valid = true, .has_frame_identity = fields.sensor_timestamp_ns != 0,
277 .sequence = fields.sequence, .sensor_timestamp_ns = fields.sensor_timestamp_ns, .count = (int)fields.count};
284 if ((fields.seen[index] != 63 && fields.seen[index] != 255) || object->box_w <= 0 || object->box_h <= 0
287 if (fields.seen[index] == 255 && (object->center_x < object->box_x || object->center_y < object->box_y
288 || object->center_x > object->box_x + object->box_w || object->center_y > object->box_y + object->box_h
292 for (size_t character = 0; character < sizeof(box->label); ++character) box->label[character] = object->label[character];
334static bool parse_detection_sidecar(const char *filename, struct object_detection_result *result)
345bool spotter_cam_pipe_read_detections(const char *filename, struct spotter_detections *detections)
358 || last_detection.sequence != sequence || last_detection.sensor_timestamp_ns != sensor_timestamp_ns) {
461 if (filename == NULL || filename[0] == '\0' || !last_detection.valid || last_detection.count <= 0) {
466 const char *photo_dir = usher_resolve_path(photo_directory, resolved_dir, sizeof(resolved_dir));
470 if (dir_len < 0 || (size_t)dir_len >= sizeof(hits_dir) || usher_ensure_directory(hits_dir) != 0) {
501 spotter_capture.settings = spotter_photo_only ? NULL : spotter_settings ? spotter_settings : "-";
541 if (!settings || !settings[0] || spotter_capture.pid > 0 || spotter_analysis.pid > 0) return -1;
Allocation-free flat key=value mechanics; callers own schemas and storage.
static bool ini_uint(const char *text, uint64_t *number)
Parse digits-only uint64; overflow and signs are rejected.
Definition bounded_ini.h:52
static bool ini_real(const char *text, double *number)
Parse finite decimal/exponent notation, rejecting range errors and suffixes.
Definition bounded_ini.h:67
static bool ini_read_file(const char *filename, char *buffer, size_t capacity, size_t *length)
Read a nonempty regular file smaller than capacity and append NUL.
Definition bounded_ini.h:98
static bool ini_parse(char *buffer, size_t length, ini_field_handler handler, void *context)
Destructively parse flat fields with blank lines and #/; comment lines.
Definition bounded_ini.h:132
Shared capability and lifecycle contract for USHER camera backends.
static bool enabled(void)
Report explicit opt-in independently of process or model readiness.
Definition dipla_camera_backend.c:75
Bounded C11 EXIF metadata and JPEG streaming interfaces.
int exif_jpeg_dimensions(FILE *input, uint32_t *width, uint32_t *height, unsigned *components)
Inspect the frame header without allocating or decoding image pixels.
Definition exifite.c:1309
void imx500_pipe_stop(struct imx500_pipe *pipe)
Close the channel, allow an exit grace period, then kill/reap if needed.
Definition imx500_pipe.c:132
int imx500_pipe_shoot(struct imx500_pipe *pipe, char *filename, size_t capacity, int number)
Request one saved photograph and qualify its acknowledgement/file.
Definition imx500_pipe.c:251
int imx500_pipe_start(struct imx500_pipe *pipe)
Replace any owned worker and require its exact READY response.
Definition imx500_pipe.c:149
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.
Definition imx500_pipe.c:239
READY/SHOT/OK process ownership without model-analysis semantics.
#define IMX500_PIPE_INITIALIZER
Safe empty lifecycle state: descriptor zero must never mean uninitialized.
Definition imx500_pipe.h:49
Small path and writable-directory helpers shared by USHER backends.
static const char * usher_resolve_path(const char *path, char *buffer, size_t buffer_size)
Expand a leading home-directory shorthand without allocating memory.
Definition path_utils.h:74
static int usher_ensure_directory(const char *path)
Create missing directory components and verify the final directory is writable.
Definition path_utils.h:97
bool sha256_file(const char *filename, char output[SHA256_HEX_SIZE])
Hash an immutable nonempty regular file with bounded streaming scratch.
Definition sha256fst.c:286
Allocation-free, portable SHA-256 checksums for memory and streams.
#define SHA256_HEX_SIZE
Required hexadecimal output capacity, including the trailing NUL.
Definition sha256fst.h:47
static bool read_detection_sidecar(const char *filename, struct object_detection_result *result, struct spotter_detections *detections)
Read a stable bounded sidecar and validate schema, dimensions, and every box.
Definition spotter_cam_pipe.c:235
void spotter_cam_pipe_deinit(void)
Stop the native camera process and clear detector-specific configuration.
Definition spotter_cam_pipe.c:532
bool spotter_cam_pipe_photo_only(void)
Report whether capture was configured without analysis.
Definition spotter_cam_pipe.c:126
void spotter_cam_pipe_last_detection_summary(char *buffer, size_t buffer_size)
Format the most recent shot's detection result for EXIF writing.
Definition spotter_cam_pipe.c:374
void spotter_cam_pipe_save_detection_copy(const char *filename)
Copy filename into a "detections" subdirectory of the photo directory if the last spotter_cam_pipe_sh...
Definition spotter_cam_pipe.c:459
int spotter_cam_pipe_set_settings(const char *settings)
Select the detector assignment before either capture or saved-picture analysis starts.
Definition spotter_cam_pipe.c:539
static bool parse_detection_sidecar(const char *filename, struct object_detection_result *result)
Read only the capture-facing detector summary.
Definition spotter_cam_pipe.c:334
void spotter_cam_pipe_configure(const struct camera_backend_host *host)
Borrow USHER's shutdown flag for both serialized native worker owners.
Definition spotter_cam_pipe.c:110
static bool detection_field(void *context, const char *key, const char *value)
Parse one bounded detector sidecar field.
Definition spotter_cam_pipe.c:165
#define USHER_SPOTTERCAM_MODEL
Native detector RPK path borrowed for the worker's lifetime.
Definition spotter_cam_pipe.c:78
int spotter_cam_pipe_shoot(char *filename, size_t filename_size, int image_number)
Request one JPEG and, when enabled, parse its matching detection sidecar.
Definition spotter_cam_pipe.c:510
bool spotter_cam_pipe_bind_frame(uint64_t sequence, uint64_t sensor_timestamp_ns)
Reject a detection result whose identity differs from the validated saved frame.
Definition spotter_cam_pipe.c:351
bool spotter_cam_pipe_read_detections(const char *filename, struct spotter_detections *detections)
Read the full detector result associated with a JPEG.
Definition spotter_cam_pipe.c:345
int spotter_cam_pipe_analyze(const char *filename, unsigned number)
Analyze a saved simulation/private picture and bind results to its source hash and request.
Definition spotter_cam_pipe.c:546
int spotter_cam_pipe_init(const char *unused)
Start and qualify native persistent capture with the selected analysis policy.
Definition spotter_cam_pipe.c:496
static int metadata_path(const char *filename, char *path, size_t path_size)
Definition spotter_cam_pipe.c:136
void spotter_cam_pipe_set_photo_directory(const char *directory)
Set the borrowed output directory before backend initialization.
Definition spotter_cam_pipe.c:367
static int copy_file(const char *source_path, const char *dest_path)
Stream a review copy without allocating another image-sized buffer.
Definition spotter_cam_pipe.c:395
int spotter_cam_pipe_set_photo_only(bool enabled)
Select or inspect the model-free capture mode before worker startup.
Definition spotter_cam_pipe.c:116
Native USHER adapter for on-sensor detection or photo-only capture.
Definition camera_backend.h:79
const volatile sig_atomic_t * running
Borrowed shutdown flag; backend workers must stop when it clears.
Definition camera_backend.h:81
Definition spotter_cam_pipe.c:148
char descriptor_hash[SHA256_HEX_SIZE]
Definition spotter_cam_pipe.c:155
struct object_detection_result objects[OBJECT_MAX_DETECTIONS]
Definition spotter_cam_pipe.c:149
One caller-serialized native worker and its borrowed configuration.
Definition imx500_pipe.h:35
Definition spotter_cam_pipe.c:89
uint64_t sensor_timestamp_ns
Definition spotter_cam_pipe.c:95
Definition spotter_cam_pipe.h:40
Definition spotter_cam_pipe.h:48