Fork me on GitHub
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/stat.h>
#include <fcntl.h>
#include <poll.h>
#include "janus.h"
#include "version.h"
#include "cmdline.h"
#include "config.h"
#include "apierror.h"
#include "debug.h"
#include "ip-utils.h"
#include "rtcp.h"
#include "auth.h"
#include "record.h"
#include "events.h"
Include dependency graph for janus.c:

Macros

#define JANUS_NAME   "Janus WebRTC Server"
 
#define JANUS_AUTHOR   "Meetecho s.r.l."
 
#define JANUS_SERVER_NAME   "MyJanusInstance"
 
#define SHLIB_EXT   ".so"
 
#define DEFAULT_SESSION_TIMEOUT   60
 
#define DEFAULT_RECLAIM_SESSION_TIMEOUT   0
 
#define DEFAULT_CANDIDATES_TIMEOUT   45
 

Functions

json_tjanus_admin_stream_summary (janus_ice_stream *stream)
 
json_tjanus_admin_component_summary (janus_ice_component *component)
 
gchar * janus_get_local_ip (void)
 Helper method to return the local IP address (autodetected by default) More...
 
gchar * janus_get_public_ip (void)
 Helper method to return the IP address to use in the SDP (autodetected by default) More...
 
void janus_set_public_ip (const char *ip)
 Helper method to overwrite the IP address to use in the SDP. More...
 
gint janus_is_stopping (void)
 Helper method to check whether the server is being shut down. More...
 
janus_sessionjanus_session_create (guint64 session_id)
 Method to create a new Janus Core-Client session. More...
 
janus_sessionjanus_session_find (guint64 session_id)
 Method to find an existing Janus Core-Client session from its ID. More...
 
void janus_session_notify_event (janus_session *session, json_t *event)
 Method to add an event to notify to the queue of notifications for this session. More...
 
gint janus_session_destroy (janus_session *session)
 Method to destroy a Janus Core-Client session. More...
 
janus_ice_handlejanus_session_handles_find (janus_session *session, guint64 handle_id)
 Method to find an existing Janus ICE handle from its ID. More...
 
void janus_session_handles_insert (janus_session *session, janus_ice_handle *handle)
 Method to insert a Janus ICE handle in a session. More...
 
gint janus_session_handles_remove (janus_session *session, janus_ice_handle *handle)
 Method to remove a Janus ICE handle from a session. More...
 
void janus_session_handles_clear (janus_session *session)
 Method to remove all Janus ICE handles from a session. More...
 
json_tjanus_session_handles_list_json (janus_session *session)
 Method to list the IDs of all Janus ICE handles of a session as JSON. More...
 
janus_requestjanus_request_new (janus_transport *transport, janus_transport_session *instance, void *request_id, gboolean admin, json_t *message)
 Helper to allocate a janus_request instance. More...
 
void janus_request_destroy (janus_request *request)
 Helper to destroy a janus_request instance. More...
 
int janus_process_incoming_request (janus_request *request)
 Helper to process an incoming request, no matter where it comes from. More...
 
int janus_process_incoming_admin_request (janus_request *request)
 Helper to process an incoming admin/monitor request, no matter where it comes from. More...
 
int janus_process_success (janus_request *request, json_t *payload)
 Method to return a successful Janus response message (JSON) to the browser. More...
 
int janus_process_error (janus_request *request, uint64_t session_id, const char *transaction, gint error, const char *format,...)
 
void janus_transport_close (gpointer key, gpointer value, gpointer user_data)
 
void janus_transportso_close (gpointer key, gpointer value, gpointer user_data)
 
void janus_eventhandler_close (gpointer key, gpointer value, gpointer user_data)
 
void janus_eventhandlerso_close (gpointer key, gpointer value, gpointer user_data)
 
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. More...
 
gint main (int argc, char *argv[])
 

Variables

int janus_log_level = LOG_INFO
 
gboolean janus_log_timestamps = FALSE
 
gboolean janus_log_colors = FALSE
 
int lock_debug = 0
 
int refcount_debug = 0
 

Transport plugin callback interface

