TURN REST API client. More...
#include <stdint.h>
#include <glib.h>
#include <jansson.h>
Go to the source code of this file.
Data Structures | |
struct | janus_json_parameter |
struct | janus_vp8_simulcast_context |
VP8 simulcasting context, in order to make sure SSRC changes result in coherent picid/temporal level increases. More... | |
struct | janus_vp9_svc_info |
VP9 SVC info, as parsed from a payload descriptor. More... | |
Macros | |
#define | JANUS_JSON_STRING JSON_STRING |
#define | JANUS_JSON_INTEGER JSON_INTEGER |
#define | JANUS_JSON_OBJECT JSON_OBJECT |
#define | JANUS_JSON_BOOL JSON_TRUE |
#define | JANUS_JSON_PARAM_REQUIRED 1 |
#define | JANUS_JSON_PARAM_POSITIVE 2 |
#define | JANUS_JSON_PARAM_NONEMPTY 4 |
#define | JANUS_VALIDATE_JSON_OBJECT_FORMAT(missing_format, invalid_format, obj, params, error_code, error_cause, log_error, missing_code, invalid_code) |
Validates the JSON object against the description of its parameters. More... | |
#define | JANUS_VALIDATE_JSON_OBJECT(obj, params, error_code, error_cause, log_error, missing_code, invalid_code) JANUS_VALIDATE_JSON_OBJECT_FORMAT("Missing mandatory element (%s)", "Invalid element type (%s should be %s)", obj, params, error_code, error_cause, log_error, missing_code, invalid_code) |
Validates the JSON object against the description of its parameters. More... | |
#define | JANUS_CHECK_SECRET(secret, obj, member, error_code, error_cause, missing_code, invalid_code, unauthorized_code) |
If the secret isn't NULL, check the secret after validating the specified member of the JSON object. More... | |
Typedefs | |
typedef struct janus_vp8_simulcast_context | janus_vp8_simulcast_context |
VP8 simulcasting context, in order to make sure SSRC changes result in coherent picid/temporal level increases. More... | |
typedef struct janus_vp9_svc_info | janus_vp9_svc_info |
VP9 SVC info, as parsed from a payload descriptor. More... | |
Functions | |
gint64 | janus_get_monotonic_time (void) |
Helper to retrieve the system monotonic time, as Glib's g_get_monotonic_time may not be available (only since 2.28) More... | |
gint64 | janus_get_real_time (void) |
Helper to retrieve the system real time, as Glib's g_get_real_time may not be available (only since 2.28) More... | |
char * | janus_string_replace (char *message, const char *old_string, const char *new_string) G_GNUC_WARN_UNUSED_RESULT |
Helper to replace strings. More... | |
gboolean | janus_is_true (const char *value) |
Helper to parse yes/no|true/false configuration values. More... | |
gboolean | janus_strcmp_const_time (const void *str1, const void *str2) |
Helper to compare strings in constant time. More... | |
guint32 | janus_random_uint32 (void) |
Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.) More... | |
guint64 | janus_random_uint64 (void) |
Helper to generate random 64-bit unsigned integers (useful for Janus IDs) More... | |
char * | janus_random_uuid (void) |
Helper to generate random UUIDs (needed by some plugins) More... | |
guint64 * | janus_uint64_dup (guint64 num) |
Helper to generate an allocated copy of a guint64 number. More... | |
int | janus_string_to_uint8 (const char *str, uint8_t *num) |
Helper method to convert a string to a uint8_t. More... | |
int | janus_string_to_uint16 (const char *str, uint16_t *num) |
Helper method to convert a string to a uint16_t. More... | |
int | janus_string_to_uint32 (const char *str, uint32_t *num) |
Helper method to convert a string to a uint32_t. More... | |
int | janus_mkdir (const char *dir, mode_t mode) |
Helper to create a new directory, and recursively create parent directories if needed. More... | |
int | janus_get_codec_pt (const char *sdp, const char *codec) |
Ugly and dirty helper to quickly get the payload type associated with a codec in an SDP. More... | |
const char * | janus_get_codec_from_pt (const char *sdp, int pt) |
Ugly and dirty helper to quickly get the codec associated with a payload type in an SDP. More... | |
int | janus_pidfile_create (const char *file) |
Create and lock a PID file. More... | |
int | janus_pidfile_remove (void) |
Unlock and remove a previously created PID file. More... | |
void | janus_protected_folder_add (const char *folder) |
Add a folder to the protected list (meaning we won't create files there, like recordings or pcap dumps) More... | |
gboolean | janus_is_folder_protected (const char *path) |
Check if the path points to a protected folder. More... | |
void | janus_protected_folders_clear (void) |
Cleanup the list of protected folder. More... | |
void | janus_get_json_type_name (int jtype, unsigned int flags, char *type_name) |
Creates a string describing the JSON type and constraint. More... | |
gboolean | janus_json_is_valid (json_t *val, json_type jtype, unsigned int flags) |
Checks whether the JSON value matches the type and constraint. More... | |
gboolean | janus_vp8_is_keyframe (const char *buffer, int len) |
Helper method to check if a VP8 frame is a keyframe or not. More... | |
gboolean | janus_vp9_is_keyframe (const char *buffer, int len) |
Helper method to check if a VP9 frame is a keyframe or not. More... | |
gboolean | janus_h264_is_keyframe (const char *buffer, int len) |
Helper method to check if an H.264 frame is a keyframe or not. More... | |
void | janus_vp8_simulcast_context_reset (janus_vp8_simulcast_context *context) |
Set (or reset) the context fields to their default values. More... | |
int | janus_vp8_parse_descriptor (char *buffer, int len, uint16_t *picid, uint8_t *tl0picidx, uint8_t *tid, uint8_t *y, uint8_t *keyidx) |
Helper method to parse a VP8 payload descriptor for useful info (e.g., when simulcasting) More... | |
void | janus_vp8_simulcast_descriptor_update (char *buffer, int len, janus_vp8_simulcast_context *context, gboolean switched) |
Use the context info to update the RTP header of a packet, if needed. More... | |
int | janus_vp9_parse_svc (char *buffer, int len, gboolean *found, janus_vp9_svc_info *info) |
Helper method to parse a VP9 payload descriptor for SVC-related info (e.g., when SVC is enabled) More... | |
guint32 | janus_push_bits (guint32 word, size_t num, guint32 val) |
Helper method to push individual bits at the end of a word. More... | |
void | janus_set1 (guint8 *data, size_t i, guint8 val) |
Helper method to set one byte at a memory position. More... | |
void | janus_set2 (guint8 *data, size_t i, guint32 val) |
Helper method to set two bytes at a memory position. More... | |
void | janus_set3 (guint8 *data, size_t i, guint32 val) |
Helper method to set three bytes at a memory position. More... | |
void | janus_set4 (guint8 *data, size_t i, guint32 val) |
Helper method to set four bytes at a memory position. More... | |
size_t | janus_gzip_compress (int compression, char *text, size_t tlen, char *compressed, size_t zlen) |
Helper method to compress a string to gzip (using zlib) More... | |
Flags helper methods | |
typedef gsize | janus_flags |
Janus flags container. More... | |
void | janus_flags_reset (janus_flags *flags) |
Janus flags reset method. More... | |
void | janus_flags_set (janus_flags *flags, gsize flag) |
Janus flags set method. More... | |
void | janus_flags_clear (janus_flags *flags, gsize flag) |
Janus flags clear method. More... | |
gboolean | janus_flags_is_set (janus_flags *flags, gsize flag) |
Janus flags check method. More... | |
TURN REST API client.
Utilities and helpers (headers)
TURN REST API client (headers)
Implementation of the draft-uberti-rtcweb-turn-rest-00
draft, that is a REST API that can be used to access TURN services, more specifically credentials to use. Currently implemented in both rfc5766-turn-server and coturn, and so should be generic enough to be usable here.
libcurl
and is optional.Implementations of a few methods that may be of use here and there in the code.
#define JANUS_CHECK_SECRET | ( | secret, | |
obj, | |||
member, | |||
error_code, | |||
error_cause, | |||
missing_code, | |||
invalid_code, | |||
unauthorized_code | |||
) |
If the secret isn't NULL, check the secret after validating the specified member of the JSON object.
secret | The secret to be checked; no check if the secret is NULL | |
obj | The JSON object to be validated | |
member | The JSON member with the secret, usually "secret" or "pin" | |
[out] | error_code | int to return error code |
[out] | error_cause | Array of char or NULL to return the error descriptions; the array has to be a global or stack variable to make sizeof work; the required size is 60 |
missing_code | The code to be returned in error_code if a parameter is missing | |
invalid_code | The code to be returned in error_code if a parameter is invalid | |
unauthorized_code | The code to be returned in error_code if the secret doesn't match |
#define JANUS_JSON_BOOL JSON_TRUE |
#define JANUS_JSON_INTEGER JSON_INTEGER |
#define JANUS_JSON_OBJECT JSON_OBJECT |
#define JANUS_JSON_PARAM_NONEMPTY 4 |
#define JANUS_JSON_PARAM_POSITIVE 2 |
#define JANUS_JSON_PARAM_REQUIRED 1 |
#define JANUS_JSON_STRING JSON_STRING |
#define JANUS_VALIDATE_JSON_OBJECT | ( | obj, | |
params, | |||
error_code, | |||
error_cause, | |||
log_error, | |||
missing_code, | |||
invalid_code | |||
) | JANUS_VALIDATE_JSON_OBJECT_FORMAT("Missing mandatory element (%s)", "Invalid element type (%s should be %s)", obj, params, error_code, error_cause, log_error, missing_code, invalid_code) |
Validates the JSON object against the description of its parameters.
obj | The JSON object to be validated | |
params | Array of struct janus_json_parameter to describe the parameters; the array has to be a global or stack variable to make sizeof work | |
[out] | error_code | int to return error code |
[out] | error_cause | Array of char or NULL to return the error descriptions; the array has to be a global or stack variable to make sizeof work; the required size is the length of the longest parameter name plus 54 for the format string and type description |
log_error | If TRUE, log any error with JANUS_LOG(LOG_ERR) | |
missing_code | The code to be returned in error_code if a parameter is missing | |
invalid_code | The code to be returned in error_code if a parameter is invalid |
#define JANUS_VALIDATE_JSON_OBJECT_FORMAT | ( | missing_format, | |
invalid_format, | |||
obj, | |||
params, | |||
error_code, | |||
error_cause, | |||
log_error, | |||
missing_code, | |||
invalid_code | |||
) |
Validates the JSON object against the description of its parameters.
missing_format | printf format to indicate a missing required parameter; needs one s for the parameter name | |
invalid_format | printf format to indicate an invalid parameter; needs two s for parameter name and type description from janus_get_json_type_name | |
obj | The JSON object to be validated | |
params | Array of struct janus_json_parameter to describe the parameters; the array has to be a global or stack variable to make sizeof work | |
[out] | error_code | int to return error code |
[out] | error_cause | Array of char or NULL to return the error descriptions; the array has to be a global or stack variable to make sizeof work; the required size is the length of the format string plus the length of the longest parameter name plus 19 for the type description |
log_error | If TRUE, log any error with JANUS_LOG(LOG_ERR) | |
missing_code | The code to be returned in error_code if a parameter is missing | |
invalid_code | The code to be returned in error_code if a parameter is invalid |
typedef gsize janus_flags |
Janus flags container.
typedef struct janus_vp8_simulcast_context janus_vp8_simulcast_context |
VP8 simulcasting context, in order to make sure SSRC changes result in coherent picid/temporal level increases.
typedef struct janus_vp9_svc_info janus_vp9_svc_info |
VP9 SVC info, as parsed from a payload descriptor.
void janus_flags_clear | ( | janus_flags * | flags, |
gsize | flag | ||
) |
Janus flags clear method.
[in] | flags | The janus_flags instance to update |
[in] | flag | The flag to clear |
gboolean janus_flags_is_set | ( | janus_flags * | flags, |
gsize | flag | ||
) |
Janus flags check method.
[in] | flags | The janus_flags instance to check |
[in] | flag | The flag to check |
void janus_flags_reset | ( | janus_flags * | flags | ) |
Janus flags reset method.
[in] | flags | The janus_flags instance to reset |
void janus_flags_set | ( | janus_flags * | flags, |
gsize | flag | ||
) |
Janus flags set method.
[in] | flags | The janus_flags instance to update |
[in] | flag | The flag to set |
const char* janus_get_codec_from_pt | ( | const char * | sdp, |
int | pt | ||
) |
Ugly and dirty helper to quickly get the codec associated with a payload type in an SDP.
sdp | The SDP to parse |
pt | The payload type to look for |
int janus_get_codec_pt | ( | const char * | sdp, |
const char * | codec | ||
) |
Ugly and dirty helper to quickly get the payload type associated with a codec in an SDP.
sdp | The SDP to parse |
codec | The codec to look for |
void janus_get_json_type_name | ( | int | jtype, |
unsigned int | flags, | ||
char * | type_name | ||
) |
Creates a string describing the JSON type and constraint.
jtype | The JSON type, e.g., JSON_STRING | |
flags | Indicates constraints for the described type | |
[out] | type_name | The type description, e.g., "a positive integer"; required size is 19 characters |
gint64 janus_get_monotonic_time | ( | void | ) |
Helper to retrieve the system monotonic time, as Glib's g_get_monotonic_time may not be available (only since 2.28)
gint64 janus_get_real_time | ( | void | ) |
Helper to retrieve the system real time, as Glib's g_get_real_time may not be available (only since 2.28)
size_t janus_gzip_compress | ( | int | compression, |
char * | text, | ||
size_t | tlen, | ||
char * | compressed, | ||
size_t | zlen | ||
) |
Helper method to compress a string to gzip (using zlib)
[in] | compression | Compression factor (1=fastest, 9=best compression) |
[in] | text | Pointer to the string to compress |
[in] | tlen | Length of the string to compress |
[in] | compressed | Pointer to the buffer where to compress the string to |
[in] | zlen | Size of the output buffer |
gboolean janus_h264_is_keyframe | ( | const char * | buffer, |
int | len | ||
) |
Helper method to check if an H.264 frame is a keyframe or not.
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
gboolean janus_is_folder_protected | ( | const char * | path | ) |
Check if the path points to a protected folder.
path | Path we need to check |
gboolean janus_is_true | ( | const char * | value | ) |
Helper to parse yes/no|true/false configuration values.
value | The configuration value to parse |
gboolean janus_json_is_valid | ( | json_t * | val, |
json_type | jtype, | ||
unsigned int | flags | ||
) |
Checks whether the JSON value matches the type and constraint.
val | The JSON value to be checked |
jtype | The JSON type, e.g., JSON_STRING |
flags | Indicates constraints for the described type |
int janus_mkdir | ( | const char * | dir, |
mode_t | mode | ||
) |
Helper to create a new directory, and recursively create parent directories if needed.
dir | Path to the new folder to create |
mode | File permissions for the new directory file |
int janus_pidfile_create | ( | const char * | file | ) |
Create and lock a PID file.
file | Path to the PID file to use |
int janus_pidfile_remove | ( | void | ) |
Unlock and remove a previously created PID file.
void janus_protected_folder_add | ( | const char * | folder | ) |
Add a folder to the protected list (meaning we won't create files there, like recordings or pcap dumps)
folder | Folder to protect |
void janus_protected_folders_clear | ( | void | ) |
Cleanup the list of protected folder.
|
inline |
Helper method to push individual bits at the end of a word.
[in] | word | Initial value of word |
[in] | num | Number of bits to push |
[in] | val | Value of bits to push |
guint32 janus_random_uint32 | ( | void | ) |
Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.)
guint64 janus_random_uint64 | ( | void | ) |
Helper to generate random 64-bit unsigned integers (useful for Janus IDs)
char* janus_random_uuid | ( | void | ) |
Helper to generate random UUIDs (needed by some plugins)
g_free
|
inline |
Helper method to set one byte at a memory position.
[in] | data | memory data pointer |
[in] | i | position in memory to change |
[in] | val | value to write |
|
inline |
Helper method to set two bytes at a memory position.
[in] | data | memory data pointer |
[in] | i | position in memory to change |
[in] | val | value to write |
|
inline |
Helper method to set three bytes at a memory position.
[in] | data | memory data pointer |
[in] | i | position in memory to change |
[in] | val | value to write |
|
inline |
Helper method to set four bytes at a memory position.
[in] | data | memory data pointer |
[in] | i | position in memory to change |
[in] | val | value to write |
gboolean janus_strcmp_const_time | ( | const void * | str1, |
const void * | str2 | ||
) |
Helper to compare strings in constant time.
str1 | The first string to compare |
str2 | The second string to compare |
char* janus_string_replace | ( | char * | message, |
const char * | old_string, | ||
const char * | new_string | ||
) |
Helper to replace strings.
message | The string that contains the text to replace, which may be freed if it is too short |
old_string | The old text to replace |
new_string | The new text |
int janus_string_to_uint16 | ( | const char * | str, |
uint16_t * | num | ||
) |
Helper method to convert a string to a uint16_t.
num
should be ignored, if the method returned an error [in] | str | The string to convert |
[out] | num | Pointer to the converted number |
-ERANGE
if the value is out of range) int janus_string_to_uint32 | ( | const char * | str, |
uint32_t * | num | ||
) |
Helper method to convert a string to a uint32_t.
num
should be ignored, if the method returned an error [in] | str | The string to convert |
[out] | num | Pointer to the converted number |
-ERANGE
if the value is out of range) int janus_string_to_uint8 | ( | const char * | str, |
uint8_t * | num | ||
) |
Helper method to convert a string to a uint8_t.
num
should be ignored, if the method returned an error [in] | str | The string to convert |
[out] | num | Pointer to the converted number |
-ERANGE
if the value is out of range) guint64* janus_uint64_dup | ( | guint64 | num | ) |
Helper to generate an allocated copy of a guint64 number.
num | The guint64 number to duplicate |
gboolean janus_vp8_is_keyframe | ( | const char * | buffer, |
int | len | ||
) |
Helper method to check if a VP8 frame is a keyframe or not.
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
int janus_vp8_parse_descriptor | ( | char * | buffer, |
int | len, | ||
uint16_t * | picid, | ||
uint8_t * | tl0picidx, | ||
uint8_t * | tid, | ||
uint8_t * | y, | ||
uint8_t * | keyidx | ||
) |
Helper method to parse a VP8 payload descriptor for useful info (e.g., when simulcasting)
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
[out] | picid | The Picture ID |
[out] | tl0picidx | Temporal level zero index |
[out] | tid | Temporal-layer index |
[out] | y | Layer sync bit |
[out] | keyidx | Temporal key frame index |
void janus_vp8_simulcast_context_reset | ( | janus_vp8_simulcast_context * | context | ) |
Set (or reset) the context fields to their default values.
[in] | context | The context to (re)set |
void janus_vp8_simulcast_descriptor_update | ( | char * | buffer, |
int | len, | ||
janus_vp8_simulcast_context * | context, | ||
gboolean | switched | ||
) |
Use the context info to update the RTP header of a packet, if needed.
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
[in] | context | The context to use as a reference |
[in] | switched | Whether there has been a source switch or not (important to compute offsets) |
gboolean janus_vp9_is_keyframe | ( | const char * | buffer, |
int | len | ||
) |
Helper method to check if a VP9 frame is a keyframe or not.
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
int janus_vp9_parse_svc | ( | char * | buffer, |
int | len, | ||
gboolean * | found, | ||
janus_vp9_svc_info * | info | ||
) |
Helper method to parse a VP9 payload descriptor for SVC-related info (e.g., when SVC is enabled)
[in] | buffer | The RTP payload to process |
[in] | len | The length of the RTP payload |
[out] | found | Whether any SVC related info has been found or not |
[out] | info | Pointer to a janus_vp9_svc_info structure for passing the parsed info back |