Fork me on GitHub
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
janus.c File Reference

Janus core. More...

#include <dlfcn.h>
#include <dirent.h>
#include <net/if.h>
#include <netdb.h>
#include <signal.h>
#include <getopt.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include "janus.h"
#include "cmdline.h"
#include "config.h"
#include "apierror.h"
#include "debug.h"
#include "rtcp.h"
#include "sdp.h"
#include "utils.h"
Include dependency graph for janus.c:

Macros

#define JANUS_NAME   "Janus WebRTC Gateway"
#define JANUS_AUTHOR   "Meetecho s.r.l."
#define JANUS_VERSION   9
#define JANUS_VERSION_STRING   "0.0.9"
#define SHLIB_EXT   ".so"
#define SESSION_TIMEOUT   60 /* FIXME Should this be higher, e.g., 120 seconds? */

Functions

void janus_admin_allow_address (const char *ip)
gboolean janus_admin_is_allowed (const char *ip)
json_t * janus_admin_stream_summary (janus_ice_stream *stream)
json_t * janus_admin_component_summary (janus_ice_component *component)
gchar * janus_get_server_pem (void)
 Helper method to return the path to the provided server certificate.
gchar * janus_get_server_key (void)
 Helper method to return the path to the provided server certificate key.
char * janus_info (const char *transaction)
gchar * janus_get_local_ip (void)
 Helper method to return the local IP address (autodetected by default)
gchar * janus_get_public_ip (void)
 Helper method to return the IP address to use in the SDP (autodetected by default)
void janus_set_public_ip (const char *ip)
 Helper method to overwrite the IP address to use in the SDP.
gint janus_is_stopping (void)
 Helper method to check whether the gateway is being shut down.
void janus_handle_signal (int signum)
 Signal handler (just used to intercept CTRL+C)
janus_sessionjanus_session_create (guint64 session_id)
 Method to create a new Janus Gateway-Client session.
janus_sessionjanus_session_find (guint64 session_id)
 Method to find an existing Janus Gateway-Client session from its ID.
janus_sessionjanus_session_find_destroyed (guint64 session_id)
 Method to find an existing Janus Gateway-Client session scheduled to be destroyed from its ID.
void janus_session_notify_event (guint64 session_id, janus_http_event *event)
 Method to add an event to notify to the queue of notifications for this session.
gint janus_session_destroy (guint64 session_id)
 Method to destroy a Janus Gateway-Client session.
void janus_session_free (janus_session *session)
 Method to actually free the resources allocated by a Janus Gateway-Client session.
