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 File Reference

Backend-neutral still-image throughput benchmark and asynchronous progress reporter. More...

#include "camera_speedtest.h"
#include "camera_capture.h"
#include "path_utils.h"
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <poll.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for camera_speedtest.c:

Go to the source code of this file.

Data Structures

struct  progress_record
struct  progress_reporter

Macros

#define SPEEDTEST_FILENAME_SIZE   512
#define SPEEDTEST_PROGRESS_CAPACITY   ((CAMERA_SPEEDTEST_SAMPLE_COUNT + 1) * 2)

Enumerations

enum  progress_kind { PROGRESS_STARTED , PROGRESS_COMPLETED }

Functions

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 monotonic_time_ns (uint64_t *time_ns)
 Read a non-negative monotonic timestamp in nanoseconds.
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 int validate_capture (const char *actual_filename, const char *expected_filename)
 Confirm that a backend produced exactly the requested usable image.
static int write_progress (struct progress_reporter *reporter, const struct progress_record *record)
 Write one progress record without waiting indefinitely for stdout.
static void * report_progress (void *argument)
 Drain queued progress records on the dedicated reporter thread.
static int reporter_start (struct progress_reporter *reporter)
 Initialize and launch the bounded progress reporter.
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.
static int reporter_stop (struct progress_reporter *reporter)
 Request reporter shutdown, drain queued output, and release its resources.
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.
int camera_speedtest_run (const struct camera_speedtest_config *config, int first_image)
 Capture one untimed warm-up image and ten timed images sequentially.

Detailed Description

Backend-neutral still-image throughput benchmark and asynchronous progress reporter.

The benchmark performs one untimed warm-up followed by ten sequential synchronous captures. It validates each returned JPEG before accepting it as evidence. Timing uses CLOCK_MONOTONIC around only the backend capture call, excluding setup, UART, EXIF, SODA, and terminal I/O. Progress is copied into a fixed-size queue and written by a separate bounded-I/O thread so an unread pipe or slow terminal cannot throttle capture requests.

Definition in file camera_speedtest.c.

Macro Definition Documentation

◆ SPEEDTEST_FILENAME_SIZE

#define SPEEDTEST_FILENAME_SIZE   512

Definition at line 46 of file camera_speedtest.c.

◆ SPEEDTEST_PROGRESS_CAPACITY

#define SPEEDTEST_PROGRESS_CAPACITY   ((CAMERA_SPEEDTEST_SAMPLE_COUNT + 1) * 2)

Definition at line 47 of file camera_speedtest.c.

Enumeration Type Documentation

◆ progress_kind

Enumerator
PROGRESS_STARTED 
PROGRESS_COMPLETED 

Definition at line 49 of file camera_speedtest.c.

Function Documentation

◆ camera_speedtest_create_output_directory()

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.

Parameters
base_directoryConfigured backend photo root.
outputReceives the new directory path.
output_sizeCapacity of output.
Returns
0 on success, otherwise -1 with errno set.

A private mode-0700 directory prevents benchmark backends, which normally replace same-number files, from racing with or overwriting mission photographs.

Definition at line 117 of file camera_speedtest.c.

◆ camera_speedtest_find_image_block()

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.

Parameters
configBackend filename information.
first_imageReceives the warm-up image number.
Returns
0 on success, -1 on invalid input, filesystem error, or exhausted range.

USHER camera backends replace an existing same-number image. Preflighting the complete block before camera initialization keeps benchmark evidence separate from mission captures and prevents accidental replacement of an existing photo.

Definition at line 404 of file camera_speedtest.c.

◆ camera_speedtest_run()

int camera_speedtest_run ( const struct camera_speedtest_config * config,
int first_image )

Capture one untimed warm-up image and ten timed images sequentially.

Parameters
configSelected and initialized camera backend.
first_imageWarm-up image number returned by camera_speedtest_find_image_block().
Returns
0 only when every requested image was captured and validated.

Only synchronous shoot time is used for camera throughput. Progress records are written through bounded nonblocking I/O by a separate reporter thread, so a slow terminal cannot delay capture requests or inflate measured camera latency. Images are retained for review.

Definition at line 438 of file camera_speedtest.c.

◆ format_image_path()

int format_image_path ( const struct camera_speedtest_config * config,
int image_number,
char * path,
size_t path_size )
static

Derive the expected JPEG path for a benchmark capture.

