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 DSCP on RTP audio packets in SIP plugin #2150

Merged
merged 2 commits into from
May 11, 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
8 changes: 8 additions & 0 deletions conf/janus.plugin.sip.jcfg.sample
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ 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' 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

}
38 changes: 38 additions & 0 deletions plugins/janus_sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ 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 int dscp_video_rtp = 0;

static GThread *handler_thread;
static void *janus_sip_handler(void *data);
Expand Down Expand Up @@ -1754,6 +1756,26 @@ 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;
}
}
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);
}
config = NULL;
Expand Down Expand Up @@ -5685,6 +5707,14 @@ 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;
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) {
session->media.audio_rtcp_fd = socket(AF_INET, SOCK_DGRAM, 0);
Expand Down Expand Up @@ -5734,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);
Expand Down