int janus_ws_client_connect (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Callback (libmicrohttpd) invoked when a new connection is attempted on the REST API.
int janus_admin_ws_client_connect (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Callback (libmicrohttpd) invoked when a new connection is attempted on the admin/monitor webserver.
int janus_ws_handler (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr)
 Callback (libmicrohttpd) invoked when an HTTP message (GET, POST, OPTIONS, etc.) is available.
janus_request_sourcejanus_request_source_new (int type, void *source, void *msg)
 Helper to allocate a janus_request_source instance.
void janus_request_source_destroy (janus_request_source *req_source)
 Helper to destroy a janus_request_source instance.
int janus_process_incoming_request (janus_request_source *source, json_t *root)
 Helper to process an incoming request, no matter where it comes from.
int janus_admin_ws_handler (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr)
 Callback (libmicrohttpd) invoked when an admin/monitor HTTP message (GET, POST, OPTIONS, etc.) is available.
int janus_process_incoming_admin_request (janus_request_source *source, json_t *root)
 Helper to process an incoming admin/monitor request, no matter where it comes from.
int janus_ws_headers (void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
 Callback (libmicrohttpd) invoked when headers of an incoming HTTP message have been parsed.
void janus_ws_request_completed (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
 Callback (libmicrohttpd) invoked when a request has been processed and can be freed.
int janus_ws_notifier (janus_request_source *source, int max_events)
 Worker to handle requests that are actually long polls.
int janus_process_success (janus_request_source *source, char *payload)
 Method to return a successful Janus response message (JSON) to the browser.
int janus_process_error (janus_request_source *source, uint64_t session_id, const char *transaction, gint error, const char *format,...)
void janus_plugin_close (gpointer key, gpointer value, gpointer user_data)
void janus_pluginso_close (gpointer key, gpointer value, gpointer user_data)
janus_pluginjanus_plugin_find (const gchar *package)
 Method to return a registered plugin instance out of its package name.
gint main (int argc, char *argv[])
void janus_http_event_free (janus_http_event *event)

Variables

GList * janus_admin_access_list = NULL
janus_mutex access_list_mutex
int janus_log_level = 0
gboolean janus_log_timestamps = FALSE
gboolean janus_log_colors = FALSE
int lock_debug = 0

Plugin callback interface

These are the callbacks implemented by the gateway core, as part of the janus_callbacks interface. Everything the plugins send the gateway is handled here.

int janus_push_event (janus_plugin_session *plugin_session, janus_plugin *plugin, const char *transaction, const char *message, const char *sdp_type, const char *sdp)
json_t * janus_handle_sdp (janus_plugin_session *plugin_session, janus_plugin *plugin, const char *sdp_type, const char *sdp)
void janus_relay_rtp (janus_plugin_session *plugin_session, int video, char *buf, int len)
void janus_relay_rtcp (janus_plugin_session *plugin_session, int video, char *buf, int len)
void janus_relay_data (janus_plugin_session *plugin_session, char *buf, int len)
void janus_close_pc (janus_plugin_session *plugin_session)
void janus_end_session (janus_plugin_session *plugin_session)

Detailed Description

Janus core.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation of the gateway core. This code takes care of the gateway initialization (command line/configuration) and setup, and implements the transports (HTTP, WebSockets, RabbitMQ) and Janus protocol (a JSON-based protocol implemented) to interact with the web applications. The core also takes care of bridging peers and plugins accordingly.

Core

Macro Definition Documentation

#define JANUS_AUTHOR   "Meetecho s.r.l."
#define JANUS_NAME   "Janus WebRTC Gateway"
#define JANUS_VERSION   9
#define JANUS_VERSION_STRING   "0.0.9"
#define SESSION_TIMEOUT   60 /* FIXME Should this be higher, e.g., 120 seconds? */
#define SHLIB_EXT   ".so"

Function Documentation

void janus_admin_allow_address ( const char *  ip)
json_t * janus_admin_component_summary ( janus_ice_component component)
gboolean janus_admin_is_allowed ( const char *  ip)
json_t * janus_admin_stream_summary ( janus_ice_stream stream)
int janus_admin_ws_client_connect ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Callback (libmicrohttpd) invoked when a new connection is attempted on the admin/monitor webserver.

int janus_admin_ws_handler ( void *  cls,
struct MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  version,
const char *  upload_data,
size_t *  upload_data_size,
void **  ptr 
)

Callback (libmicrohttpd) invoked when an admin/monitor HTTP message (GET, POST, OPTIONS, etc.) is available.

void janus_close_pc ( janus_plugin_session plugin_session)
void janus_end_session ( janus_plugin_session plugin_session)
gchar* janus_get_local_ip ( void  )

Helper method to return the local IP address (autodetected by default)

gchar* janus_get_public_ip ( void  )

Helper method to return the IP address to use in the SDP (autodetected by default)

gchar* janus_get_server_key ( void  )

Helper method to return the path to the provided server certificate key.

gchar* janus_get_server_pem ( void  )

Helper method to return the path to the provided server certificate.

json_t * janus_handle_sdp ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  sdp_type,
const char *  sdp 
)
void janus_handle_signal ( int  signum)

Signal handler (just used to intercept CTRL+C)

void janus_http_event_free ( janus_http_event event)
char * janus_info ( const char *  transaction)
gint janus_is_stopping ( void  )

Helper method to check whether the gateway is being shut down.

void janus_plugin_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
janus_plugin* janus_plugin_find ( const gchar *  package)

Method to return a registered plugin instance out of its package name.

Parameters
[in]packageThe unique package name of the plugin
Returns
The plugin instance
void janus_pluginso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
int janus_process_error ( janus_request_source source,
uint64_t  session_id,
const char *  transaction,
gint  error,
const char *  format,
  ... 
)
int janus_process_incoming_admin_request ( janus_request_source source,
json_t *  request 
)

Helper to process an incoming admin/monitor request, no matter where it comes from.

Parameters
[in]sourceThe source that originated the request
[in]requestThe JSON request
Returns
MHD_YES on success, MHD_NO otherwise
int janus_process_incoming_request ( janus_request_source source,
json_t *  request 
)

Helper to process an incoming request, no matter where it comes from.

Parameters
[in]sourceThe source that originated the request
[in]requestThe JSON request
Returns
MHD_YES on success, MHD_NO otherwise
int janus_process_success ( janus_request_source source,
char *  payload 
)

Method to return a successful Janus response message (JSON) to the browser.

Parameters
[in]sourceThe source that originated the request
[in]payloadThe stringified version of the Janus response (JSON)
Returns
MHD_YES on success, MHD_NO otherwise
int janus_push_event ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  transaction,
const char *  message,
const char *  sdp_type,
const char *  sdp 
)
void janus_relay_data ( janus_plugin_session plugin_session,
char *  buf,
int  len 
)
void janus_relay_rtcp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)
void janus_relay_rtp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)
void janus_request_source_destroy ( janus_request_source req_source)

