Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable DSCP ToS for PeerConnections #2055

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion conf/janus.jcfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ media: {
#slowlink_threshold = 4
#twcc_period = 100
#dtls_timeout = 500

# If you need DSCP packet marking and prioritization, you can configure
# the 'dscp_tos' property to a specific values, and Janus will try to
# set it on all outgoing packets using libnice. Normally, the specs
# suggest to use different values depending on whether audio, video
# or data are used, but since all PeerConnections in Janus are bundled,
# we can only use one. You can refer to this document for more info:
# https://tools.ietf.org/html/draft-ietf-tsvwg-rtcweb-qos-18#page-6
# That said, DON'T TOUCH THIS IF YOU DON'T KNOW WHAT IT MEANS!
#dscp_tos = 46
}

# NAT-related stuff: specifically, you can configure the STUN/TURN
Expand Down Expand Up @@ -311,7 +321,7 @@ nat: {
# your machine is ready. Note that Linux distributions offer such directives.
# You could use the following directive in systemd: 'After=network-online.target'
# https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=
# ignore_unreachable_ice_server = true
#ignore_unreachable_ice_server = true
}

# You can choose which of the available plugins should be
Expand Down
16 changes: 16 additions & 0 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ uint janus_get_twcc_period(void) {
return twcc_period;
}

/* DSCP Type of Service, which we can set via libnice: it's disabled by default */
static int dscp_tos = 0;
void janus_set_dscp_tos(int tos) {
dscp_tos = tos;
if(dscp_tos > 0) {
JANUS_LOG(LOG_VERB, "Setting DSCP Type of Service to %ds\n", dscp_tos);
}
}
int janus_get_dscp_tos(void) {
return dscp_tos;
}


static inline void janus_ice_free_rtp_packet(janus_rtp_packet *pkt) {
if(pkt == NULL) {
Expand Down Expand Up @@ -3417,6 +3429,10 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
}
/* Now create an ICE stream for all the media we'll handle */
handle->stream_id = nice_agent_add_stream(handle->agent, 1);
if(dscp_tos > 0) {
/* A DSCP Type of Service was configured, pass it to libnice */
nice_agent_set_stream_tos(handle->agent, handle->stream_id, dscp_tos);
}
janus_ice_stream *stream = g_malloc0(sizeof(janus_ice_stream));
janus_refcount_init(&stream->ref, janus_ice_stream_free);
janus_refcount_increase(&handle->ref);
Expand Down
6 changes: 6 additions & 0 deletions ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ void janus_set_twcc_period(uint period);
/*! \brief Method to get the current TWCC period (see above)
* @returns The current TWCC period */
uint janus_get_twcc_period(void);
/*! \brief Method to modify the DSCP Type of Service (TOS), which is disabled by default
* @param[in] tos The new TOS value (0 to disable) */
void janus_set_dscp_tos(int period);
/*! \brief Method to get the current DSCP Type of Service (see above)
* @returns The current TOS value (0 if disabled) */
int janus_get_dscp_tos(void);
/*! \brief Method to modify the event handler statistics period (i.e., the number of seconds that should pass before Janus notifies event handlers about media statistics for a PeerConnection)
* @param[in] period The new period value, in seconds */
void janus_ice_set_event_stats_period(int period);
Expand Down
14 changes: 14 additions & 0 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ static json_t *janus_info(const char *transaction) {
json_object_set_new(info, "mdns-enabled", janus_ice_is_mdns_enabled() ? json_true() : json_false());
json_object_set_new(info, "min-nack-queue", json_integer(janus_get_min_nack_queue()));
json_object_set_new(info, "twcc-period", json_integer(janus_get_twcc_period()));
if(janus_get_dscp_tos() > 0)
json_object_set_new(info, "dscp-tos", json_integer(janus_get_dscp_tos()));
if(janus_ice_get_stun_server() != NULL) {
char server[255];
g_snprintf(server, 255, "%s:%"SCNu16, janus_ice_get_stun_server(), janus_ice_get_stun_port());
Expand Down Expand Up @@ -4632,6 +4634,18 @@ gint main(int argc, char *argv[])
" Expect trouble if this is supposed to work over the internet and not just in a LAN...\n", test_ip);
}
}

/* Is there any DSCP TOS to apply? */
item = janus_config_get(config, config_media, janus_config_type_item, "dscp_tos");
if(item && item->value) {
int tos = atoi(item->value);
if(tos < 0) {
JANUS_LOG(LOG_WARN, "Ignoring dscp_tos value as it's not a positive integer\n");
} else {
janus_set_dscp_tos(tos);
}
}

/* NACK related stuff */
item = janus_config_get(config, config_media, janus_config_type_item, "min_nack_queue");
if(item && item->value) {
Expand Down