Skip to content

Commit

Permalink
Fixed a potential problem with incoming RTP streams, and removed a us…
Browse files Browse the repository at this point in the history
…eless parameter in janus_process_success that did nothing (probably a leftover)
  • Loading branch information
meetecho committed Jul 10, 2015
1 parent 550a36f commit 97c665f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
19 changes: 12 additions & 7 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,13 @@ void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_i
video = (stream->stream_id == handle->video_id ? 1 : 0);
} else {
/* Bundled streams, check SSRC */
video = (stream->video_ssrc_peer == ntohl(header->ssrc) ? 1 : 0);
guint32 packet_ssrc = ntohl(header->ssrc);
video = (stream->video_ssrc_peer == packet_ssrc ? 1 : 0);
if(!video && stream->audio_ssrc_peer != packet_ssrc) {
/* FIXME In case it happens, we should check what it is: maybe retransmissions with a different SSRC? */
JANUS_LOG(LOG_WARN, "Not video and not audio? dropping (SSRC %"SCNu32")...\n", packet_ssrc);
return;
}
//~ JANUS_LOG(LOG_VERB, "[RTP] Bundling: this is %s (video=%"SCNu64", audio=%"SCNu64", got %ld)\n",
//~ video ? "video" : "audio", stream->video_ssrc_peer, stream->audio_ssrc_peer, ntohl(header->ssrc));
}
Expand Down Expand Up @@ -1304,14 +1310,13 @@ void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_i
janus_mutex_unlock(&component->mutex);
}

/* Keep track of rtp sequence numbers, in case we need to NACK them */
/* Keep track of RTP sequence numbers, in case we need to NACK them */
/* Note: unsigned int overflow/underflow wraps (defined behavior) */
guint16 new_seqn = ntohs(header->seq_number);
guint16 cur_seqn;
int last_seqs_len = 0;
janus_mutex_lock(&component->mutex);
seq_info_t **last_seqs = video ? &component->last_seqs_video
: &component->last_seqs_audio;
seq_info_t **last_seqs = video ? &component->last_seqs_video : &component->last_seqs_audio;
seq_info_t *cur_seq = *last_seqs;
if(cur_seq) {
cur_seq = cur_seq->prev;
Expand All @@ -1321,10 +1326,10 @@ void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_i
cur_seqn = new_seqn - (guint16)1; /* Can wrap */
}
if(!janus_seq_in_range(new_seqn, cur_seqn, LAST_SEQS_MAX_LEN) &&
!janus_seq_in_range(cur_seqn, new_seqn, 1000) ) {
!janus_seq_in_range(cur_seqn, new_seqn, 1000)) {
/* Jump too big, start fresh */
JANUS_LOG(LOG_WARN, "[%"SCNu64"] big sequence number jump %hu -> %hu\n",
handle->handle_id, cur_seqn, new_seqn);
JANUS_LOG(LOG_WARN, "[%"SCNu64"] Big sequence number jump %hu -> %hu (%s stream)\n",
handle->handle_id, cur_seqn, new_seqn, video ? "video" : "audio");
janus_seq_list_free(last_seqs);
cur_seq = NULL;
cur_seqn = new_seqn - (guint16)1;
Expand Down
52 changes: 26 additions & 26 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ int janus_ws_handler(void *cls, struct MHD_Connection *connection, const char *u
goto done;
}
/* Send the success reply */
ret = janus_process_success(&source, "application/json", janus_info(NULL));
ret = janus_process_success(&source, janus_info(NULL));
goto done;
}

