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

Janus VoiceMail plugin. More...

#include "plugin.h"
#include <jansson.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <ogg/ogg.h>
#include "../debug.h"
#include "../apierror.h"
#include "../config.h"
#include "../mutex.h"
#include "../rtp.h"
#include "../utils.h"
Include dependency graph for janus_voicemail.c:

Data Structures

struct  janus_voicemail_message
 
struct  janus_voicemail_session
 

Macros

#define JANUS_VOICEMAIL_VERSION   6
 
#define JANUS_VOICEMAIL_VERSION_STRING   "0.0.6"
 
#define JANUS_VOICEMAIL_DESCRIPTION   "This is a plugin implementing a very simple VoiceMail service for Janus, recording Opus streams."
 
#define JANUS_VOICEMAIL_NAME   "JANUS VoiceMail plugin"
 
#define JANUS_VOICEMAIL_AUTHOR   "Meetecho s.r.l."
 
#define JANUS_VOICEMAIL_PACKAGE   "janus.plugin.voicemail"
 
#define sdp_template
 
#define JANUS_VOICEMAIL_ERROR_UNKNOWN_ERROR   499
 
#define JANUS_VOICEMAIL_ERROR_NO_MESSAGE   460
 
#define JANUS_VOICEMAIL_ERROR_INVALID_JSON   461
 
#define JANUS_VOICEMAIL_ERROR_INVALID_REQUEST   462
 
#define JANUS_VOICEMAIL_ERROR_MISSING_ELEMENT   463
 
#define JANUS_VOICEMAIL_ERROR_INVALID_ELEMENT   464
 
#define JANUS_VOICEMAIL_ERROR_ALREADY_RECORDING   465
 
#define JANUS_VOICEMAIL_ERROR_IO_ERROR   466
 
#define JANUS_VOICEMAIL_ERROR_LIBOGG_ERROR   467
 

Typedefs

typedef struct janus_voicemail_message janus_voicemail_message
 
typedef struct janus_voicemail_session janus_voicemail_session
 

Functions

janus_plugincreate (void)
 
int janus_voicemail_init (janus_callbacks *callback, const char *config_path)
 
void janus_voicemail_destroy (void)
 
int janus_voicemail_get_api_compatibility (void)
 
int janus_voicemail_get_version (void)
 
const char * janus_voicemail_get_version_string (void)
 
const char * janus_voicemail_get_description (void)
 
const char * janus_voicemail_get_name (void)
 
const char * janus_voicemail_get_author (void)
 
const char * janus_voicemail_get_package (void)
 
void janus_voicemail_create_session (janus_plugin_session *handle, int *error)
 
struct janus_plugin_resultjanus_voicemail_handle_message (janus_plugin_session *handle, char *transaction, json_t *message, json_t *jsep)
 
void janus_voicemail_setup_media (janus_plugin_session *handle)
 
void janus_voicemail_incoming_rtp (janus_plugin_session *handle, int video, char *buf, int len)
 
void janus_voicemail_incoming_rtcp (janus_plugin_session *handle, int video, char *buf, int len)
 
void janus_voicemail_hangup_media (janus_plugin_session *handle)
 
void janus_voicemail_destroy_session (janus_plugin_session *handle, int *error)
 
json_t * janus_voicemail_query_session (janus_plugin_session *handle)
 
void le32 (unsigned char *p, int v)
 
void le16 (unsigned char *p, int v)
 
ogg_packet * op_opushead (void)
 
ogg_packet * op_opustags (void)
 
ogg_packet * op_from_pkt (const unsigned char *pkt, int len)
 
void op_free (ogg_packet *op)
 
int ogg_write (janus_voicemail_session *session)
 
int ogg_flush (janus_voicemail_session *session)
 
void * janus_voicemail_watchdog (void *data)
 

Detailed Description

Janus VoiceMail plugin.

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

This is a plugin implementing a very simple VoiceMail service for Janus, specifically recording Opus streams. This means that it replies by providing in the SDP only support for Opus, and disabling video. When a peer contacts the plugin, the plugin starts recording the audio frames it receives and, after 10 seconds, it shuts the PeerConnection down and returns an URL to the recorded file.

