From 38789888800e1369c6c6787ae24e9181d131a26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Musset?= Date: Mon, 11 May 2020 17:06:35 +0200 Subject: [PATCH 1/2] Add DSCP on RTP audio packets in SIP plugin --- conf/janus.plugin.sip.jcfg.sample | 7 +++++++ plugins/janus_sip.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/conf/janus.plugin.sip.jcfg.sample b/conf/janus.plugin.sip.jcfg.sample index 237a24c105..4b125c0473 100644 --- a/conf/janus.plugin.sip.jcfg.sample +++ b/conf/janus.plugin.sip.jcfg.sample @@ -32,4 +32,11 @@ general: { # Whether events should be sent to event handlers (default=true) #events = false + + # If you need DSCP packet marking and prioritization, you can configure + # the 'dscp_audio_rtp' property to specific values, and Janus SIP plugin + # will set it on all outgoing audio RTP packets. + # No packet marking is done if this parameter is undefined or equal to 0 + #dscp_audio_rtp = 46 + } diff --git a/plugins/janus_sip.c b/plugins/janus_sip.c index 43094ab6ba..1ae6265eeb 100644 --- a/plugins/janus_sip.c +++ b/plugins/janus_sip.c @@ -779,6 +779,7 @@ static char *user_agent; static int register_ttl = JANUS_DEFAULT_REGISTER_TTL; static uint16_t rtp_range_min = 10000; static uint16_t rtp_range_max = 60000; +static int dscp_audio_rtp = 0; static GThread *handler_thread; static void *janus_sip_handler(void *data); @@ -1754,6 +1755,17 @@ int janus_sip_init(janus_callbacks *callback, const char *config_path) { JANUS_LOG(LOG_WARN, "Notification of events to handlers disabled for %s\n", JANUS_SIP_NAME); } + /* Is there any DSCP TOS to apply? */ + item = janus_config_get(config, config_general, janus_config_type_item, "dscp_audio_rtp"); + if(item && item->value) { + int val = atoi(item->value); + if(val < 0) { + JANUS_LOG(LOG_WARN, "Ignoring dscp_audio_rtp value as it's not a positive integer\n"); + } else { + dscp_audio_rtp = val; + } + } + janus_config_destroy(config); } config = NULL; @@ -5685,6 +5697,11 @@ static int janus_sip_allocate_local_ports(janus_sip_session *session) { return -1; if(session->media.audio_rtp_fd == -1) { session->media.audio_rtp_fd = socket(AF_INET, SOCK_DGRAM, 0); + /* Set the DSCP value if set in the config file */ + if (dscp_audio_rtp > 0) { + int optval = dscp_audio_rtp << 2; + setsockopt(session->media.audio_rtp_fd, IPPROTO_IP, IP_TOS, &optval, sizeof(optval)); + } } if(session->media.audio_rtcp_fd == -1) { session->media.audio_rtcp_fd = socket(AF_INET, SOCK_DGRAM, 0); From 09380ef4acda95baaa1e8c8b3d5d30dc897c99f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Musset?= Date: Mon, 11 May 2020 19:09:55 +0200 Subject: [PATCH 2/2] Add DSCP on RTP audio and video packets in SIP plugin --- conf/janus.plugin.sip.jcfg.sample | 5 +++-- plugins/janus_sip.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/conf/janus.plugin.sip.jcfg.sample b/conf/janus.plugin.sip.jcfg.sample index 4b125c0473..2ca14aba96 100644 --- a/conf/janus.plugin.sip.jcfg.sample +++ b/conf/janus.plugin.sip.jcfg.sample @@ -34,9 +34,10 @@ general: { #events = false # If you need DSCP packet marking and prioritization, you can configure - # the 'dscp_audio_rtp' property to specific values, and Janus SIP plugin - # will set it on all outgoing audio RTP packets. + # the 'dscp_audio_rtp' and/or 'dscp_video_rtp' property to specific values, + # and Janus SIP plugin will set it on all outgoing audio/video RTP packets. # No packet marking is done if this parameter is undefined or equal to 0 #dscp_audio_rtp = 46 + #dscp_video_rtp = 26 } diff --git a/plugins/janus_sip.c b/plugins/janus_sip.c index 1ae6265eeb..08df271431 100644 --- a/plugins/janus_sip.c +++ b/plugins/janus_sip.c @@ -780,6 +780,7 @@ static int register_ttl = JANUS_DEFAULT_REGISTER_TTL; static uint16_t rtp_range_min = 10000; static uint16_t rtp_range_max = 60000; static int dscp_audio_rtp = 0; +static int dscp_video_rtp = 0; static GThread *handler_thread; static void *janus_sip_handler(void *data); @@ -1765,6 +1766,15 @@ int janus_sip_init(janus_callbacks *callback, const char *config_path) { dscp_audio_rtp = val; } } + item = janus_config_get(config, config_general, janus_config_type_item, "dscp_video_rtp"); + if(item && item->value) { + int val = atoi(item->value); + if(val < 0) { + JANUS_LOG(LOG_WARN, "Ignoring dscp_video_rtp value as it's not a positive integer\n"); + } else { + dscp_video_rtp = val; + } + } janus_config_destroy(config); } @@ -5700,7 +5710,10 @@ static int janus_sip_allocate_local_ports(janus_sip_session *session) { /* Set the DSCP value if set in the config file */ if (dscp_audio_rtp > 0) { int optval = dscp_audio_rtp << 2; - setsockopt(session->media.audio_rtp_fd, IPPROTO_IP, IP_TOS, &optval, sizeof(optval)); + int ret = setsockopt(session->media.audio_rtp_fd, IPPROTO_IP, IP_TOS, &optval, sizeof(optval)); + if (ret < 0) { + JANUS_LOG(LOG_WARN, "Error setting IP_TOS option on audio RTP socket, value=%d, error=%s\n",optval, strerror(errno)); + } } } if(session->media.audio_rtcp_fd == -1) { @@ -5751,6 +5764,14 @@ static int janus_sip_allocate_local_ports(janus_sip_session *session) { return -1; if(session->media.video_rtp_fd == -1) { session->media.video_rtp_fd = socket(AF_INET, SOCK_DGRAM, 0); + /* Set the DSCP value if set in the config file */ + if (dscp_video_rtp > 0) { + int optval = dscp_video_rtp << 2; + int ret = setsockopt(session->media.video_rtp_fd, IPPROTO_IP, IP_TOS, &optval, sizeof(optval)); + if (ret < 0) { + JANUS_LOG(LOG_WARN, "Error setting IP_TOS option on video RTP socket, value=%d, error=%s\n",optval, strerror(errno)); + } + } } if(session->media.video_rtcp_fd == -1) { session->media.video_rtcp_fd = socket(AF_INET, SOCK_DGRAM, 0);