Expand Down Expand Up @@ -784,7 +784,7 @@ int janus_ws_handler(void *cls, struct MHD_Connection *connection, const char *u
if(event != NULL) {
if(max_events == 1) {
/* Return just this message and leave */
ret = janus_process_success(&source, "application/json", event->payload);
ret = janus_process_success(&source, event->payload);
} else {
/* The application is willing to receive more events at the same time, anything to report? */
json_t *list = json_array();
Expand Down Expand Up @@ -817,7 +817,7 @@ int janus_ws_handler(void *cls, struct MHD_Connection *connection, const char *u
/* Return the array of messages and leave */
char *event_text = json_dumps(list, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
json_decref(list);
ret = janus_process_success(&source, "application/json", event_text);
ret = janus_process_success(&source, event_text);
}
} else {
/* Still no message, wait */
Expand Down Expand Up @@ -911,7 +911,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
if(session_id == 0 && handle_id == 0) {
/* Can only be a 'Create new session', a 'Get info' or a 'Ping/Pong' request */
if(!strcasecmp(message_text, "info")) {
ret = janus_process_success(source, "application/json", janus_info(transaction_text));
ret = janus_process_success(source, janus_info(transaction_text));
goto jsondone;
}
if(!strcasecmp(message_text, "ping")) {
Expand All @@ -921,7 +921,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
json_object_set_new(reply, "transaction", json_string(transaction_text));
char *reply_text = json_dumps(reply, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
json_decref(reply);
ret = janus_process_success(source, "application/json", g_strdup(reply_text));
ret = janus_process_success(source, g_strdup(reply_text));
goto jsondone;
}
#ifdef HAVE_RABBITMQ
Expand All @@ -943,7 +943,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
json_object_set_new(reply, "transaction", json_string(transaction_text));
char *reply_text = json_dumps(reply, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
json_decref(reply);
ret = janus_process_success(source, "application/json", g_strdup(reply_text));
ret = janus_process_success(source, g_strdup(reply_text));
goto jsondone;
}
#endif
Expand Down Expand Up @@ -1020,7 +1020,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
}
if(session_id < 1) {
Expand Down Expand Up @@ -1080,7 +1080,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else if(!strcasecmp(message_text, "attach")) {
if(handle != NULL) {
/* Attach is a session-level command */
Expand Down Expand Up @@ -1133,7 +1133,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else if(!strcasecmp(message_text, "destroy")) {
if(handle != NULL) {
/* Query is a session-level command */
Expand Down Expand Up @@ -1185,7 +1185,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else if(!strcasecmp(message_text, "detach")) {
if(handle == NULL) {
/* Query is an handle-level command */
Expand Down Expand Up @@ -1216,7 +1216,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else if(!strcasecmp(message_text, "message")) {
if(handle == NULL) {
/* Query is an handle-level command */
Expand Down Expand Up @@ -1555,7 +1555,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
json_decref(jsep);
json_decref(reply);
/* Send the success reply */
ret = janus_process_success(source, "application/json", reply_text);
ret = janus_process_success(source, reply_text);
} else if(result->type == JANUS_PLUGIN_OK_WAIT) {
/* The plugin received the request but didn't process it yet, send an ack (asynchronous notifications may follow) */
json_t *reply = json_object();
Expand All @@ -1568,7 +1568,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else {
/* Something went horribly wrong! */
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_PLUGIN_MESSAGE, "%s", result->content ? g_strdup(result->content) : "Plugin returned a severe (unknown) error");
Expand Down Expand Up @@ -1853,7 +1853,7 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
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);
ret = janus_process_success(source, reply_text);
} else {
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_UNKNOWN_REQUEST, "Unknown request '%s'", message_text);
}
Expand Down Expand Up @@ -2040,7 +2040,7 @@ int janus_admin_ws_handler(void *cls, struct MHD_Connection *connection, const c
goto done;
}
/* Send the success reply */
ret = janus_process_success(&source, "application/json", janus_info(NULL));
ret = janus_process_success(&source, janus_info(NULL));
goto done;
}

Expand Down Expand Up @@ -2120,7 +2120,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
/* Can only be a 'Get all sessions' or some general setting manipulation request */
if(!strcasecmp(message_text, "info")) {
/* The generic info request */
ret = janus_process_success(source, "application/json", janus_info(transaction_text));
ret = janus_process_success(source, janus_info(transaction_text));
goto jsondone;
}
if(admin_ws_api_secret != NULL) {
Expand All @@ -2146,7 +2146,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "set_log_level")) {
/* Change the debug logging level */
Expand Down Expand Up @@ -2177,7 +2177,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "set_locking_debug")) {
/* Enable/disable the locking debug (would show a message on the console for every lock attempt) */
Expand Down Expand Up @@ -2205,7 +2205,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "set_libnice_debug")) {
/* Enable/disable the libnice debugging (http://nice.freedesktop.org/libnice/libnice-Debug-messages.html) */
Expand Down Expand Up @@ -2237,7 +2237,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "set_max_nack_queue")) {
/* Change the current value for the max NACK queue */
Expand Down Expand Up @@ -2265,7 +2265,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else if(!strcasecmp(message_text, "list_sessions")) {
/* List sessions */
Expand Down Expand Up @@ -2294,7 +2294,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else {
/* No message we know of */
Expand Down Expand Up @@ -2378,7 +2378,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
} else {
/* Handle-related */
Expand Down Expand Up @@ -2464,7 +2464,7 @@ int janus_process_incoming_admin_request(janus_request_source *source, json_t *r
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);
ret = janus_process_success(source, reply_text);
goto jsondone;
}

Expand Down Expand Up @@ -2628,7 +2628,7 @@ int janus_ws_notifier(janus_request_source *source, int max_events) {
g_free(event);
return ret;
}
ret = janus_process_success(source, NULL, payload);
ret = janus_process_success(source, payload);
if(event != NULL) {
if(event->payload && event->allocated) {
g_free(event->payload);
Expand All @@ -2639,7 +2639,7 @@ int janus_ws_notifier(janus_request_source *source, int max_events) {
return ret;
}

int janus_process_success(janus_request_source *source, const char *transaction, char *payload)
int janus_process_success(janus_request_source *source, char *payload)
{
if(!source || !payload)
return MHD_NO;
Expand Down
3 changes: 1 addition & 2 deletions janus.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ int janus_process_incoming_request(janus_request_source *source, json_t *request
int janus_process_incoming_admin_request(janus_request_source *source, json_t *request);
/*! \brief Method to return a successful Janus response message (JSON) to the browser
* @param[in] source The source that originated the request
* @param[in] transaction The Janus transaction identifier
* @param[in] payload The stringified version of the Janus response (JSON)
* @returns MHD_YES on success, MHD_NO otherwise */
int janus_process_success(janus_request_source *source, const char *transaction, char *payload);
int janus_process_success(janus_request_source *source, char *payload);
/*! \brief Method to return an error Janus response message (JSON) to the browser
* @param[in] source The source that originated the request
* @param[in] session_id Janus session identifier this error refers to
Expand Down

0 comments on commit 97c665f

Please sign in to comment.