wrapper: build libk4arecord_v2.so — the library the recorder actually dlopens

The recorder does not load the stock libk4a/libk4arecord. It dlopens a single
custom libk4arecord_v2.so: the wrapper's MKV-writing sources linked to a
pure-data shim (k4a_shim.cpp) instead of libk4a, so recording has no OrbbecSDK
dependency. That target is FTF's own (wrapper/recordv2/), absent from the stock
wrapper the Orin carried — so ship it and inject+build it, the same pattern as
the recorder in the SDK examples tree. Idempotent; only added when missing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
AngePierreandClaude Opus 5 committed 2026-09-10 17:26:06 +02:00
1 parent 526d654f68
commit cabca69c4d
3 files changed
+482 -23

No files matched your search

+54 -23
View File
@@ -1,24 +1,29 @@
#!/usr/bin/env bash
# Makes sure the Orbbec K4A wrapper is built for THIS platform, and prints where
# it is as K4A_WRAPPER_DIR=... for build_sdk.sh (the recorder example needs its
# headers) and for the recorder's runtime rpath (its libk4a.so/libk4arecord.so).
# Makes sure the Orbbec K4A wrapper is built for THIS platform, INCLUDING FTF's
# libk4arecord_v2.so, and prints K4A_WRAPPER_DIR=... for build_sdk.sh (the recorder
# example needs the headers) and for the recorder's runtime rpath.
#
# This is the libk4a provider — Orbbec's own, NOT Microsoft's Azure Kinect SDK.
# It bundles its own OrbbecSDK internally, so it builds standalone. The recorder
# dlopens the libk4a it produces (RTLD_DEEPBIND) rather than link-time linking it,
# which is why only its build/lib path matters at runtime, not link time.
# This is the libk4a provider — Orbbec's own, NOT Microsoft's Azure Kinect SDK. It
# bundles its own OrbbecSDK, so it builds standalone.
#
# Reuses an existing build (leaving a working node untouched) or clones + builds.
# The recorder does not dlopen the stock libk4a/libk4arecord. It dlopens a single
# custom library, libk4arecord_v2.so: the wrapper's own MKV-writing sources linked
# to a pure-data shim (k4a_shim.cpp) instead of libk4a — K4A-compatible recording
# with no OrbbecSDK dependency. That target is FTF's (wrapper/recordv2/ in this
# repo), not part of the stock wrapper, so it is injected and built here.
#
# Reuses an existing build; only adds the v2 target if it is missing.
set -euo pipefail
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
repo=$(cd "$here/.." && pwd)
eval "$("$here/detect_platform.sh")"
REPO_URL="${OB_K4A_REPO:-https://github.com/orbbec/OrbbecSDK-K4A-Wrapper}"
# The tag the Nano runs. A caller can override to one known to build on a newer
# JetPack.
REF="${OB_K4A_REF:-v1.10.4}"
# A usable wrapper base: headers and the stock libk4a. The v2 target is ensured
# separately, so a wrapper built before this repo existed still qualifies.
find_wrapper() {
local d="$1"
[[ -f "$d/include/k4a/k4a.h" ]] || return 1
@@ -26,42 +31,68 @@ find_wrapper() {
echo "$d"
}
# Injects FTF's recordv2 sources and builds libk4arecord_v2.so if it is not there.
# Idempotent: the add_subdirectory line and the copy are guarded.
ensure_recordv2() {
local d="$1"
[[ -f "$d/build/lib/libk4arecord_v2.so" ]] && return 0
echo ">> libk4arecord_v2.so absent — injection de recordv2 et compilation…" >&2
local dst="$d/src/orbbec/recordv2"
mkdir -p "$dst"
cp "$repo/wrapper/recordv2/CMakeLists.txt" "$dst/"
cp "$repo/wrapper/recordv2/k4a_shim.cpp" "$dst/"
local ob_cmake="$d/src/orbbec/CMakeLists.txt"
if [[ -f "$ob_cmake" ]] && ! grep -q "add_subdirectory(recordv2)" "$ob_cmake"; then
echo "add_subdirectory(recordv2)" >> "$ob_cmake"
fi
( cd "$d/build"
cmake .. -DCMAKE_BUILD_TYPE=Release >&2
make -j"$(nproc)" k4arecord_v2 >&2 )
[[ -f "$d/build/lib/libk4arecord_v2.so" ]]
}
# 1 & 2: reuse a wrapper base, then make sure the v2 target is present.
for candidate in "${K4A_WRAPPER_DIR:-}" \
"$HOME/OrbbecSDK-K4A-Wrapper" \
"$HOME/Downloads/OrbbecSDK-K4A-Wrapper"; do
[[ -z "$candidate" ]] && continue
if find_wrapper "$candidate" >/dev/null 2>&1; then
echo ">> Wrapper K4A deja bati, reutilise: $candidate" >&2
echo "K4A_WRAPPER_DIR=$candidate"
exit 0
echo ">> Wrapper K4A trouve: $candidate" >&2
if ensure_recordv2 "$candidate"; then
echo "K4A_WRAPPER_DIR=$candidate"
exit 0
fi
echo "!! libk4arecord_v2.so n'a pas pu etre bati dans $candidate" >&2
exit 1
fi
done
# 3: clone + build the wrapper base, then the v2 target.
dir="${K4A_WRAPPER_DIR:-$HOME/OrbbecSDK-K4A-Wrapper}"
echo ">> Wrapper K4A absent — clone et compilation (JetPack ${JETPACK}, ${SOC})" >&2
echo ">> ${REPO_URL} @ ${REF} -> ${dir}" >&2
if [[ ! -d "$dir/.git" ]]; then
# --recursive: the wrapper carries its OrbbecSDK and depth engine as submodules.
git clone --recursive --depth 1 --branch "$REF" "$REPO_URL" "$dir" >&2
fi
mkdir -p "$dir/build"
(
cd "$dir/build"
cmake .. -DCMAKE_BUILD_TYPE=Release >&2
make -j"$(nproc)" k4a k4arecord >&2
)
( cd "$dir/build"
cmake .. -DCMAKE_BUILD_TYPE=Release >&2
make -j"$(nproc)" k4a k4arecord >&2 )
if ! find_wrapper "$dir" >/dev/null 2>&1; then
if ! find_wrapper "$dir" >/dev/null 2>&1 || ! ensure_recordv2 "$dir"; then
cat >&2 <<EOF
!! La compilation du wrapper K4A ne s'est pas terminee comme attendu
!! (libk4a.so absent de $dir/build/lib).
!! La compilation du wrapper K4A (ou de libk4arecord_v2.so) a echoue dans $dir.
!! Bâtis-le une fois a la main, puis relance install.sh avec :
!! K4A_WRAPPER_DIR=$dir ./install.sh
EOF
exit 1
fi
echo ">> Wrapper K4A bati: $dir" >&2
echo ">> Wrapper K4A + libk4arecord_v2.so batis: $dir" >&2
echo "K4A_WRAPPER_DIR=$dir"