Since an URL is returned, the plugin allows you to configure where the recordings whould be stored (e.g., a folder in your web server, writable by the plugin) and the base path to use when returning URLs (e.g., /my/recordings/ or http://www.example.com/my/recordings).

By default the plugin saves the recordings in the html folder of this project, meaning that it can work out of the box with the VoiceMail demo we provide in the same folder.

VoiceMail API

The VoiceMail API supports just two requests, record and stop and they're both asynchronous, which means all responses (successes and errors) will be delivered as events with the same transaction.

record will instruct the plugin to start recording, while stop will make the recording stop before the 10 seconds have passed. Never send a JSEP offer with any of these requests: it's always the VoiceMail plugin that originates a JSEP offer, in response to a record request, which means your application will only have to send a JSEP answer when that happens.

The record request has to be formatted as follows:

{
        "request" : "record"
}

A successful request will result in an starting status event:

{
        "voicemail" : "event",
        "status": "starting"
}

which will be followed by a started as soon as the associated PeerConnection has been made available to the plugin:

{
        "voicemail" : "event",
        "status": "started"
}

An error instead would provide both an error code and a more verbose description of the cause of the issue:

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

The stop request instead has to be formatted as follows:

{
        "request" : "stop"
}

If the plugin detects a loss of the associated PeerConnection, whether as a result of a stop request or because the 10 seconds passed, a done status notification is triggered to inform the application the recording session is over, together with the path to the recording file itself:

{
        "voicemail" : "event",
        "status" : "done",
        "recording : "<path to the .opus file>"
}

Plugins

Macro Definition Documentation

◆ JANUS_VOICEMAIL_AUTHOR

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

◆ JANUS_VOICEMAIL_DESCRIPTION

#define JANUS_VOICEMAIL_DESCRIPTION   "This is a plugin implementing a very simple VoiceMail service for Janus, recording Opus streams."

◆ JANUS_VOICEMAIL_ERROR_ALREADY_RECORDING

#define JANUS_VOICEMAIL_ERROR_ALREADY_RECORDING   465

◆ JANUS_VOICEMAIL_ERROR_INVALID_ELEMENT

#define JANUS_VOICEMAIL_ERROR_INVALID_ELEMENT   464

◆ JANUS_VOICEMAIL_ERROR_INVALID_JSON

#define JANUS_VOICEMAIL_ERROR_INVALID_JSON   461

◆ JANUS_VOICEMAIL_ERROR_INVALID_REQUEST

#define JANUS_VOICEMAIL_ERROR_INVALID_REQUEST   462

◆ JANUS_VOICEMAIL_ERROR_IO_ERROR

#define JANUS_VOICEMAIL_ERROR_IO_ERROR   466

◆ JANUS_VOICEMAIL_ERROR_LIBOGG_ERROR

#define JANUS_VOICEMAIL_ERROR_LIBOGG_ERROR   467

◆ JANUS_VOICEMAIL_ERROR_MISSING_ELEMENT

#define JANUS_VOICEMAIL_ERROR_MISSING_ELEMENT   463

◆ JANUS_VOICEMAIL_ERROR_NO_MESSAGE

#define JANUS_VOICEMAIL_ERROR_NO_MESSAGE   460

◆ JANUS_VOICEMAIL_ERROR_UNKNOWN_ERROR

#define JANUS_VOICEMAIL_ERROR_UNKNOWN_ERROR   499

◆ JANUS_VOICEMAIL_NAME

#define JANUS_VOICEMAIL_NAME   "JANUS VoiceMail plugin"

◆ JANUS_VOICEMAIL_PACKAGE

#define JANUS_VOICEMAIL_PACKAGE   "janus.plugin.voicemail"

◆ JANUS_VOICEMAIL_VERSION

#define JANUS_VOICEMAIL_VERSION   6

◆ JANUS_VOICEMAIL_VERSION_STRING

#define JANUS_VOICEMAIL_VERSION_STRING   "0.0.6"

◆ sdp_template

#define sdp_template
Value:
"v=0\r\n" \
"o=- %"SCNu64" %"SCNu64" IN IP4 127.0.0.1\r\n" /* We need current time here */ \
"s=VoiceMail %"SCNu64"\r\n" /* VoiceMail recording ID */ \
"t=0 0\r\n" \
"m=audio 1 RTP/SAVPF %d\r\n" /* Opus payload type */ \
"c=IN IP4 1.1.1.1\r\n" \
"a=rtpmap:%d opus/48000/2\r\n" /* Opus payload type */ \
"a=recvonly\r\n" /* This plugin doesn't send any frames */

Typedef Documentation

◆ janus_voicemail_message

◆ janus_voicemail_session

Function Documentation

◆ create()

janus_plugin* create ( void  )

◆ janus_voicemail_create_session()

void janus_voicemail_create_session ( janus_plugin_session handle,
int *  error 
)

◆ janus_voicemail_destroy()

void janus_voicemail_destroy ( void  )

◆ janus_voicemail_destroy_session()

void janus_voicemail_destroy_session ( janus_plugin_session handle,
int *  error 
)

◆ janus_voicemail_get_api_compatibility()

int janus_voicemail_get_api_compatibility ( void  )

◆ janus_voicemail_get_author()

const char * janus_voicemail_get_author ( void  )

◆ janus_voicemail_get_description()

const char * janus_voicemail_get_description ( void  )

◆ janus_voicemail_get_name()

const char * janus_voicemail_get_name ( void  )

◆ janus_voicemail_get_package()

const char * janus_voicemail_get_package ( void  )

◆ janus_voicemail_get_version()

int janus_voicemail_get_version ( void  )

◆ janus_voicemail_get_version_string()

const char * janus_voicemail_get_version_string ( void  )

◆ janus_voicemail_handle_message()

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

◆ janus_voicemail_hangup_media()

void janus_voicemail_hangup_media ( janus_plugin_session handle)

◆ janus_voicemail_incoming_rtcp()

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

◆ janus_voicemail_incoming_rtp()

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

◆ janus_voicemail_init()

int janus_voicemail_init ( janus_callbacks callback,
const char *  config_path 
)

◆ janus_voicemail_query_session()

json_t * janus_voicemail_query_session ( janus_plugin_session handle)

◆ janus_voicemail_setup_media()

void janus_voicemail_setup_media ( janus_plugin_session handle)

◆ janus_voicemail_watchdog()

void * janus_voicemail_watchdog ( void *  data)

◆ le16()

void le16 ( unsigned char *  p,
int  v 
)

◆ le32()

void le32 ( unsigned char *  p,
int  v 
)

◆ ogg_flush()

int ogg_flush ( janus_voicemail_session session)

◆ ogg_write()

int ogg_write ( janus_voicemail_session session)

◆ op_free()

void op_free ( ogg_packet *  op)

◆ op_from_pkt()

ogg_packet * op_from_pkt ( const unsigned char *  pkt,
int  len 
)

◆ op_opushead()

ogg_packet * op_opushead ( void  )

◆ op_opustags()

ogg_packet * op_opustags ( void  )