summaryrefslogtreecommitdiff
path: root/bin/recv-gst-rtp-v-a
blob: dbf21c0b98c6aa956ecedc9933e1bbb21d71f87e (plain)
  1. #!/bin/sh
  2. # Receive RTP video and audio streams
  3. set -e
  4. CAMIP=${CAMIP:-$1} # origin host - default: use multicast group
  5. ACOUNT=${ACOUNT:-${2:-0}} # number of audio stream(s) to play - default: 0
  6. VCOUNT=${VCOUNT:-${3:-1}} # number of video stream(s) to display - default: 1
  7. AFORMAT=${AFORMAT:-$4} # AMR OPUS RAW - default: RAW
  8. VFORMAT=${VFORMAT:-$5} # H264 VP8 RAW - default: RAW
  9. ASINK=${ASINK:-autoaudiosink}
  10. VSINK=${VSINK:-autovideosink}
  11. set -u
  12. # set multicast groups (also for recorder host) if camera host is wildcard
  13. [ -n "$CAMIP" ] || RECMIP=239.255.0.1
  14. [ -n "$CAMIP" ] || CAMMIP=239.255.0.2
  15. RECHOST="${RECMIP:+address=$RECMIP auto-multicast=true}"
  16. CAMHOST="${CAMIP:+host=$CAMIP}${CAMMIP:+host=$CAMMIP auto-multicast=true}"
  17. # http://stackoverflow.com/a/42237307
  18. ABUFFERS=80000
  19. NETLATENCY=20
  20. case "$AFORMAT" in
  21. AMR)
  22. ACAPS=application/x-rtp,media=audio,clock-rate=8000,encoding-name=AMR,encoding-params="(string)1",octet-align="(string)1",payload=96
  23. ADEC="rtpamrdepay ! amrnbdec"
  24. ;;
  25. OPUS)
  26. ACAPS=audio/x-raw,rate=48000,channels=1,format=S16LE,layout=interleaved
  27. ADEC="rtpopusdepay ! opusdec"
  28. ;;
  29. RAW|'')
  30. ACAPS=application/x-rtp,media=audio,clock-rate=44100,encoding-name=L16,encoding-params=1,channels=1,payload=96
  31. ADEC="rtpL16depay"
  32. ;;
  33. *)
  34. echo "ERROR: Unsupported audio format: \"$AFORMAT\""
  35. exit 1
  36. ;;
  37. esac
  38. case "$VFORMAT" in
  39. H264)
  40. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=H264
  41. VDEC="rtph264depay ! avdec_h264"
  42. ;;
  43. VP8)
  44. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=VP8
  45. VDEC="rtpvp8depay ! vp8dec"
  46. ;;
  47. RAW|'')
  48. VCAPS=application/x-rtp,media=video,clock-rate=90000,encoding-name=RAW,sampling=YCbCr-4:2:0,depth="(string)8",width="(string)432",height="(string)240",payload=96,a-framerate=30
  49. VDEC="rtpvrawdepay ! videoconvert ! queue"
  50. ;;
  51. *)
  52. echo "ERROR: Unsupported video format: \"$VFORMAT\""
  53. exit 1
  54. ;;
  55. esac
  56. stream() {
  57. ID=$1
  58. CAPS=$2
  59. SINK=$3
  60. echo \
  61. udpsrc port=$((5000+ID-1)) $RECHOST caps=\""$CAPS"\" \
  62. ! rtpbin."recv_rtp_sink_$ID" rtpbin. \
  63. ! $SINK \
  64. udpsrc port=$((5010+ID-1)) $RECHOST \
  65. ! rtpbin."recv_rtcp_sink_$ID" \
  66. rtpbin."send_rtcp_src_$ID" \
  67. ! udpsink port=$((5020+ID-1)) $CAMHOST sync=false async=false
  68. }
  69. gst-launch-1.0 -v \
  70. rtpbin name=rtpbin latency=$NETLATENCY drop-on-latency=true \
  71. $(n=0;\
  72. for i in $(seq "$ACOUNT"); do n=$((n+1)); stream "$n" "$ACAPS" "$ADEC ! $ASINK buffer-time=$ABUFFERS"; done;\
  73. for i in $(seq "$VCOUNT"); do n=$((n+1)); stream "$n" "$VCAPS" "$VDEC ! $VSINK"; done;\
  74. )