Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
loom_camera_backend.c
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file loom_camera_backend.c
20 * @brief Own LOOM's AIcam specialization outside the universal USHER service.
21 * @details The capture owner and saved-photo worker have separate lifecycles:
22 * optional matching starts without acquiring IMX500, while physical capture is
23 * lazy. A failed matcher never disables ordinary photograph capture.
24 */
25#include "loom_camera_backend.h"
26#include "loom_cam.h"
27#include "imx500_pipe.h"
28
29#include <stdio.h>
30#include <string.h>
31
32#ifndef USHER_AI_CAM_PHOTO_DIR
33 /** @brief Capture destination default; backend naming remains LOOM-owned. */
34 #define USHER_AI_CAM_PHOTO_DIR "~/Pictures/sensoraia"
35#endif
36#ifndef USHER_SODA
37 /** @brief Existing post-capture analysis executable, not the LOOM matcher. */
38 #define USHER_SODA "./bin/soda"
39#endif
40
41static const char *reference_directory = USHER_LOOMCAM_REFERENCE_DIR; /**< Borrowed until worker init copies it. */
42static const char *network_model = USHER_LOOMCAM_MODEL; /**< Borrowed RPK configuration for native capture lifetime. */
43static struct imx500_pipe capture_owner = IMX500_PIPE_INITIALIZER; /**< LOOM's own neutral native worker, not detector state. */
44static const char *inference_settings_path;
45
46/** @brief Pass the service cancellation flag to the native capture owner.
47 * @param host Nullable backend host with a running flag valid through capture.
48 * @details Borrow only the flag; the host object itself need not persist. */
49static void loom_capture_configure(const struct camera_backend_host *host)
50{
51 capture_owner.running = host ? host->running : NULL;
52}
53
55{
56 if (!settings || !settings[0] || capture_owner.pid > 0) return -1;
57 if (loom_cam_set_settings(settings)) return -1;
59 return 0;
60}
61
62void loom_camera_backend_configure(const char *references, const char *model)
63{
64 reference_directory = references;
66}
67
68/** @brief Select the native capture protocol only when this owner is acquired.
69 * @param source Reserved common-backend input; native capture uses the configured RPK.
70 * @return Zero after the camera child reports READY, otherwise -1.
71 * @details Stream startup may happen earlier without camera acquisition. Delaying
72 * physical ownership until capture keeps saved-photo processing independent. */
73static int loom_capture_init(const char *source)
74{
75 (void)source;
79 network_model && !strcmp(network_model, USHER_LOOMCAM_MODEL) ? "-" : NULL;
83}
84
85/** @brief Request pixels through the neutral supervisor without detection parsing.
86 * @param filename Caller-owned destination buffer.
87 * @param capacity Writable path bytes including the terminator.
88 * @param number FC photo number used only for the output filename.
89 * @return Zero for a qualified saved image, otherwise -1. */
90static int loom_capture_shoot(char *filename, size_t capacity, int number)
91{
92 return imx500_pipe_shoot(&capture_owner, filename, capacity, number);
93}
94
95/** @brief Stop only LOOM's capture child; the saved-photo stream drains separately. */
96static void loom_capture_deinit(void)
97{
99}
100
101/** @brief Start optional saved-photo processing without acquiring another sensor.
102 * @return Zero for worker startup, otherwise -1; photograph capture remains a separate capability. */
103static int loom_stream_init(void)
104{
106 if (result != 0)
107 fprintf(stderr, "LOOM_cam: worker unavailable; photos continue without visual navigation\n");
108 return result;
109}
110
112{
113 static const struct camera_point_stream_ops stream = {
114 .init = loom_stream_init, .poll_result = loom_cam_poll_result,
115 .drain = loom_cam_deinit, .start = loom_cam_start, .stop = loom_cam_stop,
116 .enabled = loom_cam_enabled, .completion_fd = loom_cam_completion_fd
117 };
118 const struct camera_backend backend = {
119 /* LOOM consumes feature/frame evidence, not object boxes. Keep detection
120 * hooks absent instead of making an empty object result a compatibility token. */
121 .name = "loomcam", .camera_id = USHER_CAMERA_AICAM, .prefix = LOOM_IMAGE_PREFIX,
122 .init = loom_capture_init, .shoot = loom_capture_shoot,
123 .configure = loom_capture_configure,
124 .deinit = loom_capture_deinit, .soda_application = USHER_SODA,
126 .soda_option = "--aicam", .photo_directory = USHER_AI_CAM_PHOTO_DIR,
127 .mock = {.width = 2028, .height = 1520, .filename_marker = ""},
128 .image_saved = loom_cam_image_saved, .point_stream = &stream
129 };
130 return backend;
131}
#define USHER_AI_CAM_PHOTO_DIR
Definition ai_cam_pipe.c:54
@ CAMERA_CAP_FINISH_OWNED
@ CAMERA_CAP_IMAGE
@ CAMERA_CAP_PRIVATE_IMAGE
#define USHER_SODA
static unsigned capacity[COVERAGE_CAMERAS]
void imx500_pipe_stop(struct imx500_pipe *pipe)
Close the channel, allow an exit grace period, then kill/reap if needed.
int imx500_pipe_shoot(struct imx500_pipe *pipe, char *filename, size_t capacity, int number)
Request one saved photograph and qualify its acknowledgement/file.
int imx500_pipe_start(struct imx500_pipe *pipe)
Replace any owned worker and require its exact READY response.
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
bool loom_cam_poll_result(struct camera_point_result *result)
Consume a result on the serial owner; session_id carries the photo number for this stream.
Definition loom_cam.c:685
#define USHER_LOOMCAM_COMMAND
Saved-photo child executable; not another camera-acquisition process.
Definition loom_cam.c:51
bool loom_cam_start(uint32_t session_id)
Select outbound reference collection and discard old-phase mailbox work.
Definition loom_cam.c:621
bool loom_cam_stop(uint32_t session_id)
Select return matching and discard old-phase mailbox work.
Definition loom_cam.c:652
void loom_cam_deinit(void)
Cancel pending work and join the worker before reusing adapter state.
Definition loom_cam.c:695
int loom_cam_set_settings(const char *settings)
Select executable settings before starting the saved-photo worker.
Definition loom_cam.c:560
bool loom_cam_enabled(void)
Report whether this optional stream is running and not stopping.
Definition loom_cam.c:608
void loom_cam_image_saved(const char *filename, const union dc_shot_union *shot)
Copy the newest completed AIcam photo request into bounded worker storage.
Definition loom_cam.c:669
int loom_cam_completion_fd(void)
Borrow the nonblocking completion descriptor; minus one when not initialized.
Definition loom_cam.c:613
int loom_cam_init(const char *references, const char *model)
Start one saved-photo worker; does not acquire another camera.
Definition loom_cam.c:568
Bounded asynchronous saved-photo adapter for LOOM_cam.
#define LOOM_IMAGE_PREFIX
LOOM photographs and outbound references use 'o', not AIcam's 'a'.
Definition loom_cam.h:38
static struct imx500_pipe capture_owner
static void loom_capture_deinit(void)
Stop only LOOM's capture child; the saved-photo stream drains separately.
struct camera_backend loom_camera_backend_get(bool mock)
Return LOOM's descriptor without opening a sensor or starting a thread.
static int loom_capture_shoot(char *filename, size_t capacity, int number)
Request pixels through the neutral supervisor without detection parsing.
static void loom_capture_configure(const struct camera_backend_host *host)
Pass the service cancellation flag to the native capture owner.
static int loom_capture_init(const char *source)
Select the native capture protocol only when this owner is acquired.
void loom_camera_backend_configure(const char *references, const char *model)
Configure the LOOM plugin before selecting or initializing its owner.
static const char * network_model
static const char * reference_directory
static int loom_stream_init(void)
Start optional saved-photo processing without acquiring another sensor.
static const char * inference_settings_path
int loom_camera_backend_set_settings(const char *settings)
Choose one LOOM assignment before acquiring either worker.
LOOM-owned capture specialization and stream lifecycle.
#define USHER_LOOMCAM_MODEL
Expected RPK path; the framework does not fabricate a trained model.
#define USHER_LOOMCAM_REFERENCE_DIR
Default outbound archive; use independent reference storage per sortie.
const volatile sig_atomic_t * running
Borrowed shutdown flag; backend workers must stop when it clears.
Function table describing one backend's owned camera operations.
struct camera_backend::@243120217343377347337244154071360217343172026241 mock
Repeated correlated point updates from saved photos or non-image work.
One caller-serialized native worker and its borrowed configuration.
Definition imx500_pipe.h:35
const char * model
Definition imx500_pipe.h:37
const char * settings
Definition imx500_pipe.h:38
struct usher_control_result result
Definition usher.c:377
#define USHER_CAMERA_AICAM