From 17005c70824740d7095bd1a4c51f3942f4d4bc19 Mon Sep 17 00:00:00 2001 From: Lorenzo Miniero Date: Thu, 29 Jul 2021 13:12:55 +0200 Subject: [PATCH] Added support for forwarding groups in AudioBridge (#2653) --- conf/janus.plugin.audiobridge.jcfg.sample | 2 + html/audiobridgetest.js | 9 +- plugins/janus_audiobridge.c | 598 +++++++++++++++++++--- 3 files changed, 525 insertions(+), 84 deletions(-) diff --git a/conf/janus.plugin.audiobridge.jcfg.sample b/conf/janus.plugin.audiobridge.jcfg.sample index df54fbf1d5..28cb4185bc 100644 --- a/conf/janus.plugin.audiobridge.jcfg.sample +++ b/conf/janus.plugin.audiobridge.jcfg.sample @@ -16,6 +16,7 @@ # record_dir = "/path/to/" (path to save the recording to, makes record_file a relative path if provided) # allow_rtp_participants = true|false (whether participants should be allowed to join # via plain RTP as well, rather than just WebRTC, default=false) +# groups = optional, non-hierarchical, array of groups to tag participants, for external forwarding purposes only # # The following lines are only needed if you want the mixed audio # to be automatically forwarded via plain RTP to an external component @@ -28,6 +29,7 @@ # rtp_forward_ssrc = SSRC to use to use when streaming (optional: stream_id used if missing) # rtp_forward_codec = opus (default), pcma (A-Law) or pcmu (mu-Law) # rtp_forward_ptype = payload type to use when streaming (optional: only read for Opus, 100 used if missing) +# rtp_forward_group = group of participants to forward, if enabled in the room (optional: forwards full mix if missing) # rtp_forward_srtp_suite = length of authentication tag (32 or 80) # rtp_forward_srtp_crypto = "" # rtp_forward_always_on = true|false, whether silence should be forwarded when the room is empty (optional: false used if missing) diff --git a/html/audiobridgetest.js b/html/audiobridgetest.js index 7478d56a01..4bfba3384d 100644 --- a/html/audiobridgetest.js +++ b/html/audiobridgetest.js @@ -60,6 +60,9 @@ if(getQueryStringValue("room") !== "") var stereo = false; if(getQueryStringValue("stereo") !== "") stereo = (getQueryStringValue("stereo") === "true"); +var mygroup = null; // Forwarding group, if required by the room +if(getQueryStringValue("group") !== "") + mygroup = getQueryStringValue("group"); var myusername = null; var myid = null; var webrtcUp = false; @@ -426,7 +429,11 @@ function registerUsername() { } var register = { request: "join", room: myroom, display: username }; myusername = username; - mixertest.send({ message: register}); + // If the room uses forwarding groups, this is how we state ours + if(mygroup) + register["group"] = mygroup; + // Send the message + mixertest.send({ message: register }); } } diff --git a/plugins/janus_audiobridge.c b/plugins/janus_audiobridge.c index 851ed53ab4..242f1f5ade 100644 --- a/plugins/janus_audiobridge.c +++ b/plugins/janus_audiobridge.c @@ -44,6 +44,7 @@ room-: { record_dir = /path/to/ (path to save the recording to, makes record_file a relative path if provided) allow_rtp_participants = true|false (whether participants should be allowed to join via plain RTP as well, rather than just WebRTC, default=false) + groups = optional, non-hierarchical, array of groups to tag participants, for external forwarding purposes only [The following lines are only needed if you want the mixed audio to be automatically forwarded via plain RTP to an external component @@ -56,6 +57,7 @@ room-: { rtp_forward_ssrc = SSRC to use to use when streaming (optional: stream_id used if missing) rtp_forward_codec = opus (default), pcma (A-Law) or pcmu (mu-Law) rtp_forward_ptype = payload type to use when streaming (optional: only read for Opus, 100 used if missing) + rtp_forward_group = group of participants to forward, if enabled in the room (optional: forwards full mix if missing) rtp_forward_srtp_suite = length of authentication tag, if SRTP is needed (32 or 80) rtp_forward_srtp_crypto = key to use as crypto, if SRTP is needed (base64 encoded key as in SDES) rtp_forward_always_on = true|false, whether silence should be forwarded when the room is empty (optional: false used if missing) @@ -112,7 +114,9 @@ room-: { * existing RTP forwarder; \c listforwarders lists all the current RTP * forwarders on a specific AudioBridge room instance. As an alternative, * you can configure a single static RTP forwarder in the plugin - * configuration file. + * configuration file. A finer grained control of what to forward + * externally, in terms of participants mix, can be achieved using + * groups. * * \c create can be used to create a new audio room, and has to be * formatted as follows: @@ -137,7 +141,8 @@ room-: { "record" : , "record_file" : "", "record_dir" : "", - "allow_rtp_participants" : + "allow_rtp_participants" : , + "groups" : [ non-hierarchical array of string group names to use to gat participants, for external forwarding purposes only, optional] } \endverbatim * @@ -409,6 +414,7 @@ room-: { { "request" : "rtp_forward", "room" : , + "group" : "", "ssrc" : , "codec" : "", "ptype" : , @@ -420,6 +426,20 @@ room-: { "always_on" : } \endverbatim + * + * The concept of "groups" is particularly important, here, in case groups were + * enabled when creating a room. By default, in fact, if a room has groups disabled, + * then an RTP forwarder will simply relay the mix of all active participants; + * sometimes, though, an external application may want to only receive the mix + * of some of the participants, and not all of them. This is what groups are + * for: if you tag participants with a specific group name, then creating a + * new forwarder that explicitly references that group name will ensure that + * only a mix of the participants tagged with that name will be forwarded. + * As such, it's important to point out groups \b only impact forwarders, + * and \c NOT participants or how they're mixed in main mix for the room itself. + * Omitting a group name when creating a forwarder for a room where groups + * are enabled will simply fall back to the default behaviour of forwarding + * the full mix. * * Notice that, as explained above, in case you configured an \c admin_key * property and extended it to RTP forwarding as well, you'll need to provide @@ -432,6 +452,7 @@ room-: { { "audiobridge" : "success", "room" : , + "group" : "", "stream_id" : , "host" : "", "port" :