summaryrefslogtreecommitdiff
path: root/bin/recv-gst-rtp-v-a
blob: daffd252fcde64ceeb73fcb86db85d0a374447a0 (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. esac
  34. case "$AFORMAT" in
  35. AMR)
  36. ACAPS=application/x-rtp,media=audio,clock-rate=8000,encoding-name=AMR,encoding-params="(string)1",octet-align="(string)1",payload=96
  37. ADEC="rtpamrdepay ! amrnbdec"
  38. ;;
  39. OPUS)
  40. ACAPS=audio/x-raw,rate=48000,channels=1,format=S16LE,layout=interleaved
  41. ADEC="rtpopusdepay ! opusdec"
  42. ;;
  43. RAW|'')
  44. ACAPS=application/x-rtp,media=audio,clock-rate=44100,encoding-name=L16,encoding-params=1,channels=1,payload=96
  45. ADEC="rtpL16depay"
  46. ;;
  47. esac
  48. stream() {
  49. ID=$1
  50. CAPS=$2
  51. SINK=$3
  52. echo \
  53. udpsrc port=$((5000+ID-1)) $RECHOST caps=\""$CAPS"\" \
  54. ! rtpbin."recv_rtp_sink_$ID" rtpbin. \
  55. ! $SINK \
  56. udpsrc port=$((5010+ID-1)) $RECHOST \
  57. ! rtpbin."recv_rtcp_sink_$ID" \
  58. rtpbin."send_rtcp_src_$ID" \
  59. ! udpsink port=$((5020+ID-1)) $CAMHOST sync=false async=false
  60. }
  61. gst-launch-1.0 -v \
  62. rtpbin name=rtpbin latency=$NETLATENCY drop-on-latency=true \
  63. $(for i in $(seq "${VCOUNT:-1}"); do stream "$i" "$VCAPS" "$VDEC ! $VSINK"; done) \
  64. $(for j in $(seq "${ACOUNT:-0}"); do stream $((VCOUNT+j)) "$ACAPS" "$ADEC ! $ASINK buffer-time=$ABUFFERS"; done)