Loading...
Searching...
No Matches
ear_camera_backend.c
Go to the documentation of this file.
81/** @brief Guard finite values and integer conversion ranges before marking a wire point valid. */
85 && fabs(spot->lat_deg) <= EAR_LATITUDE_LIMIT_DEG && fabs(spot->lon_deg) <= EAR_LONGITUDE_LIMIT_DEG
95/** @brief Notify the serial owner without blocking; mailbox flags remain authoritative if full. */
100 do { result = write(ear_finalize_wake[1], ¬ification, sizeof(notification)); } while (result < 0 && errno == EINTR);
151 if (ear_host.queue_analysis) ear_host.queue_analysis(sound_picture, &picture_shot, USHER_CAMERA_EARCAM);
152 } else fprintf(stderr, "USHER:\tEAR session %u EXIF failed; image retained: %s\n", job->session_id, sound_picture);
153 } else fprintf(stderr, "USHER:\tEAR session %u sound-picture rendering failed\n", job->session_id);
189 session_id, spot.valid, spot.lat_deg, spot.lon_deg, spot.confidence, spot.used_count, spot.sample_count);
190 *result = (struct camera_point_result) {.session_id = session_id, .valid = ear_point_valid(&spot)};
216 if (current_ear_job) { *current_ear_job = (struct ear_finalize_job) {0}; current_ear_job = NULL; }
217 if (ear_finalize_stopping || ear_finalize_order == UINT64_MAX) { pthread_mutex_unlock(&ear_finalize_mutex); return false; }
219 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, ear_finalize_wake) != 0) {
306/** @brief Initialize supervision, not microphone readiness; hard setup failure stays latched. */
324 for (size_t slot = 0; slot < EAR_FINALIZE_JOB_COUNT; ++slot) ear_finalize_jobs[slot] = (struct ear_finalize_job) {0};
337void ear_camera_backend_set_simulated_source(double lat_deg, double lon_deg, double level_db_at_1m)
342void ear_camera_backend_set_band(double low_cut_hz, double high_cut_hz) { ear_cam_pipe_set_band(low_cut_hz, high_cut_hz); }
353 .capabilities = CAMERA_CAP_POINT_SESSION, .soda_option = "--earcam", .record = ear_cam_pipe_record,
static bool capture_running(const volatile sig_atomic_t *running)
Atomically poll a borrowed cancellation flag; NULL means no cancellation.
Definition camera_capture.h:46
bool ear_cam_pipe_set_device(const char *device)
Copy a startup ALSA PCM name into bounded adapter-owned storage.
Definition ear_cam_pipe.c:224
int ear_cam_pipe_snapshot_solve(const struct ear_session_snapshot *snapshot, struct ear_loudest_spot *result)
Solve immutable detached evidence without touching current-session state.
Definition ear_cam_pipe.c:1095
int ear_cam_pipe_init(const char *unused)
Reset session storage and start or configure the acoustic backend.
Definition ear_cam_pipe.c:871
int ear_cam_pipe_snapshot_render(const struct ear_session_snapshot *snapshot, uint32_t session_id, const struct ear_loudest_spot *result, char *filename, size_t filename_size, bool simulated)
Render detached evidence using collision-safe session-tagged JPEG/CSV names.
Definition ear_cam_pipe.c:1221
int32_t ear_cam_pipe_snapshot_number(const struct ear_session_snapshot *snapshot)
Read the last request number from immutable evidence.
Definition ear_cam_pipe.c:1102
void ear_cam_pipe_set_pose_lookup(bool(*lookup)(struct capture_observation *, uint64_t))
Set the startup-only pose callback, later called without waiting on the serial owner.
Definition ear_cam_pipe.c:219
void ear_cam_pipe_log_result(uint32_t session_id, const struct ear_loudest_spot *result)
Best-effort enqueue of a correlated result row on the serial owner.
Definition ear_cam_pipe.c:1247
void ear_cam_pipe_deinit(void)
Stop the child and clear all bounded session state.
Definition ear_cam_pipe.c:909
struct ear_session_snapshot * ear_cam_pipe_detach_session(void)
Transfer active storage to an immutable worker snapshot without copying samples.
Definition ear_cam_pipe.c:1078
bool ear_cam_pipe_begin_session(uint32_t session_id)
Begin/reset active collection without solving or waiting for log I/O.
Definition ear_cam_pipe.c:1054
void ear_cam_pipe_update_pose(void)
Retry bounded pending audio windows when the serial owner receives new poses.
Definition ear_cam_pipe.c:1012
int ear_cam_pipe_record(const union dc_shot_union *shot)
Associate the newest sound window with one flight-controller shot pose.
Definition ear_cam_pipe.c:1018
void ear_cam_pipe_set_band(double low_cut_hz, double high_cut_hz)
Set the detector band forwarded to a subsequently spawned EARcam child.
Definition ear_cam_pipe.c:254
void ear_cam_pipe_snapshot_release(struct ear_session_snapshot *snapshot)
Return detached storage to admission after all snapshot access has ended.
Definition ear_cam_pipe.c:1107
void ear_cam_pipe_set_simulated_source(double lat_deg, double lon_deg, double level_db_at_1m)
Select deterministic virtual acoustic measurements for simulation.
Definition ear_cam_pipe.c:241
Audio/pose adapter and zero-copy snapshot API for the EAR backend.
static void * finalize_ear_sessions(void *unused)
Drain stopped sessions in admission order until shutdown has no work left.
Definition ear_camera_backend.c:110
static bool ear_stop(uint32_t session_id)
Validate the active token before a zero-copy snapshot handoff.
Definition ear_camera_backend.c:259
static int ear_finalize_wake[EAR_COMPLETION_ENDPOINT_COUNT]
Definition ear_camera_backend.c:79
static void wake_ear_result_owner(void)
Notify the serial owner without blocking; mailbox flags remain authoritative if full.
Definition ear_camera_backend.c:96
static pthread_cond_t ear_finalize_available
Definition ear_camera_backend.c:76
static bool ear_poll_result(struct camera_point_result *result)
Consume one completion on the serial owner and convert physical units once.
Definition ear_camera_backend.c:168
void ear_camera_backend_set_band(double low_cut_hz, double high_cut_hz)
Forward startup tone-band selection to the audio adapter.
Definition ear_camera_backend.c:342
bool ear_camera_backend_set_device(const char *device)
Copy an ALSA PCM name before initialization or worker startup.
Definition ear_camera_backend.c:332
void ear_camera_backend_set_simulated_source(double lat_deg, double lon_deg, double level_db_at_1m)
Select deterministic synthetic audio before initialization, bypassing ALSA.
Definition ear_camera_backend.c:337
static void ear_configure(const struct camera_backend_host *host)
Copy startup-only host callbacks; worker-side queue_analysis must be thread-safe.
Definition ear_camera_backend.c:300
static void ear_deinit(void)
Drain before tearing down audio/storage, then reset quiescent finalizer state.
Definition ear_camera_backend.c:317
static int ear_completion_fd(void)
Nonblocking completion descriptor, or -1 before start/after drain.
Definition ear_camera_backend.c:298
static bool ear_point_valid(const struct ear_loudest_spot *spot)
Guard finite values and integer conversion ranges before marking a wire point valid.
Definition ear_camera_backend.c:82
static void ear_drain(void)
Close admission and join all admitted stopped-session evidence work.
Definition ear_camera_backend.c:280
static bool ear_listening(void)
Whether the serial owner should admit EAR samples for the current session.
Definition ear_camera_backend.c:296
static struct ear_finalize_job ear_finalize_jobs[EAR_FINALIZE_JOB_COUNT]
static bool ear_start(uint32_t session_id)
Reserve both finalizer capacity and adapter storage before listening.
Definition ear_camera_backend.c:210
struct camera_backend ear_camera_backend_get(void)
Return the EAR backend descriptor by value; its session hook table has static lifetime.
Definition ear_camera_backend.c:344
#define EAR_COMPLETION_ENDPOINT_COUNT
Definition ear_camera_backend.c:44
static int ear_init(const char *source)
Initialize supervision, not microphone readiness; hard setup failure stays latched.
Definition ear_camera_backend.c:307
EAR-specific startup configuration behind USHER's generic backend interface.
int image_exif_write(const char *filename, const union dc_shot_union *shot)
Add standard USHER flight metadata to a JPEG.
Definition image_exif.c:408
Flight, timing, and thermal-analysis metadata writing for captured JPEGs.
Definition camera_backend.h:79
bool(* pose_lookup)(struct capture_observation *observation, uint64_t maximum_age_us)
Bounded pose lookup supplied by USHER's shared timing owner.
Definition camera_backend.h:83
Function table describing one backend's owned camera operations.
Definition camera_backend.h:94
Definition camera_backend.h:50
Definition camera_backend.h:56
One reservation progressing through snapshot -> point -> evidence completion.
Definition ear_camera_backend.c:66
Estimated ground source, not a surveyed target or guaranteed alarm detection.
Definition earcam_core.h:37
Statically reserved sample buffer with a single active or detached owner.
Definition ear_cam_pipe.c:187
Definition usher_protocol.h:51
struct dc_shot_union::@351207206061007345226276304225222200157171312155 data