Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cs cannot be built on Armbian, so let's not depend on it #288

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ if [[ -z "${CROWSNEST_CAMERA_STREAMER_REPO_BRANCH}" ]]; then
CROWSNEST_CAMERA_STREAMER_REPO_BRANCH="master"
fi


# Paths of repos
ALL_PATHS=(
"${BASE_CN_BIN_PATH}"/"${USTREAMER_PATH}"
Expand All @@ -68,7 +67,7 @@ show_help() {
### Check if device is Raspberry Pi
is_raspberry_pi() {
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry" /proc/device-tree/model; then
grep -q "Raspberry" /proc/device-tree/model; then
echo "1"
else
echo "0"
Expand All @@ -77,13 +76,13 @@ is_raspberry_pi() {

is_bookworm() {
if [[ -f /etc/os-release ]]; then
grep -cq "bookworm" /etc/os-release &> /dev/null && echo "1" || echo "0"
grep -cq "bookworm" /etc/os-release &>/dev/null && echo "1" || echo "0"
fi
}

is_pi5() {
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry Pi 5" /proc/device-tree/model; then
grep -q "Raspberry Pi 5" /proc/device-tree/model; then
echo "1"
else
echo "0"
Expand All @@ -92,7 +91,15 @@ is_pi5() {

is_ubuntu_arm() {
if [[ "$(is_raspberry_pi)" = "1" ]] &&
grep -q "ubuntu" /etc/os-release; then
grep -q "ubuntu" /etc/os-release; then
echo "1"
else
echo "0"
fi
}

is_armbian() {
if grep -q "Armbian" /etc/os-release; then
echo "1"
else
echo "0"
Expand Down Expand Up @@ -135,9 +142,10 @@ clone_cstreamer() {
## Special handling because only supported on Raspberry Pi
[[ -n "${CROWSNEST_UNATTENDED}" ]] || CROWSNEST_UNATTENDED="0"
if { [[ "$(is_raspberry_pi)" = "0" ]] ||
[[ "$(is_pi5)" = "1" ]] ||
[[ "$(is_ubuntu_arm)" = "1" ]]; } &&
[[ "${CROWSNEST_UNATTENDED}" = "0" ]]; then
[[ "$(is_pi5)" = "1" ]] ||
[[ "$(is_ubuntu_arm)" = "1" ]] ||
[[ "$(is_armbian)" = "1" ]]; } &&
[[ "${CROWSNEST_UNATTENDED}" = "0" ]]; then
printf "Device is not supported! Cloning camera-streamer ... [SKIPPED]\n"
return
fi
Expand Down Expand Up @@ -170,11 +178,11 @@ clean_apps() {
for app in "${ALL_PATHS[@]}"; do
if [[ ! -d "${app}" ]]; then
printf "'%s' does not exist! Clean ... [SKIPPED]\n" "${app}"
else
else
printf "\nRunning 'make clean' in %s ... \n" "${app}"
pushd "${app}" &> /dev/null || exit 1
pushd "${app}" &>/dev/null || exit 1
make clean
popd &> /dev/null || exit 1
popd &>/dev/null || exit 1
fi
done
printf "\nRunning 'make clean' ... [DONE]\n"
Expand All @@ -196,9 +204,9 @@ build_apps() {
fi
if [[ -d "${path}" ]]; then
printf "Build '%s' using ${USE_PROCS##-j} Cores ... \n" "${path##*/}"
pushd "${path}" &> /dev/null || exit 1
pushd "${path}" &>/dev/null || exit 1
make "${USE_PROCS}"
popd &> /dev/null || exit 1
popd &>/dev/null || exit 1
printf "Build '%s' ... [SUCCESS]\n" "${path##*/}"
fi
done
Expand All @@ -221,31 +229,31 @@ main() {
## Get opts
while true; do
case "${1}" in
-b|--build)
build_apps
break
-b | --build)
build_apps
break
;;
-c|--clean)
clean_apps
break
-c | --clean)
clean_apps
break
;;
-d|--delete)
delete_apps
break
-d | --delete)
delete_apps
break
;;
-h|--help)
show_help
break
-h | --help)
show_help
break
;;
-r|--reclone)
delete_apps
clone_apps
break
-r | --reclone)
delete_apps
clone_apps
break
;;
*)
printf "Unknown option: %s" "${1}"
show_help
break
*)
printf "Unknown option: %s" "${1}"
show_help
break
;;
esac
done
Expand Down
9 changes: 5 additions & 4 deletions libs/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set -Ee

