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
camera_speedtest.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#include "camera_speedtest.h"
19#include "camera_capture.h"
20#include "path_utils.h"
21
22/**
23 * @file camera_speedtest.c
24 * @brief Backend-neutral still-image throughput benchmark and asynchronous progress reporter.
25 * @details The benchmark performs one untimed warm-up followed by ten sequential synchronous
26 * captures. It validates each returned JPEG before accepting it as evidence. Timing uses
27 * @c CLOCK_MONOTONIC around only the backend capture call, excluding setup, UART, EXIF, SODA,
28 * and terminal I/O. Progress is copied into a fixed-size queue and written by a separate
29 * bounded-I/O thread so an unread pipe or slow terminal cannot throttle capture requests.
30 */
31
32#include <errno.h>
33#include <fcntl.h>
34#include <inttypes.h>
35#include <limits.h>
36#include <pthread.h>
37#include <poll.h>
38#include <stdbool.h>
39#include <stdint.h>
40#include <stdio.h>
41#include <string.h>
42#include <sys/stat.h>
43#include <time.h>
44#include <unistd.h>
45
46#define SPEEDTEST_FILENAME_SIZE 512
47#define SPEEDTEST_PROGRESS_CAPACITY ((CAMERA_SPEEDTEST_SAMPLE_COUNT + 1) * 2)
48
53
62
77
78/** @brief Derive the expected JPEG path for a benchmark capture.
79 * @param config Output directory and camera prefix used by the measured backend.
80 * @param image_number Photo number.
81 * @param[out] path Path buffer.
82 * @param path_size Capacity including the terminator.
83 * @return Zero for a complete path, or -1 on formatting failure or truncation.
84 * @details Match the production naming convention so checks address the
85 * capture under test rather than a separate benchmark artifact. */
86static int format_image_path(const struct camera_speedtest_config *config,
87 int image_number, char *path, size_t path_size)
88{
89 char resolved_directory[PATH_MAX];
90 const char *directory = usher_resolve_path(config->photo_directory,
91 resolved_directory,
92 sizeof(resolved_directory));
93 int length = snprintf(path, path_size, "%s/%c%06d.jpg", directory,
94 config->filename_prefix, image_number);
95 return length >= 0 && (size_t)length < path_size ? 0 : -1;
96}
97
98/**
99 * @brief Read a non-negative monotonic timestamp in nanoseconds.
100 * @param time_ns Destination for the timestamp.
101 * @return 0 on success; -1 if the clock is unavailable, invalid, or overflows conversion.
102 * @details Nanoseconds retain sub-millisecond capture differences without requiring floating
103 * point arithmetic in the measurement loop. The conversion rejects impossible values rather
104 * than silently wrapping and publishing a plausible but false rate.
105 */
106static int monotonic_time_ns(uint64_t *time_ns)
107{
108 struct timespec now;
109 if (time_ns == NULL || clock_gettime(CLOCK_MONOTONIC, &now) != 0
110 || now.tv_sec < 0 || (uint64_t)now.tv_sec > UINT64_MAX / 1000000000ULL) {
111 return -1;
112 }
113 *time_ns = (uint64_t)now.tv_sec * 1000000000ULL + (uint64_t)now.tv_nsec;
114 return 0;
115}
116
117int camera_speedtest_create_output_directory(const char *base_directory,
118 char *output, size_t output_size)
119{
120 if (base_directory == NULL || output == NULL || output_size == 0) {
121 errno = EINVAL;
122 return -1;
123 }
124 char resolved_directory[PATH_MAX];
125 const char *base = usher_resolve_path(base_directory, resolved_directory,
126 sizeof(resolved_directory));
127 if (usher_ensure_directory(base) != 0) return -1;
128
129 uint64_t now_ns;
130 if (monotonic_time_ns(&now_ns) != 0) return -1;
131 for (unsigned attempt = 0; attempt < 100; ++attempt) {
132 int length = snprintf(output, output_size, "%s/speedtest-%ld-%" PRIu64 "-%u",
133 base, (long)getpid(), now_ns, attempt);
134 if (length < 0 || (size_t)length >= output_size) {
135 errno = ENAMETOOLONG;
136 return -1;
137 }
138 if (mkdir(output, 0700) == 0) return 0;
139 if (errno != EEXIST) return -1;
140 }
141 errno = EEXIST;
142 return -1;
143}
144
145/**
146 * @brief Confirm that a backend produced exactly the requested usable image.
147 * @param actual_filename Path returned by the backend capture operation.
148 * @param expected_filename Deterministic path reserved before capture began.
149 * @return 0 when the path matches and names a nonempty regular file; -1 otherwise.
150 * @details Path equality prevents a backend fallback or stale output from being counted as a
151 * benchmark sample. Regular-file and size checks catch missing, directory, FIFO, and empty
152 * outputs while leaving image decoding to the normal backend contract.
153 */
154static int validate_capture(const char *actual_filename, const char *expected_filename)
155{
156 if (actual_filename == NULL || strcmp(actual_filename, expected_filename) != 0) {
157 fprintf(stderr, "USHER SPEEDTEST:\tbackend returned output path '%s', expected '%s'\n",
158 actual_filename == NULL ? "(null)" : actual_filename, expected_filename);
159 return -1;
160 }
161 struct stat image_status;
162 if (stat(actual_filename, &image_status) != 0) {
163 fprintf(stderr, "USHER SPEEDTEST:\tunable to validate image %s: %s\n",
164 actual_filename, strerror(errno));
165 return -1;
166 }
167 if (!S_ISREG(image_status.st_mode) || image_status.st_size <= 0) {
168 fprintf(stderr, "USHER SPEEDTEST:\tinvalid or empty image %s\n", actual_filename);
169 return -1;
170 }
171 return 0;
172}
173
174/**
175 * @brief Write one progress record without waiting indefinitely for stdout.
176 * @param reporter Reporter owning the nonblocking output descriptor.
177 * @param record Immutable event to render.
178 * @return 0 if the complete line was written; -1 when output is unavailable or partial.
179 * @details The 100 ms poll bound is a reporting policy, not a capture timeout. On failure the
180 * reporter records the condition and the benchmark fails after draining, rather than blocking
181 * the capture loop behind a terminal or pipe consumer.
182 */
183static int write_progress(struct progress_reporter *reporter,
184 const struct progress_record *record)
185{
186 char line[SPEEDTEST_FILENAME_SIZE + 128];
187 int length;
188 if (record->kind == PROGRESS_STARTED) {
189 length = record->warmup
190 ? snprintf(line, sizeof(line), "USHER SPEEDTEST:\twarm-up capture started: %s\n",
191 record->filename)
192 : snprintf(line, sizeof(line), "USHER SPEEDTEST:\tcapture %u/%u started: %s\n",
193 record->sample, CAMERA_SPEEDTEST_SAMPLE_COUNT, record->filename);
194 } else {
195 length = record->warmup
196 ? snprintf(line, sizeof(line), "USHER SPEEDTEST:\twarm-up capture %s\n",
197 record->succeeded ? "completed" : "failed")
198 : snprintf(line, sizeof(line), "USHER SPEEDTEST:\tcapture %u/%u %s in %.3f ms\n",
200 record->succeeded ? "completed" : "failed",
201 (double)record->duration_ns / 1000000.0);
202 }
203 if (length < 0 || (size_t)length >= sizeof(line)) return -1;
204
205 struct pollfd output = {.fd = reporter->output_fd, .events = POLLOUT};
206 int poll_result;
207 do {
208 poll_result = poll(&output, 1, 100);
209 } while (poll_result < 0 && errno == EINTR);
210 if (poll_result <= 0 || (output.revents & POLLOUT) == 0) return -1;
211 ssize_t written;
212 do {
213 written = write(reporter->output_fd, line, (size_t)length);
214 } while (written < 0 && errno == EINTR);
215 return written == length ? 0 : -1;
216}
217
218/**
219 * @brief Drain queued progress records on the dedicated reporter thread.
220 * @param argument Pointer to the initialized @c progress_reporter.
221 * @return Always @c NULL when the stop request is observed.
222 * @details Records are removed under the mutex, then formatted and written without holding it.
223 * This keeps producer critical sections constant-time and ensures slow output never prevents
224 * the benchmark thread from issuing its next capture.
225 */
226static void *report_progress(void *argument)
227{
228 struct progress_reporter *reporter = argument;
229 for (;;) {
230 pthread_mutex_lock(&reporter->mutex);
231 while (reporter->count == 0 && !reporter->stopping) {
232 pthread_cond_wait(&reporter->available, &reporter->mutex);
233 }
234 if (reporter->count == 0 && reporter->stopping) {
235 pthread_mutex_unlock(&reporter->mutex);
236 return NULL;
237 }
238 struct progress_record record = reporter->records[reporter->read_index];
239 reporter->read_index = (reporter->read_index + 1) % SPEEDTEST_PROGRESS_CAPACITY;
240 --reporter->count;
241 pthread_mutex_unlock(&reporter->mutex);
242
243 if (write_progress(reporter, &record) != 0) {
244 pthread_mutex_lock(&reporter->mutex);
245 reporter->output_failed = true;
246 pthread_mutex_unlock(&reporter->mutex);
247 }
248 }
249}
250
251/**
252 * @brief Initialize and launch the bounded progress reporter.
253 * @param reporter Storage owned by the caller for the reporter lifetime.
254 * @return 0 on success; -1 after cleaning up any partially initialized resources.
255 * @details Regular redirected stdout is temporarily opened with append semantics so the
256 * reporter cannot overwrite buffered summary output. The duplicate nonblocking descriptor
257 * isolates progress backpressure from the benchmark's normal stdout stream.
258 */
259static int reporter_start(struct progress_reporter *reporter)
260{
261 reporter->read_index = 0;
262 reporter->write_index = 0;
263 reporter->count = 0;
264 reporter->stopping = false;
265 reporter->output_failed = false;
266 reporter->regular_output = false;
267 if (fflush(stdout) != 0) {
268 fprintf(stderr, "USHER SPEEDTEST:\tunable to flush progress output: %s\n",
269 strerror(errno));
270 return -1;
271 }
272 struct stat output_status;
273 if (fstat(STDOUT_FILENO, &output_status) != 0) {
274 fprintf(stderr, "USHER SPEEDTEST:\tunable to inspect progress output: %s\n",
275 strerror(errno));
276 return -1;
277 }
278 reporter->regular_output = S_ISREG(output_status.st_mode);
279 reporter->stdout_flags = fcntl(STDOUT_FILENO, F_GETFL);
280 if (reporter->stdout_flags < 0
281 || (reporter->regular_output
282 && fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags | O_APPEND) != 0)) {
283 fprintf(stderr, "USHER SPEEDTEST:\tunable to configure progress output: %s\n",
284 strerror(errno));
285 return -1;
286 }
287 reporter->output_fd = open("/proc/self/fd/1",
288 O_WRONLY | O_NONBLOCK | O_APPEND | O_CLOEXEC);
289 if (reporter->output_fd < 0) {
290 fprintf(stderr, "USHER SPEEDTEST:\tunable to open bounded progress output: %s\n",
291 strerror(errno));
292 if (reporter->regular_output) {
293 fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags);
294 }
295 return -1;
296 }
297 int result = pthread_mutex_init(&reporter->mutex, NULL);
298 if (result != 0) {
299 fprintf(stderr, "USHER SPEEDTEST:\tunable to initialize progress mutex: %s\n",
300 strerror(result));
301 close(reporter->output_fd);
302 if (reporter->regular_output) fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags);
303 return -1;
304 }
305 result = pthread_cond_init(&reporter->available, NULL);
306 if (result != 0) {
307 fprintf(stderr, "USHER SPEEDTEST:\tunable to initialize progress condition: %s\n",
308 strerror(result));
309 pthread_mutex_destroy(&reporter->mutex);
310 close(reporter->output_fd);
311 if (reporter->regular_output) fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags);
312 return -1;
313 }
314 result = pthread_create(&reporter->thread, NULL, report_progress, reporter);
315 if (result != 0) {
316 fprintf(stderr, "USHER SPEEDTEST:\tunable to start progress reporter: %s\n",
317 strerror(result));
318 pthread_cond_destroy(&reporter->available);
319 pthread_mutex_destroy(&reporter->mutex);
320 close(reporter->output_fd);
321 if (reporter->regular_output) fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags);
322 return -1;
323 }
324 return 0;
325}
326
327/**
328 * @brief Queue one capture lifecycle event without performing output I/O.
329 * @param reporter Running reporter.
330 * @param kind Start or completion event.
331 * @param sample One-based measured sample number, or zero for warm-up.
332 * @param warmup True for the excluded warm-up capture.
333 * @param succeeded Completion success state.
334 * @param duration_ns Measured duration for completion records.
335 * @param filename Expected output path copied into the fixed-size event.
336 * @return 0 if queued; -1 when the bounded queue or filename capacity is exhausted.
337 * @details The queue has room for every planned start and completion event. Exhaustion is an
338 * invariant breach, so failing explicitly is safer than silently dropping operator progress.
339 */
340static int reporter_enqueue(struct progress_reporter *reporter, enum progress_kind kind,
341 unsigned sample, bool warmup, bool succeeded,
342 uint64_t duration_ns, const char *filename)
343{
344 pthread_mutex_lock(&reporter->mutex);
345 if (reporter->count >= SPEEDTEST_PROGRESS_CAPACITY) {
346 pthread_mutex_unlock(&reporter->mutex);
347 fprintf(stderr, "USHER SPEEDTEST:\tprogress queue exhausted\n");
348 return -1;
349 }
350 struct progress_record *record = &reporter->records[reporter->write_index];
351 *record = (struct progress_record) {
352 .kind = kind,
353 .sample = sample,
354 .warmup = warmup,
355 .succeeded = succeeded,
356 .duration_ns = duration_ns
357 };
358 int length = snprintf(record->filename, sizeof(record->filename), "%s",
359 filename == NULL ? "" : filename);
360 if (length < 0 || (size_t)length >= sizeof(record->filename)) {
361 pthread_mutex_unlock(&reporter->mutex);
362 return -1;
363 }
364 reporter->write_index = (reporter->write_index + 1) % SPEEDTEST_PROGRESS_CAPACITY;
365 ++reporter->count;
366 pthread_cond_signal(&reporter->available);
367 pthread_mutex_unlock(&reporter->mutex);
368 return 0;
369}
370
371/**
372 * @brief Request reporter shutdown, drain queued output, and release its resources.
373 * @param reporter Running reporter.
374 * @return 0 only when the thread joined and all queued progress was written.
375 * @details Joining before closing the descriptor preserves event order and prevents a writer
376 * from racing descriptor reuse. Restoring redirected stdout flags keeps benchmark setup from
377 * leaking output-mode changes into callers that continue running after a failed test.
378 */
379static int reporter_stop(struct progress_reporter *reporter)
380{
381 pthread_mutex_lock(&reporter->mutex);
382 reporter->stopping = true;
383 pthread_cond_signal(&reporter->available);
384 pthread_mutex_unlock(&reporter->mutex);
385 int join_result = pthread_join(reporter->thread, NULL);
386 bool output_failed = reporter->output_failed;
387 close(reporter->output_fd);
388 if (reporter->regular_output) {
389 if (lseek(STDOUT_FILENO, 0, SEEK_END) < 0
390 || fcntl(STDOUT_FILENO, F_SETFL, reporter->stdout_flags) != 0) {
391 output_failed = true;
392 }
393 }
394 pthread_cond_destroy(&reporter->available);
395 pthread_mutex_destroy(&reporter->mutex);
396 if (join_result != 0) {
397 fprintf(stderr, "USHER SPEEDTEST:\tunable to stop progress reporter: %s\n",
398 strerror(join_result));
399 return -1;
400 }
401 return output_failed ? -1 : 0;
402}
403
405 int *first_image)
406{
407 if (config == NULL || config->photo_directory == NULL || first_image == NULL
408 || config->filename_prefix == '\0') {
409 errno = EINVAL;
410 return -1;
411 }
412 const int block_size = CAMERA_SPEEDTEST_SAMPLE_COUNT + 1;
413 int consecutive = 0;
414 for (int image_number = CAMERA_SPEEDTEST_FIRST_IMAGE;
415 image_number <= CAMERA_SPEEDTEST_LAST_IMAGE; ++image_number) {
416 char path[SPEEDTEST_FILENAME_SIZE];
417 if (format_image_path(config, image_number, path, sizeof(path)) != 0) {
418 errno = ENAMETOOLONG;
419 return -1;
420 }
421 struct stat status;
422 if (lstat(path, &status) == 0) {
423 consecutive = 0;
424 continue;
425 }
426 if (errno != ENOENT) {
427 return -1;
428 }
429 if (++consecutive == block_size) {
430 *first_image = image_number - block_size + 1;
431 return 0;
432 }
433 }
434 errno = ENOSPC;
435 return -1;
436}
437
438int camera_speedtest_run(const struct camera_speedtest_config *config, int first_image)
439{
440 if (config == NULL || config->backend_name == NULL || config->shoot == NULL
441 || config->keep_running == NULL
442 || first_image < CAMERA_SPEEDTEST_FIRST_IMAGE
444 errno = EINVAL;
445 return -1;
446 }
447
448 struct progress_reporter reporter;
449 if (reporter_start(&reporter) != 0) return -1;
450
451 uint64_t total_ns = 0;
452 uint64_t minimum_ns = UINT64_MAX;
453 uint64_t maximum_ns = 0;
454 uint64_t sequence_start_ns = 0;
455 uint64_t sequence_end_ns = 0;
456 int result = 0;
457
458 for (unsigned capture = 0; capture <= CAMERA_SPEEDTEST_SAMPLE_COUNT; ++capture) {
459 const bool warmup = capture == 0;
460 const unsigned sample = warmup ? 0 : capture;
461 const int image_number = first_image + (int)capture;
462 char expected_filename[SPEEDTEST_FILENAME_SIZE];
463 char actual_filename[SPEEDTEST_FILENAME_SIZE] = "";
464 if (!capture_running(config->keep_running)
465 || format_image_path(config, image_number, expected_filename,
466 sizeof(expected_filename)) != 0
467 || reporter_enqueue(&reporter, PROGRESS_STARTED, sample, warmup, false, 0,
468 expected_filename) != 0) {
469 result = -1;
470 break;
471 }
472
473 uint64_t started_ns;
474 uint64_t completed_ns;
475 if (monotonic_time_ns(&started_ns) != 0) {
476 fprintf(stderr, "USHER SPEEDTEST:\tmonotonic clock unavailable: %s\n",
477 strerror(errno));
478 result = -1;
479 break;
480 }
481 if (!warmup && sequence_start_ns == 0) sequence_start_ns = started_ns;
482 int shoot_result = config->shoot(actual_filename, sizeof(actual_filename), image_number);
483 if (shoot_result == 0 && (!actual_filename[0]
484 || strnlen(actual_filename, sizeof(actual_filename)) == sizeof(actual_filename))) {
485 shoot_result = -1;
486 errno = EINVAL;
487 }
488 if (monotonic_time_ns(&completed_ns) != 0 || completed_ns < started_ns) {
489 fprintf(stderr, "USHER SPEEDTEST:\tinvalid monotonic capture interval\n");
490 result = -1;
491 break;
492 }
493 uint64_t duration_ns = completed_ns - started_ns;
494 if (shoot_result == 0 && config->private_output) {
495 const int publication = usher_complete_photo(actual_filename, sizeof(actual_filename));
496 if (publication < 0) shoot_result = -1;
497 else if (publication > 0)
498 fprintf(stderr, "USHER SPEEDTEST:\tphoto published with durability/cleanup warning: %s\n", strerror(errno));
499 }
500 bool succeeded = shoot_result == 0
501 && validate_capture(actual_filename, expected_filename) == 0;
502 if (reporter_enqueue(&reporter, PROGRESS_COMPLETED, sample, warmup, succeeded,
503 duration_ns, expected_filename) != 0) {
504 result = -1;
505 break;
506 }
507 if (!succeeded) {
508 fprintf(stderr, "USHER SPEEDTEST:\t%s capture failed; aborting benchmark\n",
509 warmup ? "warm-up" : "measured");
510 result = -1;
511 break;
512 }
513 if (!capture_running(config->keep_running)) {
514 fprintf(stderr, "USHER SPEEDTEST:\tinterrupted after completed capture; aborting benchmark\n");
515 result = -1;
516 break;
517 }
518 if (warmup) continue;
519
520 sequence_end_ns = completed_ns;
521 if (UINT64_MAX - total_ns < duration_ns) {
522 fprintf(stderr, "USHER SPEEDTEST:\tcapture duration overflow\n");
523 result = -1;
524 break;
525 }
526 total_ns += duration_ns;
527 if (duration_ns < minimum_ns) minimum_ns = duration_ns;
528 if (duration_ns > maximum_ns) maximum_ns = duration_ns;
529 }
530
531 if (reporter_stop(&reporter) != 0) result = -1;
532 if (result != 0) return -1;
533 if (total_ns == 0 || minimum_ns == 0 || sequence_end_ns <= sequence_start_ns) {
534 fprintf(stderr, "USHER SPEEDTEST:\tinvalid zero-duration benchmark\n");
535 return -1;
536 }
537
538 const double total_seconds = (double)total_ns / 1000000000.0;
539 const double sequence_seconds = (double)(sequence_end_ns - sequence_start_ns) / 1000000000.0;
540 const double sustained_seconds_per_photo = sequence_seconds / CAMERA_SPEEDTEST_SAMPLE_COUNT;
541 const double capture_seconds_per_photo = total_seconds / CAMERA_SPEEDTEST_SAMPLE_COUNT;
542 printf("USHER SPEEDTEST:\tbackend: %s\n", config->backend_name);
543 printf("USHER SPEEDTEST:\tmeasured captures: %u (one warm-up excluded)\n",
545 printf("USHER SPEEDTEST:\tpractical sustained speed: %.3f photos/s "
546 "(1 photo every %.3f s, %.1f ms)\n",
547 1.0 / sustained_seconds_per_photo, sustained_seconds_per_photo,
548 sustained_seconds_per_photo * 1000.0);
549 printf("USHER SPEEDTEST:\taverage camera-call speed: %.3f photos/s "
550 "(1 photo every %.3f s, %.1f ms)\n",
551 1.0 / capture_seconds_per_photo, capture_seconds_per_photo,
552 capture_seconds_per_photo * 1000.0);
553 printf("USHER SPEEDTEST:\taverage / fastest / slowest capture time: "
554 "%.3f / %.3f / %.3f ms\n",
555 capture_seconds_per_photo * 1000.0,
556 (double)minimum_ns / 1000000.0, (double)maximum_ns / 1000000.0);
557 printf("USHER SPEEDTEST:\tfastest single capture: %.3f ms "
558 "(equivalent to %.3f photos/s)\n",
559 (double)minimum_ns / 1000000.0, 1000000000.0 / (double)minimum_ns);
560 printf("USHER SPEEDTEST:\ttotal camera-call time for %u photos: %.6f s\n",
561 CAMERA_SPEEDTEST_SAMPLE_COUNT, total_seconds);
562 printf("USHER SPEEDTEST:\timages retained in %s from %c%06d.jpg through %c%06d.jpg\n",
563 config->photo_directory, config->filename_prefix, first_image, config->filename_prefix,
564 first_image + CAMERA_SPEEDTEST_SAMPLE_COUNT);
565 return 0;
566}
Optional split-phase capture contract for USHER image backends.
static bool capture_running(const volatile sig_atomic_t *running)
Atomically poll a borrowed cancellation flag; NULL means no cancellation.
static int write_progress(struct progress_reporter *reporter, const struct progress_record *record)
Write one progress record without waiting indefinitely for stdout.
static int format_image_path(const struct camera_speedtest_config *config, int image_number, char *path, size_t path_size)
Derive the expected JPEG path for a benchmark capture.
static int reporter_enqueue(struct progress_reporter *reporter, enum progress_kind kind, unsigned sample, bool warmup, bool succeeded, uint64_t duration_ns, const char *filename)
Queue one capture lifecycle event without performing output I/O.
int camera_speedtest_create_output_directory(const char *base_directory, char *output, size_t output_size)
Atomically create a private directory for one benchmark run.
static void * report_progress(void *argument)
Drain queued progress records on the dedicated reporter thread.
int camera_speedtest_run(const struct camera_speedtest_config *config, int first_image)
Capture one untimed warm-up image and ten timed images sequentially.
static int monotonic_time_ns(uint64_t *time_ns)
Read a non-negative monotonic timestamp in nanoseconds.
static int reporter_start(struct progress_reporter *reporter)
Initialize and launch the bounded progress reporter.
progress_kind
@ PROGRESS_STARTED
@ PROGRESS_COMPLETED
static int validate_capture(const char *actual_filename, const char *expected_filename)
Confirm that a backend produced exactly the requested usable image.
#define SPEEDTEST_FILENAME_SIZE
#define SPEEDTEST_PROGRESS_CAPACITY
int camera_speedtest_find_image_block(const struct camera_speedtest_config *config, int *first_image)
Find an unused consecutive image-number block for warm-up and samples.
static int reporter_stop(struct progress_reporter *reporter)
Request reporter shutdown, drain queued output, and release its resources.
Standalone, backend-neutral still-camera throughput benchmark.
#define CAMERA_SPEEDTEST_SAMPLE_COUNT
#define CAMERA_SPEEDTEST_FIRST_IMAGE
#define CAMERA_SPEEDTEST_LAST_IMAGE
void(* close)(struct usbfs_handle *)
Definition chdkbridge.c:57
static bool capture(struct transport *transport, FILE *file, const struct capture_settings *settings)
Capture to the camera's SD card and download the resulting JPEG.
int(* open)(const struct usbfs_device *, struct usbfs_handle *)
Definition chdkbridge.c:56
static bool poll_result(struct camera_point_result *point)
Drain a bounded reply batch and publish only the active request's result.
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
Small path and writable-directory helpers shared by USHER backends.
static int usher_complete_photo(char *filename, size_t capacity)
Publish a staged photo and return its immutable public path.
Definition path_utils.h:216
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
#define PATH_MAX
Definition path_utils.h:39
static int usher_ensure_directory(const char *path)
Create missing directory components and verify the final directory is writable.
Definition path_utils.h:97
static FILE * output
Definition pose_log.c:77
Immutable dependencies for one selected and initialized camera backend.
volatile sig_atomic_t * keep_running
int(* shoot)(char *filename, size_t filename_size, int image_number)
enum progress_kind kind
char filename[SPEEDTEST_FILENAME_SIZE]
pthread_mutex_t mutex
pthread_cond_t available
struct progress_record records[SPEEDTEST_PROGRESS_CAPACITY]
struct usher_control_result result
Definition usher.c:377