Skip to content

Add JanusVRWebRTCSink plugin (net/webrtc)

Eva Pace requested to merge eva/gst-plugins-rs:net/webrtc/janusvr into main

The JanusVRWebRTCSink is a new plugin that integrates with the Video Room plugin of the Janus Gateway, which simplifies WebRTC communication.

How it works

Much like the default signaller for WebRTC, it spawns two futures, one for sending the messages, and another one for receiving.

  1. Once the plugin starts (start()), it creates the WebSocket connection with Janus (connect()).
  2. Then it creates a session there (create_session());
  3. After that, it attaches to videoroom plugin (attach_plugin());
  4. And it requests to join a room, eg: "1234" (join_room());
  5. Then there's the whole publishing the video/audio stream (publish()), handling the answer (handle_answer()), and sending the trickle event (trickle());
  6. Besides all of this, every 10 seconds, it sends a keepalive message, to keep the session alive otherwise Janus would kill it (it happens after 1 minute).

How to test it

You'll need to have:

  • Janus installed (can be done via a package manager like pacman or apt-get);
  • The janus-gateway repository to run the browser demo (it's inside the html folder);
  • This branch compiled via cargo cbuild -p gst-plugin-webrtc;
  • gst-launch with access to the locally compiled plugin (aka appending to the GST_PLUGIN_PATH env var, eg: export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:$HOME/gst-plugins-rs/target/x86_64-unknown-linux-gnu/debug/);

In one terminal run the janus CLI command, no arguments are needed. On another go to janus-gateway/html and expose the files via an HTTP server with a command like python -m http.server. Then you can open the browser, click in Demos, then Video Room (multistream) and finally "Start". Here you should be able to define a display name, publish/unpublish the stream of your webcam, leave the room, etc.

At last to test the plugin itself streaming to the demo, you can run this to test video:

$ gst-launch-1.0 videotestsrc ! janusvrwebrtcsink signaller::room-id=1234

And this to test audio:

$ gst-launch-1.0 audiotestsrc ! janusvrwebrtcsink signaller::room-id=1234

You can set the display name via signaller::display-name, eg:

$ gst-launch-1.0 videotestsrc ! janusvrwebrtcsink signaller::room-id=1234 signaller::display-name=ana

You should see the GStreamer videotestsrc/audiotestsrc output in your browser now 🙂 🎉

To end the stream & leave the room, simply do Ctrl + C (SIGINT).

Reference links

Notes

  • This plugin supports both the legacy Video Room plugin as well as the multistream one;
  • If you see a warning in the gst-launch logs related to rtpgccbwe, you can compile this plugin via cargo cbuild -p gst-plugin-rtp.

Merge request reports

Loading