Skip to content

Commit

Permalink
Janus ping/pong message and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
meetecho committed Nov 22, 2014
1 parent a3b5910 commit 742f887
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AM_CFLAGS += -Wredundant-decls # sophiasip also contains redundant declarations
# some fairly big refactoring though, which can wait.
# AM_CFLAGS += -Wshadow -Wstrict-aliasing=2

AM_CFLAGS += -fstack-protector-all -g -ggdb -rdynamic
AM_CFLAGS += -fstack-protector-all -g -ggdb -fPIC -rdynamic

# FIXME: make docs work with distcheck
DISTCHECK_CONFIGURE_FLAGS = --disable-docs --enable-post-processing
Expand Down
12 changes: 11 additions & 1 deletion janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,21 @@ int janus_process_incoming_request(janus_request_source *source, json_t *root) {
const gchar *message_text = json_string_value(message);

if(session_id == 0 && handle_id == 0) {
/* Can only be a 'Create new session' or 'Get info' request */
/* 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", g_strdup(info_text));
goto jsondone;
}
if(!strcasecmp(message_text, "ping")) {
/* Prepare JSON reply */
json_t *reply = json_object();
json_object_set_new(reply, "janus", json_string("pong"));
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));
goto jsondone;
}
if(strcasecmp(message_text, "create")) {
ret = janus_process_error(source, session_id, transaction_text, JANUS_ERROR_INVALID_REQUEST_PATH, "Unhandled request '%s' at this path", message_text);
goto jsondone;
Expand Down
65 changes: 65 additions & 0 deletions mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,71 @@ GET http://host:port/janus/<sessionid>?max_events=5
"sdp" : "v=0\r\no=[..more sdp stuff..]"
}
}
\endverbatim
*
* If you're going to \c trickle candidates rather than including them
* all in an SDP OFFER or ANSWER, there is an ad-hoc message you can use
* to do so which is called, unsurprisingly, \c trickle and which you
* can use to send one or more trickle candidates to Janus. Since such
* a message is related to a specific PeerConnection, it will need to be
* addressed to the right Handle just as the \c message introduced
* previously. A \c trickle message can contain three different kind of
* information:
*
* - a single trickle candidate;
* - an array of trickle candidates;
* - a null candidate or a \c completed JSON object to notify the end of the
* candidates.
*
* This is an example of a single candidate being trickled:
*
\verbatim
{
"janus" : "trickle",
"transaction" : "hehe83hd8dw12e",
"candidate" : {
"sdpMid" : "video",
"sdpMLineIndex" : 1,
"candidate" : "..."
}
}
\endverbatim
*
* This, instead, is an example of how to group more trickle candidates
* in a single request (particularly useful if you're wrapping Janus in
* your server and want to reduce the number of transactions):
*
\verbatim
{
"janus" : "trickle",
"transaction" : "hehe83hd8dw12e",
"candidate" : [
{
"sdpMid" : "video",
"sdpMLineIndex" : 1,
"candidate" : "..."
},
{
"sdpMid" : "video",
"sdpMLineIndex" : 1,
"candidate" : "..."
},
[..]
]
}
\endverbatim
*
* Finally, this is how you can tell Janus that you sent all the trickle
* candidates that were gathered:
*
\verbatim
{
"janus" : "trickle",
"transaction" : "hehe83hd8dw12e",
"candidate" : {
"completed" : true
}
}
\endverbatim
*
* Plugins may handle this requests synchronously or asynchronously. In
Expand Down
1 change: 1 addition & 0 deletions plugins/janus_recordplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ static void *janus_recordplay_handler(void *data) {
JANUS_LOG(LOG_ERR, "Not a playout session, can't start\n");
error_code = JANUS_RECORDPLAY_ERROR_INVALID_STATE;
g_snprintf(error_cause, 512, "Not a playout session, can't start");
goto error;
}
/* Just a final message we make use of, e.g., to receive an ANSWER to our OFFER for a playout */
if(!msg->sdp) {
Expand Down
42 changes: 42 additions & 0 deletions rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,48 @@ int janus_rtcp_remove_nacks(char *packet, int len) {
return len;
}

/* Query an existing REMB message */
uint64_t janus_rtcp_get_remb(char *packet, int len) {
if(packet == NULL || len == 0)
return 0;
rtcp_header *rtcp = (rtcp_header *)packet;
if(rtcp->version != 2)
return 0;
/* Get REMB bitrate, if any */
int total = len;
while(rtcp) {
if(rtcp->type == RTCP_PSFB) {
gint fmt = rtcp->rc;
if(fmt == 15) {
rtcp_fb *rtcpfb = (rtcp_fb *)rtcp;
rtcp_remb *remb = (rtcp_remb *)rtcpfb->fci;
if(remb->id[0] == 'R' && remb->id[1] == 'E' && remb->id[2] == 'M' && remb->id[3] == 'B') {
/* FIXME From rtcp_utility.cc */
unsigned char *_ptrRTCPData = (unsigned char *)remb;
_ptrRTCPData += 4; /* Skip unique identifier and num ssrc */
//~ JANUS_LOG(LOG_VERB, " %02X %02X %02X %02X\n", _ptrRTCPData[0], _ptrRTCPData[1], _ptrRTCPData[2], _ptrRTCPData[3]);
uint8_t brExp = (_ptrRTCPData[1] >> 2) & 0x3F;
uint32_t brMantissa = (_ptrRTCPData[1] & 0x03) << 16;
brMantissa += (_ptrRTCPData[2] << 8);
brMantissa += (_ptrRTCPData[3]);
uint64_t bitrate = brMantissa << brExp;
JANUS_LOG(LOG_VERB, "Got REMB bitrate %"SCNu64"\n", bitrate);
return bitrate;
}
}
}
/* Is this a compound packet? */
int length = ntohs(rtcp->length);
if(length == 0)
break;
total -= length*4+4;
if(total <= 0)
break;
rtcp = (rtcp_header *)((uint32_t*)rtcp + length + 1);
}
return 0;
}

/* Change an existing REMB message */
int janus_rtcp_cap_remb(char *packet, int len, uint64_t bitrate) {
if(packet == NULL || len == 0)
Expand Down
6 changes: 6 additions & 0 deletions rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ GSList *janus_rtcp_get_nacks(char *packet, int len);
* have been handled. */
int janus_rtcp_remove_nacks(char *packet, int len);

/*! \brief Inspect an existing RTCP REMB message to retrieve the reported bitrate
* @param[in] packet The message data
* @param[in] len The message data length in bytes
* @returns The reported bitrate if successful, 0 if no REMB packet was available */
uint64_t janus_rtcp_get_remb(char *packet, int len);

/*! \brief Method to modify an existing RTCP REMB message to cap the reported bitrate
* @param[in] packet The message data
* @param[in] len The message data length in bytes
Expand Down

0 comments on commit 742f887

Please sign in to comment.