summaryrefslogtreecommitdiff
path: root/bin/recv-gst-rtp-v-a
blob: 3b48d17a926afb9318ca23ab632e63428570c5b7 (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: H264
  8. AFORMAT=${AFORMAT:-$5} # AMR OPUS RAW - default: AMR
  9. set -u
  10. # set multicast groups (also for recorder host) if camera host is wildcard
  11. [ -n "$CAMIP" ] || RECMIP=239.255.0.1
  12. [ -n "$CAMIP" ] || CAMMIP=239.255.0.2
  13. RECHOST="${RECMIP:+address=$RECMIP auto-multicast=true}"
  14. CAMHOST="${CAMIP:+host=$CAMIP}${CAMMIP:+host=$CAMMIP auto-multicast=true}"
  15. case "$VFORMAT" in
  16. H264|'')
  17. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=H264
  18. VDEC="rtph264depay ! avdec_h264"
  19. ;;
  20. VP8)
  21. VCAPS=application/x-rtp,media=video,clock-rate=90000,payload=96,encoding-name=VP8
  22. VDEC="rtpvp8depay ! vp8dec"
  23. ;;
  24. RAW)
  25. 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
  26. VDEC="rtpvrawdepay ! videoconvert ! queue"
  27. ;;
  28. esac
  29. case "$AFORMAT" in
  30. AMR|'')
  31. ACAPS=application/x-rtp,media=audio,clock-rate=8000,encoding-name=AMR,encoding-params="(string)1",octet-align="(string)1",payload=96
  32. ADEC="rtpamrdepay ! amrnbdec"
  33. ;;
  34. OPUS)
  35. ACAPS=audio/x-raw,rate=48000,channels=1,format=S16LE,layout=interleaved
  36. ADEC="rtpopusdepay ! opusdec"
  37. ;;
  38. RAW)
  39. ACAPS=application/x-rtp,media=audio,clock-rate=44100,encoding-name=L16,encoding-params=1,channels=1,payload=96
  40. ADEC="rtpL16depay"
  41. ;;
  42. esac
  43. stream() {
  44. ID=$1
  45. CAPS=$2
  46. SINK=$3
  47. echo \
  48. udpsrc port=$((5000+ID-1)) $RECHOST caps=\""$CAPS"\" \
  49. ! rtpbin."recv_rtp_sink_$ID" rtpbin. \
  50. ! $SINK \
  51. udpsrc port=$((5010+ID-1)) $RECHOST \
  52. ! rtpbin."recv_rtcp_sink_$ID" \
  53. rtpbin."send_rtcp_src_$ID" \
  54. ! udpsink port=$((5020+ID-1)) $CAMHOST sync=false async=false
  55. }
  56. gst-launch-1.0 -v \
  57. rtpbin name=rtpbin \
  58. $(for i in $(seq "${VCOUNT:-1}"); do stream "$i" "$VCAPS" "$VDEC ! autovideosink"; done) \
  59. $(for j in $(seq "${ACOUNT:-0}"); do stream $((VCOUNT+j)) "$ACAPS" "$ADEC ! autoaudiosink"; done)