## Version of crowsnest
function self_version {
pushd "${BASE_CN_PATH}" &> /dev/null
pushd "${BASE_CN_PATH}" &>/dev/null
git describe --always --tags
popd &> /dev/null
popd &>/dev/null
}

# Init Traps
Expand Down Expand Up @@ -96,8 +96,9 @@ function check_apps {

## Avoid dependency check if non rpi sbc
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ "$(is_ubuntu_arm)" = "0" ]] &&
[[ "$(is_pi5)" = "0" ]]; then
[[ "$(is_ubuntu_arm)" = "0" ]] &&
[[ "$(is_armbian)" = "0" ]] &&
[[ "$(is_pi5)" = "0" ]]; then
if [[ -x "${BASE_CN_PATH}/${cstreamer}" ]]; then
log_msg "Dependency: '${cstreamer##*/}' found in ${cstreamer}."
else
Expand Down
56 changes: 32 additions & 24 deletions libs/hwhandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -Ee
### Detect Hardware
detect_avail_cams() {
local avail realpath
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null)"
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2>/dev/null)"
count="$(echo "${avail}" | wc -l)"
if [[ -d "/dev/v4l/by-id/" ]] && [[ -n "${avail}" ]]; then
log_msg "INFO: Found ${count} available v4l2 (UVC) camera(s)"
Expand All @@ -43,7 +43,7 @@ list_cam_formats() {
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "Supported Formats:"
while read -r i; do
printf "%s\t\t%s\n" "${prefix}" "${i}" >> "${CROWSNEST_LOG_PATH}"
printf "%s\t\t%s\n" "${prefix}" "${i}" >>"${CROWSNEST_LOG_PATH}"
done < <(v4l2-ctl -d "${device}" --list-formats-ext | sed '1,3d')
}

Expand All @@ -53,15 +53,15 @@ list_cam_v4l2ctrls() {
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "Supported Controls:"
while read -r i; do
printf "%s\t\t%s\n" "${prefix}" "${i}" >> "${CROWSNEST_LOG_PATH}"
printf "%s\t\t%s\n" "${prefix}" "${i}" >>"${CROWSNEST_LOG_PATH}"
done < <(v4l2-ctl -d "${device}" --list-ctrls-menus)
}

## Determine connected libcamera (CSI) device
detect_libcamera() {
local avail
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ -x "$(command -v libcamera-hello)" ]]; then
[[ -x "$(command -v libcamera-hello)" ]]; then
avail="$(libcamera-hello --list-cameras | grep -c "Available" || echo "0")"
if [[ "${avail}" = "1" ]]; then
get_libcamera_path | wc -l
Expand All @@ -76,9 +76,9 @@ detect_libcamera() {
## Spit /base/soc path for libcamera device
get_libcamera_path() {
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ -x "$(command -v libcamera-hello)" ]]; then
libcamera-hello --list-cameras | sed '1,2d' \
| grep "\(/base/*\)" | cut -d"(" -f2 | tr -d '$)'
[[ -x "$(command -v libcamera-hello)" ]]; then
libcamera-hello --list-cameras | sed '1,2d' |
grep "\(/base/*\)" | cut -d"(" -f2 | tr -d '$)'
fi
}

Expand All @@ -88,22 +88,22 @@ list_picam_resolution() {
prefix="$(date +'[%D %T]') crowsnest:"
log_msg "'libcamera' device(s) resolution(s) :"
while IFS= read -r i; do
printf "%s\t\t%s\n" "${prefix}" "${i}" >> "${CROWSNEST_LOG_PATH}"
printf "%s\t\t%s\n" "${prefix}" "${i}" >>"${CROWSNEST_LOG_PATH}"
done < <(libcamera-hello --list-cameras | sed '1,2d;s/Modes:/Colorspace:/')
}

