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

Send more packets together with nice_agent_send_messages_nonblocking #2295

Closed
wants to merge 10 commits into from
7 changes: 7 additions & 0 deletions conf/janus.jcfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ general: {
# As such, if you want to use this you should
# provision the correct value according to the
# available resources (e.g., CPUs available).
#disable_sendmmsg = true # By default, Janus tries to take advantage of
# sendmmsg to send multiple packets at the same
# time and optimize media delivery, by reducing
# the number of system calls. If you want to
# disable this behaviour and make it work more
# like Janus did previously, by sending one
# packet at the time, uncomment this property.
#allow_loop_indication = true # In case a static number of event loops is
# configured as explained above, by default
# new handles will be allocated on one loop or
Expand Down
20 changes: 20 additions & 0 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ gboolean janus_is_opaqueid_in_api_enabled(void) {
return opaqueid_in_api;
}

/* Since #2295, we support sendmmsg to send multiple packets at the same time
* and optimize media delivery; this can disabled at startup, if needed */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can disabled at startup

be seems to be missing before disabled.

static gboolean use_sendmmsg = TRUE;
void janus_disable_sendmmsg(void) {
JANUS_LOG(LOG_WARN, "Disabling sendmmsg mode, will send one packet at a time\n");
use_sendmmsg = FALSE;
}
gboolean janus_is_sendmmsg_enabled(void) {
return use_sendmmsg;
}

/* Only needed in case we're using static event loops spawned at startup (disabled by default) */
typedef struct janus_ice_static_event_loop {
int id;
Expand Down Expand Up @@ -5118,6 +5129,15 @@ static gboolean janus_ice_send_or_store(janus_ice_handle *handle,
janus_ice_component *component, janus_ice_queued_packet *pkt) {
if(!handle || !component || !pkt)
return FALSE;
if(!use_sendmmsg) {
/* We're not using sendmmsg, use nice_agent_send right away */
int sent = nice_agent_send(handle->agent, component->stream_id,
component->component_id, pkt->length, (const gchar *)pkt->data);
if(sent < pkt->length) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] ... only sent %d bytes? (was %d)\n", handle->handle_id, sent, pkt->length);
}
return sent == pkt->length;
}
/* First of all, let's set this packet in the first available NiceOutputMessage */
if(component->pending_messages_num == JANUS_MAX_PENDING_MESSAGES) {
JANUS_LOG(LOG_WARN, "[%"SCNu64"] Too many packets pending? Dumping this packet...\n", handle->handle_id);
Expand Down
5 changes: 5 additions & 0 deletions ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ void janus_enable_opaqueid_in_api(void);
/*! \brief Method to check whether opaque ID have to be added to Janus API responses/events
* @returns TRUE if they need to be present, FALSE otherwise */
gboolean janus_is_opaqueid_in_api_enabled(void);
/*! \brief Method to disable the new sendmmsg mode */
void janus_disable_sendmmsg(void);
/*! \brief Method to check whether the sendmmsg mode is enabled
* @returns TRUE if it's enabled (default), FALSE otherwise */
gboolean janus_is_sendmmsg_enabled(void);


/*! \brief Helper method to get a string representation of a libnice ICE state
Expand Down
6 changes: 6 additions & 0 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ static json_t *janus_info(const char *transaction) {
json_object_set_new(info, "turn-server", json_string(server));
}
json_object_set_new(info, "static-event-loops", json_integer(janus_ice_get_static_event_loops()));
if(!janus_is_sendmmsg_enabled())
json_object_set_new(info, "sendmmsg-enabled", json_false());
json_object_set_new(info, "api_secret", api_secret ? json_true() : json_false());
json_object_set_new(info, "auth_token", janus_auth_is_enabled() ? json_true() : json_false());
json_object_set_new(info, "event_handlers", janus_events_is_enabled() ? json_true() : json_false());
Expand Down Expand Up @@ -4835,6 +4837,10 @@ gint main(int argc, char *argv[])
loops_api = janus_is_true(item->value);
janus_ice_set_static_event_loops(loops, loops_api);
}
/* Also check if we need to disable the new sendmmsg mode */
item = janus_config_get(config, config_general, janus_config_type_item, "disable_sendmmsg");
if(item && item->value && janus_is_true(item->value))
janus_disable_sendmmsg();
/* Initialize the ICE stack now */
janus_ice_init(ice_lite, ice_tcp, full_trickle, ignore_mdns, ipv6, rtp_min_port, rtp_max_port);
if(janus_ice_set_stun_server(stun_server, stun_port) < 0) {
Expand Down