libpeer Documentation
repository·main·Indexed 23 days ago
https://github.com/sepfy/libpeerA portable WebRTC implementation written in C using BSD sockets, optimized for IoT and embedded devices such as ESP32, Raspberry Pi, and RP2040 Pico W. It supports video, audio, and data streaming with codecs including H264, OPUS, and G.711 PCM, and signaling via WHIP and MQTT. The library provides platform-specific examples for MJPEG over datachannel on ESP32, ping-pong functionality on Pico W, and two-way audio/video streaming on Raspberry Pi.
What's inside libpeer
- libpeer is a portable WebRTC implementation written in C using BSD sockets, designed for IoT and embedded devices like ESP32 and Raspberry Pi. It supports video/audio streaming, data channels, and various signaling methods.
Configure and build the Pico W project
mainSet the required environment variables for the SDK paths and your WiFi credentials, then use CMake to configure the build in the
libpeer/examples/pico/builddirectory.$ export PICO_SDK_PATH=<your PICO SDK path>/pico-sdk $ export FREERTOS_KERNEL_PATH=<your FreeRTOS kernel path>/FreeRTOS-Kernel $ export WIFI_SSID=<your WIFI SSID> $ export WIFI_PASSWORD=<your WIFI password> $ cd libpeer/examples/pico $ mkdir build $ cd build $ cmake ..Build the Raspberry Pi example
mainTo build the Raspberry Pi camera and audio example, clone the
libpeerrepository recursively, navigate to the example directory, and usecmaketo generate the build files.$ git clone --recursive https://github.com/sepfy/libpeer $ cd libpeer/examples/raspberrypi $ mkdir build && cd build $ cmake .. $ makePatch libsrtp for RP2040 PICO W compatibility
mainBefore building, you must modify
libpeer/third_party/libsrtp/include/srtp.hto change the signature ofsrtp_remove_streamfromunsigned inttouint32_tfor thessrcparameter.@@ -614,7 +614,7 @@ srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy); * - [other] otherwise. * */ -srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc); +srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc); /** * @brief srtp_update() updates all streams in the session.Platform-specific examples for libpeer
mainlibpeer provides specialized examples for different hardware platforms:
- ESP32: Demonstrates MJPEG over datachannel.
- PICO: Demonstrates ping-pong functionality using datachannel.
- Raspberry Pi: Demonstrates video and two-way audio streaming.
Setup libpeer for ESP32
mainTo use libpeer on ESP32 hardware for streaming JPEG images over WebRTC data channels, follow these steps:
- Install ESP-IDF: Ensure you have ESP-IDF version 5.2 or higher installed.
- Download libpeer: Clone the repository and navigate to the ESP32 example directory.
- Obtain Signaling URL: Visit the libpeer test website and copy the provided URL.
- Configure Build: Use
idf.py menuconfigto set your Signaling URL and WiFi credentials. - Build and Flash: Compile the project and flash it to your device using the ESP-IDF tools.
# Install esp-idf (v5.2 or higher) $ git clone -b v5.2.2 https://github.com/espressif/esp-idf.git $ cd esp-idf $ source install.sh $ source export.sh # Download Required Libraries $ git clone https://github.com/sepfy/libpeer $ cd libpeer/examples/esp32 # Build the Project $ idf.py build # Flash and Test $ idf.py flashBuild a home camera with Raspberry Pi
mainThis example demonstrates how to build a home camera using a Raspberry Pi that supports camera video streaming and two-way audio communication usinglibpeer.Setup libpeer for RP2040 PICO W
mainTo establish a DataChannel connection between a Raspberry Pi Pico W and the web, you must first clone the necessary repositories recursively to ensure all submodules are included.
Required repositories:
libpeerpico-sdkFreeRTOS-Kernel
$ git clone --recursive https://github.com/sepfy/libpeer $ git clone --recurisve https://github.com/raspberrypi/pico-sdk $ git clone --recursive https://github.com/FreeRTOS/FreeRTOS-KernelBuild and run the libpeer generic example
mainTo test libpeer on a Linux-based system, follow these steps to install dependencies, build the library, download test media, and run the generic sample application. You will need a URL from the libpeer test website to connect.
$ sudo apt -y install git cmake $ git clone --recursive https://github.com/sepfy/libpeer $ cd libpeer $ cmake -S . -B build && cmake --build build $ wget http://www.live555.com/liveMedia/public/264/test.264 # Download test video file $ wget https://mauvecloud.net/sounds/alaw08m.wav # Download test audio file $ ./examples/generic/sample -u <URL>Flash the Pico W firmware
mainOnce the build is complete, use
picotoolto load the generated.uf2file onto your device.$ sudo picotool load -f pico_peer.uf2Install dependencies for Raspberry Pi example
mainBefore building the example, you must install the necessary GStreamer plugins, development libraries, and build tools on your Raspberry Pi OS Lite image.
$ sudo apt update $ sudo apt install -y gstreamer1.0-libcamera gstreamer1.0-alsa gstreamer1.0-tools gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-plugins-good libgstreamer1.0-dev git cmakeConfigure ESP32 build settings
mainAfter downloading the example, you must configure the connection parameters using the ESP-IDF configuration tool. Run
idf.py menuconfigand update the following sections:- Peer Connection Configuration ->
Signaling URL: Enter the URL copied from the libpeer test website. - Example Connection Configuration ->
WiFi SSIDandWiFi Password: Enter your local network credentials.
$ idf.py menuconfig- Peer Connection Configuration ->