Skip to content

ownerofglory/go-pion-raspi-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go + Pion (WebRTC) on Raspberry Pi PoC

It's a PoC WebRTC client for Raspberry Pi, built with Pion (GitHub Repo) and GStreamer. It connects to a signaling server, streams camera/microphone over WebRTC, and supports data channels for testing peer connections

Prerequisites

I tested it on a Raspberry Pi model 4B (1GB RAM, 1,4 GHz ARM Cortex-A53 Quad-Core-CPU) but I guess it can easily run on a smaller model like Raspberry Pi Zero or Raspberry Pi Zero 2 W

  • Gstreamer installed on Raspberry Pi
  • (Optional) Go installed, otherwise cross-compile the program for raspi
  • Camera [and microphone if needed], connected to raspi
  • Signaling server or any other mean to exchange the SPD messages and ICE-candidates
  • Set the env var, e.g:
  export SIGNAL_WS_URL=wss://your.host/webrtc-signaling/ws
  export SIGNAL_ORIGIN=https://your.host # (must match AllowedOrigins)
  export RTC_CONFIG_URL=https://your.host/webrtc-signaling/api/rtc-config
  
  #  optional:
  # export VIDEO_PORT=5004
  # export AUDIO_PORT=5006
  # export GST_VIDEO_PIPELINE='libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast key-int-max=60 ! h264parse config-interval=1 ! rtph264pay pt=96 config-interval=1 ! udpsink host=127.0.0.1 port=5004'
  # export GST_AUDIO_PIPELINE='alsasrc ! audioconvert ! audioresample ! opusenc bitrate=24000 ! rtpopuspay pt=111 ! udpsink host=127.0.0.1 port=5006'

I used my own "playground" signaling server on websockets

Run

Download the binary

wget https://github.com/ownerofglory/go-pion-raspi-poc/releases/download/v1.0.0/pi-client-arm64.zip
unzip pi-client-arm64.zip

OR

[Cross-]compile for Raspi

make

Drop the program into your raspi

scp ./build/pi-client-arm64 <user>@<raspberry_host>:~

Run on Raspi

Once the env variable set:

./pi-client-arm64

OR Set the env variables inline

SIGNAL_WS_URL=wss://your.host/webrtc-signaling/ws \
SIGNAL_ORIGIN=https://your.host \
RTC_CONFIG_URL=https://your.host/webrtc-signaling/api/rtc-config \
./pi-client-arm64

Example running with my "playground" signaling server

Copy your user ID

Use the user id to call your Raspberry PI from the other host

Troubleshooting

Once both peers exchanges their session information you'll see similar log output

If the issues is with the camera try running the Gstreamer pipeline on your Raspberry Pi to see whether the video is working overall

Set <your_other_host_ip> to the IP of your machine within your local network and start transmitting video from Raspberry Pi

gst-launch-1.0 libcamerasrc ! video/x-raw,width=640,height=480,framerate=30/1 !   \
videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=ultrafast !     \
rtph264pay config-interval=1 pt=96 !     udpsink host=<your_other_host_ip> port=5000 

On your other machine start the receiver pipeline. Example for MacOS:

gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, media=video, encoding-name=H264, payload=96" ! \
    rtph264depay ! avdec_h264 ! autovideosink

About

a PoC WebRTC client for Raspberry Pi, built with Pion and GStreamer

Topics

Resources

License

Stars

Watchers

Forks