REFACTOR: Ensure shellcheck compatibility
* Modified install.sh * Added libs/ustreamer.sh * Added libs/v4l2rtspserver.sh * Modified uninstall.sh * Modified webcamd REFACTOR: Split run_rtsp to libs/v4l2rtspserver.sh * Modified webcamd accordingly REFACTOR: Split run_ustreamer to libs/ustreamer.sh * Updated webcamd accordingly Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
parent
064c4deb61
commit
a186b4e09e
45
install.sh
45
install.sh
@ -8,6 +8,9 @@
|
|||||||
# Version 2
|
# Version 2
|
||||||
########
|
########
|
||||||
|
|
||||||
|
# shellcheck enable=requires-variable-braces
|
||||||
|
## disabeld SC2086 for some lines because there we want 'word splitting'
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
## Debug
|
## Debug
|
||||||
@ -63,9 +66,9 @@ function install_cleanup_trap() {
|
|||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
# make sure that all child processed die when we die
|
# make sure that all child processed die when we die
|
||||||
local pids=$(jobs -pr)
|
|
||||||
echo -e "Killed by user ...\r\nGoodBye ...\r"
|
echo -e "Killed by user ...\r\nGoodBye ...\r"
|
||||||
[ -n "$pids" ] && kill $pids && sleep 5 && kill -9 $pids
|
# shellcheck disable=2046
|
||||||
|
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
|
||||||
}
|
}
|
||||||
##
|
##
|
||||||
|
|
||||||
@ -75,10 +78,9 @@ function err_exit {
|
|||||||
echo -e "ERROR: Stopping $(basename "$0")."
|
echo -e "ERROR: Stopping $(basename "$0")."
|
||||||
echo -e "Goodbye..."
|
echo -e "Goodbye..."
|
||||||
fi
|
fi
|
||||||
if [ -n "$(jobs -pr)" ]; then
|
# shellcheck disable=2046
|
||||||
kill $(jobs -pr)
|
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
|
||||||
fi
|
exit 1
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### Init ERR Trap
|
### Init ERR Trap
|
||||||
@ -87,7 +89,8 @@ trap 'err_exit $? $LINENO' ERR
|
|||||||
### Import config from custompios.
|
### Import config from custompios.
|
||||||
function import_config {
|
function import_config {
|
||||||
if [ -f "${HOME}/crowsnest/custompios/crowsnest/config" ]; then
|
if [ -f "${HOME}/crowsnest/custompios/crowsnest/config" ]; then
|
||||||
source ${HOME}/crowsnest/custompios/crowsnest/config
|
# shellcheck source-path=file_templates/custompios/crowsnest/config
|
||||||
|
source "$PWD"/custompios/crowsnest/config
|
||||||
else
|
else
|
||||||
echo -e "${TITLE}\n"
|
echo -e "${TITLE}\n"
|
||||||
echo -e "OOPS!\nConfiguration File missing! Exiting..."
|
echo -e "OOPS!\nConfiguration File missing! Exiting..."
|
||||||
@ -124,7 +127,7 @@ function remove_existing_webcamd {
|
|||||||
fi
|
fi
|
||||||
if [ -d "${HOME}/mjpg-streamer" ]; then
|
if [ -d "${HOME}/mjpg-streamer" ]; then
|
||||||
echo -en "Removing 'mjpg-streamer' ...\r"
|
echo -en "Removing 'mjpg-streamer' ...\r"
|
||||||
sudo rm -rf ${HOME}/mjpg-streamer > /dev/null
|
sudo rm -rf "${HOME}"/mjpg-streamer > /dev/null
|
||||||
echo -e "Removing 'mjpg-streamer' ... \t[OK]\r"
|
echo -e "Removing 'mjpg-streamer' ... \t[OK]\r"
|
||||||
fi
|
fi
|
||||||
if [ -f "/etc/systemd/system/webcamd.service" ]; then
|
if [ -f "/etc/systemd/system/webcamd.service" ]; then
|
||||||
@ -135,7 +138,7 @@ function remove_existing_webcamd {
|
|||||||
if [ -f "/var/log/webcamd.log" ]; then
|
if [ -f "/var/log/webcamd.log" ]; then
|
||||||
echo -en "Removing 'webcamd.log' ...\r"
|
echo -en "Removing 'webcamd.log' ...\r"
|
||||||
sudo rm -f /var/log/webcamd.log > /dev/null
|
sudo rm -f /var/log/webcamd.log > /dev/null
|
||||||
sudo rm -f ${HOME}/klipper_logs/webcamd.log > /dev/null
|
sudo rm -f "${HOME}"/klipper_logs/webcamd.log > /dev/null
|
||||||
echo -e "Removing 'webcamd.log' ... \t[OK]\r"
|
echo -e "Removing 'webcamd.log' ... \t[OK]\r"
|
||||||
fi
|
fi
|
||||||
if [ -f "/etc/logrotate.d/webcamd" ]; then
|
if [ -f "/etc/logrotate.d/webcamd" ]; then
|
||||||
@ -178,6 +181,7 @@ function install_crowsnest {
|
|||||||
echo -e "\nInstall webcamd Service ..."
|
echo -e "\nInstall webcamd Service ..."
|
||||||
## Install Dependencies
|
## Install Dependencies
|
||||||
echo -e "Installing 'crowsnest' Dependencies ..."
|
echo -e "Installing 'crowsnest' Dependencies ..."
|
||||||
|
# shellcheck disable=2086
|
||||||
sudo apt install --yes --no-install-recommends $CROWSNEST_DEPS > /dev/null
|
sudo apt install --yes --no-install-recommends $CROWSNEST_DEPS > /dev/null
|
||||||
echo -e "Installing 'crowsnest' Dependencies ... [OK]"
|
echo -e "Installing 'crowsnest' Dependencies ... [OK]"
|
||||||
## Link webcamd to $PATH
|
## Link webcamd to $PATH
|
||||||
@ -188,6 +192,7 @@ function install_crowsnest {
|
|||||||
# Make sure not to overwrite existing!
|
# Make sure not to overwrite existing!
|
||||||
if [ ! -f "${CROWSNEST_DEFAULT_CONF_DIR}/webcam.conf" ]; then
|
if [ ! -f "${CROWSNEST_DEFAULT_CONF_DIR}/webcam.conf" ]; then
|
||||||
echo -en "Copying webcam.conf ...\r"
|
echo -en "Copying webcam.conf ...\r"
|
||||||
|
# shellcheck disable=2086
|
||||||
sudo -u "${BASE_USER}" cp -rf $PWD/sample_configs/${CROWSNEST_DEFAULT_CONF} "${CROWSNEST_DEFAULT_CONF_DIR}"/webcam.conf
|
sudo -u "${BASE_USER}" cp -rf $PWD/sample_configs/${CROWSNEST_DEFAULT_CONF} "${CROWSNEST_DEFAULT_CONF_DIR}"/webcam.conf
|
||||||
echo -e "Copying webcam.conf ... [OK]\r"
|
echo -e "Copying webcam.conf ... [OK]\r"
|
||||||
fi
|
fi
|
||||||
@ -214,26 +219,27 @@ function install_ustreamer {
|
|||||||
bin_path="/usr/local/bin"
|
bin_path="/usr/local/bin"
|
||||||
echo -e "\nInstalling ustreamer ..."
|
echo -e "\nInstalling ustreamer ..."
|
||||||
echo -e "Installing ustreamer Dependencies ..."
|
echo -e "Installing ustreamer Dependencies ..."
|
||||||
|
# shellcheck disable=2086
|
||||||
sudo apt install --yes --no-install-recommends $CROWSNEST_USTREAMER_DEPS > /dev/null
|
sudo apt install --yes --no-install-recommends $CROWSNEST_USTREAMER_DEPS > /dev/null
|
||||||
echo -e "Installing ustreamer Dependencies ... \t[OK]"
|
echo -e "Installing ustreamer Dependencies ... \t[OK]"
|
||||||
echo -e "Cloning ustreamer Repo ..."
|
echo -e "Cloning ustreamer Repo ..."
|
||||||
pushd ${HOME} > /dev/null
|
pushd "${HOME}" > /dev/null
|
||||||
git clone "${CROWSNEST_USTREAMER_REPO_SHIP}" --depth=1
|
git clone "${CROWSNEST_USTREAMER_REPO_SHIP}" --depth=1
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
echo -e "Cloning ustreamer Repo ... [OK]"
|
echo -e "Cloning ustreamer Repo ... [OK]"
|
||||||
pushd ${HOME}/ustreamer > /dev/null
|
pushd "${HOME}"/ustreamer > /dev/null
|
||||||
echo -e "Compiling ustreamer ..."
|
echo -e "Compiling ustreamer ..."
|
||||||
if [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
|
if [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
|
||||||
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "y" ]; then
|
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "y" ]; then
|
||||||
echo -e "Compile ustreamer with OMX and GPIO Support..."
|
echo -e "Compile ustreamer with OMX and GPIO Support..."
|
||||||
WITH_OMX=1 WITH_GPIO=1 make -j$(nproc)
|
WITH_OMX=1 WITH_GPIO=1 make -j"$(nproc)"
|
||||||
elif [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
|
elif [ "${CROWSNEST_USTREAMER_WITH_OMX}" = "y" ] && \
|
||||||
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "n" ]; then
|
[ "${CROWSNEST_USTREAMER_WITH_GPIO}" = "n" ]; then
|
||||||
echo -e "Compile ustreamer with OMX Support..."
|
echo -e "Compile ustreamer with OMX Support..."
|
||||||
WITH_OMX=1 make -j $(nproc)
|
WITH_OMX=1 make -j"$(nproc)"
|
||||||
else
|
else
|
||||||
echo -e"Compile ustreamer without OMX and GPIO Support..."
|
echo -e"Compile ustreamer without OMX and GPIO Support..."
|
||||||
make -j $(nproc)
|
make -j"$(nproc)"
|
||||||
fi
|
fi
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
echo -en "Linking ustreamer ...\r"
|
echo -en "Linking ustreamer ...\r"
|
||||||
@ -249,16 +255,17 @@ function install_v4l2rtspserver {
|
|||||||
bin_path="/usr/local/bin"
|
bin_path="/usr/local/bin"
|
||||||
echo -e "\nInstalling v4l2rtspserver ..."
|
echo -e "\nInstalling v4l2rtspserver ..."
|
||||||
echo -e "Installing v4l2rtspserver Dependencies ..."
|
echo -e "Installing v4l2rtspserver Dependencies ..."
|
||||||
|
# shellcheck disable=2086
|
||||||
sudo apt install --yes --no-install-recommends $CROWSNEST_V4L2RTSP_DEPS > /dev/null
|
sudo apt install --yes --no-install-recommends $CROWSNEST_V4L2RTSP_DEPS > /dev/null
|
||||||
echo -e "Installing v4l2rtspserver Dependencies ... \t[OK]"
|
echo -e "Installing v4l2rtspserver Dependencies ... \t[OK]"
|
||||||
echo -e "Cloning v4l2rtspserver Repo ..."
|
echo -e "Cloning v4l2rtspserver Repo ..."
|
||||||
pushd ${HOME} > /dev/null
|
pushd "${HOME}" > /dev/null
|
||||||
git clone "${CROWSNEST_V4L2RTSP_REPO_SHIP}" --depth=1
|
git clone "${CROWSNEST_V4L2RTSP_REPO_SHIP}" --depth=1
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
echo -e "Cloning v4l2rtspserver Repo ... [OK]"
|
echo -e "Cloning v4l2rtspserver Repo ... [OK]"
|
||||||
pushd ${HOME}/v4l2rtspserver > /dev/null
|
pushd "${HOME}"/v4l2rtspserver > /dev/null
|
||||||
echo -e "Compiling v4l2rtspserver ..."
|
echo -e "Compiling v4l2rtspserver ..."
|
||||||
cmake . && make -j $(nproc)
|
cmake . && make -j"$(nproc)"
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
echo -en "Linking v4l2rtspserver ...\r"
|
echo -en "Linking v4l2rtspserver ...\r"
|
||||||
sudo ln -sf "${v4l2rtsp_bin}" "${bin_path}" > /dev/null
|
sudo ln -sf "${v4l2rtsp_bin}" "${bin_path}" > /dev/null
|
||||||
@ -301,7 +308,7 @@ detect_existing_webcamd
|
|||||||
## Golang not needed for now!
|
## Golang not needed for now!
|
||||||
# enable_backports
|
# enable_backports
|
||||||
echo -e "Running apt update first ..."
|
echo -e "Running apt update first ..."
|
||||||
sudo apt update
|
sudo apt update
|
||||||
install_crowsnest
|
install_crowsnest
|
||||||
install_ustreamer
|
install_ustreamer
|
||||||
install_v4l2rtspserver
|
install_v4l2rtspserver
|
||||||
@ -309,4 +316,4 @@ install_v4l2rtspserver
|
|||||||
install_raspicam_fix
|
install_raspicam_fix
|
||||||
goodbye_msg
|
goodbye_msg
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
61
libs/ustreamer.sh
Normal file
61
libs/ustreamer.sh
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#### ustreamer library
|
||||||
|
|
||||||
|
#### webcamd - A webcam Service for multiple Cams and Stream Services.
|
||||||
|
####
|
||||||
|
#### written by Stephan Wendel aka KwadFan
|
||||||
|
#### Copyright 2021
|
||||||
|
#### https://github.com/mainsail-crew/crowsnest
|
||||||
|
####
|
||||||
|
#### This File is distributed under GPLv3
|
||||||
|
####
|
||||||
|
|
||||||
|
# Exit upon Errors
|
||||||
|
set -e
|
||||||
|
|
||||||
|
|
||||||
|
function run_ustreamer {
|
||||||
|
local cam_section ustreamer_bin device port resolution fps custom
|
||||||
|
local raspicam start_param wwwroot
|
||||||
|
cam_section="${1}"
|
||||||
|
ustreamer_bin="$(whereis ustreamer | awk '{print $2}')"
|
||||||
|
device="$(get_param "cam ${cam_section}" device)"
|
||||||
|
port=$(get_param "cam ${cam_section}" port)
|
||||||
|
resolution=$(get_param "cam ${cam_section}" resolution)
|
||||||
|
fps=$(get_param "cam ${cam_section}" max_fps)
|
||||||
|
custom="$(get_param "cam ${cam_section}" custom_flags 2> /dev/null)"
|
||||||
|
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
|
||||||
|
awk 'NR==2 {print $1}')"
|
||||||
|
check_section "${cam_section}"
|
||||||
|
wwwroot="$(dirname $(readlink -qe $(whereis webcamd)))/ustreamer-www"
|
||||||
|
#Raspicam Workaround
|
||||||
|
if [ "${device}" == "${raspicam}" ]; then
|
||||||
|
start_param=(
|
||||||
|
--host 127.0.0.1 -p "${port}" -m MJPEG --device-timeout=5
|
||||||
|
--buffers=3 -r "${resolution}" -f "${fps}" --allow-origin=\*
|
||||||
|
--static "${wwwroot}"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
start_param=(
|
||||||
|
-d "${device}" -r "${resolution}" -f "${fps}"
|
||||||
|
--host 127.0.0.1 -p "${port}" --allow-origin=\*
|
||||||
|
--device-timeout=2 --static "${wwwroot}"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
# Custom Flag Handling
|
||||||
|
if [ -n "${custom}" ]; then
|
||||||
|
start_param=(${start_param[@]} "${custom}" )
|
||||||
|
fi
|
||||||
|
log_msg "Starting ustreamer with Device ${device} ..."
|
||||||
|
echo "Parameters: ${start_param[*]}" | \
|
||||||
|
log_output "ustreamer [cam ${cam_section}]"
|
||||||
|
# Ustreamer is designed to run even if the device is not ready or readable.
|
||||||
|
# I dont like that! ustreamer has to exit if Cam isnt there.
|
||||||
|
if [ -e "${device}" ]; then
|
||||||
|
"${ustreamer_bin}" ${start_param[*]} 2>&1 | \
|
||||||
|
log_output "ustreamer [cam ${cam_section}]"
|
||||||
|
else
|
||||||
|
log_msg "ERROR: Start of ustreamer [cam ${cam_section}] failed!"
|
||||||
|
fi
|
||||||
|
}
|
45
libs/v4l2rtspserver.sh
Normal file
45
libs/v4l2rtspserver.sh
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#### ustreamer library
|
||||||
|
|
||||||
|
#### webcamd - A webcam Service for multiple Cams and Stream Services.
|
||||||
|
####
|
||||||
|
#### written by Stephan Wendel aka KwadFan
|
||||||
|
#### Copyright 2021
|
||||||
|
#### https://github.com/mainsail-crew/crowsnest
|
||||||
|
####
|
||||||
|
#### This File is distributed under GPLv3
|
||||||
|
####
|
||||||
|
|
||||||
|
# Exit upon Errors
|
||||||
|
set -e
|
||||||
|
|
||||||
|
function run_rtsp {
|
||||||
|
local cam_section rtsp_bin device port resolution fps custom
|
||||||
|
local raspicam start_param
|
||||||
|
cam_section="${1}"
|
||||||
|
rtsp_bin="$(whereis v4l2rtspserver | awk '{print $2}')"
|
||||||
|
device="$(get_param "cam ${cam_section}" device)"
|
||||||
|
port=$(get_param "cam ${cam_section}" port)
|
||||||
|
resolution=$(get_param "cam ${cam_section}" resolution)
|
||||||
|
fps=$(get_param "cam ${cam_section}" max_fps)
|
||||||
|
custom="$(get_param "cam ${cam_section}" custom_flags 2> /dev/null)"
|
||||||
|
check_section "${cam_section}"
|
||||||
|
split_res="$(echo "${resolution}" | \
|
||||||
|
awk -F 'x' '{print "-W "$1 " -H "$2}')"
|
||||||
|
start_param=(
|
||||||
|
-I 0.0.0.0 -P "${port}" "${split_res}" -F "${fps}" \
|
||||||
|
"${device}"
|
||||||
|
)
|
||||||
|
# Custom Flag Handling
|
||||||
|
if [ -n "${custom}" ]; then
|
||||||
|
start_param=(${start_param[@]} "${custom}" )
|
||||||
|
fi
|
||||||
|
log_msg "Starting v4l2rtspserver with Device ${device} ..."
|
||||||
|
echo "Parameters: ${start_param[*]}" | \
|
||||||
|
log_output "v4l2rtspserver [cam ${cam_section}]"
|
||||||
|
|
||||||
|
"${rtsp_bin}" ${start_param[*]} 2>&1 | \
|
||||||
|
log_output "v4l2rtspserver [cam ${cam_section}]"
|
||||||
|
log_msg "ERROR: Start of v4l2rtspserver [cam ${cam_section}] failed!"
|
||||||
|
}
|
17
uninstall.sh
17
uninstall.sh
@ -8,13 +8,15 @@
|
|||||||
# Version 1.1
|
# Version 1.1
|
||||||
########
|
########
|
||||||
|
|
||||||
|
# shellcheck enable=requires-variable-braces
|
||||||
|
|
||||||
|
## Exit on Error
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
## Debug
|
## Debug
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
# Global Vars
|
# Global Vars
|
||||||
BASE_USER=$(whoami)
|
|
||||||
TITLE="crowsnest - A Webcam Daemon for Raspberry Pi OS"
|
TITLE="crowsnest - A Webcam Daemon for Raspberry Pi OS"
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
@ -45,9 +47,9 @@ function install_cleanup_trap() {
|
|||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
# make sure that all child processed die when we die
|
# make sure that all child processed die when we die
|
||||||
local pids=$(jobs -pr)
|
|
||||||
echo -e "Killed by user ...\r\nGoodBye ...\r"
|
echo -e "Killed by user ...\r\nGoodBye ...\r"
|
||||||
[ -n "$pids" ] && kill $pids && sleep 5 && kill -9 $pids
|
# shellcheck disable=2046
|
||||||
|
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
|
||||||
}
|
}
|
||||||
##
|
##
|
||||||
|
|
||||||
@ -57,10 +59,9 @@ function err_exit {
|
|||||||
echo -e "ERROR: Stopping $(basename "$0")."
|
echo -e "ERROR: Stopping $(basename "$0")."
|
||||||
echo -e "Goodbye..."
|
echo -e "Goodbye..."
|
||||||
fi
|
fi
|
||||||
if [ -n "$(jobs -pr)" ]; then
|
# shellcheck disable=2046
|
||||||
kill $(jobs -pr)
|
[ -n "$(jobs -pr)" ] && kill $(jobs -pr) && sleep 5 && kill -9 $(jobs -pr)
|
||||||
fi
|
exit 1
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### Init ERR Trap
|
### Init ERR Trap
|
||||||
@ -162,4 +163,4 @@ install_cleanup_trap
|
|||||||
welcome_msg
|
welcome_msg
|
||||||
ask_uninstall
|
ask_uninstall
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
87
webcamd
87
webcamd
@ -12,9 +12,6 @@
|
|||||||
####
|
####
|
||||||
#### Version 3
|
#### Version 3
|
||||||
|
|
||||||
### Disable shellcheck Errors
|
|
||||||
# shellcheck disable=1091
|
|
||||||
|
|
||||||
# Exit upon Errors
|
# Exit upon Errors
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -22,89 +19,17 @@ set -e
|
|||||||
BASE_CN_PATH="$(dirname "$(readlink -f "${0}")")"
|
BASE_CN_PATH="$(dirname "$(readlink -f "${0}")")"
|
||||||
|
|
||||||
## Import Librarys
|
## Import Librarys
|
||||||
source "${BASE_CN_PATH}/libs/core.sh"
|
# shellcheck source-path=SCRIPTDIR/libs/
|
||||||
source "${BASE_CN_PATH}/libs/configparser.sh"
|
source "${BASE_CN_PATH}/libs/configparser.sh"
|
||||||
|
source "${BASE_CN_PATH}/libs/core.sh"
|
||||||
source "${BASE_CN_PATH}/libs/hwhandler.sh"
|
source "${BASE_CN_PATH}/libs/hwhandler.sh"
|
||||||
|
source "${BASE_CN_PATH}/libs/init_stream.sh"
|
||||||
source "${BASE_CN_PATH}/libs/logging.sh"
|
source "${BASE_CN_PATH}/libs/logging.sh"
|
||||||
source "${BASE_CN_PATH}/libs/messages.sh"
|
source "${BASE_CN_PATH}/libs/messages.sh"
|
||||||
source "${BASE_CN_PATH}/libs/watchdog.sh"
|
source "${BASE_CN_PATH}/libs/v4l2rtspserver.sh"
|
||||||
source "${BASE_CN_PATH}/libs/init_stream.sh"
|
source "${BASE_CN_PATH}/libs/ustreamer.sh"
|
||||||
source "${BASE_CN_PATH}/libs/v4l2_control.sh"
|
source "${BASE_CN_PATH}/libs/v4l2_control.sh"
|
||||||
|
source "${BASE_CN_PATH}/libs/watchdog.sh"
|
||||||
function run_ustreamer {
|
|
||||||
local cam_section ustreamer_bin device port resolution fps custom
|
|
||||||
local raspicam start_param wwwroot
|
|
||||||
cam_section="${1}"
|
|
||||||
ustreamer_bin="$(whereis ustreamer | awk '{print $2}')"
|
|
||||||
device="$(get_param "cam ${cam_section}" device)"
|
|
||||||
port=$(get_param "cam ${cam_section}" port)
|
|
||||||
resolution=$(get_param "cam ${cam_section}" resolution)
|
|
||||||
fps=$(get_param "cam ${cam_section}" max_fps)
|
|
||||||
custom="$(get_param "cam ${cam_section}" custom_flags 2> /dev/null)"
|
|
||||||
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
|
|
||||||
awk 'NR==2 {print $1}')"
|
|
||||||
check_section "${cam_section}"
|
|
||||||
wwwroot="$(dirname $(readlink -qe $(whereis webcamd)))/ustreamer-www"
|
|
||||||
#Raspicam Workaround
|
|
||||||
if [ "${device}" == "${raspicam}" ]; then
|
|
||||||
start_param=(
|
|
||||||
--host 127.0.0.1 -p "${port}" -m MJPEG --device-timeout=5
|
|
||||||
--buffers=3 -r "${resolution}" -f "${fps}" --allow-origin=\*
|
|
||||||
--static "${wwwroot}"
|
|
||||||
)
|
|
||||||
else
|
|
||||||
start_param=(
|
|
||||||
-d "${device}" -r "${resolution}" -f "${fps}"
|
|
||||||
--host 127.0.0.1 -p "${port}" --allow-origin=\*
|
|
||||||
--device-timeout=2 --static "${wwwroot}"
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
# Custom Flag Handling
|
|
||||||
if [ -n "${custom}" ]; then
|
|
||||||
start_param=(${start_param[@]} "${custom}" )
|
|
||||||
fi
|
|
||||||
log_msg "Starting ustreamer with Device ${device} ..."
|
|
||||||
echo "Parameters: ${start_param[*]}" | \
|
|
||||||
log_output "ustreamer [cam ${cam_section}]"
|
|
||||||
# Ustreamer is designed to run even if the device is not ready or readable.
|
|
||||||
# I dont like that! ustreamer has to exit if Cam isnt there.
|
|
||||||
if [ -e "${device}" ]; then
|
|
||||||
"${ustreamer_bin}" ${start_param[*]} 2>&1 | \
|
|
||||||
log_output "ustreamer [cam ${cam_section}]"
|
|
||||||
else
|
|
||||||
log_msg "ERROR: Start of ustreamer [cam ${cam_section}] failed!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_rtsp {
|
|
||||||
local cam_section rtsp_bin device port resolution fps custom
|
|
||||||
local raspicam start_param
|
|
||||||
cam_section="${1}"
|
|
||||||
rtsp_bin="$(whereis v4l2rtspserver | awk '{print $2}')"
|
|
||||||
device="$(get_param "cam ${cam_section}" device)"
|
|
||||||
port=$(get_param "cam ${cam_section}" port)
|
|
||||||
resolution=$(get_param "cam ${cam_section}" resolution)
|
|
||||||
fps=$(get_param "cam ${cam_section}" max_fps)
|
|
||||||
custom="$(get_param "cam ${cam_section}" custom_flags 2> /dev/null)"
|
|
||||||
check_section "${cam_section}"
|
|
||||||
split_res="$(echo "${resolution}" | \
|
|
||||||
awk -F 'x' '{print "-W "$1 " -H "$2}')"
|
|
||||||
start_param=(
|
|
||||||
-I 0.0.0.0 -P "${port}" "${split_res}" -F "${fps}" \
|
|
||||||
"${device}"
|
|
||||||
)
|
|
||||||
# Custom Flag Handling
|
|
||||||
if [ -n "${custom}" ]; then
|
|
||||||
start_param=(${start_param[@]} "${custom}" )
|
|
||||||
fi
|
|
||||||
log_msg "Starting v4l2rtspserver with Device ${device} ..."
|
|
||||||
echo "Parameters: ${start_param[*]}" | \
|
|
||||||
log_output "v4l2rtspserver [cam ${cam_section}]"
|
|
||||||
|
|
||||||
"${rtsp_bin}" ${start_param[*]} 2>&1 | \
|
|
||||||
log_output "v4l2rtspserver [cam ${cam_section}]"
|
|
||||||
log_msg "ERROR: Start of v4l2rtspserver [cam ${cam_section}] failed!"
|
|
||||||
}
|
|
||||||
|
|
||||||
#### MAIN
|
#### MAIN
|
||||||
## Args given?
|
## Args given?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user