1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-FileCopyrightText: Copyright 2026 Au-Zone Technologies
// SPDX-License-Identifier: Apache-2.0
//! Hand-rolled FFI for the CUDA nvJPEG decode API.
//!
//! These declarations mirror the on-target `nvjpeg.h` (CUDA 12.6 / nvJPEG
//! 12.3.3, verified on the Orin Nano). The library is loaded via `dlopen` (see
//! [`super::loader`]) — there is no link-time dependency, so only the subset of
//! types and entry points the backend uses is declared here. The `CudaStream`
//! is the `cudaStream_t` from `edgefirst_tensor::CudaStream`.
use ;
/// `NVJPEG_MAX_COMPONENT` — the channel/pitch array length in `nvjpegImage_t`.
pub const NVJPEG_MAX_COMPONENT: usize = 4;
/// `nvjpegStatus_t` — `0` is `NVJPEG_STATUS_SUCCESS`.
pub type NvjpegStatus = c_int;
pub const NVJPEG_STATUS_SUCCESS: NvjpegStatus = 0;
/// `nvjpegOutputFormat_t` — only the interleaved-RGB output is used. nvJPEG
/// writes a single packed RGB plane into `channel[0]` at `pitch[0]`, doing the
/// YCbCr→RGB conversion on the GPU.
pub type NvjpegOutputFormat = c_int;
pub const NVJPEG_OUTPUT_RGBI: NvjpegOutputFormat = 5;
/// `nvjpegBackend_t` — `DEFAULT` resolves to GPU-hybrid on this build. The
/// dedicated-hardware backend (`NVJPEG_BACKEND_HARDWARE = 3`) is unsupported on
/// Orin (`nvjpegCreateEx` returns status 7), so it is never requested.
pub type NvjpegBackend = c_int;
pub const NVJPEG_BACKEND_DEFAULT: NvjpegBackend = 0;
/// Opaque library handle (`nvjpegHandle_t`).
pub type NvjpegHandle = *mut c_void;
/// Opaque per-decode state (`nvjpegJpegState_t`).
pub type NvjpegJpegState = *mut c_void;
/// `cudaStream_t`, shared with the tensor crate's CUDA interop.
pub type CudaStream = CudaStream;
/// `nvjpegImage_t { unsigned char* channel[4]; size_t pitch[4]; }`.
///
/// The `channel` pointers are caller-provided **device** pointers and `pitch`
/// the per-plane row stride in bytes. For `NVJPEG_OUTPUT_RGBI` only
/// `channel[0]`/`pitch[0]` are consulted.
/// `nvjpegCreateEx(backend, dev_allocator, pinned_allocator, flags, &handle)`.
/// The allocators are passed as null (library-managed) and `flags` as 0.
pub type FnCreateEx = unsafe extern "C" fn ;
/// `nvjpegJpegStateCreate(handle, &state)`.
pub type FnJpegStateCreate =
unsafe extern "C" fn ;
/// `nvjpegGetImageInfo(handle, data, len, &nComponents, &subsampling, widths[4], heights[4])`.
pub type FnGetImageInfo = unsafe extern "C" fn ;
/// `nvjpegDecode(handle, state, data, len, output_format, &image, stream)`.
/// Asynchronous: GPU work is submitted to `stream`.
pub type FnDecode = unsafe extern "C" fn ;
/// `nvjpegDestroy(handle)`.
pub type FnDestroy = unsafe extern "C" fn ;
/// `nvjpegJpegStateDestroy(state)`.
pub type FnJpegStateDestroy = unsafe extern "C" fn ;