get_libcamera_controls() {
local ust_bin flags
flags=( --camera-type=libcamera --camera-list_options )
flags=(--camera-type=libcamera --camera-list_options)
ust_bin="${BASE_CN_PATH}/bin/camera-streamer/camera-streamer"
if [[ -x "${ust_bin}" ]]; then
"${ust_bin}" "${flags[@]}" --camera-path="$(get_libcamera_path)" 2> /dev/null | \
sed 's/device//g;/^SNAPSHOT/q' | sed '/^SNAPSHOT/d' | \
sed '/^CAMERA/d;/- property/d' | sed '/camera-streamer Version:/d' | \
sed 's/- available option: //g' | sed '/^$/d;' | \
sed 's/([0-9]*[a-z,0-9]\, /(/g' | sed '/type=7/d;/type=4/d;/type=Rectangle/d' | \
sed 's/type=1/bool/g;s/type=3/int/g;s/type=5/float/g' | sed 's/type=//g;' | \
sed 's/\[/min=/g;s/\.\./ max=/g;s/\]$//g'
"${ust_bin}" "${flags[@]}" --camera-path="$(get_libcamera_path)" 2>/dev/null |
sed 's/device//g;/^SNAPSHOT/q' | sed '/^SNAPSHOT/d' |
sed '/^CAMERA/d;/- property/d' | sed '/camera-streamer Version:/d' |
sed 's/- available option: //g' | sed '/^$/d;' |
sed 's/([0-9]*[a-z,0-9]\, /(/g' | sed '/type=7/d;/type=4/d;/type=Rectangle/d' |
sed 's/type=1/bool/g;s/type=3/int/g;s/type=5/float/g' | sed 's/type=//g;' |
sed 's/\[/min=/g;s/\.\./ max=/g;s/\]$//g'
else
log_msg "WARN: 'libcamera' device option can not be displayed, because"
log_msg "WARN: camera-streamer is not installed"
Expand All @@ -127,17 +127,17 @@ list_picam_controls() {
function detect_legacy {
local avail
if [[ "$(is_raspberry_pi)" = "1" ]] &&
command -v vcgencmd &> /dev/null; then
if vcgencmd get_camera &> /dev/null; then
avail="$( vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)"
command -v vcgencmd &>/dev/null; then
if vcgencmd get_camera &>/dev/null; then
avail="$(vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)"
fi
fi
echo "${avail:-0}"
}

function dev_is_legacy {
v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}'
v4l2-ctl --list-devices | grep -A1 -e 'mmal' |
awk 'NR==2 {print $1}'
}

## Determine if cam has H.264 Hardware encoder
Expand All @@ -161,7 +161,7 @@ detect_mjpeg() {
## Check if device is raspberry sbc
is_raspberry_pi() {
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry" /proc/device-tree/model; then
grep -q "Raspberry" /proc/device-tree/model; then
echo "1"
else
echo "0"
Expand All @@ -170,7 +170,7 @@ is_raspberry_pi() {

is_pi5() {
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry Pi 5" /proc/device-tree/model; then
grep -q "Raspberry Pi 5" /proc/device-tree/model; then
echo "1"
else
echo "0"
Expand All @@ -179,7 +179,15 @@ is_pi5() {

is_ubuntu_arm() {
if [[ "$(is_raspberry_pi)" = "1" ]] &&
grep -q "ubuntu" /etc/os-release; then
grep -q "ubuntu" /etc/os-release; then
echo "1"
else
echo "0"
fi
}

is_armbian() {
if grep -q "Armbian" /etc/os-release; then
echo "1"
else
echo "0"
Expand Down
31 changes: 17 additions & 14 deletions libs/init_stream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ function construct_streamer {
mode="$(get_param "cam ${cams}" mode)"
check_section "${cams}"
case ${mode} in
[mM]ulti | camera-streamer)
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[mM]ulti | camera-streamer)
if [[ "$(is_raspberry_pi)" = "1" ]] &&
[[ "$(is_ubuntu_arm)" = "0" ]] &&
[[ "$(is_armbian)" = "0" ]] &&
[[ "$(is_pi5)" = "0" ]]; then
MULTI_INSTANCES+=( "${cams}" )
else
log_msg "WARN: Mode 'camera-streamer' is not supported on your device!"
log_msg "WARN: Falling back to Mode 'ustreamer'"
MJPG_INSTANCES+=( "${cams}" )
fi
MULTI_INSTANCES+=("${cams}")
else
log_msg "WARN: Mode 'camera-streamer' is not supported on your device!"
log_msg "WARN: Falling back to Mode 'ustreamer'"
MJPG_INSTANCES+=("${cams}")
fi
;;
mjpg | mjpeg | ustreamer)
MJPG_INSTANCES+=( "${cams}" )
mjpg | mjpeg | ustreamer)
MJPG_INSTANCES+=("${cams}")
;;
?|*)
unknown_mode_msg
MJPG_INSTANCES+=( "${cams}" )
? | *)
unknown_mode_msg
MJPG_INSTANCES+=("${cams}")

;;
esac
Expand All @@ -53,6 +54,8 @@ function construct_streamer {
if [ "${#MJPG_INSTANCES[@]}" != "0" ]; then
run_mjpg "${MJPG_INSTANCES[*]}"
fi
sleep 2 & sleep_pid="$!" ; wait "${sleep_pid}"
sleep 2 &
sleep_pid="$!"
wait "${sleep_pid}"
log_msg " ... Done!"
}
Loading