Fork me on GitHub
Data Structures | Macros | Typedefs | Functions
janus_videocall.c File Reference

Janus VideoCall plugin. More...

#include "plugin.h"
#include <jansson.h>
#include "../debug.h"
#include "../apierror.h"
#include "../config.h"
#include "../mutex.h"
#include "../record.h"
#include "../rtp.h"
#include "../rtcp.h"
#include "../utils.h"
Include dependency graph for janus_videocall.c:

Data Structures

struct  janus_videocall_message
 
struct  janus_videocall_session
 

Macros

#define JANUS_VIDEOCALL_VERSION   6
 
#define JANUS_VIDEOCALL_VERSION_STRING   "0.0.6"
 
#define JANUS_VIDEOCALL_DESCRIPTION   "This is a simple video call plugin for Janus, allowing two WebRTC peers to call each other through the gateway."
 
#define JANUS_VIDEOCALL_NAME   "JANUS VideoCall plugin"
 
#define JANUS_VIDEOCALL_AUTHOR   "Meetecho s.r.l."
 
#define JANUS_VIDEOCALL_PACKAGE   "janus.plugin.videocall"
 
#define JANUS_VIDEOCALL_ERROR_UNKNOWN_ERROR   499
 
#define JANUS_VIDEOCALL_ERROR_NO_MESSAGE   470
 
#define JANUS_VIDEOCALL_ERROR_INVALID_JSON   471
 
#define JANUS_VIDEOCALL_ERROR_INVALID_REQUEST   472
 
#define JANUS_VIDEOCALL_ERROR_REGISTER_FIRST   473
 
#define JANUS_VIDEOCALL_ERROR_INVALID_ELEMENT   474
 
#define JANUS_VIDEOCALL_ERROR_MISSING_ELEMENT   475
 
#define JANUS_VIDEOCALL_ERROR_USERNAME_TAKEN   476
 
#define JANUS_VIDEOCALL_ERROR_ALREADY_REGISTERED   477
 
#define JANUS_VIDEOCALL_ERROR_NO_SUCH_USERNAME   478
 
#define JANUS_VIDEOCALL_ERROR_USE_ECHO_TEST   479
 
#define JANUS_VIDEOCALL_ERROR_ALREADY_IN_CALL   480
 
#define JANUS_VIDEOCALL_ERROR_NO_CALL   481
 
#define JANUS_VIDEOCALL_ERROR_MISSING_SDP   482
 

Typedefs

typedef struct janus_videocall_message janus_videocall_message
 
typedef struct janus_videocall_session janus_videocall_session
 

Functions

janus_plugincreate (void)
 
int janus_videocall_init (janus_callbacks *callback, const char *config_path)
 
void janus_videocall_destroy (void)
 
int janus_videocall_get_api_compatibility (void)
 
int janus_videocall_get_version (void)
 
const char * janus_videocall_get_version_string (void)
 
const char * janus_videocall_get_description (void)
 
const char * janus_videocall_get_name (void)
 
const char * janus_videocall_get_author (void)
 
const char * janus_videocall_get_package (void)
 
void janus_videocall_create_session (janus_plugin_session *handle, int *error)
 
struct janus_plugin_resultjanus_videocall_handle_message (janus_plugin_session *handle, char *transaction, json_t *message, json_t *jsep)
 
void janus_videocall_setup_media (janus_plugin_session *handle)
 
void janus_videocall_incoming_rtp (janus_plugin_session *handle, int video, char *buf, int len)
 
void janus_videocall_incoming_rtcp (janus_plugin_session *handle, int video, char *buf, int len)
 
void janus_videocall_incoming_data (janus_plugin_session *handle, char *buf, int len)
 
void janus_videocall_slow_link (janus_plugin_session *handle, int uplink, int video)
 
void janus_videocall_hangup_media (janus_plugin_session *handle)
 
void janus_videocall_destroy_session (janus_plugin_session *handle, int *error)
 
json_tjanus_videocall_query_session (janus_plugin_session *handle)
 

Detailed Description

Janus VideoCall plugin.

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

