gst-plugins-rs/net/webrtc/examples
François Laignel 83d70d3471 webrtc: add RFC 7273 support
This commit implements [RFC 7273] (NTP & PTP clock signalling & synchronization)
for `webrtcsink` by adding the "ts-refclk" & "mediaclk" SDP media attributes to
identify the clock. These attributes are handled by `rtpjitterbuffer` on the
consumer side. They MUST be part of the SDP offer.

When used with an NTP or PTP clock, "mediaclk" indicates the RTP offset at the
clock's origin. Because the payloaders are not instantiated when the offer is
sent to the consumer, the RTP offset is set to 0 and the payloader
`timstamp-offset`s are set accordingly when they are created.

The `webrtc-precise-sync` examples were updated to be able to start with an NTP
(default), a PTP or the system clock (on the receiver only). The rtp jitter
buffer will synchronize with the clock signalled in the SDP offer provided the
sender is started with `--do-clock-signalling` & the receiver with
`--expect-clock-signalling`.

[RFC 7273]: https://datatracker.ietf.org/doc/html/rfc7273

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1500>
2024-04-12 14:18:09 +02:00
..
webrtcsink-custom-signaller webrtc: Remove unnecessary manual Send+Sync implementations for signallers 2024-01-18 10:01:25 +02:00
webrtcsink-stats webrtc: examples: Update package-lock.json 2022-12-26 23:10:40 +00:00
README.md webrtc: add RFC 7273 support 2024-04-12 14:18:09 +02:00
webrtc-precise-sync-recv.rs webrtc: add RFC 7273 support 2024-04-12 14:18:09 +02:00
webrtc-precise-sync-send.rs webrtc: add RFC 7273 support 2024-04-12 14:18:09 +02:00
webrtcsink-high-quality-tune.rs webrtcsink: expose consumer-pipeline-created signal 2023-05-25 13:15:52 +02:00
webrtcsink-stats-server.rs use new debug and parse API 2023-12-04 15:58:21 +01:00

webrtcsink examples

Collection of webrtcsink examples

webrtcsink-stats-server

A simple application that instantiates a webrtcsink and serves stats over websockets.

The application expects a signalling server to be running at ws://localhost:8443, similar to the usage example in the main README.

cargo run --example webrtcsink-stats-server

Once it is running, follow the instruction in the webrtcsink-stats folder to run an example client.

webrtcsink-custom-signaller

An example of custom signaller implementation, see the corresponding README for more details on code and usage.

WebRTC precise synchronization example

This example demonstrates a sender / receiver setup which ensures precise synchronization of multiple streams in a single session.

RFC 6051-style rapid synchronization of RTP streams is available as an option. Se the Instantaneous RTP synchronization... blog post for details about this mode and an example based on RTSP instead of WebRTC.

The examples can also be used for RFC 7273 NTP or PTP clock signalling and synchronization.

Signaller

The example uses the default WebRTC signaller. Launch it using the following command:

cargo run --bin gst-webrtc-signalling-server

Receiver

The receiver awaits for new audio & video stream publishers and render the streams using auto sink elements. Launch it using the following command:

cargo r --example webrtc-precise-sync-recv

The default configuration should work for a local test. For a multi-host setup, see the available options:

cargo r --example webrtc-precise-sync-recv -- --help

E.g.: the following will force avdec_h264 over hardware decoders, activate debug logs for the receiver and connect to the signalling server at the specified address:

GST_PLUGIN_FEATURE_RANK=avdec_h264:MAX \
WEBRTC_PRECISE_SYNC_RECV_LOG=debug \
cargo r --example webrtc-precise-sync-recv -- --server 192.168.1.22

Sender

The sender publishes audio & video test streams. Launch it using the following command:

cargo r --example webrtc-precise-sync-send

The default configuration should work for a local test. For a multi-host setup, to set the number of audio / video streams, to enable rapid synchronization or to force the video encoder, see the available options:

cargo r --example webrtc-precise-sync-send -- --help

E.g.: the following will force H264 and x264enc over hardware encoders, activate debug logs for the sender and connect to the signalling server at the specified address:

GST_PLUGIN_FEATURE_RANK=264enc:MAX \
WEBRTC_PRECISE_SYNC_SEND_LOG=debug \
cargo r --example webrtc-precise-sync-send -- \
  --server 192.168.1.22 --video-caps video/x-h264

The pipeline latency

The --pipeline-latency argument configures a static latency of 1s by default. This needs to be higher than the sum of the sender latency and the receiver latency of the receiver with the highest latency. As this can't be known automatically and depends on many factors, this has to be known for the overall system and configured accordingly.

The default configuration is on the safe side and favors synchronization over low latency. Depending on the use case, shorter or larger values should be used.

RFC 7273 NTP or PTP clock signalling and synchronization

For RFC 7273 NTP or PTP clock signalling and synchronization, you can use commands such as:

Receiver

cargo r --example webrtc-precise-sync-recv -- --expect-clock-signalling

Sender

cargo r --example webrtc-precise-sync-send -- --clock ntp --do-clock-signalling \
  --video-streams 0 --audio-streams 2