Skip to content

Commit 76b00ea

Browse files
Add larod-sys (#182)
This adds the `larod-sys` crate as an initial step to adding a later `larod` crate. The implementation closely follows existing sys crates. `apps/object_detection/src/main.rs`: - We need an example app that depends on the sys crate in order to trigger a build of the bindings so that we can check that the tracked bindings are up to date. The added example is meant to eventually match its namesake for `acap-native-sdk-examples`. --------- Co-authored-by: AP Ljungquist <[email protected]>
1 parent ac2cb60 commit 76b00ea

File tree

12 files changed

+874
-1
lines changed

12 files changed

+874
-1
lines changed

Cargo.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ bbox-sys = { path = "crates/bbox-sys" }
5858
cargo-acap-build = { path = "crates/cargo-acap-build" }
5959
cli-version = { path = "crates/cli-version" }
6060
device-manager = { path = "crates/device-manager" }
61+
larod-sys = { path = "crates/larod-sys" }
6162
licensekey = { path = "crates/licensekey" }
6263
licensekey-sys = { path = "crates/licensekey-sys" }
6364
mdb = { path = "crates/mdb" }

apps-aarch64.checksum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dfd925c003c30164c00dfc51676b6e1317a0fa6d target-aarch64/acap/consume_analytics_
88
5712d955c8ea45a774597a6032a16af72a24e118 target-aarch64/acap/hello_world_0_0_0_aarch64.eap
99
222f821339cf36e88596d85427740de3536573bf target-aarch64/acap/inspect_env_0_0_0_aarch64.eap
1010
74d6106b8f0afe7e3342ae3b470d8b81e7aa5150 target-aarch64/acap/licensekey_handler_0_0_0_aarch64.eap
11+
9deb95dbb3d67596d9f7cbc2aa05b3fb4d812025 target-aarch64/acap/object_detection_1_0_0_aarch64.eap
1112
5dc0969dcbe6ca09aabcef9530a0f77786932b22 target-aarch64/acap/reverse_proxy_0_0_0_aarch64.eap
1213
c94b3ba49a3897617dc13599ffbc0642681133e5 target-aarch64/acap/send_event_1_0_0_aarch64.eap
1314
9df8dead66b245aa19d3aafa758871118b8cc25f target-aarch64/acap/using_a_build_script_0_0_0_aarch64.eap

apps-aarch64.filesize

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
1406 target-aarch64/acap/hello_world_0_0_0_aarch64.eap
99
1441 target-aarch64/acap/inspect_env_0_0_0_aarch64.eap
1010
1430 target-aarch64/acap/licensekey_handler_0_0_0_aarch64.eap
11+
1408 target-aarch64/acap/object_detection_1_0_0_aarch64.eap
1112
10362 target-aarch64/acap/reverse_proxy_0_0_0_aarch64.eap
1213
3430 target-aarch64/acap/send_event_1_0_0_aarch64.eap
1314
899 target-aarch64/acap/using_a_build_script_0_0_0_aarch64.eap

apps/object_detection/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "object_detection"
3+
version = "0.0.0"
4+
edition.workspace = true
5+
publish = false
6+
7+
[dependencies]
8+
anyhow = { workspace = true }
9+
log = { workspace = true }
10+
11+
acap-logging = { workspace = true }
12+
larod-sys = { workspace = true }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"schemaVersion": "1.4.0",
3+
"acapPackageConf": {
4+
"setup": {
5+
"appName": "object_detection",
6+
"vendor": "Axis Communications",
7+
"runMode": "never",
8+
"version": "1.0.0"
9+
}
10+
}
11+
}

apps/object_detection/src/main.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! This application loads a larod model which takes an image as input and outputs values
2+
//! corresponding to the class, score and location of detected objects in the image.
3+
//!
4+
//! # Arguments
5+
//!
6+
//! 1. `MODEL`: a string describing the path to the model.
7+
//! 2. `WIDTH`: an integer for the input width. ß
8+
//! 3. `HEIGHT`: an integer for the input height.
9+
//! 4. `QUALITY`: an integer for the desired jpeg quality.
10+
//! 5. `RAW_WIDTH`: an integer for camera width resolution.
11+
//! 6. `RAW_HEIGHT`: an integer for camera height resolution.
12+
//! 7. `THRESHOLD`: an integer ranging from 0 to 100 to select good detections.
13+
//! 8. `LABELSFILE`: a string describing the path to the label txt.
14+
15+
use log::{error, info};
16+
17+
fn main() {
18+
acap_logging::init_logger();
19+
let mut conn: *mut larod_sys::larodConnection = std::ptr::null_mut();
20+
let mut error: *mut larod_sys::larodError = std::ptr::null_mut();
21+
if unsafe { !larod_sys::larodConnect(&mut conn, &mut error) } {
22+
error!("Could not connect to larod");
23+
return;
24+
}
25+
assert!(error.is_null());
26+
27+
let mut num_sessions = u64::MAX;
28+
if unsafe { !larod_sys::larodGetNumSessions(conn, &mut num_sessions, &mut error) } {
29+
error!("Could not get the number of sessions");
30+
return;
31+
}
32+
33+
info!("Number of sessions: {num_sessions}");
34+
todo!("Implement the real example")
35+
}

crates/larod-sys/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
build = "build.rs"
3+
name = "larod-sys"
4+
version = "0.0.0"
5+
edition.workspace = true
6+
license = "MIT"
7+
8+
[build-dependencies]
9+
bindgen = { workspace = true }
10+
pkg-config = { workspace = true }

crates/larod-sys/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::{env, path};
2+
3+
fn populated_bindings(dst: &path::PathBuf) {
4+
let library = pkg_config::Config::new().probe("liblarod").unwrap();
5+
let mut bindings = bindgen::Builder::default()
6+
.header("wrapper.h")
7+
.allowlist_recursively(false)
8+
.allowlist_function("^(larod.*)$")
9+
.allowlist_type("^(_?larod.*)$")
10+
.default_enum_style(bindgen::EnumVariation::NewType {
11+
is_global: false,
12+
is_bitfield: true,
13+
})
14+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
15+
.layout_tests(false);
16+
for path in library.include_paths {
17+
bindings = bindings.clang_args(&["-F", path.to_str().unwrap()]);
18+
}
19+
bindings.generate().unwrap().write_to_file(dst).unwrap();
20+
}
21+
22+
fn main() {
23+
let dst = path::PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
24+
if env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default() != "x86_64" {
25+
populated_bindings(&dst);
26+
}
27+
}

0 commit comments

Comments
 (0)