summaryrefslogtreecommitdiff
path: root/bin/recv-gst-rtp-v-a
blob: 17cd16eb423a7c8a4d5b1da956692b315d32e7e8 (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. case "$VFORMAT" in
  18. H264)
  19. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=H264
  20. VDEC="rtph264depay ! avdec_h264"
  21. ;;
  22. VP8)
  23. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=VP8
  24. VDEC="rtpvp8depay ! vp8dec"
  25. ;;
  26. RAW|'')
  27. 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
  28. VDEC="rtpvrawdepay ! videoconvert ! queue"
  29. ;;
  30. esac
  31. case "$AFORMAT" in
  32. AMR)
  33. ACAPS=application/x-rtp,media=audio,clock-rate=8000,encoding-name=AMR,encoding-params="(string)1",octet-align="(string)1",payload=96
  34. ADEC="rtpamrdepay ! amrnbdec"
  35. ;;
  36. OPUS)
  37. ACAPS=audio/x-raw,rate=48000,channels=1,format=S16LE,layout=interleaved
  38. ADEC="rtpopusdepay ! opusdec"
  39. ;;
  40. RAW|'')
  41. ACAPS=application/x-rtp,media=audio,clock-rate=44100,encoding-name=L16,encoding-params=1,channels=1,payload=96
  42. ADEC="rtpL16depay"
  43. ;;
  44. esac
  45. stream() {
  46. ID=$1
  47. CAPS=$2
  48. SINK=$3
  49. echo \
  50. udpsrc port=$((5000+ID-1)) $RECHOST caps=\""$CAPS"\" \
  51. ! rtpbin."recv_rtp_sink_$ID" rtpbin. \
  52. ! $SINK \
  53. udpsrc port=$((5010+ID-1)) $RECHOST \
  54. ! rtpbin."recv_rtcp_sink_$ID" \
  55. rtpbin."send_rtcp_src_$ID" \
  56. ! udpsink port=$((5020+ID-1)) $CAMHOST sync=false async=false
  57. }
  58. gst-launch-1.0 -v \
  59. rtpbin name=rtpbin \
  60. $(for i in $(seq "${VCOUNT:-1}"); do stream "$i" "$VCAPS" "$VDEC ! $VSINK"; done) \
  61. $(for j in $(seq "${ACOUNT:-0}"); do stream $((VCOUNT+j)) "$ACAPS" "$ADEC ! $ASINK"; done)