This is a simple video call plugin for Janus, allowing two WebRTC peers to call each other through the gateway. The idea is to provide a similar service as the well known AppRTC demo (https://apprtc.appspot.com), but with the media flowing through the gateway rather than being peer-to-peer.

The plugin provides a simple fake registration mechanism. A peer attaching to the plugin needs to specify a username, which acts as a "phone number": if the username is free, it is associated with the peer, which means he/she can be "called" using that username by another peer. Peers can either "call" another peer, by specifying their username, or wait for a call. The approach used by this plugin is similar to the one employed by the echo test one: all frames (RTP/RTCP) coming from one peer are relayed to the other.

Just as in the janus_videocall.c plugin, there are knobs to control whether audio and/or video should be muted or not, and if the bitrate of the peer needs to be capped by means of REMB messages.

Video Call API

All requests you can send in the Video Call API are asynchronous, which means all responses (successes and errors) will be delivered as events with the same transaction.

The supported requests are list , register , call , accept , set and hangup . list allows you to get a list of all the registered peers; register can be used to register a username to call and be called; call is used to start a video call with somebody through the plugin, while accept is used to accept the call in case one is invited instead of inviting; set can be used to configure some call-related settings (e.g., a cap on the send bandwidth); finally, hangup can be used to terminate the communication at any time, either to hangup an ongoing call or to cancel/decline a call that hasn't started yet.

The list request has to be formatted as follows:

{
        "request" : "list"
}

A successful request will result in an array of peers to be returned:

{
        "videocall" : "event",
        "result" : {
                "list": [       // Array of peers
                        "alice78",
                        "bob51",
                        // others
                ]
        }
}

An error instead (and the same applies to all other requests, so this won't be repeated) would provide both an error code and a more verbose description of the cause of the issue:

{
        "videocall" : "event",
        "error_code" : <numeric ID, check Macros below>,
        "error" : "<error description as a string>"
}

To register a username to call and be called, the register request can be used. This works on a "first come, first served" basis: there's no authetication involved, you just specify the username you'd like to use and, if free, it's assigned to you. The request has to be formatted as follows:

{
        "request" : "register",
        "username" : "<desired unique username>"
}

If successul, this will result in a registered event:

{
        "videocall" : "event",
        "result" : {
                "event" : "registered",
                "username" : "<same username, registered>"
        }
}

Once you're registered, you can either start a new call or wait to be called by someone else who knows your username. To start a new call, the call request can be used: this request must be attached to a JSEP offer containing the WebRTC-related info to setup a new media session. A call request has to be formatted as follows:

{
        "request" : "call",
        "username" : "<username to call>"
}

If successul, this will result in a calling event:

{
        "videocall" : "event",
        "result" : {
                "event" : "calling",
                "username" : "<same username, registered>"
        }
}

At the same time, the user being called will receive an incomingcall event

{
        "videocall" : "event",
        "result" : {
                "event" : "incomingcall",
                "username" : "<your username>"
        }
}

To accept the call, the accept request can be used. This request must be attached to a JSEP answer containing the WebRTC-related information to complete the actual PeerConnection setup. A accept request has to be formatted as follows:

{
        "request" : "accept"
}

If successul, both the caller and the callee will receive an accepted event to notify them about the success of the signalling:

{
        "videocall" : "event",
        "result" : {
                "event" : "accepted",
                "username" : "<caller username>"
        }
}

At this point, the media-related settings of the call can be modified on either side by means of a set request, which acts pretty much as the one in the Echo Test API . The set request has to be formatted as follows. All the attributes (except request) are optional, so any request can contain a subset of them:

{
        "request" : "set",
        "audio" : true|false,
        "video" : true|false,
        "bitrate" : <numeric bitrate value>,
        "record" : true|false,
        "filename" : <base path/filename to use for the recording>
}

audio instructs the plugin to do or do not relay audio frames; video does the same for video; bitrate caps the bandwidth to force on the browser encoding side (e.g., 128000 for 128kbps); record enables or disables the recording of this peer; in case recording is enabled, filename allows to specify a base path/filename to use for the files (-audio.mjr and -video.mjr are automatically appended). Beware that enabling the recording only records this user's contribution, and not the whole call: to record both sides, you need to enable recording for both the peers in the call.

A successful request will result in a set event:

{
        "videocall" : "event",
        "result" : {
                "event" : "set"
        }
}

To decline an incoming call, cancel an attempt to call or simply hangup an ongoing conversation, the hangup request can be used, which has to be formatted as follows:

{
        "request" : "hangup"
}

Whatever the reason of a call being closed (e.g., a hangup request, a PeerConnection being closed, or something else), both parties in the communication will receive a hangup event:

{
        "videocall" : "event",
        "result" : {
                "event" : "hangup",
                "username" : "<username of who closed the communication>",
                "reason" : "<description of what happened>"
        }
}

plugins

Macro Definition Documentation

◆ JANUS_VIDEOCALL_AUTHOR

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

◆ JANUS_VIDEOCALL_DESCRIPTION

#define JANUS_VIDEOCALL_DESCRIPTION   "This is a simple video call plugin for Janus, allowing two WebRTC peers to call each other through the gateway."

◆ JANUS_VIDEOCALL_ERROR_ALREADY_IN_CALL

#define JANUS_VIDEOCALL_ERROR_ALREADY_IN_CALL   480

◆ JANUS_VIDEOCALL_ERROR_ALREADY_REGISTERED

#define JANUS_VIDEOCALL_ERROR_ALREADY_REGISTERED   477

◆ JANUS_VIDEOCALL_ERROR_INVALID_ELEMENT

#define JANUS_VIDEOCALL_ERROR_INVALID_ELEMENT   474

◆ JANUS_VIDEOCALL_ERROR_INVALID_JSON

#define JANUS_VIDEOCALL_ERROR_INVALID_JSON   471

◆ JANUS_VIDEOCALL_ERROR_INVALID_REQUEST

#define JANUS_VIDEOCALL_ERROR_INVALID_REQUEST   472

◆ JANUS_VIDEOCALL_ERROR_MISSING_ELEMENT

#define JANUS_VIDEOCALL_ERROR_MISSING_ELEMENT   475

◆ JANUS_VIDEOCALL_ERROR_MISSING_SDP

#define JANUS_VIDEOCALL_ERROR_MISSING_SDP   482

◆ JANUS_VIDEOCALL_ERROR_NO_CALL

#define JANUS_VIDEOCALL_ERROR_NO_CALL   481

◆ JANUS_VIDEOCALL_ERROR_NO_MESSAGE

#define JANUS_VIDEOCALL_ERROR_NO_MESSAGE   470

◆ JANUS_VIDEOCALL_ERROR_NO_SUCH_USERNAME

#define JANUS_VIDEOCALL_ERROR_NO_SUCH_USERNAME   478

◆ JANUS_VIDEOCALL_ERROR_REGISTER_FIRST

#define JANUS_VIDEOCALL_ERROR_REGISTER_FIRST   473

◆ JANUS_VIDEOCALL_ERROR_UNKNOWN_ERROR

#define JANUS_VIDEOCALL_ERROR_UNKNOWN_ERROR   499

◆ JANUS_VIDEOCALL_ERROR_USE_ECHO_TEST

#define JANUS_VIDEOCALL_ERROR_USE_ECHO_TEST   479

◆ JANUS_VIDEOCALL_ERROR_USERNAME_TAKEN

#define JANUS_VIDEOCALL_ERROR_USERNAME_TAKEN   476

◆ JANUS_VIDEOCALL_NAME

#define JANUS_VIDEOCALL_NAME   "JANUS VideoCall plugin"

◆ JANUS_VIDEOCALL_PACKAGE

#define JANUS_VIDEOCALL_PACKAGE   "janus.plugin.videocall"

◆ JANUS_VIDEOCALL_VERSION

#define JANUS_VIDEOCALL_VERSION   6

◆ JANUS_VIDEOCALL_VERSION_STRING

#define JANUS_VIDEOCALL_VERSION_STRING   "0.0.6"

Typedef Documentation

◆ janus_videocall_message

◆ janus_videocall_session

Function Documentation

◆ create()

janus_plugin* create ( void  )

◆ janus_videocall_create_session()

void janus_videocall_create_session ( janus_plugin_session handle,
int *  error 
)

◆ janus_videocall_destroy()

void janus_videocall_destroy ( void  )

◆ janus_videocall_destroy_session()

void janus_videocall_destroy_session ( janus_plugin_session handle,
int *  error 
)

◆ janus_videocall_get_api_compatibility()

int janus_videocall_get_api_compatibility ( void  )

◆ janus_videocall_get_author()

const char * janus_videocall_get_author ( void  )

◆ janus_videocall_get_description()

const char * janus_videocall_get_description ( void  )

◆ janus_videocall_get_name()

const char * janus_videocall_get_name ( void  )

◆ janus_videocall_get_package()

const char * janus_videocall_get_package ( void  )

◆ janus_videocall_get_version()

int janus_videocall_get_version ( void  )

◆ janus_videocall_get_version_string()

const char * janus_videocall_get_version_string ( void  )

◆ janus_videocall_handle_message()

struct janus_plugin_result * janus_videocall_handle_message ( janus_plugin_session handle,
char *  transaction,
json_t message,
json_t jsep 
)

◆ janus_videocall_hangup_media()

void janus_videocall_hangup_media ( janus_plugin_session handle)

◆ janus_videocall_incoming_data()

void janus_videocall_incoming_data ( janus_plugin_session handle,
char *  buf,
int  len 
)

◆ janus_videocall_incoming_rtcp()

void janus_videocall_incoming_rtcp ( janus_plugin_session handle,
int  video,
char *  buf,
int  len 
)

◆ janus_videocall_incoming_rtp()

void janus_videocall_incoming_rtp ( janus_plugin_session handle,
int  video,
char *  buf,
int  len 
)

◆ janus_videocall_init()

int janus_videocall_init ( janus_callbacks callback,
const char *  config_path 
)

◆ janus_videocall_query_session()

json_t * janus_videocall_query_session ( janus_plugin_session handle)

◆ janus_videocall_setup_media()

void janus_videocall_setup_media ( janus_plugin_session handle)

◆ janus_videocall_slow_link()

void janus_videocall_slow_link ( janus_plugin_session handle,
int  uplink,
int  video 
)