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 <poll.h>
#include "janus.h"
#include "version.h"
#include "cmdline.h"
#include "config.h"
#include "apierror.h"
#include "log.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 Gateway"
 
#define JANUS_AUTHOR   "Meetecho s.r.l."
 
#define JANUS_VERSION   25
 
#define JANUS_VERSION_STRING   "0.2.5"
 
#define JANUS_SERVER_NAME   "MyJanusInstance"
 
#define SHLIB_EXT   ".so"
 
#define DEFAULT_SESSION_TIMEOUT   60
 

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 gateway is being shut down. More...
 
janus_sessionjanus_session_create (guint64 session_id)
 Method to create a new Janus Gateway-Client session. More...
 
janus_sessionjanus_session_find (guint64 session_id)
 Method to find an existing Janus Gateway-Client session from its ID. More...
 
janus_sessionjanus_session_find_destroyed (guint64 session_id)
 Method to find an existing Janus Gateway-Client session scheduled to be destroyed 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 (guint64 session_id)
 Method to destroy a Janus Gateway-Client session. More...
 
void janus_session_free (janus_session *session)
 Method to actually free the resources allocated by a Janus Gateway-Client session. More...
 
janus_requestjanus_request_new (janus_transport *transport, void *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
 

Transport plugin callback interface

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

GThreadPool * tasks = NULL
 
void janus_transport_incoming_request (janus_transport *plugin, void *transport, void *request_id, gboolean admin, json_t *message, json_error_t *error)
 
void janus_transport_gone (janus_transport *plugin, void *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 gateway core, as part of the janus_callbacks interface. Everything the plugins send the gateway 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)
 
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)
 

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 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

◆ DEFAULT_SESSION_TIMEOUT

#define DEFAULT_SESSION_TIMEOUT   60

◆ JANUS_AUTHOR

#define JANUS_AUTHOR   "Meetecho s.r.l."

◆ JANUS_NAME

#define JANUS_NAME   "Janus WebRTC Gateway"

◆ JANUS_SERVER_NAME

#define JANUS_SERVER_NAME   "MyJanusInstance"

◆ JANUS_VERSION

#define JANUS_VERSION   25

◆ JANUS_VERSION_STRING

#define JANUS_VERSION_STRING   "0.2.5"

◆ SHLIB_EXT

#define SHLIB_EXT   ".so"

Function Documentation

◆ janus_admin_component_summary()

json_t * janus_admin_component_summary ( janus_ice_component component)

◆ janus_admin_stream_summary()

json_t * janus_admin_stream_summary ( janus_ice_stream stream)

◆ janus_eventhandler_close()

void janus_eventhandler_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ janus_eventhandlerso_close()

void janus_eventhandlerso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ janus_get_local_ip()

gchar* janus_get_local_ip ( void  )

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

◆ janus_get_public_ip()

gchar* janus_get_public_ip ( void  )

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

◆ janus_is_stopping()

gint janus_is_stopping ( void  )

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

◆ janus_plugin_close()

void janus_plugin_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ janus_plugin_close_pc()

void janus_plugin_close_pc ( janus_plugin_session plugin_session)

◆ janus_plugin_end_session()

void janus_plugin_end_session ( janus_plugin_session plugin_session)

◆ janus_plugin_find()

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

◆ janus_plugin_handle_sdp()

json_t * janus_plugin_handle_sdp ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  sdp_type,
const char *  sdp 
)

◆ janus_plugin_notify_event()

void janus_plugin_notify_event ( janus_plugin plugin,
janus_plugin_session plugin_session,
json_t event 
)

◆ janus_plugin_push_event()

int janus_plugin_push_event ( janus_plugin_session plugin_session,
janus_plugin plugin,
const char *  transaction,
json_t message,
json_t jsep 
)

◆ janus_plugin_relay_data()

void janus_plugin_relay_data ( janus_plugin_session plugin_session,
char *  buf,
int  len 
)

◆ janus_plugin_relay_rtcp()

void janus_plugin_relay_rtcp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)

◆ janus_plugin_relay_rtp()

void janus_plugin_relay_rtp ( janus_plugin_session plugin_session,
int  video,
char *  buf,
int  len 
)

◆ janus_pluginso_close()

void janus_pluginso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ janus_process_error()

int janus_process_error ( janus_request request,
uint64_t  session_id,
const char *  transaction,
gint  error,
const char *  format,
  ... 
)

◆ janus_process_incoming_admin_request()

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

◆ janus_process_incoming_request()

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

◆ janus_process_success()

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

◆ janus_request_destroy()

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_new()

janus_request* janus_request_new ( janus_transport transport,
void *  instance,
void *  request_id,
gboolean  admin,
json_t message 
)

Helper to allocate a janus_request instance.

Parameters
[in]transportPointer to the transport
[in]instanceOpaque pointer to the transport-provided 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_create()

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

◆ janus_session_destroy()

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_find()

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_find_destroyed()

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

◆ janus_session_free()

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

◆ janus_session_notify_event()

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 Gateway-Client session instance to notify
[in]eventThe event to notify as a Jansson JSON object

◆ janus_set_public_ip()

void janus_set_public_ip ( const char *  ip)

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

◆ janus_transport_close()

void janus_transport_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ janus_transport_gone()

void janus_transport_gone ( janus_transport plugin,
void *  transport 
)

◆ janus_transport_incoming_request()

void janus_transport_incoming_request ( janus_transport plugin,
void *  transport,
void *  request_id,
gboolean  admin,
json_t message,
json_error_t *  error 
)

◆ janus_transport_is_api_secret_needed()

gboolean janus_transport_is_api_secret_needed ( janus_transport plugin)

◆ janus_transport_is_api_secret_valid()

gboolean janus_transport_is_api_secret_valid ( janus_transport plugin,
const char *  apisecret 
)

◆ janus_transport_is_auth_token_needed()

gboolean janus_transport_is_auth_token_needed ( janus_transport plugin)

◆ janus_transport_is_auth_token_valid()

gboolean janus_transport_is_auth_token_valid ( janus_transport plugin,
const char *  token 
)

◆ janus_transport_notify_event()

void janus_transport_notify_event ( janus_transport plugin,
void *  transport,
json_t event 
)

◆ janus_transport_task()

void janus_transport_task ( gpointer  data,
gpointer  user_data 
)

◆ janus_transportso_close()

void janus_transportso_close ( gpointer  key,
gpointer  value,
gpointer  user_data 
)

◆ main()

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

Variable Documentation

◆ janus_log_colors

gboolean janus_log_colors = FALSE

◆ janus_log_level

int janus_log_level = LOG_INFO

◆ janus_log_timestamps

gboolean janus_log_timestamps = FALSE

◆ lock_debug

int lock_debug = 0

◆ tasks

GThreadPool* tasks = NULL