These are the callbacks implemented by the Janus core, as part of the janus_transport_callbacks interface. Everything the transport plugins send the core is handled here.

void janus_transport_incoming_request (janus_transport *plugin, janus_transport_session *transport, void *request_id, gboolean admin, json_t *message, json_error_t *error)
 
void janus_transport_gone (janus_transport *plugin, janus_transport_session *transport)
 
gboolean janus_transport_is_api_secret_needed (janus_transport *plugin)
 
gboolean janus_transport_is_api_secret_valid (janus_transport *plugin, const char *apisecret)
 
gboolean janus_transport_is_auth_token_needed (janus_transport *plugin)
 
gboolean janus_transport_is_auth_token_valid (janus_transport *plugin, const char *token)
 
void janus_transport_notify_event (janus_transport *plugin, void *transport, json_t *event)
 
void janus_transport_task (gpointer data, gpointer user_data)
 

Plugin callback interface

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

int janus_plugin_push_event (janus_plugin_session *plugin_session, janus_plugin *plugin, const char *transaction, json_t *message, json_t *jsep)
 
json_tjanus_plugin_handle_sdp (janus_plugin_session *plugin_session, janus_plugin *plugin, const char *sdp_type, const char *sdp, gboolean restart)
 
void janus_plugin_relay_rtp (janus_plugin_session *plugin_session, int video, char *buf, int len)
 
void janus_plugin_relay_rtcp (janus_plugin_session *plugin_session, int video, char *buf, int len)
 
void janus_plugin_relay_data (janus_plugin_session *plugin_session, char *buf, int len)
 
void janus_plugin_close_pc (janus_plugin_session *plugin_session)
 
void janus_plugin_end_session (janus_plugin_session *plugin_session)
 
void janus_plugin_notify_event (janus_plugin *plugin, janus_plugin_session *plugin_session, json_t *event)
 
gboolean janus_plugin_auth_is_signature_valid (janus_plugin *plugin, const char *token)
 
gboolean janus_plugin_auth_signature_contains (janus_plugin *plugin, const char *token, const char *desc)
 

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 Janus core. This code takes care of the server initialization (command line/configuration) and setup, and makes use of the available transport plugins (by default HTTP, WebSockets, RabbitMQ, if compiled) and Janus protocol (a JSON-based protocol) to interact with the applications, whether they're web based or not. The core also takes care of bridging peers and plugins accordingly, in terms of both messaging and real-time media transfer via WebRTC.

Core

Macro Definition Documentation

#define DEFAULT_CANDIDATES_TIMEOUT   45
#define DEFAULT_RECLAIM_SESSION_TIMEOUT   0
#define DEFAULT_SESSION_TIMEOUT   60
#define JANUS_AUTHOR   "Meetecho s.r.l."
#define JANUS_NAME   "Janus WebRTC Server"
#define JANUS_SERVER_NAME   "MyJanusInstance"
#define SHLIB_EXT   ".so"

Function Documentation

json_t * janus_admin_component_summary ( janus_ice_component component)
json_t * janus_admin_stream_summary ( janus_ice_stream stream)
void janus_eventhandler_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
void janus_eventhandlerso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
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)

gint janus_is_stopping ( void  )

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

gboolean janus_plugin_auth_is_signature_valid ( janus_plugin plugin,
const char *  token 
)
gboolean janus_plugin_auth_signature_contains ( janus_plugin plugin,
const char *  token,
const char *  desc 
)
void janus_plugin_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
void janus_plugin_close_pc ( janus_plugin_session plugin_session)
void janus_plugin_end_session ( janus_plugin_session plugin_session)
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
json_t * janus_plugin_handle_sdp ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  sdp_type,
const char *  sdp,
gboolean  restart 
)
void janus_plugin_notify_event ( janus_plugin plugin,
janus_plugin_session plugin_session,
json_t event 
)
int janus_plugin_push_event ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  transaction,
json_t message,
json_t jsep 
)
void janus_plugin_relay_data ( janus_plugin_session plugin_session,
char *  buf,
int  len 
)
void janus_plugin_relay_rtcp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)
void janus_plugin_relay_rtp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)
void janus_pluginso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
int janus_process_error ( janus_request request,
uint64_t  session_id,
const char *  transaction,
gint  error,
const char *  format,
  ... 
)
int janus_process_incoming_admin_request ( janus_request request)

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

