Loading...
Searching...
No Matches
janus.c File Reference
Core

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 <openssl/rand.h>`
`#include "janus.h"`
`#include "version.h"`
`#include "options.h"`
`#include "config.h"`
`#include "apierror.h"`
`#include "debug.h"`
`#include "ip-utils.h"`
`#include "rtcp.h"`
`#include "rtpfwd.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_t * | janus_admin_peerconnection_summary (janus_ice_peerconnection *pc)
json_t * | janus_admin_peerconnection_medium_summary (janus_ice_peerconnection_medium *medium)
gchar * | janus_get_local_ip (void)
| Helper method to return the local IP address (autodetected by default).
guint | janus_get_public_ip_count (void)
| Helper method to return the number of public IP addresses (if configured for 1-1 NAT).
gchar * | janus_get_public_ip (guint index)
| Helper method to return a given public IP address to use in the SDP (if multiple are configured for 1-1 NAT).
void | janus_add_public_ip (const gchar *ip)
gboolean | janus_has_public_ipv4_ip (void)
| Helper method to check if we have at least one manually passed public IPv4 address (for 1-1 NAT management).
gboolean | janus_has_public_ipv6_ip (void)
| Helper method to check if we have at least one manually passed public IPv6 address (for 1-1 NAT management).
gint | janus_is_stopping (void)
| Helper method to check whether the server is being shut down.
gboolean | janus_is_webrtc_encryption_enabled (void)
| Helper method to check whether WebRTC encryption is (as it should) enabled.
janus_session * | janus_session_create (guint64 session_id)
| Method to create a new Janus Core-Client session.
janus_session * | janus_session_find (guint64 session_id)
| Method to find an existing Janus Core-Client session from its ID.
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.
gint | janus_session_destroy (janus_session *session)
| Method to destroy a 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.
void | janus_session_handles_insert (janus_session *session, janus_ice_handle *handle)
| Method to insert a Janus ICE handle in a session.
gint | janus_session_handles_remove (janus_session *session, janus_ice_handle *handle)
| Method to remove a Janus ICE handle from a session.
void | janus_session_handles_clear (janus_session *session)
| Method to remove all Janus ICE handles from a session.
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.
janus_request * | janus_request_new (janus_transport *transport, janus_transport_session *instance, void *request_id, gboolean admin, json_t *message, json_error_t *error)
| Helper to allocate a janus_request instance.
void | janus_request_destroy (janus_request *request)
| Helper to destroy a janus_request instance.
int | janus_process_incoming_request (janus_request *request)
| Helper to process an incoming request, no matter where it comes from.
int | janus_process_incoming_admin_request (janus_request *request)
| Helper to process an incoming admin/monitor request, no matter where it comes from.
int | janus_process_success (janus_request *request, json_t *payload)
| Method to return a successful Janus response message (JSON) to the browser.
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_logger_close (gpointer key, gpointer value, gpointer user_data)
void | janus_loggerso_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_plugin * | janus_plugin_find (const gchar *package)
| Method to return a registered plugin instance out of its package name.
gint | main (int argc, char *argv[])

## Variables

gboolean | public_ips_ipv4 = FALSE
gboolean | public_ips_ipv6 = FALSE
int | janus_log_level = LOG_INFO
gboolean | janus_log_timestamps = FALSE
gboolean | janus_log_colors = FALSE
char * | janus_log_global_prefix = NULL
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_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_relay_rtp (janus_plugin_session *plugin_session, janus_plugin_rtp *packet)
void | janus_plugin_relay_rtcp (janus_plugin_session *plugin_session, janus_plugin_rtcp *packet)
void | janus_plugin_relay_data (janus_plugin_session *plugin_session, janus_plugin_data *message)
void | janus_plugin_send_pli (janus_plugin_session *plugin_session)
void | janus_plugin_send_pli_stream (janus_plugin_session *plugin_session, int mindex)
void | janus_plugin_send_remb (janus_plugin_session *plugin_session, uint32_t bitrate)
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_signed (void)
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

Copyright
  GNU General Public License v3

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

## DEFAULT_CANDIDATES_TIMEOUT

#define DEFAULT_CANDIDATES_TIMEOUT 45

## DEFAULT_RECLAIM_SESSION_TIMEOUT

#define DEFAULT_RECLAIM_SESSION_TIMEOUT 0

## DEFAULT_SESSION_TIMEOUT

#define DEFAULT_SESSION_TIMEOUT 60

## JANUS_AUTHOR

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

## JANUS_NAME

#define JANUS_NAME "Janus WebRTC Server"

## JANUS_SERVER_NAME

#define JANUS_SERVER_NAME "MyJanusInstance"

## SHLIB_EXT

#define SHLIB_EXT ".so"

## Function Documentation

## janus_add_public_ip()

void janus_add_public_ip | ( | const gchar * | ip | ) |

## janus_admin_peerconnection_medium_summary()

json_t * janus_admin_peerconnection_medium_summary | ( | janus_ice_peerconnection_medium * | medium | ) |

## janus_admin_peerconnection_summary()

json_t * janus_admin_peerconnection_summary | ( | janus_ice_peerconnection * | pc | ) |

## 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 | ( | guint | index | ) |

Helper method to return a given public IP address to use in the SDP (if multiple are configured for 1-1 NAT).

## janus_get_public_ip_count()

guint janus_get_public_ip_count | ( | void |  | ) |

Helper method to return the number of public IP addresses (if configured for 1-1 NAT).

## janus_has_public_ipv4_ip()

gboolean janus_has_public_ipv4_ip | ( | void |  | ) |

Helper method to check if we have at least one manually passed public IPv4 address (for 1-1 NAT management).

## janus_has_public_ipv6_ip()

gboolean janus_has_public_ipv6_ip | ( | void |  | ) |

Helper method to check if we have at least one manually passed public IPv6 address (for 1-1 NAT management).

## janus_is_stopping()

gint janus_is_stopping | ( | void |  | ) |

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

## janus_is_webrtc_encryption_enabled()

gboolean janus_is_webrtc_encryption_enabled | ( | void |  | ) |

Helper method to check whether WebRTC encryption is (as it should) enabled.

Note
  This is required by the ICE and DTLS portions of the code to decide whether to do the DTLS handshake, and whether SRTP encryption is required. Disabling the WebRTC encryption is supposed to be a debugging tool you can use with the Chrome setting with the same name, `--disable-webrtc-encryption` , and you should NEVER use it otherwise (it would simply not work with regular WebRTC endpoints).

Returns
  TRUE if WebRTC encryption is enabled (the default), and FALSE otherwise

## janus_logger_close()

void janus_logger_close | ( | gpointer | key,
|  | gpointer | value,
|  | gpointer | user_data )

## janus_loggerso_close()

void janus_loggerso_close | ( | gpointer | key,
|  | gpointer | value,
|  | gpointer | user_data )

## janus_plugin_auth_is_signature_valid()

gboolean janus_plugin_auth_is_signature_valid | ( | janus_plugin * | plugin,
|  | const char * | token )

## janus_plugin_auth_is_signed()

gboolean janus_plugin_auth_is_signed | ( | void |  | ) |

## janus_plugin_auth_signature_contains()

gboolean janus_plugin_auth_signature_contains | ( | janus_plugin * | plugin,
|  | const char * | token,
|  | const char * | desc )

## 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] | package | The 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,
|  | gboolean | restart )

## 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,
|  | janus_plugin_data * | message )

## janus_plugin_relay_rtcp()

void janus_plugin_relay_rtcp | ( | janus_plugin_session * | plugin_session,
|  | janus_plugin_rtcp * | packet )

## janus_plugin_relay_rtp()

void janus_plugin_relay_rtp | ( | janus_plugin_session * | plugin_session,
|  | janus_plugin_rtp * | packet )

## janus_plugin_send_pli()

void janus_plugin_send_pli | ( | janus_plugin_session * | plugin_session | ) |

## janus_plugin_send_pli_stream()

void janus_plugin_send_pli_stream | ( | janus_plugin_session * | plugin_session,
|  | int | mindex )

## janus_plugin_send_remb()

void janus_plugin_send_remb | ( | janus_plugin_session * | plugin_session,
|  | uint32_t | bitrate )

## 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] | request | The 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] | request | The 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] | request | The request instance and its source
  [in] | payload | The 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] | request | The 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,
|  | janus_transport_session * | instance,
|  | void * | request_id,
|  | gboolean | admin,
|  | json_t * | message,
|  | json_error_t * | error )

Helper to allocate a janus_request instance.

Parameters

  [in] | transport | Pointer to the transport
  [in] | instance | Pointer to the transport-provided session instance
  [in] | request_id | Opaque pointer to the request ID, if available
  [in] | admin | Whether this is a Janus API or Admin API request
  [in] | message | Opaque pointer to the original request, if available
  [in] | error | If the transport detected a JSON parsing error, the error content

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 Core-Client session.

Parameters

  [in] | session_id | The 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

## janus_session_destroy()

gint janus_session_destroy | ( | janus_session * | session | ) |

Method to destroy a Janus Core-Client session.

Parameters

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

Parameters

  [in] | session_id | The Janus Core-Client session ID

Returns
  The created Janus Core-Client session if successful, NULL otherwise

## janus_session_handles_clear()

void janus_session_handles_clear | ( | janus_session * | session | ) |

Method to remove all Janus ICE handles from a session.

Parameters

  [in] | session | The Janus Core-Client session

## janus_session_handles_find()

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] | session | The Janus Core-Client session this ICE handle belongs to
  [in] | handle_id | The Janus ICE handle ID

Returns
  The Janus ICE handle if successful, NULL otherwise

## janus_session_handles_insert()

void janus_session_handles_insert | ( | janus_session * | session,
|  | janus_ice_handle * | handle )

Method to insert a Janus ICE handle in a session.

Parameters

  [in] | session | The Janus Core-Client session
  [in] | handle | The Janus ICE handle

## janus_session_handles_list_json()

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] | session | The Janus Core-Client session

Returns
  The JSON array

## janus_session_handles_remove()

gint janus_session_handles_remove | ( | janus_session * | session,
|  | janus_ice_handle * | handle )

Method to remove a Janus ICE handle from a session.

Parameters

  [in] | session | The Janus Core-Client session
  [in] | handle | The Janus ICE handle

Returns
  The error code of janus_ice_handle_destroy

## 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] | session | The Janus Core-Client session this notification is related to
  [in] | event | The event to notify as a Jansson JSON object

## janus_transport_close()

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

## janus_transport_gone()

void janus_transport_gone | ( | janus_transport * | plugin,
|  | janus_transport_session * | transport )

## janus_transport_incoming_request()

void janus_transport_incoming_request | ( | janus_transport * | plugin,
|  | janus_transport_session * | 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_global_prefix

char* janus_log_global_prefix = NULL

## janus_log_level

int janus_log_level = LOG_INFO

## janus_log_timestamps

gboolean janus_log_timestamps = FALSE

## lock_debug

int lock_debug = 0

## public_ips_ipv4

gboolean public_ips_ipv4 = FALSE

## public_ips_ipv6

gboolean public_ips_ipv6 = FALSE

## refcount_debug

int refcount_debug = 0