Skip to content

Commit

Permalink
Add go2rtc as rtsp server program
Browse files Browse the repository at this point in the history
  • Loading branch information
roleoroleo committed Sep 20, 2024
1 parent 36da7ad commit 6d4a564
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 44 deletions.
3 changes: 3 additions & 0 deletions src/go2rtc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore the install dir
_install/
go2rtc/go2rtc
7 changes: 7 additions & 0 deletions src/go2rtc/cleanup.go2rtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

cd go2rtc
rm -f go2rtc
7 changes: 7 additions & 0 deletions src/go2rtc/compile.go2rtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

mkdir -p ./_install/bin || exit 1
cp go2rtc/go2rtc ./_install/bin || exit 1
12 changes: 12 additions & 0 deletions src/go2rtc/init.go2rtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

rm -rf ./_install

cd go2rtc
rm -f go2rtc
wget https://github.com/AlexxIT/go2rtc/releases/download/v1.9.4/go2rtc_linux_arm || exit 1
mv go2rtc_linux_arm go2rtc || exit 1
chmod 0755 go2rtc || exit 1
8 changes: 8 additions & 0 deletions src/go2rtc/install.go2rtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

mkdir -p ../../build/yi-hack/bin/ || exit 1

rsync -av ./_install/* ../../build/yi-hack/ || exit 1
115 changes: 79 additions & 36 deletions src/static/static/yi-hack/script/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,27 @@ init_config()
fi

if [[ $(get_config RTSP) == "yes" ]] ; then
RTSP_DAEMON="rRTSPServer"
RTSP_AUDIO_COMPRESSION=$(get_config RTSP_AUDIO)
if [ "$RTSP_AUDIO" == "aac" ]; then
H264GRABBER_AUDIO="-a"
if [[ $(get_config RTSP_ALT) == "alternative" ]] ; then
RTSP_DAEMON="rtsp_server_yi"
elif [[ $(get_config RTSP_ALT) == "go2rtc" ]] ; then
RTSP_DAEMON="go2rtc"
else
RTSP_DAEMON="rRTSPServer"
fi

if [[ $(get_config RTSP_ALT) == "yes" ]] ; then
RTSP_DAEMON="rtsp_server_yi"
RTSP_AUDIO_COMPRESSION=$(get_config RTSP_AUDIO)
if [ "$RTSP_AUDIO_COMPRESSION" == "aac" ]; then
H264GRABBER_AUDIO="-a"
fi

if [[ "$RTSP_AUDIO_COMPRESSION" == "none" ]] ; then
RTSP_AUDIO_COMPRESSION="no"
fi
if [ ! -z $RTSP_AUDIO_COMPRESSION ]; then
RTSP_AUDIO_COMPRESSION="-a "$RTSP_AUDIO_COMPRESSION
RTSP_AUDIO="-a "$RTSP_AUDIO_COMPRESSION
fi
if [ ! -z $RTSP_PORT ]; then
RTSP_PORT="-p "$RTSP_PORT
P_RTSP_PORT="-p "$RTSP_PORT
fi
if [ ! -z $USERNAME ]; then
RTSP_USER="-u "$USERNAME
Expand Down Expand Up @@ -107,39 +110,77 @@ init_config()

start_rtsp()
{
# If "null" use default

if [ "$1" == "low" ] || [ "$1" == "high" ] || [ "$1" == "both" ]; then
RTSP_RES=$1
fi
if [ "$2" == "aac" ]; then
H264GRABBER_AUDIO="-a"
fi
if [ "$2" == "no" ] || [ "$2" == "yes" ] || [ "$2" == "alaw" ] || [ "$2" == "ulaw" ] || [ "$2" == "pcm" ] || [ "$2" == "aac" ] ; then
RTSP_AUDIO_COMPRESSION="-a "$2
RTSP_AUDIO_COMPRESSION=$2
RTSP_AUDIO="-a "$2
fi

if [[ $RTSP_RES == "low" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r low $H264GRABBER_AUDIO -f &
sleep 1
if [ "$RTSP_ALT" == "go2rtc" ]; then
echo "streams:" > /tmp/go2rtc.yaml
if [ "$RTSP_RES" == "high" ] || [ "$RTSP_RES" == "both" ]; then
echo " ch0_0.h264:" >> /tmp/go2rtc.yaml
echo " - exec:h264grabber -m h52ga -r high#backchannel=0" >> /tmp/go2rtc.yaml
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r low $RTSP_AUDIO_COMPRESSION $RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
elif [[ $RTSP_RES == "high" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r high $H264GRABBER_AUDIO -f &
sleep 1
if [ "$RTSP_RES" != "low" ] && [ "$RTSP_AUDIO_COMPRESSION" == "aac" ] ; then
echo " - exec:h264grabber -m $MODEL_SUFFIX -r none -a#backchannel=0" >> /tmp/go2rtc.yaml
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r high $RTSP_AUDIO_COMPRESSION $RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
elif [[ $RTSP_RES == "both" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r both $H264GRABBER_AUDIO -f &
sleep 1
if [ "$RTSP_RES" == "low" ] || [ "$RTSP_RES" == "both" ]; then
echo " ch0_1.h264:" >> /tmp/go2rtc.yaml
echo " - exec:h264grabber -m $MODEL_SUFFIX -r low#backchannel=0" >> /tmp/go2rtc.yaml
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r both $RTSP_AUDIO_COMPRESSION $RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
fi
if [ "$RTSP_RES" == "low" ] && [ "$RTSP_AUDIO_COMPRESSION" == "aac" ] ; then
echo " - exec:h264grabber -m $MODEL_SUFFIX -r none -a#backchannel=0" >> /tmp/go2rtc.yaml
fi

echo "" >> /tmp/go2rtc.yaml
echo "api:" >> /tmp/go2rtc.yaml
echo " listen: \"\"" >> /tmp/go2rtc.yaml
echo "" >> /tmp/go2rtc.yaml
echo "webrtc:" >> /tmp/go2rtc.yaml
echo " listen: \"\"" >> /tmp/go2rtc.yaml
echo "" >> /tmp/go2rtc.yaml
echo "rtsp:" >> /tmp/go2rtc.yaml
echo " listen: \":$RTSP_PORT\"" >> /tmp/go2rtc.yaml
if [ ! -z $USERNAME ]; then
echo " username: \"$USERNAME\"" >> /tmp/go2rtc.yaml
echo " password: \"$PASSWORD\"" >> /tmp/go2rtc.yaml
fi

$RTSP_DAEMON -c /tmp/go2rtc.yaml -d
else

WD_COUNT=$(ps | grep wd_rtsp.sh | grep -v grep | grep -c ^)
if [ $WD_COUNT -eq 0 ]; then
(sleep 30; $YI_HACK_PREFIX/script/wd_rtsp.sh >/dev/null) &
if [[ $RTSP_RES == "low" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r low $H264GRABBER_AUDIO -f &
sleep 1
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r low $RTSP_AUDIO $P_RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
elif [[ $RTSP_RES == "high" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r high $H264GRABBER_AUDIO -f &
sleep 1
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r high $RTSP_AUDIO $P_RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
elif [[ $RTSP_RES == "both" ]]; then
if [ "$RTSP_ALT" == "yes" ]; then
h264grabber -m $MODEL_SUFFIX -r both $H264GRABBER_AUDIO -f &
sleep 1
fi
$RTSP_DAEMON -m $MODEL_SUFFIX -r both $RTSP_AUDIO $P_RTSP_PORT $RTSP_USER $RTSP_PASSWORD $B_ONVIF_AUDIO_BC &
fi

WD_COUNT=$(ps | grep wd_rtsp.sh | grep -v grep | grep -c ^)
if [ $WD_COUNT -eq 0 ]; then
(sleep 30; $YI_HACK_PREFIX/script/wd_rtsp.sh >/dev/null) &
fi
fi
}

Expand All @@ -151,13 +192,15 @@ stop_rtsp()

start_onvif()
{
if [[ "$2" == "none" ]]; then
# If "null" use default

if [[ "$2" == "null" ]]; then
ONVIF_WM_SNAPSHOT=$(get_config ONVIF_WM_SNAPSHOT)
WATERMARK="&watermark="$ONVIF_WM_SNAPSHOT
elif [[ "$2" == "yes" ]]; then
WATERMARK="&watermark=yes"
fi
if [[ "$1" == "none" ]]; then
if [[ "$1" == "null" ]]; then
ONVIF_PROFILE=$(get_config ONVIF_PROFILE)
elif [[ "$1" == "low" ]] || [[ "$1" == "high" ]] || [[ "$1" == "both" ]]; then
ONVIF_PROFILE=$1
Expand Down Expand Up @@ -289,7 +332,7 @@ stop_wsdd()

start_ftpd()
{
if [[ "$1" == "none" ]] ; then
if [[ "$1" == "null" ]] ; then
if [[ $(get_config BUSYBOX_FTPD) == "yes" ]] ; then
FTPD_DAEMON="busybox"
else
Expand All @@ -308,7 +351,7 @@ start_ftpd()

stop_ftpd()
{
if [[ "$1" == "none" ]] ; then
if [[ "$1" == "null" ]] ; then
if [[ $(get_config BUSYBOX_FTPD) == "yes" ]] ; then
FTPD_DAEMON="busybox"
else
Expand All @@ -335,10 +378,10 @@ ps_program()
fi
}

NAME="none"
ACTION="none"
PARAM1="none"
PARAM2="none"
NAME="null"
ACTION="null"
PARAM1="null"
PARAM2="null"
RES=""

if [ $# -lt 2 ]; then
Expand Down
3 changes: 2 additions & 1 deletion src/www/httpd/htdocs/js/modules/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ APP.configurations = (function($) {
$.each(response, function(key, state) {
if (key == "HOSTNAME" || key == "TIMEZONE" || key == "TIMELAPSE_DT" || key == "TIMELAPSE_VDT" || key == "NTP_SERVER" || key == "HTTPD_PORT" || key == "RTSP_PORT" || key == "USERNAME")
$('input[type="text"][data-key="' + key + '"]').prop('value', state);
else if (key == "RTSP_STREAM" || key == "RTSP_AUDIO" || key=="SWAP_SWAPPINESS")
else if (key == "RTSP_ALT" || key == "RTSP_STREAM" || key == "RTSP_AUDIO" || key=="SWAP_SWAPPINESS")
$('select[data-key="' + key + '"]').prop('value', state);
else if (key == "PASSWORD" || key == "SSH_PASSWORD")
$('input[type="password"][data-key="' + key + '"]').prop('value', state);
Expand Down Expand Up @@ -69,6 +69,7 @@ APP.configurations = (function($) {
configs["TIMELAPSE_VDT"] = $('input[type="text"][data-key="TIMELAPSE_VDT"]').prop('value');
configs["NTP_SERVER"] = $('input[type="text"][data-key="NTP_SERVER"]').prop('value');
configs["HTTPD_PORT"] = $('input[type="text"][data-key="HTTPD_PORT"]').prop('value');
configs["RTSP_ALT"] = $('select[data-key="RTSP_ALT"]').prop('value');
configs["RTSP_STREAM"] = $('select[data-key="RTSP_STREAM"]').prop('value');
configs["RTSP_AUDIO"] = $('select[data-key="RTSP_AUDIO"]').prop('value');
configs["RTSP_PORT"] = $('input[type="text"][data-key="RTSP_PORT"]').prop('value');
Expand Down
18 changes: 11 additions & 7 deletions src/www/httpd/htdocs/pages/configurations.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ <h4 class="no-margin">General</h4>
</td>
</tr>
<tr class="row">
<td>RTSP alternative server</td>
<td>RTSP server program</td>
<td>
<label class="switch small">
<input type="checkbox" data-key="RTSP_ALT"/>
<span class="slider round"></span>
<span class="switch-text"></span>
</label>
<div class="standard-select">
<select data-key="RTSP_ALT" id="RTSP_ALT">
<option value="standard">Standard (based on live555 library)</option>
<option value="alternative">Alternative</option>
<option value="go2rtc">go2rtc</option>
</select>
</div>
<span class="switch-description">
Use alternative RTSP server instead of the live555 based one.
Select the RTSP server program.
<br/>
Note: go2rtc supports only aac audio.
</span>
</td>
</tr>
Expand Down

0 comments on commit 6d4a564

Please sign in to comment.