#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Short-Description: Start rtsp service
# Description:       Enable RTMP Streaming Video
### END INIT INFO

. /opt/wz_mini/wz_mini.conf

case "$1" in
	start)
		echo "#####$(basename "$0")#####"

		if ([[ "$RTSP_LOW_RES_ENABLED" == "true" ]] || [[ "$RTSP_HI_RES_ENABLED" == "true" ]]) && [[ "$RTMP_STREAM_ENABLED" == "true" ]] && ([[ "$RTSP_LOW_RES_ENABLE_AUDIO" == "true" ]] || [[ "$RTSP_HI_RES_ENABLE_AUDIO" == "true" ]]); then
			if [[ "$RTMP_STREAM_DISABLE_AUDIO" == "true" ]]; then
				RTMP_AUDIO="no_audio"
			fi
			echo "delay RTMP server"
			#Follow the delay from the RTSP server
			sleep 5
			/opt/wz_mini/bin/rtmp-stream.sh "$RTMP_STREAM_SERVICE" "$RTMP_AUDIO" &
		fi
		;;
	stop)
		pkill dnsmasq
		;;
	restart)
		$0 stop
		$0 start
		;;
	*)
		echo "Usage: $0 {start|stop}"
		exit 1
		;;
esac