Helper to destroy a janus_request_source instance.

Parameters
[in]req_sourceThe janus_request_source instance to destroy
Note
The opaque pointers in the instance are not destroyed, that's up to you
janus_request_source* janus_request_source_new ( int  type,
void *  source,
void *  msg 
)

Helper to allocate a janus_request_source instance.

Parameters
[in]typeThe source type
[in]sourceOpaque pointer to the source
[in]msgOpaque pointer to the original request, if available
Returns
A pointer to a janus_request_source instance if successful, NULL otherwise
janus_session* janus_session_create ( guint64  session_id)

Method to create a new Janus Gateway-Client session.

Parameters
[in]session_idThe desired Janus Gateway-Client session ID, or 0 if it needs to be generated randomly
Returns
The created Janus Gateway-Client session if successful, NULL otherwise
gint janus_session_destroy ( guint64  session_id)

Method to destroy a Janus Gateway-Client session.

Parameters
[in]session_idThe Janus Gateway-Client session ID to destroy
Returns
0 in case of success, a negative integer otherwise
janus_session* janus_session_find ( guint64  session_id)

Method to find an existing Janus Gateway-Client session from its ID.

Parameters
[in]session_idThe Janus Gateway-Client session ID
Returns
The created Janus Gateway-Client session if successful, NULL otherwise
janus_session* janus_session_find_destroyed ( guint64  session_id)

Method to find an existing Janus Gateway-Client session scheduled to be destroyed from its ID.

Parameters
[in]session_idThe Janus Gateway-Client session ID
Returns
The created Janus Gateway-Client session if successful, NULL otherwise
void janus_session_free ( janus_session session)

Method to actually free the resources allocated by a Janus Gateway-Client session.

Parameters
[in]sessionThe Janus Gateway-Client session instance to free
void janus_session_notify_event ( guint64  session_id,
janus_http_event event 
)

Method to add an event to notify to the queue of notifications for this session.

Parameters
[in]session_idThe Janus Gateway-Client session ID
[in]eventThe janus_http_event instance to add to the queue
void janus_set_public_ip ( const char *  ip)

Helper method to overwrite the IP address to use in the SDP.

int janus_ws_client_connect ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Callback (libmicrohttpd) invoked when a new connection is attempted on the REST API.

int janus_ws_handler ( void *  cls,
struct MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  version,
const char *  upload_data,
size_t *  upload_data_size,
void **  ptr 
)

Callback (libmicrohttpd) invoked when an HTTP message (GET, POST, OPTIONS, etc.) is available.

int janus_ws_headers ( void *  cls,
enum MHD_ValueKind  kind,
const char *  key,
const char *  value 
)

Callback (libmicrohttpd) invoked when headers of an incoming HTTP message have been parsed.

int janus_ws_notifier ( janus_request_source source,
int  max_events 
)

Worker to handle requests that are actually long polls.

As this method handles a long poll, it doesn't return until an event (e.g., pushed by a plugin) is available, or a timeout (30 seconds) has been fired. In case of a timeout, a keep-alive Janus response (JSON) is sent to tell the browser that the session is still valid.

Parameters
[in]sourceThe janus_request_source instance that is handling the request
[in]max_eventsThe maximum number of events that can be returned in a single response (by default just one; if more, an array is returned)
Returns
MHD_YES on success, MHD_NO otherwise
Todo:
Improve the Janus protocol keep-alive mechanism in JavaScript
void janus_ws_request_completed ( void *  cls,
struct MHD_Connection *  connection,
void **  con_cls,
enum MHD_RequestTerminationCode  toe 
)

Callback (libmicrohttpd) invoked when a request has been processed and can be freed.

gint main ( int  argc,
char *  argv[] 
)

Variable Documentation

janus_mutex access_list_mutex
GList* janus_admin_access_list = NULL
gboolean janus_log_colors = FALSE
int janus_log_level = 0
gboolean janus_log_timestamps = FALSE
int lock_debug = 0