summaryrefslogtreecommitdiff
path: root/bin/recv-gst-rtp-v-a
blob: 2289d045472777bd3313c4b5273e1ad3617afcf7 (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. VCOUNT=${VCOUNT:-$2} # number of video stream(s) to display - default: 1
  6. ACOUNT=${ACOUNT:-$3} # number of audio stream(s) to play - default: 0
  7. VFORMAT=${VFORMAT:-$4} # H264 VP8 RAW - default: RAW
  8. AFORMAT=${AFORMAT:-$5} # AMR OPUS RAW - default: RAW
  9. VSINK=${VSINK:-autovideosink}
  10. ASINK=${ASINK:-autoaudiosink}
  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 "$VFORMAT" in
  21. H264)
  22. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=H264
  23. VDEC="rtph264depay ! avdec_h264"
  24. ;;
  25. VP8)
  26. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=VP8
  27. VDEC="rtpvp8depay ! vp8dec"
  28. ;;
  29. RAW|'')
  30. 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
  31. VDEC="rtpvrawdepay ! videoconvert ! queue"
  32. ;;
  33. *)
  34. echo "ERROR: Unsupported video format: \"$VFORMAT\""
  35. exit 1
  36. ;;
  37. esac
  38. case "$AFORMAT" in
  39. AMR)
  40. ACAPS=application/x-rtp,media=audio,clock-rate=8000,encoding-name=AMR,encoding-params="(string)1",octet-align="(string)1",payload=96
  41. ADEC="rtpamrdepay ! amrnbdec"
  42. ;;
  43. OPUS)
  44. ACAPS=audio/x-raw,rate=48000,channels=1,format=S16LE,layout=interleaved
  45. ADEC="rtpopusdepay ! opusdec"
  46. ;;
  47. RAW|'')
  48. ACAPS=application/x-rtp,media=audio,clock-rate=44100,encoding-name=L16,encoding-params=1,channels=1,payload=96
  49. ADEC="rtpL16depay"
  50. ;;
  51. *)
  52. echo "ERROR: Unsupported audio format: \"$AFORMAT\""
  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. $(for i in $(seq "${VCOUNT:-1}"); do stream "$i" "$VCAPS" "$VDEC ! $VSINK"; done) \
  72. $(for j in $(seq "${ACOUNT:-0}"); do stream $((VCOUNT+j)) "$ACAPS" "$ADEC ! $ASINK buffer-time=$ABUFFERS"; done)