From 0f8af140c7bb285a3fabadcc7e3fb234a724086f Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Mon, 7 Oct 2019 10:48:24 +1100 Subject: [PATCH 1/3] streameye.sh: switch from gstreamer to v4l2multi_stream_mmal --- .../raspberrypi/overlay/usr/bin/streameye.sh | 221 ++++++------------ .../raspberrypi2/overlay/usr/bin/streameye.sh | 221 ++++++------------ .../raspberrypi3/overlay/usr/bin/streameye.sh | 221 ++++++------------ .../raspberrypi4/overlay/usr/bin/streameye.sh | 221 ++++++------------ 4 files changed, 284 insertions(+), 600 deletions(-) diff --git a/board/raspberrypi/overlay/usr/bin/streameye.sh b/board/raspberrypi/overlay/usr/bin/streameye.sh index 9f63710c3c..1f593f188a 100755 --- a/board/raspberrypi/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi/overlay/usr/bin/streameye.sh @@ -17,7 +17,10 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then + if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then + logger -t streameye -s "not running, respawning" + start + elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -30,109 +33,6 @@ function watch() { done } -function configure_v4l2_cam() { - video_arg="-d $1" - - horizontal_flip="0" - hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null - - vertical_flip="0" - vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null - - rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${rotate}" ]; then rotate="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null - - brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${brightness}" ]; then brightness="50"; fi - v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null - - contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${contrast}" ]; then contrast="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null - - saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${saturation}" ]; then saturation="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null - - sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${sharpness}" ]; then sharpness="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null - - vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${vstab}" ]; then vstab="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null - - shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${shutter}" ]; then shutter="0"; fi - if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null - - iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${iso}" ]; then iso="0"; fi - if [ "${iso}" -ge 800 ]; then iso="4" - elif [ "${iso}" -ge 400 ]; then iso="3" - elif [ "${iso}" -ge 200 ]; then iso="2" - elif [ "${iso}" -ge 100 ]; then iso="1" - else iso="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null - - awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${awb}" = "off" ]; then awb="0" - elif [ "${awb}" = "auto" ]; then awb="1" - elif [ "${awb}" = "sunlight" ]; then awb="6" - elif [ "${awb}" = "cloudy" ]; then awb="8" - elif [ "${awb}" = "shade" ]; then awb="9" - elif [ "${awb}" = "tungsten" ]; then awb="4" - elif [ "${awb}" = "fluorescent" ]; then awb="3" - elif [ "${awb}" = "incandescent" ]; then awb="2" - elif [ "${awb}" = "flash" ]; then awb="7" - elif [ "${awb}" = "horizon" ]; then awb="5" - else awb="1" - fi - v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null - - metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${metering}" = "spot" ]; then metering="2" - elif [ "${metering}" = "center" ]; then metering="1" - else metering="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null - - scene="0" - exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${exposure}" = "off" ]; then - exposure="1" - else - if [ "${exposure}" = "night" ]; then scene="8" - elif [ "${exposure}" = "backlight" ]; then scene="1" - elif [ "${exposure}" = "sports" ]; then scene="11" - elif [ "${exposure}" = "snow" ]; then scene="2" - elif [ "${exposure}" = "beach" ]; then scene="2" - elif [ "${exposure}" = "fireworks" ]; then scene="6" - fi - exposure="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null - v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null - - ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${ev}" ]; then ev="0"; fi - ev=$(expr ${ev} + 25) - ev=$(expr ${ev} / 2) - if [ "${ev}" -gt 24 ]; then ev="24"; fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null - - video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi - v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null -} - function invalid_opt() { local e match="$1" shift @@ -143,70 +43,91 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" + rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" + # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + # still need iptables? + #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then + audio_path=",${AUDIO_DEV}" + + # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - audio_extras="" + # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG + audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) if [ -n "${audio_bitrate}" ]; then - audio_extras="${audio_extras},rate=${audio_bitrate}" + audio_opts="${audio_opts} -A ${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_extras="${audio_extras},channels=${audio_channels}" + audio_opts="${audio_opts} -C ${audio_channels}" + fi + if [ -n "${audio_format}" ]; then + audio_opts="${audio_opts} -a ${audio_format}" fi - audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" - fi - video_path="/dev/video0" - if [ -n "${VIDEO_DEV}" ]; then - video_path=${VIDEO_DEV} fi + # hardcode to 90 for now + video_path="/dev/video90" + rmmod v4l2loopback + modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - # Only configure camera if it is a Pi Cam - if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then - configure_v4l2_cam ${video_path} + valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") + raspimjpeg_opts="--videoout ${video_path}" + while read line; do + key=$(echo ${line} | cut -d ' ' -f 1) + if invalid_opt "${key}" "${valid_opts[@]}"; then + continue + fi + if echo "${line}" | grep false &>/dev/null; then + continue + fi + if echo "${line}" | grep true &>/dev/null; then + line=${key} + fi + raspimjpeg_opts="${raspimjpeg_opts} --${line}" + done < ${RASPIMJPEG_CONF} + + video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_iso}" ]; then + raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" fi - width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - video_extras="" - if [ -n "${width}" ]; then - video_extras="${video_extras},width=${width}" - fi - if [ -n "${height}" ]; then - video_extras="${video_extras},height=${height}" - fi - if [ -n "${framerate}" ]; then - video_extras="${video_extras},framerate=${framerate}/1" - fi - video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then + raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & + rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" + video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_framerate}" ]; then + rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" + fi + + v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & sleep 10 - gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & - sleep 5 + v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & + fi - iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + # still need iptables? + #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -247,9 +168,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -260,25 +181,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${gst_launch_pid}" ]; then - kill -HUP "${gst_launch_pid}" &>/dev/null + + if [ -n "${v4l2rtspserver_pid}" ]; then + kill -HUP "${v4l2rtspserver_pid}" &>/dev/null count=0 - while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${gst_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true fi - if [ -n "${test_launch_pid}" ]; then - kill -HUP "${test_launch_pid}" &>/dev/null + if [ -n "${v4l2multi_stream_mmal_pid}" ]; then + kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null count=0 - while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${test_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi2/overlay/usr/bin/streameye.sh b/board/raspberrypi2/overlay/usr/bin/streameye.sh index 9f63710c3c..1f593f188a 100755 --- a/board/raspberrypi2/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi2/overlay/usr/bin/streameye.sh @@ -17,7 +17,10 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then + if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then + logger -t streameye -s "not running, respawning" + start + elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -30,109 +33,6 @@ function watch() { done } -function configure_v4l2_cam() { - video_arg="-d $1" - - horizontal_flip="0" - hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null - - vertical_flip="0" - vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null - - rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${rotate}" ]; then rotate="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null - - brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${brightness}" ]; then brightness="50"; fi - v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null - - contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${contrast}" ]; then contrast="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null - - saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${saturation}" ]; then saturation="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null - - sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${sharpness}" ]; then sharpness="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null - - vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${vstab}" ]; then vstab="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null - - shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${shutter}" ]; then shutter="0"; fi - if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null - - iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${iso}" ]; then iso="0"; fi - if [ "${iso}" -ge 800 ]; then iso="4" - elif [ "${iso}" -ge 400 ]; then iso="3" - elif [ "${iso}" -ge 200 ]; then iso="2" - elif [ "${iso}" -ge 100 ]; then iso="1" - else iso="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null - - awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${awb}" = "off" ]; then awb="0" - elif [ "${awb}" = "auto" ]; then awb="1" - elif [ "${awb}" = "sunlight" ]; then awb="6" - elif [ "${awb}" = "cloudy" ]; then awb="8" - elif [ "${awb}" = "shade" ]; then awb="9" - elif [ "${awb}" = "tungsten" ]; then awb="4" - elif [ "${awb}" = "fluorescent" ]; then awb="3" - elif [ "${awb}" = "incandescent" ]; then awb="2" - elif [ "${awb}" = "flash" ]; then awb="7" - elif [ "${awb}" = "horizon" ]; then awb="5" - else awb="1" - fi - v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null - - metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${metering}" = "spot" ]; then metering="2" - elif [ "${metering}" = "center" ]; then metering="1" - else metering="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null - - scene="0" - exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${exposure}" = "off" ]; then - exposure="1" - else - if [ "${exposure}" = "night" ]; then scene="8" - elif [ "${exposure}" = "backlight" ]; then scene="1" - elif [ "${exposure}" = "sports" ]; then scene="11" - elif [ "${exposure}" = "snow" ]; then scene="2" - elif [ "${exposure}" = "beach" ]; then scene="2" - elif [ "${exposure}" = "fireworks" ]; then scene="6" - fi - exposure="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null - v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null - - ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${ev}" ]; then ev="0"; fi - ev=$(expr ${ev} + 25) - ev=$(expr ${ev} / 2) - if [ "${ev}" -gt 24 ]; then ev="24"; fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null - - video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi - v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null -} - function invalid_opt() { local e match="$1" shift @@ -143,70 +43,91 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" + rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" + # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + # still need iptables? + #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then + audio_path=",${AUDIO_DEV}" + + # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - audio_extras="" + # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG + audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) if [ -n "${audio_bitrate}" ]; then - audio_extras="${audio_extras},rate=${audio_bitrate}" + audio_opts="${audio_opts} -A ${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_extras="${audio_extras},channels=${audio_channels}" + audio_opts="${audio_opts} -C ${audio_channels}" + fi + if [ -n "${audio_format}" ]; then + audio_opts="${audio_opts} -a ${audio_format}" fi - audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" - fi - video_path="/dev/video0" - if [ -n "${VIDEO_DEV}" ]; then - video_path=${VIDEO_DEV} fi + # hardcode to 90 for now + video_path="/dev/video90" + rmmod v4l2loopback + modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - # Only configure camera if it is a Pi Cam - if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then - configure_v4l2_cam ${video_path} + valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") + raspimjpeg_opts="--videoout ${video_path}" + while read line; do + key=$(echo ${line} | cut -d ' ' -f 1) + if invalid_opt "${key}" "${valid_opts[@]}"; then + continue + fi + if echo "${line}" | grep false &>/dev/null; then + continue + fi + if echo "${line}" | grep true &>/dev/null; then + line=${key} + fi + raspimjpeg_opts="${raspimjpeg_opts} --${line}" + done < ${RASPIMJPEG_CONF} + + video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_iso}" ]; then + raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" fi - width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - video_extras="" - if [ -n "${width}" ]; then - video_extras="${video_extras},width=${width}" - fi - if [ -n "${height}" ]; then - video_extras="${video_extras},height=${height}" - fi - if [ -n "${framerate}" ]; then - video_extras="${video_extras},framerate=${framerate}/1" - fi - video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then + raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & + rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" + video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_framerate}" ]; then + rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" + fi + + v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & sleep 10 - gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & - sleep 5 + v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & + fi - iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + # still need iptables? + #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -247,9 +168,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -260,25 +181,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${gst_launch_pid}" ]; then - kill -HUP "${gst_launch_pid}" &>/dev/null + + if [ -n "${v4l2rtspserver_pid}" ]; then + kill -HUP "${v4l2rtspserver_pid}" &>/dev/null count=0 - while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${gst_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true fi - if [ -n "${test_launch_pid}" ]; then - kill -HUP "${test_launch_pid}" &>/dev/null + if [ -n "${v4l2multi_stream_mmal_pid}" ]; then + kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null count=0 - while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${test_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi3/overlay/usr/bin/streameye.sh b/board/raspberrypi3/overlay/usr/bin/streameye.sh index 9f63710c3c..1f593f188a 100755 --- a/board/raspberrypi3/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi3/overlay/usr/bin/streameye.sh @@ -17,7 +17,10 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then + if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then + logger -t streameye -s "not running, respawning" + start + elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -30,109 +33,6 @@ function watch() { done } -function configure_v4l2_cam() { - video_arg="-d $1" - - horizontal_flip="0" - hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null - - vertical_flip="0" - vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null - - rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${rotate}" ]; then rotate="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null - - brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${brightness}" ]; then brightness="50"; fi - v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null - - contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${contrast}" ]; then contrast="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null - - saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${saturation}" ]; then saturation="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null - - sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${sharpness}" ]; then sharpness="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null - - vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${vstab}" ]; then vstab="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null - - shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${shutter}" ]; then shutter="0"; fi - if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null - - iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${iso}" ]; then iso="0"; fi - if [ "${iso}" -ge 800 ]; then iso="4" - elif [ "${iso}" -ge 400 ]; then iso="3" - elif [ "${iso}" -ge 200 ]; then iso="2" - elif [ "${iso}" -ge 100 ]; then iso="1" - else iso="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null - - awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${awb}" = "off" ]; then awb="0" - elif [ "${awb}" = "auto" ]; then awb="1" - elif [ "${awb}" = "sunlight" ]; then awb="6" - elif [ "${awb}" = "cloudy" ]; then awb="8" - elif [ "${awb}" = "shade" ]; then awb="9" - elif [ "${awb}" = "tungsten" ]; then awb="4" - elif [ "${awb}" = "fluorescent" ]; then awb="3" - elif [ "${awb}" = "incandescent" ]; then awb="2" - elif [ "${awb}" = "flash" ]; then awb="7" - elif [ "${awb}" = "horizon" ]; then awb="5" - else awb="1" - fi - v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null - - metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${metering}" = "spot" ]; then metering="2" - elif [ "${metering}" = "center" ]; then metering="1" - else metering="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null - - scene="0" - exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${exposure}" = "off" ]; then - exposure="1" - else - if [ "${exposure}" = "night" ]; then scene="8" - elif [ "${exposure}" = "backlight" ]; then scene="1" - elif [ "${exposure}" = "sports" ]; then scene="11" - elif [ "${exposure}" = "snow" ]; then scene="2" - elif [ "${exposure}" = "beach" ]; then scene="2" - elif [ "${exposure}" = "fireworks" ]; then scene="6" - fi - exposure="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null - v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null - - ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${ev}" ]; then ev="0"; fi - ev=$(expr ${ev} + 25) - ev=$(expr ${ev} / 2) - if [ "${ev}" -gt 24 ]; then ev="24"; fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null - - video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi - v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null -} - function invalid_opt() { local e match="$1" shift @@ -143,70 +43,91 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" + rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" + # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + # still need iptables? + #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then + audio_path=",${AUDIO_DEV}" + + # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - audio_extras="" + # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG + audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) if [ -n "${audio_bitrate}" ]; then - audio_extras="${audio_extras},rate=${audio_bitrate}" + audio_opts="${audio_opts} -A ${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_extras="${audio_extras},channels=${audio_channels}" + audio_opts="${audio_opts} -C ${audio_channels}" + fi + if [ -n "${audio_format}" ]; then + audio_opts="${audio_opts} -a ${audio_format}" fi - audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" - fi - video_path="/dev/video0" - if [ -n "${VIDEO_DEV}" ]; then - video_path=${VIDEO_DEV} fi + # hardcode to 90 for now + video_path="/dev/video90" + rmmod v4l2loopback + modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - # Only configure camera if it is a Pi Cam - if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then - configure_v4l2_cam ${video_path} + valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") + raspimjpeg_opts="--videoout ${video_path}" + while read line; do + key=$(echo ${line} | cut -d ' ' -f 1) + if invalid_opt "${key}" "${valid_opts[@]}"; then + continue + fi + if echo "${line}" | grep false &>/dev/null; then + continue + fi + if echo "${line}" | grep true &>/dev/null; then + line=${key} + fi + raspimjpeg_opts="${raspimjpeg_opts} --${line}" + done < ${RASPIMJPEG_CONF} + + video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_iso}" ]; then + raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" fi - width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - video_extras="" - if [ -n "${width}" ]; then - video_extras="${video_extras},width=${width}" - fi - if [ -n "${height}" ]; then - video_extras="${video_extras},height=${height}" - fi - if [ -n "${framerate}" ]; then - video_extras="${video_extras},framerate=${framerate}/1" - fi - video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then + raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & + rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" + video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_framerate}" ]; then + rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" + fi + + v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & sleep 10 - gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & - sleep 5 + v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & + fi - iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + # still need iptables? + #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -247,9 +168,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -260,25 +181,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${gst_launch_pid}" ]; then - kill -HUP "${gst_launch_pid}" &>/dev/null + + if [ -n "${v4l2rtspserver_pid}" ]; then + kill -HUP "${v4l2rtspserver_pid}" &>/dev/null count=0 - while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${gst_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true fi - if [ -n "${test_launch_pid}" ]; then - kill -HUP "${test_launch_pid}" &>/dev/null + if [ -n "${v4l2multi_stream_mmal_pid}" ]; then + kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null count=0 - while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${test_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi4/overlay/usr/bin/streameye.sh b/board/raspberrypi4/overlay/usr/bin/streameye.sh index 9f63710c3c..1f593f188a 100755 --- a/board/raspberrypi4/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi4/overlay/usr/bin/streameye.sh @@ -17,7 +17,10 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then + if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then + logger -t streameye -s "not running, respawning" + start + elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -30,109 +33,6 @@ function watch() { done } -function configure_v4l2_cam() { - video_arg="-d $1" - - horizontal_flip="0" - hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null - - vertical_flip="0" - vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi - v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null - - rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${rotate}" ]; then rotate="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null - - brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${brightness}" ]; then brightness="50"; fi - v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null - - contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${contrast}" ]; then contrast="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null - - saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${saturation}" ]; then saturation="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null - - sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${sharpness}" ]; then sharpness="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null - - vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${vstab}" ]; then vstab="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null - - shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${shutter}" ]; then shutter="0"; fi - if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null - - iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${iso}" ]; then iso="0"; fi - if [ "${iso}" -ge 800 ]; then iso="4" - elif [ "${iso}" -ge 400 ]; then iso="3" - elif [ "${iso}" -ge 200 ]; then iso="2" - elif [ "${iso}" -ge 100 ]; then iso="1" - else iso="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null - - awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${awb}" = "off" ]; then awb="0" - elif [ "${awb}" = "auto" ]; then awb="1" - elif [ "${awb}" = "sunlight" ]; then awb="6" - elif [ "${awb}" = "cloudy" ]; then awb="8" - elif [ "${awb}" = "shade" ]; then awb="9" - elif [ "${awb}" = "tungsten" ]; then awb="4" - elif [ "${awb}" = "fluorescent" ]; then awb="3" - elif [ "${awb}" = "incandescent" ]; then awb="2" - elif [ "${awb}" = "flash" ]; then awb="7" - elif [ "${awb}" = "horizon" ]; then awb="5" - else awb="1" - fi - v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null - - metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${metering}" = "spot" ]; then metering="2" - elif [ "${metering}" = "center" ]; then metering="1" - else metering="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null - - scene="0" - exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ "${exposure}" = "off" ]; then - exposure="1" - else - if [ "${exposure}" = "night" ]; then scene="8" - elif [ "${exposure}" = "backlight" ]; then scene="1" - elif [ "${exposure}" = "sports" ]; then scene="11" - elif [ "${exposure}" = "snow" ]; then scene="2" - elif [ "${exposure}" = "beach" ]; then scene="2" - elif [ "${exposure}" = "fireworks" ]; then scene="6" - fi - exposure="0" - fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null - v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null - - ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${ev}" ]; then ev="0"; fi - ev=$(expr ${ev} + 25) - ev=$(expr ${ev} / 2) - if [ "${ev}" -gt 24 ]; then ev="24"; fi - v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null - - video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi - v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null -} - function invalid_opt() { local e match="$1" shift @@ -143,70 +43,91 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" + rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" + # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + # still need iptables? + #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then + audio_path=",${AUDIO_DEV}" + + # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - audio_extras="" + # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG + audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) if [ -n "${audio_bitrate}" ]; then - audio_extras="${audio_extras},rate=${audio_bitrate}" + audio_opts="${audio_opts} -A ${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_extras="${audio_extras},channels=${audio_channels}" + audio_opts="${audio_opts} -C ${audio_channels}" + fi + if [ -n "${audio_format}" ]; then + audio_opts="${audio_opts} -a ${audio_format}" fi - audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" - fi - video_path="/dev/video0" - if [ -n "${VIDEO_DEV}" ]; then - video_path=${VIDEO_DEV} fi + # hardcode to 90 for now + video_path="/dev/video90" + rmmod v4l2loopback + modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - # Only configure camera if it is a Pi Cam - if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then - configure_v4l2_cam ${video_path} + valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") + raspimjpeg_opts="--videoout ${video_path}" + while read line; do + key=$(echo ${line} | cut -d ' ' -f 1) + if invalid_opt "${key}" "${valid_opts[@]}"; then + continue + fi + if echo "${line}" | grep false &>/dev/null; then + continue + fi + if echo "${line}" | grep true &>/dev/null; then + line=${key} + fi + raspimjpeg_opts="${raspimjpeg_opts} --${line}" + done < ${RASPIMJPEG_CONF} + + video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_iso}" ]; then + raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" fi - width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - video_extras="" - if [ -n "${width}" ]; then - video_extras="${video_extras},width=${width}" - fi - if [ -n "${height}" ]; then - video_extras="${video_extras},height=${height}" - fi - if [ -n "${framerate}" ]; then - video_extras="${video_extras},framerate=${framerate}/1" - fi - video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then + raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & + rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" + video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -n "${video_framerate}" ]; then + rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" + fi + + v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & sleep 10 - gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & - sleep 5 + v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & + fi - iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + # still need iptables? + #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -247,9 +168,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -260,25 +181,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${gst_launch_pid}" ]; then - kill -HUP "${gst_launch_pid}" &>/dev/null + + if [ -n "${v4l2rtspserver_pid}" ]; then + kill -HUP "${v4l2rtspserver_pid}" &>/dev/null count=0 - while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${gst_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true fi - if [ -n "${test_launch_pid}" ]; then - kill -HUP "${test_launch_pid}" &>/dev/null + if [ -n "${v4l2multi_stream_mmal_pid}" ]; then + kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null count=0 - while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${test_launch_pid}" &>/dev/null || true + kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true fi } From 9759ded2316751860ca85cc42ed9f495b574f0f7 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Mon, 7 Oct 2019 10:49:19 +1100 Subject: [PATCH 2/3] raspberry pi builds: enable ffmpeg package --- configs/raspberrypi2_defconfig | 30 ++++++------------------------ configs/raspberrypi3_defconfig | 30 ++++++------------------------ configs/raspberrypi4_defconfig | 30 ++++++------------------------ configs/raspberrypi_defconfig | 31 ++++++------------------------- 4 files changed, 24 insertions(+), 97 deletions(-) diff --git a/configs/raspberrypi2_defconfig b/configs/raspberrypi2_defconfig index f66e0ac74c..9256eda1a6 100644 --- a/configs/raspberrypi2_defconfig +++ b/configs/raspberrypi2_defconfig @@ -22,35 +22,17 @@ BR2_PACKAGE_MOTIONEYE=y BR2_PACKAGE_ALSA_UTILS=y BR2_PACKAGE_ALSA_UTILS_AMIXER=y BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_FFMPEG=y BR2_PACKAGE_FFMPEG_GPL=y BR2_PACKAGE_FFMPEG_NONFREE=y -BR2_PACKAGE_GSTREAMER1=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ADDER=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIOTESTSRC=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ENCODING=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_TCP=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ALSA=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_JPEG=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUDIOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUTODETECT=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIPART=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTSP=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2_PROBE=y -BR2_PACKAGE_GST1_PLUGINS_BAD=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VIDEOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_FDK_AAC=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VOAACENC=y -BR2_PACKAGE_GST1_INTERPIPE=y -BR2_PACKAGE_GST1_LIBAV=y -BR2_PACKAGE_GST1_RTSP_SERVER=y -BR2_PACKAGE_GST_OMX=y -BR2_PACKAGE_GSTREAMER1_EDITING_SERVICES=y +BR2_PACKAGE_FFMPEG_FFMPEG=y +BR2_PACKAGE_FFMPEG_SWSCALE=y BR2_PACKAGE_LIBWEBCAM=y BR2_PACKAGE_MOTION=y BR2_PACKAGE_STREAMEYE=y +BR2_PACKAGE_V4L2LOOPBACK=y +BR2_PACKAGE_V4L2RTSPSERVER=y +BR2_PACKAGE_V4L2TOOLS=y BR2_PACKAGE_GZIP=y BR2_PACKAGE_JQ=y BR2_PACKAGE_CIFS_UTILS=y diff --git a/configs/raspberrypi3_defconfig b/configs/raspberrypi3_defconfig index e8d0f25881..6c9d0753be 100644 --- a/configs/raspberrypi3_defconfig +++ b/configs/raspberrypi3_defconfig @@ -22,35 +22,17 @@ BR2_PACKAGE_MOTIONEYE=y BR2_PACKAGE_ALSA_UTILS=y BR2_PACKAGE_ALSA_UTILS_AMIXER=y BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_FFMPEG=y BR2_PACKAGE_FFMPEG_GPL=y BR2_PACKAGE_FFMPEG_NONFREE=y -BR2_PACKAGE_GSTREAMER1=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ADDER=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIOTESTSRC=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ENCODING=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_TCP=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ALSA=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_JPEG=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUDIOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUTODETECT=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIPART=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTSP=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2_PROBE=y -BR2_PACKAGE_GST1_PLUGINS_BAD=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VIDEOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_FDK_AAC=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VOAACENC=y -BR2_PACKAGE_GST1_INTERPIPE=y -BR2_PACKAGE_GST1_LIBAV=y -BR2_PACKAGE_GST1_RTSP_SERVER=y -BR2_PACKAGE_GST_OMX=y -BR2_PACKAGE_GSTREAMER1_EDITING_SERVICES=y +BR2_PACKAGE_FFMPEG_FFMPEG=y +BR2_PACKAGE_FFMPEG_SWSCALE=y BR2_PACKAGE_LIBWEBCAM=y BR2_PACKAGE_MOTION=y BR2_PACKAGE_STREAMEYE=y +BR2_PACKAGE_V4L2LOOPBACK=y +BR2_PACKAGE_V4L2RTSPSERVER=y +BR2_PACKAGE_V4L2TOOLS=y BR2_PACKAGE_GZIP=y BR2_PACKAGE_JQ=y BR2_PACKAGE_CIFS_UTILS=y diff --git a/configs/raspberrypi4_defconfig b/configs/raspberrypi4_defconfig index e52bf8d369..08c8be9129 100644 --- a/configs/raspberrypi4_defconfig +++ b/configs/raspberrypi4_defconfig @@ -22,36 +22,18 @@ BR2_PACKAGE_MOTIONEYE=y BR2_PACKAGE_ALSA_UTILS=y BR2_PACKAGE_ALSA_UTILS_AMIXER=y BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_FFMPEG=y BR2_PACKAGE_FFMPEG_GPL=y BR2_PACKAGE_FFMPEG_NONFREE=y +BR2_PACKAGE_FFMPEG_FFMPEG=y +BR2_PACKAGE_FFMPEG_SWSCALE=y BR2_PACKAGE_FFMPEG_EXTRACONF="--disable-omx" -BR2_PACKAGE_GSTREAMER1=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ADDER=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIOTESTSRC=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ENCODING=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_TCP=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ALSA=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_JPEG=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUDIOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUTODETECT=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIPART=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTSP=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2_PROBE=y -BR2_PACKAGE_GST1_PLUGINS_BAD=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VIDEOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_FDK_AAC=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VOAACENC=y -BR2_PACKAGE_GST1_INTERPIPE=y -BR2_PACKAGE_GST1_LIBAV=y -BR2_PACKAGE_GST1_RTSP_SERVER=y -BR2_PACKAGE_GST_OMX=y -BR2_PACKAGE_GSTREAMER1_EDITING_SERVICES=y BR2_PACKAGE_LIBWEBCAM=y BR2_PACKAGE_MOTION=y BR2_PACKAGE_STREAMEYE=y +BR2_PACKAGE_V4L2LOOPBACK=y +BR2_PACKAGE_V4L2RTSPSERVER=y +BR2_PACKAGE_V4L2TOOLS=y BR2_PACKAGE_GZIP=y BR2_PACKAGE_JQ=y BR2_PACKAGE_CIFS_UTILS=y diff --git a/configs/raspberrypi_defconfig b/configs/raspberrypi_defconfig index b3fd3a09be..33b41c4151 100644 --- a/configs/raspberrypi_defconfig +++ b/configs/raspberrypi_defconfig @@ -29,35 +29,17 @@ BR2_PACKAGE_MOTIONEYE=y BR2_PACKAGE_ALSA_UTILS=y BR2_PACKAGE_ALSA_UTILS_AMIXER=y BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_FFMPEG=y BR2_PACKAGE_FFMPEG_GPL=y BR2_PACKAGE_FFMPEG_NONFREE=y -BR2_PACKAGE_GSTREAMER1=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ADDER=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_AUDIOTESTSRC=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ENCODING=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_TCP=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEORATE=y -BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ALSA=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_JPEG=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUDIOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_AUTODETECT=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIPART=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_RTSP=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2=y -BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_V4L2_PROBE=y -BR2_PACKAGE_GST1_PLUGINS_BAD=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VIDEOPARSERS=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_FDK_AAC=y -BR2_PACKAGE_GST1_PLUGINS_BAD_PLUGIN_VOAACENC=y -BR2_PACKAGE_GST1_INTERPIPE=y -BR2_PACKAGE_GST1_LIBAV=y -BR2_PACKAGE_GST1_RTSP_SERVER=y -BR2_PACKAGE_GST_OMX=y -BR2_PACKAGE_GSTREAMER1_EDITING_SERVICES=y +BR2_PACKAGE_FFMPEG_FFMPEG=y +BR2_PACKAGE_FFMPEG_SWSCALE=y BR2_PACKAGE_LIBWEBCAM=y BR2_PACKAGE_MOTION=y BR2_PACKAGE_STREAMEYE=y +BR2_PACKAGE_V4L2LOOPBACK=y +BR2_PACKAGE_V4L2RTSPSERVER=y +BR2_PACKAGE_V4L2TOOLS=y BR2_PACKAGE_GZIP=y BR2_PACKAGE_JQ=y BR2_PACKAGE_CIFS_UTILS=y @@ -99,7 +81,6 @@ BR2_PACKAGE_PYTHON_VERSIONTOOLS=y BR2_PACKAGE_CA_CERTIFICATES=y BR2_PACKAGE_LIBSSH2=y BR2_PACKAGE_LIBFUSE=y -BR2_PACKAGE_JPEG_TURBO=y BR2_PACKAGE_LIBV4L=y BR2_PACKAGE_LIBV4L_UTILS=y BR2_PACKAGE_LIBTHEORA=y From 2aee64c383caf17657ee5d010a48c72fe084d4b2 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Mon, 7 Oct 2019 16:58:31 +1100 Subject: [PATCH 3/3] Revert "streameye.sh: switch from gstreamer to v4l2multi_stream_mmal" This reverts commit 0f8af140c7bb285a3fabadcc7e3fb234a724086f. --- .../raspberrypi/overlay/usr/bin/streameye.sh | 221 ++++++++++++------ .../raspberrypi2/overlay/usr/bin/streameye.sh | 221 ++++++++++++------ .../raspberrypi3/overlay/usr/bin/streameye.sh | 221 ++++++++++++------ .../raspberrypi4/overlay/usr/bin/streameye.sh | 221 ++++++++++++------ 4 files changed, 600 insertions(+), 284 deletions(-) diff --git a/board/raspberrypi/overlay/usr/bin/streameye.sh b/board/raspberrypi/overlay/usr/bin/streameye.sh index 1f593f188a..9f63710c3c 100755 --- a/board/raspberrypi/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi/overlay/usr/bin/streameye.sh @@ -17,10 +17,7 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then + if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -33,6 +30,109 @@ function watch() { done } +function configure_v4l2_cam() { + video_arg="-d $1" + + horizontal_flip="0" + hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null + + vertical_flip="0" + vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null + + rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${rotate}" ]; then rotate="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null + + brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${brightness}" ]; then brightness="50"; fi + v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null + + contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${contrast}" ]; then contrast="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null + + saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${saturation}" ]; then saturation="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null + + sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${sharpness}" ]; then sharpness="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null + + vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${vstab}" ]; then vstab="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null + + shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${shutter}" ]; then shutter="0"; fi + if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null + + iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${iso}" ]; then iso="0"; fi + if [ "${iso}" -ge 800 ]; then iso="4" + elif [ "${iso}" -ge 400 ]; then iso="3" + elif [ "${iso}" -ge 200 ]; then iso="2" + elif [ "${iso}" -ge 100 ]; then iso="1" + else iso="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null + + awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${awb}" = "off" ]; then awb="0" + elif [ "${awb}" = "auto" ]; then awb="1" + elif [ "${awb}" = "sunlight" ]; then awb="6" + elif [ "${awb}" = "cloudy" ]; then awb="8" + elif [ "${awb}" = "shade" ]; then awb="9" + elif [ "${awb}" = "tungsten" ]; then awb="4" + elif [ "${awb}" = "fluorescent" ]; then awb="3" + elif [ "${awb}" = "incandescent" ]; then awb="2" + elif [ "${awb}" = "flash" ]; then awb="7" + elif [ "${awb}" = "horizon" ]; then awb="5" + else awb="1" + fi + v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null + + metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${metering}" = "spot" ]; then metering="2" + elif [ "${metering}" = "center" ]; then metering="1" + else metering="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null + + scene="0" + exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${exposure}" = "off" ]; then + exposure="1" + else + if [ "${exposure}" = "night" ]; then scene="8" + elif [ "${exposure}" = "backlight" ]; then scene="1" + elif [ "${exposure}" = "sports" ]; then scene="11" + elif [ "${exposure}" = "snow" ]; then scene="2" + elif [ "${exposure}" = "beach" ]; then scene="2" + elif [ "${exposure}" = "fireworks" ]; then scene="6" + fi + exposure="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null + v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null + + ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${ev}" ]; then ev="0"; fi + ev=$(expr ${ev} + 25) + ev=$(expr ${ev} / 2) + if [ "${ev}" -gt 24 ]; then ev="24"; fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null + + video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi + v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null +} + function invalid_opt() { local e match="$1" shift @@ -43,91 +143,70 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" - rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" - # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - # still need iptables? - #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP - audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then - audio_path=",${AUDIO_DEV}" - - # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG - audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + audio_extras="" if [ -n "${audio_bitrate}" ]; then - audio_opts="${audio_opts} -A ${audio_bitrate}" + audio_extras="${audio_extras},rate=${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_opts="${audio_opts} -C ${audio_channels}" - fi - if [ -n "${audio_format}" ]; then - audio_opts="${audio_opts} -a ${audio_format}" + audio_extras="${audio_extras},channels=${audio_channels}" fi + audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" + fi + video_path="/dev/video0" + if [ -n "${VIDEO_DEV}" ]; then + video_path=${VIDEO_DEV} fi - # hardcode to 90 for now - video_path="/dev/video90" - rmmod v4l2loopback - modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") - raspimjpeg_opts="--videoout ${video_path}" - while read line; do - key=$(echo ${line} | cut -d ' ' -f 1) - if invalid_opt "${key}" "${valid_opts[@]}"; then - continue - fi - if echo "${line}" | grep false &>/dev/null; then - continue - fi - if echo "${line}" | grep true &>/dev/null; then - line=${key} - fi - raspimjpeg_opts="${raspimjpeg_opts} --${line}" - done < ${RASPIMJPEG_CONF} - - video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_iso}" ]; then - raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" + # Only configure camera if it is a Pi Cam + if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then + configure_v4l2_cam ${video_path} fi + width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + video_extras="" + if [ -n "${width}" ]; then + video_extras="${video_extras},width=${width}" + fi + if [ -n "${height}" ]; then + video_extras="${video_extras},height=${height}" + fi + if [ -n "${framerate}" ]; then + video_extras="${video_extras},framerate=${framerate}/1" + fi + video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then - raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" - video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_framerate}" ]; then - rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" - fi - - v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & sleep 10 - v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & - + gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + sleep 5 fi - # still need iptables? - #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -168,9 +247,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -181,25 +260,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${v4l2rtspserver_pid}" ]; then - kill -HUP "${v4l2rtspserver_pid}" &>/dev/null + + if [ -n "${gst_launch_pid}" ]; then + kill -HUP "${gst_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true + kill -KILL "${gst_launch_pid}" &>/dev/null || true fi - if [ -n "${v4l2multi_stream_mmal_pid}" ]; then - kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null + if [ -n "${test_launch_pid}" ]; then + kill -HUP "${test_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true + kill -KILL "${test_launch_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi2/overlay/usr/bin/streameye.sh b/board/raspberrypi2/overlay/usr/bin/streameye.sh index 1f593f188a..9f63710c3c 100755 --- a/board/raspberrypi2/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi2/overlay/usr/bin/streameye.sh @@ -17,10 +17,7 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then + if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -33,6 +30,109 @@ function watch() { done } +function configure_v4l2_cam() { + video_arg="-d $1" + + horizontal_flip="0" + hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null + + vertical_flip="0" + vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null + + rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${rotate}" ]; then rotate="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null + + brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${brightness}" ]; then brightness="50"; fi + v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null + + contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${contrast}" ]; then contrast="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null + + saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${saturation}" ]; then saturation="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null + + sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${sharpness}" ]; then sharpness="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null + + vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${vstab}" ]; then vstab="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null + + shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${shutter}" ]; then shutter="0"; fi + if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null + + iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${iso}" ]; then iso="0"; fi + if [ "${iso}" -ge 800 ]; then iso="4" + elif [ "${iso}" -ge 400 ]; then iso="3" + elif [ "${iso}" -ge 200 ]; then iso="2" + elif [ "${iso}" -ge 100 ]; then iso="1" + else iso="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null + + awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${awb}" = "off" ]; then awb="0" + elif [ "${awb}" = "auto" ]; then awb="1" + elif [ "${awb}" = "sunlight" ]; then awb="6" + elif [ "${awb}" = "cloudy" ]; then awb="8" + elif [ "${awb}" = "shade" ]; then awb="9" + elif [ "${awb}" = "tungsten" ]; then awb="4" + elif [ "${awb}" = "fluorescent" ]; then awb="3" + elif [ "${awb}" = "incandescent" ]; then awb="2" + elif [ "${awb}" = "flash" ]; then awb="7" + elif [ "${awb}" = "horizon" ]; then awb="5" + else awb="1" + fi + v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null + + metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${metering}" = "spot" ]; then metering="2" + elif [ "${metering}" = "center" ]; then metering="1" + else metering="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null + + scene="0" + exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${exposure}" = "off" ]; then + exposure="1" + else + if [ "${exposure}" = "night" ]; then scene="8" + elif [ "${exposure}" = "backlight" ]; then scene="1" + elif [ "${exposure}" = "sports" ]; then scene="11" + elif [ "${exposure}" = "snow" ]; then scene="2" + elif [ "${exposure}" = "beach" ]; then scene="2" + elif [ "${exposure}" = "fireworks" ]; then scene="6" + fi + exposure="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null + v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null + + ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${ev}" ]; then ev="0"; fi + ev=$(expr ${ev} + 25) + ev=$(expr ${ev} / 2) + if [ "${ev}" -gt 24 ]; then ev="24"; fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null + + video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi + v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null +} + function invalid_opt() { local e match="$1" shift @@ -43,91 +143,70 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" - rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" - # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - # still need iptables? - #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP - audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then - audio_path=",${AUDIO_DEV}" - - # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG - audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + audio_extras="" if [ -n "${audio_bitrate}" ]; then - audio_opts="${audio_opts} -A ${audio_bitrate}" + audio_extras="${audio_extras},rate=${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_opts="${audio_opts} -C ${audio_channels}" - fi - if [ -n "${audio_format}" ]; then - audio_opts="${audio_opts} -a ${audio_format}" + audio_extras="${audio_extras},channels=${audio_channels}" fi + audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" + fi + video_path="/dev/video0" + if [ -n "${VIDEO_DEV}" ]; then + video_path=${VIDEO_DEV} fi - # hardcode to 90 for now - video_path="/dev/video90" - rmmod v4l2loopback - modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") - raspimjpeg_opts="--videoout ${video_path}" - while read line; do - key=$(echo ${line} | cut -d ' ' -f 1) - if invalid_opt "${key}" "${valid_opts[@]}"; then - continue - fi - if echo "${line}" | grep false &>/dev/null; then - continue - fi - if echo "${line}" | grep true &>/dev/null; then - line=${key} - fi - raspimjpeg_opts="${raspimjpeg_opts} --${line}" - done < ${RASPIMJPEG_CONF} - - video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_iso}" ]; then - raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" + # Only configure camera if it is a Pi Cam + if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then + configure_v4l2_cam ${video_path} fi + width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + video_extras="" + if [ -n "${width}" ]; then + video_extras="${video_extras},width=${width}" + fi + if [ -n "${height}" ]; then + video_extras="${video_extras},height=${height}" + fi + if [ -n "${framerate}" ]; then + video_extras="${video_extras},framerate=${framerate}/1" + fi + video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then - raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" - video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_framerate}" ]; then - rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" - fi - - v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & sleep 10 - v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & - + gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + sleep 5 fi - # still need iptables? - #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -168,9 +247,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -181,25 +260,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${v4l2rtspserver_pid}" ]; then - kill -HUP "${v4l2rtspserver_pid}" &>/dev/null + + if [ -n "${gst_launch_pid}" ]; then + kill -HUP "${gst_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true + kill -KILL "${gst_launch_pid}" &>/dev/null || true fi - if [ -n "${v4l2multi_stream_mmal_pid}" ]; then - kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null + if [ -n "${test_launch_pid}" ]; then + kill -HUP "${test_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true + kill -KILL "${test_launch_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi3/overlay/usr/bin/streameye.sh b/board/raspberrypi3/overlay/usr/bin/streameye.sh index 1f593f188a..9f63710c3c 100755 --- a/board/raspberrypi3/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi3/overlay/usr/bin/streameye.sh @@ -17,10 +17,7 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then + if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -33,6 +30,109 @@ function watch() { done } +function configure_v4l2_cam() { + video_arg="-d $1" + + horizontal_flip="0" + hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null + + vertical_flip="0" + vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null + + rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${rotate}" ]; then rotate="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null + + brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${brightness}" ]; then brightness="50"; fi + v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null + + contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${contrast}" ]; then contrast="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null + + saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${saturation}" ]; then saturation="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null + + sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${sharpness}" ]; then sharpness="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null + + vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${vstab}" ]; then vstab="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null + + shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${shutter}" ]; then shutter="0"; fi + if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null + + iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${iso}" ]; then iso="0"; fi + if [ "${iso}" -ge 800 ]; then iso="4" + elif [ "${iso}" -ge 400 ]; then iso="3" + elif [ "${iso}" -ge 200 ]; then iso="2" + elif [ "${iso}" -ge 100 ]; then iso="1" + else iso="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null + + awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${awb}" = "off" ]; then awb="0" + elif [ "${awb}" = "auto" ]; then awb="1" + elif [ "${awb}" = "sunlight" ]; then awb="6" + elif [ "${awb}" = "cloudy" ]; then awb="8" + elif [ "${awb}" = "shade" ]; then awb="9" + elif [ "${awb}" = "tungsten" ]; then awb="4" + elif [ "${awb}" = "fluorescent" ]; then awb="3" + elif [ "${awb}" = "incandescent" ]; then awb="2" + elif [ "${awb}" = "flash" ]; then awb="7" + elif [ "${awb}" = "horizon" ]; then awb="5" + else awb="1" + fi + v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null + + metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${metering}" = "spot" ]; then metering="2" + elif [ "${metering}" = "center" ]; then metering="1" + else metering="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null + + scene="0" + exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${exposure}" = "off" ]; then + exposure="1" + else + if [ "${exposure}" = "night" ]; then scene="8" + elif [ "${exposure}" = "backlight" ]; then scene="1" + elif [ "${exposure}" = "sports" ]; then scene="11" + elif [ "${exposure}" = "snow" ]; then scene="2" + elif [ "${exposure}" = "beach" ]; then scene="2" + elif [ "${exposure}" = "fireworks" ]; then scene="6" + fi + exposure="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null + v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null + + ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${ev}" ]; then ev="0"; fi + ev=$(expr ${ev} + 25) + ev=$(expr ${ev} / 2) + if [ "${ev}" -gt 24 ]; then ev="24"; fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null + + video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi + v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null +} + function invalid_opt() { local e match="$1" shift @@ -43,91 +143,70 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" - rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" - # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - # still need iptables? - #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP - audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then - audio_path=",${AUDIO_DEV}" - - # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG - audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + audio_extras="" if [ -n "${audio_bitrate}" ]; then - audio_opts="${audio_opts} -A ${audio_bitrate}" + audio_extras="${audio_extras},rate=${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_opts="${audio_opts} -C ${audio_channels}" - fi - if [ -n "${audio_format}" ]; then - audio_opts="${audio_opts} -a ${audio_format}" + audio_extras="${audio_extras},channels=${audio_channels}" fi + audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" + fi + video_path="/dev/video0" + if [ -n "${VIDEO_DEV}" ]; then + video_path=${VIDEO_DEV} fi - # hardcode to 90 for now - video_path="/dev/video90" - rmmod v4l2loopback - modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") - raspimjpeg_opts="--videoout ${video_path}" - while read line; do - key=$(echo ${line} | cut -d ' ' -f 1) - if invalid_opt "${key}" "${valid_opts[@]}"; then - continue - fi - if echo "${line}" | grep false &>/dev/null; then - continue - fi - if echo "${line}" | grep true &>/dev/null; then - line=${key} - fi - raspimjpeg_opts="${raspimjpeg_opts} --${line}" - done < ${RASPIMJPEG_CONF} - - video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_iso}" ]; then - raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" + # Only configure camera if it is a Pi Cam + if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then + configure_v4l2_cam ${video_path} fi + width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + video_extras="" + if [ -n "${width}" ]; then + video_extras="${video_extras},width=${width}" + fi + if [ -n "${height}" ]; then + video_extras="${video_extras},height=${height}" + fi + if [ -n "${framerate}" ]; then + video_extras="${video_extras},framerate=${framerate}/1" + fi + video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then - raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" - video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_framerate}" ]; then - rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" - fi - - v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & sleep 10 - v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & - + gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + sleep 5 fi - # still need iptables? - #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -168,9 +247,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -181,25 +260,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${v4l2rtspserver_pid}" ]; then - kill -HUP "${v4l2rtspserver_pid}" &>/dev/null + + if [ -n "${gst_launch_pid}" ]; then + kill -HUP "${gst_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true + kill -KILL "${gst_launch_pid}" &>/dev/null || true fi - if [ -n "${v4l2multi_stream_mmal_pid}" ]; then - kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null + if [ -n "${test_launch_pid}" ]; then + kill -HUP "${test_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true + kill -KILL "${test_launch_pid}" &>/dev/null || true fi } diff --git a/board/raspberrypi4/overlay/usr/bin/streameye.sh b/board/raspberrypi4/overlay/usr/bin/streameye.sh index 1f593f188a..9f63710c3c 100755 --- a/board/raspberrypi4/overlay/usr/bin/streameye.sh +++ b/board/raspberrypi4/overlay/usr/bin/streameye.sh @@ -17,10 +17,7 @@ function watch() { while true; do sleep 5 if [ "${PROTO}" = "rtsp" ]; then - if ! ps aux | grep v4l2multi_stream_mmal | grep -v grep &>/dev/null; then - logger -t streameye -s "not running, respawning" - start - elif ! ps aux | grep v4l2rtspserver | grep -v grep &>/dev/null; then + if ! ps aux | grep test-launch | grep -v grep &>/dev/null; then logger -t streameye -s "not running, respawning" start fi @@ -33,6 +30,109 @@ function watch() { done } +function configure_v4l2_cam() { + video_arg="-d $1" + + horizontal_flip="0" + hflip=$(grep -e ^hflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${hflip}" = "true" ]; then horizontal_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=horizontal_flip=${horizontal_flip} &>/dev/null + + vertical_flip="0" + vflip=$(grep -e ^vflip ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${vflip}" = "true" ]; then vertical_flip="1"; fi + v4l2-ctl ${video_arg} --set-ctrl=vertical_flip=${vertical_flip} &>/dev/null + + rotate=$(grep -e ^rotation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${rotate}" ]; then rotate="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=rotate=${rotate} &>/dev/null + + brightness=$(grep -e ^brightness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${brightness}" ]; then brightness="50"; fi + v4l2-ctl ${video_arg} --set-ctrl=brightness=${brightness} &>/dev/null + + contrast=$(grep -e ^contrast ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${contrast}" ]; then contrast="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=contrast=${contrast} &>/dev/null + + saturation=$(grep -e ^saturation ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${saturation}" ]; then saturation="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=saturation=${saturation} &>/dev/null + + sharpness=$(grep -e ^sharpness ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${sharpness}" ]; then sharpness="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=sharpness=${sharpness} &>/dev/null + + vstab=$(grep -e ^vstab ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${vstab}" ]; then vstab="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=image_stabilization=${vstab} &>/dev/null + + shutter=$(grep -e ^shutter ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${shutter}" ]; then shutter="0"; fi + if [ "${#shutter}" -gt 2 ]; then shutter=$(echo ${shutter/%??/}); else shutter="0"; fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_time_absolute=${shutter} &>/dev/null + + iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${iso}" ]; then iso="0"; fi + if [ "${iso}" -ge 800 ]; then iso="4" + elif [ "${iso}" -ge 400 ]; then iso="3" + elif [ "${iso}" -ge 200 ]; then iso="2" + elif [ "${iso}" -ge 100 ]; then iso="1" + else iso="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=iso_sensitivity=${iso} &>/dev/null + + awb=$(grep -e ^awb ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${awb}" = "off" ]; then awb="0" + elif [ "${awb}" = "auto" ]; then awb="1" + elif [ "${awb}" = "sunlight" ]; then awb="6" + elif [ "${awb}" = "cloudy" ]; then awb="8" + elif [ "${awb}" = "shade" ]; then awb="9" + elif [ "${awb}" = "tungsten" ]; then awb="4" + elif [ "${awb}" = "fluorescent" ]; then awb="3" + elif [ "${awb}" = "incandescent" ]; then awb="2" + elif [ "${awb}" = "flash" ]; then awb="7" + elif [ "${awb}" = "horizon" ]; then awb="5" + else awb="1" + fi + v4l2-ctl ${video_arg} --set-ctrl=white_balance_auto_preset=${awb} &>/dev/null + + metering=$(grep -e ^metering ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${metering}" = "spot" ]; then metering="2" + elif [ "${metering}" = "center" ]; then metering="1" + else metering="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=exposure_metering_mode=${awb} &>/dev/null + + scene="0" + exposure=$(grep -e ^exposure ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ "${exposure}" = "off" ]; then + exposure="1" + else + if [ "${exposure}" = "night" ]; then scene="8" + elif [ "${exposure}" = "backlight" ]; then scene="1" + elif [ "${exposure}" = "sports" ]; then scene="11" + elif [ "${exposure}" = "snow" ]; then scene="2" + elif [ "${exposure}" = "beach" ]; then scene="2" + elif [ "${exposure}" = "fireworks" ]; then scene="6" + fi + exposure="0" + fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure=${exposure} &>/dev/null + v4l2-ctl ${video_arg} --set-ctrl=scene_mode=${scene} &>/dev/null + + ev=$(grep -e ^ev ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${ev}" ]; then ev="0"; fi + ev=$(expr ${ev} + 25) + ev=$(expr ${ev} / 2) + if [ "${ev}" -gt 24 ]; then ev="24"; fi + v4l2-ctl ${video_arg} --set-ctrl=auto_exposure_bias=${ev} &>/dev/null + + video_bitrate=$(grep -e ^bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + if [ -z "${video_bitrate}" ]; then video_bitrate="1000000"; fi + v4l2-ctl ${video_arg} --set-ctrl=video_bitrate=${video_bitrate} &>/dev/null +} + function invalid_opt() { local e match="$1" shift @@ -43,91 +143,70 @@ function invalid_opt() { function start() { source ${STREAMEYE_CONF} streameye_opts="-p ${PORT}" - rtspserver_opts="" if [ -n "${CREDENTIALS}" ] && [ "${AUTH}" = "basic" ]; then streameye_opts="${streameye_opts} -a basic -c ${CREDENTIALS}" - # TODO: Add RTSP Auth fi - + if [ "${PROTO}" = "rtsp" ]; then - pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${pid}" ]; then return fi - + RTSP_PORT=${RTSP_PORT:-554} - # still need iptables? - #iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT - #iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -A INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -A INPUT -p tcp --dport ${RTSP_PORT} -j DROP - audio_path="" audio_opts="" if [ -n "${AUDIO_DEV}" ]; then - audio_path=",${AUDIO_DEV}" - - # Audio bitrate: default 44100 audio_bitrate=$(grep -e ^audio_bitrate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Audio channels: default 2 audio_channels=$(grep -e ^audio_channels ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - # Valid audio formats: S16_BE, S16_LE, S24_BE, S24_LE, S32_BE, S32_LE, ALAW, MULAW, S8, MPEG - audio_format=$(grep -e ^audio_format ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + audio_extras="" if [ -n "${audio_bitrate}" ]; then - audio_opts="${audio_opts} -A ${audio_bitrate}" + audio_extras="${audio_extras},rate=${audio_bitrate}" fi if [ -n "${audio_channels}" ]; then - audio_opts="${audio_opts} -C ${audio_channels}" - fi - if [ -n "${audio_format}" ]; then - audio_opts="${audio_opts} -a ${audio_format}" + audio_extras="${audio_extras},channels=${audio_channels}" fi + audio_opts="alsasrc device=${AUDIO_DEV} ! audioresample ! audio/x-raw${audio_extras} ! queue ! voaacenc ! rtpmp4gpay pt=97 name=pay1" + fi + video_path="/dev/video0" + if [ -n "${VIDEO_DEV}" ]; then + video_path=${VIDEO_DEV} fi - # hardcode to 90 for now - video_path="/dev/video90" - rmmod v4l2loopback - modprobe v4l2loopback video_nr=90 if [ -e "${video_path}" ]; then - valid_opts=("analoggain" "awb" "awbgains" "bitrate" "brightness" "colfx" "contrast" "denoise" "digitalgain" "drc" "ev" "exposure" "flicker" "framerate" "height" "hflip" "imxfx" "intra" "irefresh" "level" "metering" "profile" "roi" "rotation" "saturation" "sharpness" "shutter" "vflip" "vstab" "width" "mjpegbitrate" "mjpegframerate" "mjpegwidth" "mjpegheight") - raspimjpeg_opts="--videoout ${video_path}" - while read line; do - key=$(echo ${line} | cut -d ' ' -f 1) - if invalid_opt "${key}" "${valid_opts[@]}"; then - continue - fi - if echo "${line}" | grep false &>/dev/null; then - continue - fi - if echo "${line}" | grep true &>/dev/null; then - line=${key} - fi - raspimjpeg_opts="${raspimjpeg_opts} --${line}" - done < ${RASPIMJPEG_CONF} - - video_iso=$(grep -e ^iso ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_iso}" ]; then - raspimjpeg_opts="${raspimjpeg_opts} --ISO ${video_iso}" + # Only configure camera if it is a Pi Cam + if v4l2-ctl -d ${video_path} -D | grep -q 'bm2835 mmal'; then + configure_v4l2_cam ${video_path} fi + width=$(grep -e ^width ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + height=$(grep -e ^height ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) + video_extras="" + if [ -n "${width}" ]; then + video_extras="${video_extras},width=${width}" + fi + if [ -n "${height}" ]; then + video_extras="${video_extras},height=${height}" + fi + if [ -n "${framerate}" ]; then + video_extras="${video_extras},framerate=${framerate}/1" + fi + video_opts="v4l2src device=${video_path} ! video/x-h264${video_extras} ! h264parse ! rtph264pay name=pay0 pt=96" if [ -r ${MOTIONEYE_CONF} ] && grep 'log-level debug' ${MOTIONEYE_CONF} >/dev/null; then - raspimjpeg_opts="${raspimjpeg_opts} -v" streameye_opts="${streameye_opts} -d" fi - rtspserver_opts="${rtspserver_opts} -P ${RTSP_PORT} -u h264" - video_framerate=$(grep -e ^framerate ${RASPIMJPEG_CONF} | cut -d ' ' -f 2) - if [ -n "${video_framerate}" ]; then - rtspserver_opts="${rtspserver_opts} -F ${video_framerate}" - fi - - v4l2multi_stream_mmal ${raspimjpeg_opts} -o - 2>${RASPIMJPEG_LOG} | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + test-launch -p ${RTSP_PORT} -m h264 "\"( ${video_opts} ${audio_opts} )\"" &>${GSTREAMER_LOG} & sleep 10 - v4l2rtspserver ${rtspserver_opts} ${audio_opts} ${video_path}${audio_path} & - + gst-launch-1.0 -v rtspsrc location=rtsp://127.0.0.1:${RTSP_PORT}/h264 latency=0 drop-on-latency=1 ! rtph264depay ! h264parse ! omxh264dec ! videorate ! video/x-raw,framerate=5/1 ! jpegenc ! filesink location=/dev/stdout | streameye ${streameye_opts} &>${STREAMEYE_LOG} & + sleep 5 fi - # still need iptables? - #iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP - #iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT + iptables -D INPUT -p tcp --dport ${RTSP_PORT} -j DROP + iptables -D INPUT -p tcp -s localhost --dport ${RTSP_PORT} -j ACCEPT else pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) @@ -168,9 +247,9 @@ function stop() { # stop the raspimjpeg process raspimjpeg_pid=$(ps | grep raspimjpeg.py | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the gst-launch-1.0 process - v4l2rtspserver_pid=$(ps | grep v4l2rtspserver | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + gst_launch_pid=$(ps | grep gst-launch-1.0 | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) # stop the test-launch process - v4l2multi_stream_mmal_pid=$(ps | grep v4l2multi_stream_mmal | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) + test_launch_pid=$(ps | grep test-launch | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1) if [ -n "${raspimjpeg_pid}" ]; then kill -HUP "${raspimjpeg_pid}" &>/dev/null @@ -181,25 +260,25 @@ function stop() { done kill -KILL "${raspimjpeg_pid}" &>/dev/null || true fi - - if [ -n "${v4l2rtspserver_pid}" ]; then - kill -HUP "${v4l2rtspserver_pid}" &>/dev/null + + if [ -n "${gst_launch_pid}" ]; then + kill -HUP "${gst_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2rtspserver_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${gst_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2rtspserver_pid}" &>/dev/null || true + kill -KILL "${gst_launch_pid}" &>/dev/null || true fi - if [ -n "${v4l2multi_stream_mmal_pid}" ]; then - kill -HUP "${v4l2multi_stream_mmal_pid}" &>/dev/null + if [ -n "${test_launch_pid}" ]; then + kill -HUP "${test_launch_pid}" &>/dev/null count=0 - while kill -0 "${v4l2multi_stream_mmal_pid}" &>/dev/null && [ ${count} -lt 5 ]; do + while kill -0 "${test_launch_pid}" &>/dev/null && [ ${count} -lt 5 ]; do sleep 1 count=$((${count} + 1)) done - kill -KILL "${v4l2multi_stream_mmal_pid}" &>/dev/null || true + kill -KILL "${test_launch_pid}" &>/dev/null || true fi }