GStreamer WebRTC

Abstract

GStreamer WebRTC

Category

Learning note

Authors

Walter Fan

Status

WIP

Updated

2024-08-21

Overview

We can use webrtcbin to setup connection with other peer

sudo apt-get install -y libgstreamer1.0-dev \
gstreamer1.0-libav libglib2.0-dev \
gstreamer1.0-tools gstreamer1.0-nice gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-plugins-good \
libgstreamer-plugins-bad1.0-dev libsoup2.4-dev libjson-glib-dev


gst-inspect-1.0 webrtcbin

详细描述参见 https://gstreamer.freedesktop.org/documentation/webrtc/?gi-language=c

+----GInitiallyUnowned
    +----GstObject
            +----GstElement
                +----GstBin
                        +----GstWebRTCBin

它的一进一出由以下两个 Pad 控制 * GstWebRTCBinSinkPad * GstWebRTCBinSrcPad

Signals

on-data-channel

on-ice-candidate

on-negotiation-needed

on-new-transceiver

prepare-data-channel

request-aux-sender

Action Signals

add-ice-candidate …

Properties

bundle-policy …

Example

详细代码参见 https://gitlab.freedesktop.org/gstreamer/gst-examples/-/tree/master/webrtc

  • install gstreamer and related plugin

sudo apt-get install -y gstreamer1.0-tools gstreamer1.0-nice gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-plugins-good libgstreamer1.0-dev git libglib2.0-dev libgstreamer-plugins-bad1.0-dev libsoup2.4-dev libjson-glib-dev
git clone git@github.com:imdark/gstreamer-webrtc-demo.git

cd sendrecv/gst
make
  • go to js folder and start a simple http server

#!/usr/bin/python
import BaseHTTPServer, SimpleHTTPServer
import ssl

httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 8443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./certs_and_key.pem', server_side=True)
httpd.serve_forever()

Reference