Skip to content

Commit

Permalink
Merge develop branch (#163)
Browse files Browse the repository at this point in the history
* Fix makefile flags on low memory devices (#124)

* Fix `makefile` flags on low memory devices

On devices with less than 512MB existing devices will use `-j2` due to wrong condition.

* docs: Update index with correct heading and link to backends (#131)

This is a follow-up to #108 and fixes heading and hyperlink to the list of backends

* Typo in `core.sh` (#138)

* Fix makefile flags on low memory devices (#124) (#125)

* Fix `makefile` flags on low memory devices

On devices with less than 512MB existing devices will use `-j2` due to wrong condition.

Co-authored-by: Kamil Trzciński <[email protected]>

* Typo in `core.sh`

'Dependencys' --> dependencies

---------

Co-authored-by: Stephan Wendel <[email protected]>
Co-authored-by: Kamil Trzciński <[email protected]>

* Fix makefile flags on low memory devices (#124) (#125) (#144)

* Fix `makefile` flags on low memory devices

On devices with less than 512MB existing devices will use `-j2` due to wrong condition.

Co-authored-by: Kamil Trzciński <[email protected]>

* docs(messages.sh): fix typos, improve spelling (#145)

* feat: add legacy cam support (#146)

* feat: add legacy cam support

Signed-off-by: Patrick Gehrsitz <[email protected]>

* feat: add blockyfix

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: add ustreamer legacy cam workaround

Signed-off-by: Patrick Gehrsitz <[email protected]>

---------

Signed-off-by: Patrick Gehrsitz <[email protected]>

* Fix makefile flags on low memory devices (#124) (#125) (#147)

* Fix `makefile` flags on low memory devices

On devices with less than 512MB existing devices will use `-j2` due to wrong condition.

Co-authored-by: Kamil Trzciński <[email protected]>

* fix: fix make config empty path (#148)

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: fix default_path_msg function name (#149)

* fix: fix default_path_msg function name

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: fix message

Signed-off-by: Patrick Gehrsitz <[email protected]>

---------

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: fix libcamera-apps-lite not getting updated (#160)

libcamera-apps-lite is needed for libcamera-hello.
Crowsnest uses libcamera-hello to detected raspicams

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: fix Shellcheck test error (#153)

* fix: fix Shellcheck test error

Signed-off-by: Patrick Gehrsitz <[email protected]>

* style: remove empty condition

Signed-off-by: Patrick Gehrsitz <[email protected]>

---------

Signed-off-by: Patrick Gehrsitz <[email protected]>

* fix: fix CustomPiOS docker build error (#158)

This should skip any check of `SUDO_USER`

Tested with Win & Linux host with Docker 

Signed-off-by: Patrick Gehrsitz <[email protected]>

---------

Signed-off-by: Patrick Gehrsitz <[email protected]>
Co-authored-by: Kamil Trzciński <[email protected]>
Co-authored-by: DeviousFusion <[email protected]>
Co-authored-by: Sergei <[email protected]>
Co-authored-by: Patrick Gehrsitz <[email protected]>
  • Loading branch information
5 people authored Aug 11, 2023
1 parent 8b54eae commit f6e2156
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A wrapper script for webcam streaming on Raspberry Pi OS Lite images like [Mains
- [Contribute](#contribute)
- [How to support us?](#how-to-support-us)
- [CustomPiOS-module](#custompios-module)
- [What 'Backends' uses crowsnest?](#what-backends-uses-crowsnest)
- [What 'Backends' does crowsnest use](#what-backends-does-crowsnest-use)
- [Credits](#credits)

---
Expand Down
2 changes: 1 addition & 1 deletion libs/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function check_apps {
# print_cfg, see libs/logging.sh L#75
# pint_cams, see libs/logging.sh L#84
function initial_check {
log_msg "INFO: Checking Dependencys"
log_msg "INFO: Checking Dependencies"
check_dep "crudini"
check_dep "find"
check_dep "xargs"
Expand Down
17 changes: 17 additions & 0 deletions libs/hwhandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ get_libcamera_path() {
fi
}

# Determine connected "legacy" device
function detect_legacy {
local avail
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry" /proc/device-tree/model; then
avail="$(vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)"
else
avail="0"
fi
echo "${avail}"
}

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

## Determine if cam has H.264 Hardware encoder
## call detect_h264 <nameornumber> ex.: detect_h264 foobar
## returns 1 = true / 0 = false ( numbers are strings! not int!)
Expand Down
11 changes: 10 additions & 1 deletion libs/logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function print_cfg {
function print_cams {
local total v4l
v4l="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null | wc -l)"
total="$((v4l+($(detect_libcamera))))"
total="$((v4l+($(detect_libcamera))+($(detect_legacy))))"
if [ "${total}" -eq 0 ]; then
log_msg "ERROR: No usable Devices Found. Stopping $(basename "${0}")."
exit 1
Expand All @@ -100,6 +100,15 @@ function print_cams {
if [[ "$(detect_libcamera)" -ne 0 ]]; then
log_msg "Detected 'libcamera' device -> $(get_libcamera_path)"
fi
if [[ "$(detect_legacy)" -ne 0 ]]; then
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}')"
log_msg "Detected 'Raspicam' Device -> ${raspicam}"
if [[ ! "${CROWSNEST_LOG_LEVEL}" = "quiet" ]]; then
list_cam_formats "${raspicam}"
list_cam_v4l2ctrls "${raspicam}"
fi
fi
if [[ -d "/dev/v4l/by-id/" ]]; then
detect_avail_cams
fi
Expand Down
16 changes: 11 additions & 5 deletions libs/ustreamer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ run_mjpg() {
for instance in ${cams} ; do
run_ustreamer "${instance}" &
done
blockyfix
brokenfocus
return
}
Expand All @@ -45,12 +46,17 @@ run_ustreamer() {
start_param=( --host 127.0.0.1 -p "${pt}" )
fi

# Add device
start_param+=( -d "${dev}" --device-timeout=2 )
#Raspicam Workaround
if [[ "${dev}" = "$(dev_is_legacy)" ]]; then
start_param+=( -m MJPEG --device-timeout=5 --buffers=3 )
else
# Add device
start_param+=( -d "${dev}" --device-timeout=2 )

# Use MJPEG Hardware encoder if possible
if [ "$(detect_mjpeg "${cam_sec}")" = "1" ]; then
start_param+=( -m MJPEG --encoder=HW )
# Use MJPEG Hardware encoder if possible
if [ "$(detect_mjpeg "${cam_sec}")" = "1" ]; then
start_param+=( -m MJPEG --encoder=HW )
fi
fi

# set max framerate
Expand Down
27 changes: 27 additions & 0 deletions libs/v4l2_control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,30 @@ function brokenfocus {
main

}

# This function is to set bitrate on raspicams.
# If raspicams set to variable bitrate, they tend to show
# a "block-like" view after reboots
# To prevent that blockyfix should apply constant bitrate befor start of ustreamer
# See https://github.com/mainsail-crew/crowsnest/issues/33
function blockyfix {
local dev v4l2ctl

# call set_bitrate <device>
function set_bitrate {
v4l2-ctl -d "${1}" -c video_bitrate_mode=1 2> /dev/null
v4l2-ctl -d "${1}" -c video_bitrate=15000000 2> /dev/null
}

for cam in $(configured_cams); do
dev="$(get_param "cam ${cam}" device)"
v4l2ctl="$(get_param "cam ${cam}" v4l2ctl)"
if [ "${dev}" = "$(dev_is_legacy)" ]; then
if [ -z "${v4l2ctl}" ] ||
[ "$(grep -c "video_bitrate" <<< "${v4l2ctl}")" == "0" ]; then
set_bitrate "${dev}"
blockyfix_msg_1
fi
fi
done
}
17 changes: 6 additions & 11 deletions tools/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ set -Ee
CN_CONFIG_USER=$(whoami)
CN_CONFIG_CONFIGFILE="tools/.config"
CN_CONFIG_ROOTPATH="/home/${CN_CONFIG_USER}/printer_data"
# CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
# CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
# CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
# CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
CN_USTREAMER_REPO="https://github.com/pikvm/ustreamer.git"
CN_USTREAMER_BRANCH="master"
CN_CAMERA_STREAMER_REPO="https://github.com/ayufan-research/camera-streamer.git"
Expand Down Expand Up @@ -165,20 +165,15 @@ specify_root_path() {
local reply
root_path_msg
default_path_msg
read -erp "Please enter path: " reply
if [[ -z "${reply}" ]]; then
echo -e "CROWSNEST_CONFIG_PATH=\"${CN_CONFIG_CONFIGPATH}\"" >> \
"${CN_CONFIG_CONFIGFILE}"
return 0
fi
read -erp "Please enter path: " -i "${CN_CONFIG_ROOTPATH}" reply
if [[ -n "${reply}" ]]; then
CN_CONFIG_ROOTPATH="${reply}"
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
return 0
fi
return 0
}

specify_config_path() {
Expand Down
2 changes: 1 addition & 1 deletion tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ main() {
exit 1
fi

if [[ -z "${SUDO_USER}" ]]; then
if [[ -z "${SUDO_USER}" ]] && [[ "${CROWSNEST_UNATTENDED}" != "1" ]]; then
need_sudo_msg
exit 1
fi
Expand Down
23 changes: 12 additions & 11 deletions tools/libs/messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -Ee
# set -x


TITLE="\e[31mcrowsnest\e[0m - A webcam daemon for multiple Cams and stream services."
TITLE="\e[31mcrowsnest\e[0m - A webcam daemon for multiple cams and stream services."

### Messages
msg() {
Expand All @@ -48,45 +48,46 @@ status_msg() {

not_as_root_msg() {
msg "\n\tPlease do NOT run this script as root!\n"
msg "\tLogin in as regular user and run with '\e[32msudo make install\e[0m'\n\n"
msg "\tLogin in as a regular user and run with '\e[32msudo make install\e[0m'\n\n"
}

need_sudo_msg() {
msg "\n\tYou need to run this script with sudo priviledges!"
msg "\n\tYou need to run this script with sudo privileges!"
msg "\tPlease try '\e[32msudo make install\e[0m'\n\nExiting..."
}

not_supported_msg() {
msg "\nDebian 10 (buster) has reached end of life.\n"
msg "Therefor crowsnest has also end support for this.\n"
msg "We are sorry for inconvinience...\n"
msg "Therefore, crowsnest has also ended support for it.\n"
msg "Please upgrade to a supported OS release,"
msg "we are sorry for the inconvenience.\n"
}

welcome_msg() {
msg "${TITLE}\n"
msg "\t\e[34mAhoi!\e[0m"
msg "\t\e[34mAhoy!\e[0m"
msg "\tThank you for installing crowsnest ;)"
msg "\tThis will take a while ... "
msg "\tPlease reboot after installation has finished.\n"
msg "\tPlease reboot after the installation has finished.\n"
sleep 1
}

config_msg() {
msg "\nConfig file not found!\n\tUsing defaults ..."
msg "\tThis uses paths located in 'printer_data' of your Home Folder."
msg "\tThis uses paths located in 'printer_data' of your home folder."
}

goodbye_msg() {
msg "\nInstallation \e[32msuccessful\e[0m.\n"
msg "\t\e[33mTo take changes effect, you need to reboot your machine!\e[0m\n"
msg "\t\e[33mReboot your machine for the changes to take effect!\e[0m\n"
}

unattended_success_msg() {
msg "\nInstallation \e[32msuccessful\e[0m.\n"
}

error_msg() {
msg "Something went wrong!\nPlease copy the last output and head over to\n"
msg "Something went wrong!\nPlease copy the latest output, head over to\n"
msg "\thttps://discord.gg/mainsail\n"
msg "open a ticket in #supportforum ..."
msg "and open a ticket in #supportforum..."
}
2 changes: 1 addition & 1 deletion tools/libs/pkglist-rpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ PKGLIST="git crudini bsdutils findutils v4l-utils curl"
### Ustreamer Dependencies
PKGLIST="${PKGLIST} build-essential libevent-dev libjpeg-dev libbsd-dev"
### Camera-Streamer Dependencies
PKGLIST="${PKGLIST} cmake libavformat-dev libavutil-dev libavcodec-dev libcamera-dev"
PKGLIST="${PKGLIST} cmake libavformat-dev libavutil-dev libavcodec-dev libcamera-dev libcamera-apps-lite"
PKGLIST="${PKGLIST} liblivemedia-dev pkg-config xxd build-essential cmake libssl-dev"
2 changes: 1 addition & 1 deletion tools/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -Ee
# set -x

# Global Vars
TITLE="\e[31mcrowsnest\e[0m - A webcam daemon for multiple Cams and stream services."
TITLE="\e[31mcrowsnest\e[0m - A webcam daemon for multiple cams and stream services."
SRC_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd -P)"
SERVICE_FILE="/etc/systemd/system/crowsnest.service"

Expand Down

0 comments on commit f6e2156

Please sign in to comment.