Fix imp_helper.sh from a recursive function call rather than looping (#302)

This script was calling hi/lo updates without honoring the loop
interval. This was also calling itself recursively which could lead
to memory issues for long running cameras.
This commit is contained in:
Leo 2022-09-30 17:59:42 -06:00 committed by GitHub
parent de23abb057
commit b7b1e37854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,27 +10,26 @@ export WZMINI_CFG=/opt/wz_mini/wz_mini.conf
DELAY_BETWEEN=2 DELAY_BETWEEN=2
RE_RUN_DELAY=60 RE_RUN_DELAY=60
PARM=1
hi_res_monitor() { hi_res_monitor() {
if [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then if [[ "$RTSP_HI_RES_ENABLED" != "true" ]] ; then
return
fi
if [[ "$RTSP_HI_RES_ENC_PARAMETER" != "" ]] ; then if [[ "$RTSP_HI_RES_ENC_PARAMETER" != "" ]] ; then
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then
/system/bin/impdbg --enc_rc_s 0:0:4:$RTSP_HI_RES_ENC_PARAMETER /system/bin/impdbg --enc_rc_s 0:0:4:$RTSP_HI_RES_ENC_PARAMETER
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
echo "Invalid encoder value" echo "Invalid encoder value $RTSP_HI_RES_ENC_PARAMETER"
fi fi
else else
if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then if [[ $RTSP_HI_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then
/system/bin/impdbg --enc_rc_s 0:44:4:$RTSP_HI_RES_ENC_PARAMETER /system/bin/impdbg --enc_rc_s 0:44:4:$RTSP_HI_RES_ENC_PARAMETER
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
echo "Invalid encoder value" echo "Invalid encoder value $RTSP_HI_RES_ENC_PARAMETER"
fi fi
fi fi
fi fi
@ -39,11 +38,9 @@ hi_res_monitor() {
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
/system/bin/impdbg --enc_rc_s 0:28:4:$RTSP_HI_RES_MAX_BITRATE /system/bin/impdbg --enc_rc_s 0:28:4:$RTSP_HI_RES_MAX_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
/system/bin/impdbg --enc_rc_s 0:52:4:$RTSP_HI_RES_MAX_BITRATE /system/bin/impdbg --enc_rc_s 0:52:4:$RTSP_HI_RES_MAX_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi fi
fi fi
@ -53,7 +50,6 @@ hi_res_monitor() {
else else
/system/bin/impdbg --enc_rc_s 0:48:4:$RTSP_HI_RES_TARGET_BITRATE /system/bin/impdbg --enc_rc_s 0:48:4:$RTSP_HI_RES_TARGET_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi fi
fi fi
@ -61,44 +57,32 @@ hi_res_monitor() {
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
/system/bin/impdbg --enc_rc_s 0:8:4:$RTSP_HI_RES_FPS /system/bin/impdbg --enc_rc_s 0:8:4:$RTSP_HI_RES_FPS
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
/system/bin/impdbg --enc_rc_s 0:80:4:$RTSP_HI_RES_FPS /system/bin/impdbg --enc_rc_s 0:80:4:$RTSP_HI_RES_FPS
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi fi
fi fi
if [ $PARM == 1 ]; then
echo "No Hi-Res imp variables enabled, check Low-Res"
fi
low_res_monitor
else
echo "Hi-Res RTSP not enabled"
low_res_monitor
fi
} }
low_res_monitor () { low_res_monitor () {
if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]]; then if [[ "$RTSP_LOW_RES_ENABLED" != "true" ]] ; then
return
fi
if [[ "$RTSP_LOW_RES_ENC_PARAMETER" != "" ]] ; then if [[ "$RTSP_LOW_RES_ENC_PARAMETER" != "" ]] ; then
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then
/system/bin/impdbg --enc_rc_s 1:0:4:$RTSP_LOW_RES_ENC_PARAMETER /system/bin/impdbg --enc_rc_s 1:0:4:$RTSP_LOW_RES_ENC_PARAMETER
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
echo "Invalid encoder value" echo "Invalid encoder value $RTSP_LOW_RES_ENC_PARAMETER"
fi fi
else else
if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then if [[ $RTSP_LOW_RES_ENC_PARAMETER =~ "^[0|1|2|4|8]$" ]] ; then
/system/bin/impdbg --enc_rc_s 1:44:4:$RTSP_LOW_RES_ENC_PARAMETER /system/bin/impdbg --enc_rc_s 1:44:4:$RTSP_LOW_RES_ENC_PARAMETER
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
echo "Invalid encoder value" echo "Invalid encoder value $RTSP_LOW_RES_ENC_PARAMETER"
fi fi
fi fi
fi fi
@ -107,11 +91,9 @@ low_res_monitor () {
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
/system/bin/impdbg --enc_rc_s 1:28:4:$RTSP_LOW_RES_MAX_BITRATE /system/bin/impdbg --enc_rc_s 1:28:4:$RTSP_LOW_RES_MAX_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
/system/bin/impdbg --enc_rc_s 1:52:4:$RTSP_LOW_RES_MAX_BITRATE /system/bin/impdbg --enc_rc_s 1:52:4:$RTSP_LOW_RES_MAX_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi fi
fi fi
@ -121,7 +103,6 @@ low_res_monitor () {
else else
/system/bin/impdbg --enc_rc_s 1:48:4:$RTSP_LOW_RES_TARGET_BITRATE /system/bin/impdbg --enc_rc_s 1:48:4:$RTSP_LOW_RES_TARGET_BITRATE
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi fi
fi fi
@ -129,30 +110,32 @@ low_res_monitor () {
if [ -f /opt/wz_mini/tmp/.T20 ] ; then if [ -f /opt/wz_mini/tmp/.T20 ] ; then
/system/bin/impdbg --enc_rc_s 1:8:4:$RTSP_LOW_RES_FPS /system/bin/impdbg --enc_rc_s 1:8:4:$RTSP_LOW_RES_FPS
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
else else
/system/bin/impdbg --enc_rc_s 1:80:4:$RTSP_LOW_RES_FPS /system/bin/impdbg --enc_rc_s 1:80:4:$RTSP_LOW_RES_FPS
sleep $DELAY_BETWEEN sleep $DELAY_BETWEEN
PARM=$((PARM+1))
fi
fi
if [ $PARM == 1 ]; then
echo "No Low-Res imp variables enabled, exit"
break
fi
else
echo "Low-Res RTSP not enabled"
if [[ "$RTSP_HI_RES_ENABLED" == "true" ]] && [ $PARM -gt 1 ]; then
hi_res_monitor
else
break
fi fi
fi fi
} }
if [[ "$1" == "-h" ]] ; then
echo "Usage: $0 [-f]"
echo " Sets hardware encoder settings. Use -f to run once before quitting.."
exit 0
fi
if [[ "$1" == "-f" ]] ; then
hi_res_monitor
low_res_monitor
exit 0
fi
while true; do while true; do
hi_res_monitor hi_res_monitor
low_res_monitor
echo "Restart imp_helper.sh, sleep for $RE_RUN_DELAY" echo "Restart imp_helper.sh, sleep for $RE_RUN_DELAY"
sleep $RE_RUN_DELAY sleep $RE_RUN_DELAY
done done