Parameters
[in]requestThe request instance and its source
Returns
0 on success, a negative integer otherwise
int janus_process_incoming_request ( janus_request request)

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

Parameters
[in]requestThe JSON request
Returns
0 on success, a negative integer otherwise
int janus_process_success ( janus_request request,
json_t payload 
)

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

Parameters
[in]requestThe request instance and its source
[in]payloadThe payload to return as a JSON object
Returns
0 on success, a negative integer otherwise
void janus_request_destroy ( janus_request request)

Helper to destroy a janus_request instance.

Parameters
[in]requestThe janus_request instance to destroy
Note
The opaque pointers in the instance are not destroyed, that's up to you
janus_request* janus_request_new ( janus_transport transport,
janus_transport_session instance,
void *  request_id,
gboolean  admin,
json_t message 
)

Helper to allocate a janus_request instance.

Parameters
[in]transportPointer to the transport
[in]instancePointer to the transport-provided session instance
[in]request_idOpaque pointer to the request ID, if available
[in]adminWhether this is a Janus API or Admin API request
[in]messageOpaque pointer to the original request, if available
Returns
A pointer to a janus_request instance if successful, NULL otherwise
janus_session* janus_session_create ( guint64  session_id)

Method to create a new Janus Core-Client session.

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

Method to destroy a Janus Core-Client session.

Parameters
[in]sessionThe Janus Core-Client session 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 Core-Client session from its ID.

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

Method to remove all Janus ICE handles from a session.

Parameters
[in]sessionThe Janus Core-Client session
janus_ice_handle* janus_session_handles_find ( janus_session session,
guint64  handle_id 
)

Method to find an existing Janus ICE handle from its ID.

Parameters
[in]sessionThe Janus Core-Client session this ICE handle belongs to
[in]handle_idThe Janus ICE handle ID
Returns
The Janus ICE handle if successful, NULL otherwise
void janus_session_handles_insert ( janus_session session,
janus_ice_handle handle 
)

Method to insert a Janus ICE handle in a session.

Parameters
[in]sessionThe Janus Core-Client session
[in]handleThe Janus ICE handle
json_t* janus_session_handles_list_json ( janus_session session)

Method to list the IDs of all Janus ICE handles of a session as JSON.

Parameters
[in]sessionThe Janus Core-Client session
Returns
The JSON array
gint janus_session_handles_remove ( janus_session session,
janus_ice_handle handle 
)

Method to remove a Janus ICE handle from a session.

Parameters
[in]sessionThe Janus Core-Client session
[in]handleThe Janus ICE handle
Returns
The error code of janus_ice_handle_destroy
void janus_session_notify_event ( janus_session session,
json_t event 
)

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

Parameters
[in]sessionThe Janus Core-Client session this notification is related to
[in]eventThe event to notify as a Jansson JSON object
void janus_set_public_ip ( const char *  ip)

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

void janus_transport_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
void janus_transport_gone ( janus_transport plugin,
janus_transport_session transport 
)
void janus_transport_incoming_request ( janus_transport plugin,
janus_transport_session transport,
void *  request_id,
gboolean  admin,
json_t message,
json_error_t *  error 
)
gboolean janus_transport_is_api_secret_needed ( janus_transport plugin)
gboolean janus_transport_is_api_secret_valid ( janus_transport plugin,
const char *  apisecret 
)
gboolean janus_transport_is_auth_token_needed ( janus_transport plugin)
gboolean janus_transport_is_auth_token_valid ( janus_transport plugin,
const char *  token 
)
void janus_transport_notify_event ( janus_transport plugin,
void *  transport,
json_t event 
)
void janus_transport_task ( gpointer  data,
gpointer  user_data 
)
void janus_transportso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
gint main ( int  argc,
char *  argv[] 
)

Variable Documentation

gboolean janus_log_colors = FALSE
int janus_log_level = LOG_INFO
gboolean janus_log_timestamps = FALSE
int lock_debug = 0
int refcount_debug = 0