32#include <condition_variable>
47#include <linux/dma-buf.h>
48#include <linux/videodev2.h>
50#include <libcamera/control_ids.h>
51#include <libcamera/libcamera.h>
52#include <libcamera/property_ids.h>
57constexpr unsigned camera_buffer_count = 3;
58constexpr unsigned maximum_camera_buffer_count = 4;
59constexpr unsigned jpeg_luma_lines_per_mcu = 16;
60constexpr unsigned jpeg_chroma_lines_per_mcu = 8;
61constexpr size_t maximum_mapped_plane_bytes = 32 * 1024 * 1024;
62constexpr int64_t camera_frame_duration_us = 125000;
63constexpr int camera_request_timeout_seconds = 5;
64constexpr int tensor_startup_timeout_seconds = 70;
65constexpr unsigned capture_width_alignment = 16;
66constexpr unsigned capture_height_alignment = 2;
67constexpr uint32_t imx500_network_firmware_control = 0x00982901;
68constexpr uint32_t imx500_inference_roi_control = 0x00982900;
72 jpeg_error_mgr manager;
82 longjmp(
reinterpret_cast<JpegError *
>(codec->err)->jump, 1);
92const libcamera::ControlValue *named_metadata(
const libcamera::ControlList &metadata,
93 const char *name, libcamera::ControlType type)
95 if (!metadata.idMap()) {
98 for (
const auto &entry : metadata) {
99 const auto identifier = metadata.idMap()->find(entry.first);
100 if (identifier != metadata.idMap()->end() && identifier->second->name() == name
101 && entry.second.type() == type && entry.second.isArray()) {
102 return &entry.second;
118 explicit MappedFrame(libcamera::FrameBuffer *buffer)
120 if (buffer->planes().empty() || buffer->planes().size() > mappings_.size()
121 || buffer->metadata().planes().size() != buffer->planes().size()
122 || buffer->metadata().status != libcamera::FrameMetadata::FrameSuccess) {
123 std::fprintf(stderr,
"invalid camera buffer: planes=%zu metadata_planes=%zu status=%d\n",
124 buffer->planes().size(), buffer->metadata().planes().size(),
125 static_cast<int>(buffer->metadata().status));
126 throw std::runtime_error(
"invalid camera buffer");
129 const long page = sysconf(_SC_PAGESIZE);
131 throw std::runtime_error(
"invalid page size");
133 for (
size_t index = 0; index < buffer->planes().
size(); ++index) {
134 const auto &plane = buffer->planes()[index];
135 auto &mapping = mappings_[index];
136 mapping.fd = plane.fd.get();
137 bool duplicate =
false;
138 for (
size_t previous = 0; previous < index; ++previous) {
139 duplicate = duplicate || mappings_[previous].fd == mapping.fd;
144 dma_buf_sync sync{DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ};
145 if (ioctl(mapping.fd, DMA_BUF_IOCTL_SYNC, &sync) != 0) {
146 throw std::runtime_error(
"DMA read sync failed");
148 mapping.synced =
true;
150 const size_t offset = plane.offset % size_t(page);
153 mapping.length = size_t(plane.length) + offset;
154 if (!plane.length || mapping.length > maximum_mapped_plane_bytes) {
155 throw std::runtime_error(
"camera plane too large");
157 mapping.base = mmap(
nullptr, mapping.length, PROT_READ, MAP_SHARED,
158 mapping.fd, plane.offset - offset);
159 if (mapping.base == MAP_FAILED) {
160 throw std::runtime_error(
"camera buffer mmap failed");
162 data[index] =
static_cast<const uint8_t *
>(mapping.base) + offset;
163 lengths[index] = std::min(plane.length, buffer->metadata().planes()[index].bytesused);
172 ~MappedFrame() { release(); }
174 MappedFrame(
const MappedFrame &) =
delete;
176 MappedFrame &operator=(
const MappedFrame &) =
delete;
178 std::array<const uint8_t *, 3> data{};
179 std::array<size_t, 3> lengths{};
185 void release()
noexcept
187 for (
auto &mapping : mappings_) {
188 if (mapping.base != MAP_FAILED) {
189 munmap(mapping.base, mapping.length);
191 if (mapping.synced) {
192 dma_buf_sync sync{DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ};
193 if (ioctl(mapping.fd, DMA_BUF_IOCTL_SYNC, &sync) != 0) {
194 std::perror(
"DMA read sync end");
202 void *base = MAP_FAILED;
207 std::array<Mapping, 3> mappings_{};
215bool valid_path(
const char *filename)
220 const size_t length = strnlen(filename,
PATH_MAX);
221 return length >= 5 && length <=
PATH_MAX - 32 && filename[0] ==
'/'
222 && std::strcmp(filename + length - 4,
".jpg") == 0
223 && std::strpbrk(filename,
"\r\n") ==
nullptr;
226bool valid_yuv420_layout(
unsigned width,
unsigned height,
unsigned stride)
229 && width % 2 == 0 && height % 2 == 0 && stride % 2 == 0
230 && stride >= ((width + capture_width_alignment - 1) / capture_width_alignment)
231 * capture_width_alignment;
260 other.owner_ =
nullptr;
261 other.release_ =
nullptr;
279 unsigned width,
unsigned height,
unsigned stride,
283 size_t capture_size = 0;
291 || (processor && processor->
embed && !processor->
embed(*view, &document))
292 ||
exif_serialize(&document, capture_exif,
sizeof(capture_exif), &capture_size))
return false;
294 FILE *file = std::fopen(path,
"wbx");
298 jpeg_compress_struct codec{};
300 codec.err = jpeg_std_error(&
error.manager);
304 if (setjmp(
error.jump)) {
305 jpeg_destroy_compress(&codec);
310 jpeg_create_compress(&codec);
311 jpeg_stdio_dest(&codec, file);
312 codec.image_width = width;
313 codec.image_height = height;
314 codec.input_components = 3;
315 codec.in_color_space = JCS_YCbCr;
316 jpeg_set_defaults(&codec);
319 codec.raw_data_in = TRUE;
320 jpeg_set_quality(&codec, 90, TRUE);
322 codec.dct_method = JDCT_FLOAT;
323 jpeg_start_compress(&codec, TRUE);
324 if (capture_size) jpeg_write_marker(&codec, JPEG_APP0 + 1, capture_exif,
static_cast<unsigned>(capture_size));
325 while (codec.next_scanline < height) {
326 JSAMPROW rows[3][jpeg_luma_lines_per_mcu]{};
327 JSAMPARRAY components[3]{rows[0], rows[1], rows[2]};
328 for (
unsigned row = 0;
row < jpeg_luma_lines_per_mcu; ++
row) {
331 rows[0][
row] =
const_cast<JSAMPROW
>(
332 planes[0] + std::min(codec.next_scanline +
row, height - 1) * stride);
333 if (
row < jpeg_chroma_lines_per_mcu) {
334 for (
size_t component = 1; component < 3; ++component) {
335 rows[component][
row] =
const_cast<JSAMPROW
>(
337 + std::min(codec.next_scanline / 2 +
row, height / 2 - 1) * (stride / 2));
341 jpeg_write_raw_data(&codec, components, jpeg_luma_lines_per_mcu);
343 jpeg_finish_compress(&codec);
344 jpeg_destroy_compress(&codec);
347 bool written = std::fflush(file) == 0 && fsync(fileno(file)) == 0;
348 if (std::fclose(file) != 0) {
359bool encode_jpeg(
const char *path,
const std::array<const uint8_t *, 3> &planes,
360 unsigned width,
unsigned height,
unsigned stride)
362 if (!path || !path[0] || !planes[0] || !planes[1] || !planes[2]
363 || !valid_yuv420_layout(width, height, stride))
return false;
372 std::shared_ptr<libcamera::Camera>
camera;
374 std::unique_ptr<libcamera::FrameBufferAllocator>
allocator;
375 std::vector<std::unique_ptr<libcamera::Request>>
requests;
376 std::array<int64_t, 2>
frame_duration{camera_frame_duration_us, camera_frame_duration_us};
411 request->reuse(libcamera::Request::ReuseBuffers);
413 std::lock_guard<std::mutex> lock(
mutex);
425 auto &state = *
static_cast<Impl *
>(owner);
426 libcamera::Request *
request = state.leased;
427 state.leased =
nullptr;
444 if (
request->status() == libcamera::Request::RequestCancelled) {
447 const auto &buffers =
request->buffers();
448 const auto buffer = buffers.find(
configuration->at(0).stream());
449 const auto status = buffer != buffers.end() && buffer->second
457 std::lock_guard<std::mutex> lock(
mutex);
464 std::lock_guard<std::mutex> lock(
mutex);
465 const auto timestamp =
request->metadata().get(libcamera::controls::SensorTimestamp);
484 for (
const auto &entry : std::filesystem::directory_iterator(
"/sys/class/video4linux")) {
485 if (entry.path().filename().string().find(
"v4l-subdev") != 0) {
488 std::error_code
error;
489 const auto driver = std::filesystem::canonical(entry.path() /
"device/driver",
error);
490 if (!
error && driver.filename() ==
"imx500") {
491 if (!device.empty()) {
492 throw std::runtime_error(
"ambiguous IMX500 subdevice");
494 device =
"/dev/" + entry.path().filename().string();
497 const int sensor =
::open(device.c_str(), O_RDWR | O_CLOEXEC);
499 throw std::runtime_error(
"cannot open IMX500 subdevice");
501 v4l2_control firmware{};
502 firmware.id = imx500_network_firmware_control;
504 firmware.value = INT32_MAX;
505 const int status = ioctl(sensor, VIDIOC_S_CTRL, &firmware);
507 if (status != 0)
throw std::runtime_error(
"IMX500 network unload failed");
513 throw std::runtime_error(
"cannot open network.rpk");
518 int status = ioctl(sensor, VIDIOC_S_CTRL, &firmware);
520 v4l2_ext_control roi{};
521 roi.id = imx500_inference_roi_control;
522 roi.size =
sizeof(region);
523 roi.p_u32 = region.data();
524 v4l2_ext_controls controls{};
526 controls.controls = &roi;
528 status = ioctl(sensor, VIDIOC_S_EXT_CTRLS, &controls);
533 throw std::runtime_error(
"IMX500 firmware/ROI control failed");
547void Camera::open(
const char *model,
unsigned width,
unsigned height,
bool photo_only)
549 auto &state = *
impl_;
550 if (state.acquired || state.started) {
551 throw std::runtime_error(
"camera already open");
553 if (photo_only && model)
throw std::invalid_argument(
"photo-only capture cannot load a model");
554 if (state.manager.start() != 0) {
555 throw std::runtime_error(
"libcamera startup failed");
557 for (
const auto &candidate : state.manager.cameras()) {
558 const auto name = candidate->properties().get(libcamera::properties::Model);
559 if ((!model && !photo_only) || (name && name->find(
"imx500") != std::string::npos)) {
561 throw std::runtime_error(
"capture requires exactly one eligible camera");
563 state.camera = candidate;
566 if (!state.camera || state.camera->acquire() != 0) {
567 throw std::runtime_error(
"IMX500 unavailable or busy");
569 state.acquired =
true;
573#ifdef SENSORAIA_LIBCAMERA_STD_SPAN
574 const auto sensor = state.camera->properties().get(libcamera::properties::PixelArrayArea);
577 const auto sensor = state.camera->properties().get(libcamera::properties::PixelArraySize);
580 if ((model || photo_only) && !expected_sensor) {
581 throw std::runtime_error(
"unexpected IMX500 geometry");
584 state.configuration = state.camera->generateConfiguration({libcamera::StreamRole::StillCapture});
585 if (!state.configuration || state.configuration->empty()) {
586 throw std::runtime_error(
"no still stream");
588 auto &stream = state.configuration->at(0);
589 stream.size = {width, height};
590 stream.pixelFormat = libcamera::formats::YUV420;
591 stream.colorSpace = libcamera::ColorSpace::Sycc;
592 state.configuration->orientation = libcamera::Orientation::Rotate0;
593 stream.bufferCount = camera_buffer_count;
596 if (state.configuration->validate() == libcamera::CameraConfiguration::Invalid
597 || state.configuration->orientation != libcamera::Orientation::Rotate0
598 || stream.size != libcamera::Size(width, height)
599 || stream.pixelFormat != libcamera::formats::YUV420
600 || stream.colorSpace != libcamera::ColorSpace::Sycc || stream.stride % 2
601 || stream.stride < ((width + capture_width_alignment - 1) / capture_width_alignment)
602 * capture_width_alignment
603 || stream.bufferCount == 0
604 || stream.bufferCount > maximum_camera_buffer_count
605 || state.camera->configure(state.configuration.get()) != 0) {
606 throw std::runtime_error(
"unsupported still configuration");
608 state.allocator = std::make_unique<libcamera::FrameBufferAllocator>(state.camera);
609 if (state.allocator->allocate(stream.stream()) < 0) {
610 throw std::runtime_error(
"camera buffer allocation failed");
612 for (
const auto &buffer : state.allocator->buffers(stream.stream())) {
615 auto request = state.camera->createRequest();
616 if (!
request ||
request->addBuffer(stream.stream(), buffer.get()) != 0) {
617 throw std::runtime_error(
"camera request allocation failed");
619 state.requests.push_back(std::move(
request));
621 if (state.requests.empty())
throw std::runtime_error(
"camera allocated no capture buffers");
623 libcamera::ControlList controls(state.camera->controls());
625 controls.set(libcamera::controls::FrameDurationLimits,
626 Span<const int64_t, 2>(state.frame_duration));
630 if (state.camera->start(&controls) != 0) {
631 throw std::runtime_error(
"camera start failed");
633 state.started =
true;
634 for (
auto &
request : state.requests) {
644 auto &state = *
impl_;
645 std::unique_lock<std::mutex> lock(state.mutex);
646 if (!state.started || state.leased) {
647 throw std::runtime_error(
"camera not started or previous frame still leased");
650 if (clock_gettime(CLOCK_BOOTTIME, &now) != 0) {
651 throw std::runtime_error(
"capture clock failed");
653 state.minimum_timestamp = int64_t(now.tv_sec) * 1000000000 + now.tv_nsec;
657 if (!state.ready.wait_for(lock, std::chrono::seconds(camera_request_timeout_seconds),
658 [&state] { return state.completed || state.failed; })) {
659 state.wanted =
false;
660 throw std::runtime_error(
"camera frame timeout");
663 throw std::runtime_error(
"camera request or frame failed");
667 state.leased = state.completed;
668 state.completed =
nullptr;
673 const auto *
request = state.leased;
677 const auto *tensor = named_metadata(
request->metadata(),
"CnnOutputTensor", libcamera::ControlTypeFloat);
678 const auto *info = named_metadata(
request->metadata(),
"CnnOutputTensorInfo", libcamera::ControlTypeByte);
680 view.
tensor = tensor->get<Span<const float>>();
683 view.
tensor_info = info->get<Span<const uint8_t>>();
685 const auto crop =
request->metadata().get(libcamera::controls::ScalerCrop);
690 view.
image = state.configuration->at(0).size;
692 const auto sensor =
request->metadata().get(libcamera::controls::SensorTimestamp);
694 const auto exposure =
request->metadata().get(libcamera::controls::ExposureTime);
695 const auto duration =
request->metadata().get(libcamera::controls::FrameDuration);
713 unsigned stride,
const char *filename,
const FrameProcessor &processor)
716 || !planes[0] || !planes[1] || !planes[2]
717 || !valid_yuv420_layout(view.
image.width, view.
image.height, stride)) {
720 const std::string path(filename);
722 const std::string temporary = path +
".capture.tmp";
725 if (std::filesystem::exists(path) || (!sidecar.empty() && std::filesystem::exists(sidecar))) {
740 bool analysis_written =
false;
744 if (processor.
write && !sidecar.empty()) analysis_written = processor.
write(view, sidecar.c_str());
747 const bool published = link(temporary.c_str(), path.c_str()) == 0;
748 unlink(temporary.c_str());
752 if (analysis_written) {
753 unlink(sidecar.c_str());
760 unlink(temporary.c_str());
761 if (analysis_written) {
762 unlink(sidecar.c_str());
773 struct SavePolicy {
const char *filename;
const FrameProcessor *processor; } policy{filename, &processor};
775 unsigned stride,
void *context) {
776 const auto &
save = *
static_cast<SavePolicy *
>(context);
786 bool (*visitor)(
const FrameView &,
const std::array<const uint8_t *, 3> &,
787 unsigned,
void *),
void *context)
789 auto &state = *
impl_;
790 if (!visitor ||
frame.owner_ !=
impl_.get() ||
frame.release_ ==
nullptr || !state.leased) {
794 const auto &stream = state.configuration->at(0);
795 auto *buffer =
request->buffers().at(stream.stream());
796 MappedFrame mapped(buffer);
799 auto planes = mapped.data;
800 const size_t luma = size_t(stream.stride) * stream.size.height;
801 const size_t chroma = luma / 4;
802 if (buffer->planes().size() == 1 && mapped.lengths[0] >= luma + 2 * chroma) {
803 planes[1] = planes[0] + luma;
804 planes[2] = planes[1] + chroma;
805 }
else if (buffer->planes().size() != 3 || mapped.lengths[0] < luma
806 || mapped.lengths[1] < chroma || mapped.lengths[2] < chroma) {
809 return visitor(
frame.view(), planes, stream.stride, context);
822 const bool photo_only = std::strcmp(argv[2],
"--photo-only") == 0;
827 const FrameProcessor &selected_processor = photo_only ? photo_processor : processor;
828 const char *timing_setting = std::getenv(
"USHER_AI_CAM_TIMING");
829 const bool report_timing = timing_setting && std::strcmp(timing_setting,
"1") == 0;
830 const bool probe = std::strcmp(argv[1],
"--probe") == 0;
831 const bool serve = std::strcmp(argv[1],
"--serve") == 0;
832 const bool capture = std::strcmp(argv[1],
"--capture") == 0;
833 if ((!probe && !serve && !
capture) || (probe && argc != 3)
834 || (serve && argc != 5) || (
capture && argc != 4)) {
838 unsigned width = 2028;
839 unsigned height = 1520;
841 char *end_width =
nullptr;
842 char *end_height =
nullptr;
844 const unsigned long parsed_width = std::strtoul(argv[3], &end_width, 10);
845 const unsigned long parsed_height = std::strtoul(argv[4], &end_height, 10);
846 if (errno || end_width == argv[3] || end_height == argv[4] || *end_width || *end_height
851 width =
static_cast<unsigned>(parsed_width);
852 height =
static_cast<unsigned>(parsed_height);
855 camera.open(photo_only ?
nullptr : argv[2], width, height, photo_only);
859 const auto deadline = std::chrono::steady_clock::now()
860 + std::chrono::seconds(tensor_startup_timeout_seconds);
862 while (std::chrono::steady_clock::now() < deadline) {
865 throw std::runtime_error(
"unexpected IMX500 inference metadata in photo-only mode");
872 throw std::runtime_error(
"no fresh valid IMX500 tensor before startup deadline");
875 std::puts(photo_only ?
"camera frame received" :
"IMX500 frame and output tensor received");
883 throw std::runtime_error(
"unexpected IMX500 inference metadata in photo-only mode");
884 return camera.save(
frame, argv[3], selected_processor) ? 0 : 1;
889 if (std::fflush(stdout) != 0) {
893 while (std::fgets(command,
sizeof(command), stdin)) {
894 const size_t length = std::strlen(command);
897 if (length == 0 || command[length - 1] !=
'\n' || std::strncmp(command,
"SHOT ", 5) != 0) {
900 command[length - 1] =
'\0';
903 std::chrono::steady_clock::time_point capture_started{}, capture_completed{};
904 if (report_timing) capture_started = std::chrono::steady_clock::now();
907 throw std::runtime_error(
"unexpected IMX500 inference metadata in photo-only mode");
908 if (report_timing) capture_completed = std::chrono::steady_clock::now();
909 const bool saved =
camera.save(
frame, command + 5, selected_processor);
911 const auto save_completed = std::chrono::steady_clock::now();
912 std::fprintf(stderr,
"%s TIMING: capture_ms=%.3f save_ms=%.3f exposure_us=%lld frame_us=%lld\n",
914 std::chrono::duration<double, std::milli>(capture_completed - capture_started).
count(),
915 std::chrono::duration<double, std::milli>(save_completed - capture_completed).
count(),
916 static_cast<long long>(
frame.view().exposure_us),
917 static_cast<long long>(
frame.view().frame_duration_us));
919 std::puts(saved ?
"OK" :
"ERROR");
920 if (std::fflush(stdout) != 0) {
924 return std::ferror(stdin) ? 1 : 0;
925 }
catch (
const std::exception &
error) {
926 std::fprintf(stderr,
"%s: %s\n", application,
error.what());
933 if (argc < 2 || argc > 4)
return 2;
934 char photo_only[] =
"--photo-only";
935 char *arguments[] = {argv[0], argv[1], photo_only,
936 argc > 2 ? argv[2] :
nullptr,
937 argc > 3 ? argv[3] :
nullptr,
nullptr};
939 return run_worker(argc + 1, arguments, processor, application);
void(* close)(struct usbfs_handle *)
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 *)
One exclusive IMX500 owner with bounded reusable YUV420 buffers.
bool with_pixels(const FrameLease &frame, bool(*visitor)(const FrameView &, const std::array< const uint8_t *, 3 > &, unsigned, void *), void *context)
Grant scoped CPU pixel access without transferring DMA/frame ownership.
bool save(const FrameLease &frame, const char *filename, const FrameProcessor &processor)
Map a leased frame and publish its JPEG plus available evidence.
~Camera()
Stop streaming before freeing requests/buffers and releasing the camera.
void open(const char *model, unsigned width=2028, unsigned height=1520, bool photo_only=false)
Acquire one eligible camera and configure bounded capture, uploading an RPK only when requested.
std::unique_ptr< Impl > impl_
Camera()
Construct unopened camera state; construction does not acquire the sensor.
FrameLease capture()
Lease a fresh post-request exposure and its own tensor metadata.
Exactly-once release of a borrowed frame, including exception exits.
FrameLease(FrameView view, void *owner, Release release) noexcept
Associate borrowed evidence with exactly one release operation.
void(*)(void *) noexcept Release
Nonthrowing release callback; a destructor must never unwind through it.
~FrameLease()
Release once on every scope exit, including a processing exception.
const FrameView & view() const noexcept
Read evidence only while this unmoved lease remains alive.
union dc_shot_union request
static struct inference_context network
int exif_serialize(const struct exif_document *document, unsigned char *payload, size_t capacity, size_t *size)
Serialize a document into one complete EXIF APP1 payload.
#define EXIF_MAX_PAYLOAD
APP1 payload ceiling: the JPEG length includes its own two bytes.
Neutral IMX500 frame ownership, JPEG publication and worker protocol.
uint8_t row[LWIR_MAX_WIDTH *3U]
static void jpeg_failure(j_common_ptr encoder)
libjpeg error_exit replacement: abandon the photo instead of exiting.
struct jpeg_error_mgr error
uint8_t frame[LWIR_MAX_FRAME_BYTES]
constexpr FrameStatus frame_status(libcamera::FrameMetadata::Status status)
Map libcamera metadata to this worker's frame disposition.
bool photo_only_frame(const FrameView &frame)
Confirm that a frame carries no neural output.
bool encode_jpeg(const char *path, const std::array< const uint8_t *, 3 > &planes, unsigned width, unsigned height, unsigned stride)
Encode validated YUV420 planes directly, without full-frame RGB staging.
int run_worker(int argc, char **argv, const FrameProcessor &processor, const char *application)
Run the shared probe/capture/READY-SHOT-OK worker with supplied model policy.
constexpr bool valid_capture_dimensions(unsigned width, unsigned height)
Check that capture dimensions meet the worker's raster policy.
static bool encode_frame_jpeg(const char *path, const std::array< const uint8_t *, 3 > &planes, unsigned width, unsigned height, unsigned stride, const FrameView *view, const FrameProcessor *processor)
Encode one YUV420 frame with optional same-exposure EXIF metadata.
bool publish_frame(const FrameView &view, const std::array< const uint8_t *, 3 > &planes, unsigned stride, const char *filename, const FrameProcessor &processor)
Publish caller-validated YUV420 planes and same-exposure evidence.
int run_photo_worker(int argc, char **argv, const char *application)
Run photo-only probe, capture or serve without model loading or inference.
constexpr unsigned sensor_height
Physical IMX500 array height; model input dimensions are separate policy.
constexpr unsigned sensor_width
Physical IMX500 array width, used to reject an unexpected sensor geometry.
Caller-owned bounded writer with no heap allocation.
Capture resources and the callback-to-owner handoff, not model results.
libcamera::Request * completed
static void configure_model(const char *model)
Load an RPK or clear a retained network through the driver control.
std::unique_ptr< libcamera::FrameBufferAllocator > allocator
std::array< int64_t, 2 > frame_duration
libcamera::Request * leased
void recycle(libcamera::Request *request)
Return an unneeded or fully consumed request to the bounded camera queue.
std::vector< std::unique_ptr< libcamera::Request > > requests
std::unique_ptr< libcamera::CameraConfiguration > configuration
std::condition_variable ready
int64_t minimum_timestamp
libcamera::CameraManager manager
static void release_lease(void *owner) noexcept
Recycle the sole leased request without throwing through its destructor.
~Impl()
Unwind partial/full startup in libcamera's resource-lifetime order.
std::shared_ptr< libcamera::Camera > camera
void complete(libcamera::Request *request)
Hold one fresh requested exposure; immediately recycle other callbacks.
Stack-owned model-specific operations; no dynamic plugin allocation.
const char * sidecar_suffix
bool(* validate)(const FrameView &frame)
bool(* embed)(const FrameView &frame, exif_document *document)
bool(* write)(const FrameView &frame, const char *filename)
Borrowed same-exposure evidence, without object or navigation semantics.
Span< const uint8_t > tensor_info
int64_t frame_duration_us
Span< const float > tensor
libcamera::Rectangle crop
uint64_t sensor_timestamp_ns
Timing evidence for one exposure, with microsecond uncertainty.
uint64_t monotonic_us
Estimated exposure/readout-window midpoint in MONOTONIC microseconds.
uint64_t time_error_us
Conservative alignment allowance, not calibrated accuracy.
static struct camera_backend camera
bool usher_frame_document(const struct usher_frame_timing *timing, unsigned width, unsigned height, struct exif_document *document)
Initialize capture EXIF for the JPEG encoded from this exposure.
struct usher_frame_timing usher_frame_timing_estimate(uint64_t sequence, uint64_t sensor_ns, int64_t exposure_us, int64_t duration_us)
Translate fresh sensor evidence into a cautious pose-alignment time.
C interface for conservative frame-time estimation and EXIF evidence.