S15v4l2rtspserver 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:
  4. # Short-Description: Start RTSP Server
  5. # Description: Provide RTSP Streaming Video over IP
  6. ### END INIT INFO
  7. . /opt/wz_mini/wz_mini.conf
  8. RTSP=/opt/wz_mini/log/v4l2rtspserver
  9. if [[ -e $RTSP.log || -L $RTSP.log ]] ; then
  10. i=0
  11. while [[ -e $RTSP.log.$i || -L $RTSP.log.$i ]] ; do
  12. let i++
  13. done
  14. mv $RTSP.log $RTSP.log.$i
  15. RTSP=$RTSP
  16. fi
  17. touch -- "$RTSP".log
  18. case "$1" in
  19. start)
  20. echo "#####$(basename "$0")#####"
  21. if [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  22. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  23. HI_VIDEO_DEV="/dev/video6"
  24. else
  25. HI_VIDEO_DEV="/dev/video1"
  26. fi
  27. if [[ "$RTSP_PASSWORD" = "" ]]; then
  28. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  29. fi
  30. echo "Enable video ch 0"
  31. /opt/wz_mini/bin/cmd video 0 on > /dev/null
  32. if [[ "$RTSP_HI_RES_ENABLE_AUDIO" == "true" ]]; then
  33. echo "Enable audio ch 0"
  34. /opt/wz_mini/bin/cmd audio 0 on > /dev/null
  35. AUDIO_CH="-C 1"
  36. AUDIO_FMT="-a S16_LE"
  37. DEVICE1="$HI_VIDEO_DEV,hw:0,0"
  38. else
  39. DEVICE1="$HI_VIDEO_DEV"
  40. echo "rtsp hi_res audio disabled"
  41. fi
  42. else
  43. echo "rtsp hi_res disabled"
  44. fi
  45. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]]; then
  46. if [ -f /opt/wz_mini/tmp/.T20 ]; then
  47. LOW_VIDEO_DEV="/dev/video7"
  48. else
  49. LOW_VIDEO_DEV="/dev/video2"
  50. fi
  51. echo "Enable video ch 1"
  52. /opt/wz_mini/bin/cmd video 1 on > /dev/null
  53. if [[ "$RTSP_PASSWORD" = "" ]]; then
  54. RTSP_PASSWORD=$(cat /opt/wz_mini/tmp/wlan0_mac)
  55. fi
  56. if [[ "$RTSP_LOW_RES_ENABLE_AUDIO" == "true" ]]; then
  57. echo "Enable video ch 1"
  58. /opt/wz_mini/bin/cmd audio 1 on > /dev/null
  59. AUDIO_CH="-C 1"
  60. AUDIO_FMT="-a S16_LE"
  61. DEVICE2="$LOW_VIDEO_DEV,hw:2,0"
  62. else
  63. DEVICE2="$LOW_VIDEO_DEV"
  64. echo "rtsp low_res audio disabled"
  65. fi
  66. else
  67. echo "rtsp low_res disabled"
  68. fi
  69. if [[ "$RTSP_LOW_RES_ENABLED" == "true" ]] || [[ "$RTSP_HI_RES_ENABLED" == "true" ]]; then
  70. echo "delay RTSP for iCamera"
  71. #This delay is required. Sometimes, if you start the rtsp server too soon, live view will break on the app.
  72. sleep 5
  73. if [[ "$RTSP_AUTH_DISABLE" == "true" ]]; then
  74. echo "Starting RTSP server"
  75. LD_LIBRARY_PATH=/opt/wz_mini/lib LD_PRELOAD=/system/lib/libsetunbuf.so /opt/wz_mini/bin/v4l2rtspserver $AUDIO_CH $AUDIO_FMT -F0 -P "$RTSP_PORT" $DEVICE1 $DEVICE2 > $RTSP.log 2>&1 &
  76. else
  77. echo "Starting RTSP server"
  78. LD_LIBRARY_PATH=/opt/wz_mini/lib LD_PRELOAD=/system/lib/libsetunbuf.so /opt/wz_mini/bin/v4l2rtspserver $AUDIO_CH $AUDIO_FMT -F0 -U "$RTSP_LOGIN":"$RTSP_PASSWORD" -P "$RTSP_PORT" $DEVICE1 $DEVICE2 > $RTSP.log 2>&1 &
  79. fi
  80. sleep 1
  81. echo "Set imp variables via helper"
  82. /opt/wz_mini/usr/bin/imp_helper.sh > /dev/null 2>&1 &
  83. fi
  84. sync;echo 3 > /proc/sys/vm/drop_caches
  85. ;;
  86. stop)
  87. pkill v4l2rtspserver
  88. cmd video 0 off
  89. cmd audio 0 off
  90. cmd video 1 off
  91. cmd audio 1 off
  92. pkill imp_helper.sh
  93. ;;
  94. restart)
  95. $0 stop
  96. $0 start
  97. ;;
  98. *)
  99. echo "Usage: $0 {start|stop}"
  100. exit 1
  101. ;;
  102. esac