Skip to content

Commit

Permalink
Fixed incorrect DSCP value being set (see #2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Apr 30, 2020
1 parent 03e0f63 commit d3ba049
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions conf/janus.jcfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ media: {
#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
# the 'dscp' 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
#dscp = 46
}

# NAT-related stuff: specifically, you can configure the STUN/TURN
Expand Down
22 changes: 11 additions & 11 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,16 @@ 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);
/* DSCP value, which we can set via libnice: it's disabled by default */
static int dscp_ef = 0;
void janus_set_dscp(int dscp) {
dscp_ef = dscp;
if(dscp_ef > 0) {
JANUS_LOG(LOG_VERB, "Setting DSCP EF to %d\n", dscp_ef);
}
}
int janus_get_dscp_tos(void) {
return dscp_tos;
int janus_get_dscp(void) {
return dscp_ef;
}


Expand Down Expand Up @@ -3458,9 +3458,9 @@ 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);
if(dscp_ef > 0) {
/* A DSCP value was configured, shift it and pass it to libnice as a TOS */
nice_agent_set_stream_tos(handle->agent, handle->stream_id, dscp_ef << 2);
}
janus_ice_stream *stream = g_malloc0(sizeof(janus_ice_stream));
janus_refcount_init(&stream->ref, janus_ice_stream_free);
Expand Down
12 changes: 6 additions & 6 deletions ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +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 DSCP value to set, which is disabled by default
* @param[in] dscp The new DSCP value (0 to disable) */
void janus_set_dscp(int dscp);
/*! \brief Method to get the current DSCP value (see above)
* @returns The current DSCP value (0 if disabled) */
int janus_get_dscp(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
16 changes: 9 additions & 7 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +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_get_dscp() > 0)
json_object_set_new(info, "dscp", json_integer(janus_get_dscp()));
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 @@ -4645,13 +4645,15 @@ gint main(int argc, char *argv[])
}

/* Is there any DSCP TOS to apply? */
item = janus_config_get(config, config_media, janus_config_type_item, "dscp_tos");
item = janus_config_get(config, config_media, janus_config_type_item, "dscp");
if(!item || !item->value) /* Just for backwards compatibility */
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");
int dscp = atoi(item->value);
if(dscp < 0) {
JANUS_LOG(LOG_WARN, "Ignoring dscp value as it's not a positive integer\n");
} else {
janus_set_dscp_tos(tos);
janus_set_dscp(dscp);
}
}

Expand Down

0 comments on commit d3ba049

Please sign in to comment.