Parameters
configOutput directory and camera prefix used by the measured backend.
image_numberPhoto number.
[out]pathPath buffer.
path_sizeCapacity including the terminator.
Returns
Zero for a complete path, or -1 on formatting failure or truncation.

Match the production naming convention so checks address the capture under test rather than a separate benchmark artifact.

Definition at line 86 of file camera_speedtest.c.

◆ monotonic_time_ns()

int monotonic_time_ns ( uint64_t * time_ns)
static

Read a non-negative monotonic timestamp in nanoseconds.

Parameters
time_nsDestination for the timestamp.
Returns
0 on success; -1 if the clock is unavailable, invalid, or overflows conversion.

Nanoseconds retain sub-millisecond capture differences without requiring floating point arithmetic in the measurement loop. The conversion rejects impossible values rather than silently wrapping and publishing a plausible but false rate.

Definition at line 106 of file camera_speedtest.c.

◆ report_progress()

void * report_progress ( void * argument)
static

Drain queued progress records on the dedicated reporter thread.

Parameters
argumentPointer to the initialized progress_reporter.
Returns
Always NULL when the stop request is observed.

Records are removed under the mutex, then formatted and written without holding it. This keeps producer critical sections constant-time and ensures slow output never prevents the benchmark thread from issuing its next capture.

Definition at line 226 of file camera_speedtest.c.

◆ reporter_enqueue()

int reporter_enqueue ( struct progress_reporter * reporter,
enum progress_kind kind,
unsigned sample,
bool warmup,
bool succeeded,
uint64_t duration_ns,
const char * filename )
static

Queue one capture lifecycle event without performing output I/O.

Parameters
reporterRunning reporter.
kindStart or completion event.
sampleOne-based measured sample number, or zero for warm-up.
warmupTrue for the excluded warm-up capture.
succeededCompletion success state.
duration_nsMeasured duration for completion records.
filenameExpected output path copied into the fixed-size event.
Returns
0 if queued; -1 when the bounded queue or filename capacity is exhausted.

The queue has room for every planned start and completion event. Exhaustion is an invariant breach, so failing explicitly is safer than silently dropping operator progress.

Definition at line 340 of file camera_speedtest.c.

◆ reporter_start()

int reporter_start ( struct progress_reporter * reporter)
static

Initialize and launch the bounded progress reporter.

Parameters
reporterStorage owned by the caller for the reporter lifetime.
Returns
0 on success; -1 after cleaning up any partially initialized resources.

Regular redirected stdout is temporarily opened with append semantics so the reporter cannot overwrite buffered summary output. The duplicate nonblocking descriptor isolates progress backpressure from the benchmark's normal stdout stream.

Definition at line 259 of file camera_speedtest.c.

◆ reporter_stop()

int reporter_stop ( struct progress_reporter * reporter)
static

Request reporter shutdown, drain queued output, and release its resources.

Parameters
reporterRunning reporter.
Returns
0 only when the thread joined and all queued progress was written.

Joining before closing the descriptor preserves event order and prevents a writer from racing descriptor reuse. Restoring redirected stdout flags keeps benchmark setup from leaking output-mode changes into callers that continue running after a failed test.

Definition at line 379 of file camera_speedtest.c.

◆ validate_capture()

int validate_capture ( const char * actual_filename,
const char * expected_filename )
static

Confirm that a backend produced exactly the requested usable image.

Parameters
actual_filenamePath returned by the backend capture operation.
expected_filenameDeterministic path reserved before capture began.
Returns
0 when the path matches and names a nonempty regular file; -1 otherwise.

Path equality prevents a backend fallback or stale output from being counted as a benchmark sample. Regular-file and size checks catch missing, directory, FIFO, and empty outputs while leaving image decoding to the normal backend contract.

Definition at line 154 of file camera_speedtest.c.

◆ write_progress()

int write_progress ( struct progress_reporter * reporter,
const struct progress_record * record )
static

Write one progress record without waiting indefinitely for stdout.

Parameters
reporterReporter owning the nonblocking output descriptor.
recordImmutable event to render.
Returns
0 if the complete line was written; -1 when output is unavailable or partial.

The 100 ms poll bound is a reporting policy, not a capture timeout. On failure the reporter records the condition and the benchmark fails after draining, rather than blocking the capture loop behind a terminal or pipe consumer.

Definition at line 183 of file camera_speedtest.c.