SHARE
TWEET

Untitled

a guest Apr 5th, 2018 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. exec 3>/tmp/"${0##*/}".1debug$$
  4. export BASH_XTRACEFD=3
  5. set -x
  6. echo "$@" >&3
  7. env >&3
  8.  
  9. send() {
  10.  
  11. echo "Sending $1" >&3
  12. echo "$1" >&2
  13.  
  14. }
  15.  
  16. while read -r cmd; do
  17. echo "Got \"$cmd\"" >&3
  18. case $cmd in
  19. "Version?")
  20. send "OK:1.0.0"
  21. ;;
  22. "HasTuner?")
  23. send "OK:No"
  24. ;;
  25. "CloseRecorder")
  26. send "OK:Terminating"
  27. exit 0
  28. ;;
  29. "HasPictureAttributes?")
  30. send "OK:No"
  31. ;;
  32. "FlowControl?")
  33. send "OK:XON/XOFF"
  34. ;;
  35. BlockSize:*)
  36. send "OK"
  37. ;;
  38. TuneChannel:*)
  39. channel=${cmd##*:}
  40. case $channel in
  41. 3) URL="https://..."
  42. ;;
  43. 4) URL="https://..."
  44. ;;
  45. esac
  46. send "OK"
  47. ;;
  48. "LockTimeout?")
  49. send "OK:10000"
  50. ;;
  51. "SignalStrengthPercent?")
  52. send "OK:100"
  53. ;;
  54. "HasLock?")
  55. send "OK:Yes"
  56. ;;
  57. "StartStreaming")
  58. ffmpeg -i "udp://@239.255.42.42:5004" -acodec copy -vcodec copy -f mpegts - 2>&3 &
  59. ffmpeg_pid=$!
  60. send "OK:Started"
  61. ;;
  62. "StopStreaming")
  63. if [ -n "$ffmpeg_pid" ] && [ -d /proc/$ffmpeg_pid ]; then
  64. kill  $ffmpeg_pid
  65. fi
  66. send "OK:Stopped"
  67. ;;
  68. "IsOpen?")
  69. if [ -n "$ffmpeg_pid" ] && [ -d /proc/$ffmpeg_pid ]; then
  70. send "OK:Open"
  71. else
  72. send "OK:No"
  73. fi
  74. ;;
  75. "XON")
  76. echo "Uh oh! need to handle \"$cmd\" at $(date)" >&3
  77. send "OK"
  78. ;;
  79. "XOFF")
  80. echo "Uh oh! need to handle \"$cmd\" at $(date)" >&3
  81. send "OK"
  82. ;;
  83. *)
  84. echo "Unknown cmd \"$cmd\"" >&3
  85. ;;
  86. esac
  87. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top