Skip to content

Commit

Permalink
Made max NACK value configurable (command line, configuration file, a…
Browse files Browse the repository at this point in the history
…dmin API)
  • Loading branch information
meetecho committed Nov 22, 2014
1 parent 0274437 commit 47dacad
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Once you have installed all the dependencies, just use:

sh autogen.sh

to generate the configure file (Note that this requires the 'autoconf' package on debian). After that, configure and compile as
to generate the configure file. After that, configure and compile as
usual to start the whole compilation process:

./configure --prefix=/opt/janus
Expand Down Expand Up @@ -221,6 +221,8 @@ or on the command line:
vmnet8,192.168.0.1,10.0.0.1 or
vmnet,192.168., default=vmnet)
-e, --public-ip=ipaddress Public address of the machine, to use in SDP
-q, --max-nack-queue=number Maximum size of the NACK queue per user for
retransmissions
-r, --rtp-port-range=min-max Port range to use for RTP/RTCP (only available
if the installed libnice supports it)
-d, --debug-level=1-7 Debug/logging level (0=disable debugging,
Expand Down
4 changes: 3 additions & 1 deletion conf/janus.cfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ cert_key = @certdir@/mycert.key


; Media-related stuff: right now, you can only configure whether you want
; to enable IPv6 support (still WIP, so handle with care) and the range of
; to enable IPv6 support (still WIP, so handle with care), the maximum size
; of the NACK queue for retransmissions per handle and the range of
; ports to use for RTP and RTCP (by default, no range is envisaged).
; If you change any setting in the lines below, remember to uncomment the
; [media] category as well, which is commented by default!
;[media]
;ipv6 = true
;max_nack_queue = 300
;rtp_port_range = 20000-40000


Expand Down
12 changes: 10 additions & 2 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ gboolean janus_is_rtcp(gchar *buf) {


/* Maximum value for the NACK queue */
#define MAX_NACK_QUEUE 300
#define DEFAULT_MAX_NACK_QUEUE 300
static uint max_nack_queue = DEFAULT_MAX_NACK_QUEUE;
void janus_set_max_nack_queue(uint mnq) {
max_nack_queue = mnq;
JANUS_LOG(LOG_VERB, "Setting max NACK queue to %d\n", max_nack_queue);
}
uint janus_get_max_nack_queue(void) {
return max_nack_queue;
}


/* libnice initialization */
Expand Down Expand Up @@ -1506,7 +1514,7 @@ void *janus_ice_send_thread(void *data) {
p->length = protected;
janus_mutex_lock(&component->mutex);
component->retransmit_buffer = g_list_append(component->retransmit_buffer, p);
if(g_list_length(component->retransmit_buffer) > MAX_NACK_QUEUE) {
if(g_list_length(component->retransmit_buffer) > max_nack_queue) {
/* We only keep a limited window of packets, get rid of the oldest one */
GList *first = g_list_first(component->retransmit_buffer);
p = (janus_rtp_packet *)first->data;
Expand Down
6 changes: 6 additions & 0 deletions ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ gboolean janus_ice_is_ignored(const char *ip);
/*! \brief Method to check whether IPv6 candidates are enabled/supported or not (still WIP)
* @returns true if IPv6 candidates are enabled/supported, false otherwise */
gboolean janus_ice_is_ipv6_enabled(void);
/*! \brief Method to modify the max NACK value (i.e., the number of packets per handle to store for retransmissions)
* @param[in] mnq The new max NACK value */
void janus_set_max_nack_queue(uint mnq);
/*! \brief Method to get the current max NACK value (i.e., the number of packets per handle to store for retransmissions)
* @returns The current max NACK value */
uint janus_get_max_nack_queue(void);


/*! \brief Helper method to get a string representation of a libnice ICE state
Expand Down
46 changes: 45 additions & 1 deletion janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,8 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
json_object_set_new(reply, "transaction", json_string(transaction_text));
json_t *status = json_object();
json_object_set_new(status, "log_level", json_integer(log_level));
json_object_set_new(status, "locking_debug", json_integer(0));
json_object_set_new(status, "locking_debug", json_integer(lock_debug));
json_object_set_new(status, "max_nack_queue", json_integer(janus_get_max_nack_queue()));
json_object_set_new(reply, "status", status);
/* Convert to a string */
char *reply_text = json_dumps(reply, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
Expand Down Expand Up @@ -1983,6 +1984,34 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
/* Send the success reply */
ret = janus_process_success(source, "application/json", reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "set_max_nack_queue")) {
/* Change the current value for the max NACK queue */
json_t *mnq = json_object_get(root, "max_nack_queue");
if(!mnq) {
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_MISSING_MANDATORY_ELEMENT, "Missing mandatory element (max_nack_queue)");
goto jsondone;
}
if(!json_is_integer(mnq)) {
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_INVALID_ELEMENT_TYPE, "Invalid element type (max_nack_queue should be an integer)");
goto jsondone;
}
int mnq_num = json_integer_value(mnq);
if(mnq_num < 0) {
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_INVALID_ELEMENT_TYPE, "Invalid element type (max_nack_queue should be a positive integer)");
goto jsondone;
}
janus_set_max_nack_queue(mnq_num);
/* Prepare JSON reply */
json_t *reply = json_object();
json_object_set_new(reply, "janus", json_string("success"));
json_object_set_new(reply, "transaction", json_string(transaction_text));
json_object_set_new(reply, "max_nack_queue", json_integer(janus_get_max_nack_queue()));
/* Convert to a string */
char *reply_text = json_dumps(reply, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
json_decref(reply);
/* Send the success reply */
ret = janus_process_success(source, "application/json", reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "list_sessions")) {
/* List sessions */
session_id = 0;
Expand Down Expand Up @@ -3589,6 +3618,11 @@ gint main(int argc, char *argv[])
if(args_info.ipv6_candidates_given) {
janus_config_add_item(config, "media", "ipv6", "true");
}
if(args_info.max_nack_queue_given) {
char mnq[20];
g_snprintf(mnq, 20, "%d", args_info.max_nack_queue_arg);
janus_config_add_item(config, "media", "max_nack_queue", mnq);
}
if(args_info.rtp_port_range_given) {
janus_config_add_item(config, "media", "rtp_port_range", args_info.rtp_port_range_arg);
}
Expand Down Expand Up @@ -3773,6 +3807,15 @@ gint main(int argc, char *argv[])
JANUS_LOG(LOG_FATAL, "Invalid STUN address %s:%u\n", stun_server, stun_port);
exit(1);
}
item = janus_config_get_item_drilldown(config, "media", "max_nack_queue");
if(item && item->value) {
int mnq = atoi(item->value);
if(mnq < 0) {
JANUS_LOG(LOG_WARN, "Ignoring max_nack_queue value as it's not a positive integer\n");
} else {
janus_set_max_nack_queue(mnq);
}
}

/* Is there a public_ip value to be used for NAT traversal instead? */
item = janus_config_get_item_drilldown(config, "nat", "public_ip");
Expand Down Expand Up @@ -3867,6 +3910,7 @@ gint main(int argc, char *argv[])
!janus_plugin->get_description ||
!janus_plugin->get_package ||
!janus_plugin->get_name ||
!janus_plugin->get_name ||
!janus_plugin->create_session ||
!janus_plugin->handle_message ||
!janus_plugin->setup_media ||
Expand Down
1 change: 1 addition & 0 deletions janus.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option "stun-server" S "STUN server(:port) to use, if needed (e.g., gateway behi
option "ice-ignore-list" X "Comma-separated list of interfaces or IP addresses to ignore for ICE gathering; partial strings are supported (e.g., vmnet8,192.168.0.1,10.0.0.1 or vmnet,192.168., default=vmnet)" string typestr="list" optional
option "public-ip" e "Public address of the machine, to use in SDP" string typestr="ipaddress" optional
option "ipv6-candidates" 6 "Whether to enable IPv6 candidates or not (experimental)" flag off
option "max-nack-queue" q "Maximum size of the NACK queue per user for retransmissions" int typestr="number" optional
option "rtp-port-range" r "Port range to use for RTP/RTCP" string typestr="min-max" optional
option "debug-level" d "Debug/logging level (0=disable debugging, 7=maximum debug level; default=4)" int typestr="1-7" optional
option "apisecret" a "API secret all requests need to pass in order to be accepted by Janus (useful when wrapping Janus API requests in a server, none by default)" string typestr="randomstring" optional
Expand Down
8 changes: 4 additions & 4 deletions rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ int janus_rtcp_fix_ssrc(char *packet, int len, int fixssrc, uint32_t newssrcl, u
rtcp_remb *remb = (rtcp_remb *)rtcpfb->fci;
if(remb->id[0] == 'R' && remb->id[1] == 'E' && remb->id[2] == 'M' && remb->id[3] == 'B') {
JANUS_LOG(LOG_HUGE, " #%d REMB -- PSFB (206)\n", pno);
if(fixssrc && newssrcr) {
remb->ssrc[0] = htonl(newssrcr);
}
/* FIXME From rtcp_utility.cc */
unsigned char *_ptrRTCPData = (unsigned char *)remb;
_ptrRTCPData += 4; // Skip unique identifier and num ssrc
Expand All @@ -248,10 +251,6 @@ int janus_rtcp_fix_ssrc(char *packet, int len, int fixssrc, uint32_t newssrcl, u
uint64_t bitRate = brMantissa << brExp;
JANUS_LOG(LOG_HUGE, " -- -- -- REMB: %u * 2^%u = %"SCNu64" (%d SSRCs, %u)\n",
brMantissa, brExp, bitRate, numssrc, ntohl(remb->ssrc[0]));

if(fixssrc && newssrcr) {
remb->ssrc[0] = htonl(newssrcr);
}
} else {
JANUS_LOG(LOG_HUGE, " #%d AFB ?? -- PSFB (206)\n", pno);
}
Expand All @@ -269,6 +268,7 @@ int janus_rtcp_fix_ssrc(char *packet, int len, int fixssrc, uint32_t newssrcl, u
}
/* Is this a compound packet? */
int length = ntohs(rtcp->length);
JANUS_LOG(LOG_HUGE, " RTCP PT length: %d bytes\n", length*4+4);
if(length == 0) {
//~ JANUS_LOG(LOG_HUGE, " 0-length, end of compound packet\n");
break;
Expand Down

0 comments on commit 47dacad

Please sign in to comment.