Loading...
Searching...
No Matches
utils.h File Reference
Core

TURN REST API client. More...

`#include <stdint.h>`
`#include <glib.h>`
`#include <jansson.h>`
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

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...
struct | janus_red_block
| Helper struct to address a specific RED block. More...

## Macros

#define | JANUS_JSON_STRING JSON_STRING
#define | JANUS_JSON_INTEGER JSON_INTEGER
#define | JANUS_JSON_OBJECT JSON_OBJECT
#define | JANUS_JSON_ARRAY JSON_ARRAY
#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 | htonll(x)
#define | ntohll(x)
#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.
#define | JANUS_VALIDATE_JSON_OBJECT(obj, params, error_code, error_cause, log_error, missing_code, invalid_code)
| Validates the JSON object against the description of its parameters.
#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.

## 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.
typedef struct janus_vp9_svc_info | janus_vp9_svc_info
| VP9 SVC info, as parsed from a payload descriptor.
typedef struct janus_red_block | janus_red_block
| Helper struct to address a specific RED block.

## Functions

void | janus_mark_started (void)
gint64 | janus_get_monotonic_time_internal (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_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).
char * | janus_string_replace (char *message, const char *old_string, const char *new_string) G_GNUC_WARN_UNUSED_RESULT
| Helper to replace strings.
size_t | janus_strlcat (char *dest, const char *src, size_t dest_size)
| Helper method to concatenate strings and log an error if truncation occurred.
int | janus_strlcat_fast (char *dest, const char *src, size_t dest_size, size_t *offset)
| Alternative helper method to concatenate strings and log an error if truncation occurred, which uses memccpy instead of g_strlcat and so is supposed to be faster.
gboolean | janus_is_true (const char *value)
| Helper to parse yes/no|true/false configuration values.
gboolean | janus_strcmp_const_time (const void *str1, const void *str2)
| Helper to compare strings in constant time.
guint32 | janus_random_uint32 (void)
| Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.).
guint64 | janus_random_uint64_full (void)
| Helper to generate random 64-bit unsigned integers.
guint64 | janus_random_uint64 (void)
| Helper to generate random 52 bit unsigned integers.
char * | janus_random_uuid (void)
| Helper to generate random UUIDs (needed by some plugins) Warning: this will fall back to a non-cryptographically safe PRNG in case the crypto library RAND_bytes() call fails.
guint64 * | janus_uint64_dup (guint64 num)
| Helper to generate an allocated copy of a guint64 number.
guint64 | janus_uint64_hash (guint64 num)
| Helper to hash a guint64 number to another guint64 number.
int | janus_string_to_uint8 (const char *str, uint8_t *num)
| Helper method to convert a string to a uint8_t.
int | janus_string_to_uint16 (const char *str, uint16_t *num)
| Helper method to convert a string to a uint16_t.
int | janus_string_to_uint32 (const char *str, uint32_t *num)
| Helper method to convert a string to a uint32_t.
int | janus_mkdir (const char *dir, mode_t mode)
| Helper to create a new directory, and recursively create parent directories if needed.
gchar * | janus_make_absolute_path (const gchar *base_dir, const gchar *path)
| Helper to convert `path` relative to `base_dir` to absolute path. If `path` already represents absolute path then just g_strdup it.
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.
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.
int | janus_pidfile_create (const char *file)
| Create and lock a PID file.
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).
gboolean | janus_is_folder_protected (const char *path)
| Check if the path points to a protected folder.
void | janus_protected_folders_clear (void)
| Cleanup the list of protected folder.
void | janus_get_json_type_name (int jtype, unsigned int flags, char *type_name)
| Creates a string describing the JSON type and constraint.
gboolean | janus_json_is_valid (json_t *val, json_type jtype, unsigned int flags)
| Checks whether the JSON value matches the type and constraint.
gboolean | janus_vp8_is_keyframe (const char *buffer, int len)
| Helper method to check if a VP8 frame is a keyframe or not.
gboolean | janus_vp9_is_keyframe (const char *buffer, int len)
| Helper method to check if a VP9 frame is a keyframe or not.
gboolean | janus_h264_is_keyframe (const char *buffer, int len)
| Helper method to check if an H.264 frame is a keyframe or not.
gboolean | janus_h264_is_i_frame (const char *buffer, int len)
| Helper method to check if an H.264 frame contains an I-Frame or not.
gboolean | janus_h264_is_b_frame (const char *buffer, int len)
| Helper method to check if an H.264 frame contains a B-Frame or not.
gboolean | janus_av1_is_keyframe (const char *buffer, int len)
| Helper method to check if an AV1 frame is a keyframe or not.
gboolean | janus_h265_is_keyframe (const char *buffer, int len)
| Helper method to check if an H.265 frame is a keyframe or not.
gboolean | janus_is_keyframe (int codec, const char *buffer, int len)
| Helper method to check if keyframe or not, using one of the codec specific helper methods according to the provided codec type.
void | janus_vp8_simulcast_context_reset (janus_vp8_simulcast_context *context)
| Set (or reset) the context fields to their default values.
int | janus_vp8_parse_descriptor (char *buffer, int len, gboolean *m, 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).
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.
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).
GList * | janus_red_parse_blocks (char *buffer, int len)
| Helper method to parse an RTP payload to return a list of RED blocks.
int | janus_red_pack_blocks (char *buffer, int len, GList *blocks)
| Helper method to pack multiple buffers in a RED payload.
int | janus_red_replace_block_pt (char *buffer, int len, int pt)
| Helper method to overwrite all RTP payload types in RED blocks.
guint32 | janus_push_bits (guint32 word, size_t num, guint32 val)
| Helper method to push individual bits at the end of a word.
void | janus_set1 (guint8 *data, size_t i, guint8 val)
| Helper method to set one byte at a memory position.
void | janus_set2 (guint8 *data, size_t i, guint32 val)
| Helper method to set two bytes at a memory position.
void | janus_set3 (guint8 *data, size_t i, guint32 val)
| Helper method to set three bytes at a memory position.
void | janus_set4 (guint8 *data, size_t i, guint32 val)
| Helper method to set four bytes at a memory position.
uint8_t | janus_bitstream_getbit (uint8_t *base, uint32_t offset)
| Helpers to read a bit from a bitstream.
uint32_t | janus_bitstream_getbits (uint8_t *base, uint8_t num, uint32_t *offset)
| Helpers to read agroup of bits from a bitstream.
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).

## Flags helper methods

typedef gsize | janus_flags
| Janus flags container.
void | janus_flags_reset (janus_flags *flags)
| Janus flags reset method.
void | janus_flags_set (janus_flags *flags, gsize flag)
| Janus flags set method.
void | janus_flags_clear (janus_flags *flags, gsize flag)
| Janus flags clear method.
gboolean | janus_flags_is_set (janus_flags *flags, gsize flag)
| Janus flags check method.

## Detailed Description

TURN REST API client.

Utilities and helpers (headers).

TURN REST API client (headers).

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

Note
  This implementation depends on `libcurl` and is optional.

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

Implementations of a few methods that may be of use here and there in the code.

Core

## Macro Definition Documentation

## htonll

#define htonll | ( |  | x | ) |

Value:
((1==htonl(1)) ? (x) : ((guint64)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))

## JANUS_CHECK_SECRET

#define JANUS_CHECK_SECRET | ( |  | secret,
|  |  | obj,
|  |  | member,
|  |  | error_code,
|  |  | error_cause,
|  |  | missing_code,
|  |  | invalid_code,
|  |  | unauthorized_code )

Value:
do { \
if (secret) { \
static struct janus_json_parameter secret_parameters[] = { \
{member, JSON_STRING, JANUS_JSON_PARAM_REQUIRED} \
}; \
JANUS_VALIDATE_JSON_OBJECT(obj, secret_parameters, error_code, error_cause, TRUE, missing_code, invalid_code); \
if(error_code == 0 && !janus_strcmp_const_time((secret), json_string_value(json_object_get(obj, member)))) { \
error_code = (unauthorized_code); \
JANUS_LOG(LOG_ERR, "Unauthorized (wrong %s)\n", member); \
if(error_cause != NULL) \
g_snprintf(error_cause, sizeof(error_cause), "Unauthorized (wrong %s)", member); \
} \
} \
} while(0)
LOG_ERR
#define LOG_ERR
Non-fatal error.
Definition debug.h:43
janus_json_parameter
Definition utils.h:29
janus_strcmp_const_time
gboolean janus_strcmp_const_time(const void *str1, const void *str2)
Helper to compare strings in constant time.
Definition utils.c:61
JANUS_JSON_PARAM_REQUIRED
#define JANUS_JSON_PARAM_REQUIRED
Definition utils.h:25

If the secret isn't NULL, check the secret after validating the specified member of the JSON object.

Parameters

  | 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

## JANUS_JSON_ARRAY

#define JANUS_JSON_ARRAY JSON_ARRAY

## JANUS_JSON_BOOL

#define JANUS_JSON_BOOL JSON_TRUE

## JANUS_JSON_INTEGER

#define JANUS_JSON_INTEGER JSON_INTEGER

## JANUS_JSON_OBJECT

#define JANUS_JSON_OBJECT JSON_OBJECT

## JANUS_JSON_PARAM_NONEMPTY

#define JANUS_JSON_PARAM_NONEMPTY 4

## JANUS_JSON_PARAM_POSITIVE

#define JANUS_JSON_PARAM_POSITIVE 2

## JANUS_JSON_PARAM_REQUIRED

#define JANUS_JSON_PARAM_REQUIRED 1

## JANUS_JSON_STRING

#define JANUS_JSON_STRING JSON_STRING

## JANUS_VALIDATE_JSON_OBJECT

#define JANUS_VALIDATE_JSON_OBJECT | ( |  | obj,
|  |  | params,
|  |  | error_code,
|  |  | error_cause,
|  |  | log_error,
|  |  | missing_code,
|  |  | invalid_code )

Value:
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)
JANUS_VALIDATE_JSON_OBJECT_FORMAT
#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.
Definition utils.h:266

Validates the JSON object against the description of its parameters.

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

## JANUS_VALIDATE_JSON_OBJECT_FORMAT

#define JANUS_VALIDATE_JSON_OBJECT_FORMAT | ( |  | missing_format,
|  |  | invalid_format,
|  |  | obj,
|  |  | params,
|  |  | error_code,
|  |  | error_cause,
|  |  | log_error,
|  |  | missing_code,
|  |  | invalid_code )

Value:
do { \
error_code = 0; \
unsigned int i; \
for(i = 0; i < sizeof(params) / sizeof(struct janus_json_parameter); i++) { \
json_t *val = json_object_get(obj, params[i].name); \
if(!val) { \
if((params[i].flags & JANUS_JSON_PARAM_REQUIRED) != 0) { \
error_code = (missing_code); \
if(log_error) \
JANUS_LOG(LOG_ERR, missing_format "\n", params[i].name); \
if(error_cause != NULL) \
g_snprintf(error_cause, sizeof(error_cause), missing_format, params[i].name); \
break; \
} \
continue; \
} \
if(!janus_json_is_valid(val, params[i].jtype, params[i].flags)) { \
error_code = (invalid_code); \
char type_name[20]; \
janus_get_json_type_name(params[i].jtype, params[i].flags, type_name); \
if(log_error) \
JANUS_LOG(LOG_ERR, invalid_format "\n", params[i].name, type_name); \
if(error_cause != NULL) \
g_snprintf(error_cause, sizeof(error_cause), invalid_format, params[i].name, type_name); \
break; \
} \
} \
} while(0)
json_t
struct json_t json_t
Definition plugin.h:236
janus_json_is_valid
gboolean janus_json_is_valid(json_t *val, json_type jtype, unsigned int flags)
Checks whether the JSON value matches the type and constraint.
Definition utils.c:667

Validates the JSON object against the description of its parameters.

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

## ntohll

#define ntohll | ( |  | x | ) |

Value:
((1==ntohl(1)) ? (x) : ((guint64)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))

## Typedef Documentation

## janus_flags

typedef gsize janus_flags

Janus flags container.

## janus_red_block

typedef struct janus_red_block janus_red_block

Helper struct to address a specific RED block.

## janus_vp8_simulcast_context

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.

## janus_vp9_svc_info

typedef struct janus_vp9_svc_info janus_vp9_svc_info

VP9 SVC info, as parsed from a payload descriptor.

## Function Documentation

## janus_av1_is_keyframe()

gboolean janus_av1_is_keyframe | ( | const char * | buffer,
|  | int | len )

Helper method to check if an AV1 frame is a keyframe or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_bitstream_getbit()

uint8_t janus_bitstream_getbit | ( | uint8_t * | base,
|  | uint32_t | offset )

Helpers to read a bit from a bitstream.

Parameters

  [in] | base | Pointer to the start of the bitstream
  [in] | offset | Offset in bits from the start

Returns
  The value of the bit

## janus_bitstream_getbits()

uint32_t janus_bitstream_getbits | ( | uint8_t * | base,
|  | uint8_t | num,
|  | uint32_t * | offset )

Helpers to read agroup of bits from a bitstream.

Parameters

  [in] | base | Pointer to the start of the bitstream
  [in] | num | The number of bits to read
  [in] | offset | Offset in bits from the start

Returns
  The value of the bits

## janus_flags_clear()

void janus_flags_clear | ( | janus_flags * | flags,
|  | gsize | flag )

Janus flags clear method.

Parameters

  [in] | flags | The janus_flags instance to update
  [in] | flag | The flag to clear

## janus_flags_is_set()

gboolean janus_flags_is_set | ( | janus_flags * | flags,
|  | gsize | flag )

Janus flags check method.

Parameters

  [in] | flags | The janus_flags instance to check
  [in] | flag | The flag to check

Returns
  true if the flag is set, false otherwise

## janus_flags_reset()

void janus_flags_reset | ( | janus_flags * | flags | ) |

Janus flags reset method.

Parameters

  [in] | flags | The janus_flags instance to reset

## janus_flags_set()

void janus_flags_set | ( | janus_flags * | flags,
|  | gsize | flag )

Janus flags set method.

Parameters

  [in] | flags | The janus_flags instance to update
  [in] | flag | The flag to set

## janus_get_codec_from_pt()

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.

Parameters

  sdp | The SDP to parse
  pt | The payload type to look for

Returns
  The codec name, if found, NULL otherwise

## janus_get_codec_pt()

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.

Parameters

  sdp | The SDP to parse
  codec | The codec to look for

Returns
  The payload type, if found, -1 otherwise

## janus_get_json_type_name()

void janus_get_json_type_name | ( | int | jtype,
|  | unsigned int | flags,
|  | char * | type_name )

Creates a string describing the JSON type and constraint.

Parameters

  | 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

## janus_get_monotonic_time()

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

Note
  The monotonic time will be normalized from the Janus start time

Returns
  The system monotonic time

## janus_get_monotonic_time_internal()

gint64 janus_get_monotonic_time_internal | ( | void |  | ) |

Helper to retrieve the system monotonic time, as Glib's g_get_monotonic_time may not be available (only since 2.28).

Returns
  The system monotonic time

## janus_get_real_time()

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

Returns
  The system real time

## janus_gzip_compress()

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

Note
  It's up to you to provide a buffer large enough for the compressed data: in case the buffer isn't large enough, the request will fail

Parameters

  [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

Returns
  The size of the compressed data, if successful, or 0 otherwise

## janus_h264_is_b_frame()

gboolean janus_h264_is_b_frame | ( | const char * | buffer,
|  | int | len )

Helper method to check if an H.264 frame contains a B-Frame or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a B-Frame, FALSE otherwise

## janus_h264_is_i_frame()

gboolean janus_h264_is_i_frame | ( | const char * | buffer,
|  | int | len )

Helper method to check if an H.264 frame contains an I-Frame or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's an I-Frame, FALSE otherwise

## janus_h264_is_keyframe()

gboolean janus_h264_is_keyframe | ( | const char * | buffer,
|  | int | len )

Helper method to check if an H.264 frame is a keyframe or not.

Note
  This checks the presence of an SPS NAL (7), nor an I-Frame (5), since SPS/PPS are what's needed for a browser to actually be able to decode a stream. If for some reason you want to check for I-Frames instead, use the janus_h264_is_i_frame() function

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_h265_is_keyframe()

gboolean janus_h265_is_keyframe | ( | const char * | buffer,
|  | int | len )

Helper method to check if an H.265 frame is a keyframe or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_is_folder_protected()

gboolean janus_is_folder_protected | ( | const char * | path | ) |

Check if the path points to a protected folder.

Parameters

  path | Path we need to check

Returns
  TRUE if the folder is protected, and FALSE otherwise

## janus_is_keyframe()

gboolean janus_is_keyframe | ( | int | codec,
|  | const char * | buffer,
|  | int | len )

Helper method to check if keyframe or not, using one of the codec specific helper methods according to the provided codec type.

Parameters

  [in] | codec | The janus_videocodec used for this RTP payload
  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_is_true()

gboolean janus_is_true | ( | const char * | value | ) |

Helper to parse yes/no|true/false configuration values.

Parameters

  value | The configuration value to parse

Returns
  true if the value contains a "yes", "YES", "true", TRUE", "1", false otherwise

## janus_json_is_valid()

gboolean janus_json_is_valid | ( | json_t * | val,
|  | json_type | jtype,
|  | unsigned int | flags )

Checks whether the JSON value matches the type and constraint.

Parameters

  val | The JSON value to be checked
  jtype | The JSON type, e.g., JSON_STRING
  flags | Indicates constraints for the described type

Returns
  TRUE if the value is valid

## janus_make_absolute_path()

gchar * janus_make_absolute_path | ( | const gchar * | base_dir,
|  | const gchar * | path )

Helper to convert `path` relative to `base_dir` to absolute path. If `path` already represents absolute path then just g_strdup it.

Parameters

  [in] | base_dir | Path which will be prepended to `path` if it's relative
  [in] | path | Some relative or absolute path

Returns
  g_strdup'ed absolute path. Should be freed with g_free() when no longer needed

## janus_mark_started()

void janus_mark_started | ( | void |  | ) |

Helper method used by the core to mark when Janus started

## janus_mkdir()

int janus_mkdir | ( | const char * | dir,
|  | mode_t | mode )

Helper to create a new directory, and recursively create parent directories if needed.

Parameters

  dir | Path to the new folder to create
  mode | File permissions for the new directory file

Returns
  An integer like the regular mkdir does

Note
  A failure may indicate that creating any of the subdirectories failed: some may still have been created

## janus_pidfile_create()

int janus_pidfile_create | ( | const char * | file | ) |

Create and lock a PID file.

Parameters

  file | Path to the PID file to use

Returns
  0 if successful, a negative integer otherwise

## janus_pidfile_remove()

int janus_pidfile_remove | ( | void |  | ) |

Unlock and remove a previously created PID file.

Returns
  0 if successful, a negative integer otherwise

## janus_protected_folder_add()

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

Parameters

  folder | Folder to protect

## janus_protected_folders_clear()

void janus_protected_folders_clear | ( | void |  | ) |

Cleanup the list of protected folder.

## janus_push_bits()

guint32 janus_push_bits | ( | guint32 | word,
|  | size_t | num,
|  | guint32 | val )

inline

Helper method to push individual bits at the end of a word.

Parameters

  [in] | word | Initial value of word
  [in] | num | Number of bits to push
  [in] | val | Value of bits to push

Returns
  0 New word value

## janus_random_uint32()

guint32 janus_random_uint32 | ( | void |  | ) |

Helper to generate random 32-bit unsigned integers (useful for SSRCs, etc.).

Note
  Warning: this will fall back to a non-cryptographically safe PRNG in case the crypto library RAND_bytes() call fails.

Returns
  A (mostly crypto-safe) random 32-bit unsigned integer

## janus_random_uint64()

guint64 janus_random_uint64 | ( | void |  | ) |

Helper to generate random 52 bit unsigned integers.

Note
  The reason for 52 instead of 64 bits: Javascript does not have real integers, its builtin "number" type is a float64. Thus, only integer values up to `Number.MAX_SAFE_INTEGER == 2^53 - 1 == 9007199254740991` can be safely represented in Javascript. This method returns such numbers. Use this method instead of janus_random_uint64_full() whenever you generate numbers which might end up in Javascript (via JSON API). This method is called janus_random_uint64() instead of janus_random_uint52() (or similar) for backwards compatibility. Warning: this will fall back to a non-cryptographically safe PRNG in case the crypto library RAND_bytes() call fails.

Returns
  A (mostly crypto-safe) random 64-bit unsigned integer

## janus_random_uint64_full()

guint64 janus_random_uint64_full | ( | void |  | ) |

Helper to generate random 64-bit unsigned integers.

Note
  Unlike janus_random_uint64(), which actually only generates 52 bits, this generates the full 64 bits. See the janus_random_uint64() docstring for details. Warning: this will fall back to a non-cryptographically safe PRNG in case the crypto library RAND_bytes() call fails.

Returns
  A (mostly crypto-safe) random 52-bit unsigned integer

## janus_random_uuid()

char * janus_random_uuid | ( | void |  | ) |

Helper to generate random UUIDs (needed by some plugins) Warning: this will fall back to a non-cryptographically safe PRNG in case the crypto library RAND_bytes() call fails.

Returns
  A (mostly crypto-safe) random UUID string, which must be deallocated with `g_free`

## janus_red_pack_blocks()

int janus_red_pack_blocks | ( | char * | buffer,
|  | int | len,
|  | GList * | blocks )

Helper method to pack multiple buffers in a RED payload.

Parameters

  [in] | buffer | The RTP payload to write to
  [in] | len | The size of the RTP payload buffer
  [in] | blocks | Linked list of janus_red_block instances to add to the payload

Returns
  The size of the RED payload in case of success, a negative integer otherwise

## janus_red_parse_blocks()

GList * janus_red_parse_blocks | ( | char * | buffer,
|  | int | len )

Helper method to parse an RTP payload to return a list of RED blocks.

Note
  The returned list is owned by the caller, and must be freed

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  An allocated GList of janus_red_block, if successful, NULL otherwise

## janus_red_replace_block_pt()

int janus_red_replace_block_pt | ( | char * | buffer,
|  | int | len,
|  | int | pt )

Helper method to overwrite all RTP payload types in RED blocks.

Parameters

  [in] | buffer | The RED block payload to update
  [in] | len | The size of the payload buffer
  [in] | pt | The RTP payload type to set in all blocks

Returns
  0 in case of success, a negative integer otherwise

## janus_set1()

void janus_set1 | ( | guint8 * | data,
|  | size_t | i,
|  | guint8 | val )

inline

Helper method to set one byte at a memory position.

Parameters

  [in] | data | memory data pointer
  [in] | i | position in memory to change
  [in] | val | value to write

## janus_set2()

void janus_set2 | ( | guint8 * | data,
|  | size_t | i,
|  | guint32 | val )

inline

Helper method to set two bytes at a memory position.

Parameters

  [in] | data | memory data pointer
  [in] | i | position in memory to change
  [in] | val | value to write

## janus_set3()

void janus_set3 | ( | guint8 * | data,
|  | size_t | i,
|  | guint32 | val )

inline

Helper method to set three bytes at a memory position.

Parameters

  [in] | data | memory data pointer
  [in] | i | position in memory to change
  [in] | val | value to write

## janus_set4()

void janus_set4 | ( | guint8 * | data,
|  | size_t | i,
|  | guint32 | val )

inline

Helper method to set four bytes at a memory position.

Parameters

  [in] | data | memory data pointer
  [in] | i | position in memory to change
  [in] | val | value to write

## janus_strcmp_const_time()

gboolean janus_strcmp_const_time | ( | const void * | str1,
|  | const void * | str2 )

Helper to compare strings in constant time.

Parameters

  str1 | The first string to compare
  str2 | The second string to compare

Returns
  true if the strings are the same, false otherwise

## janus_string_replace()

char * janus_string_replace | ( | char * | message,
|  | const char * | old_string,
|  | const char * | new_string )

Helper to replace strings.

Parameters

  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

Returns
  A pointer to the updated text string (re-allocated or just updated)

## janus_string_to_uint16()

int janus_string_to_uint16 | ( | const char * | str,
|  | uint16_t * | num )

Helper method to convert a string to a uint16_t.

Note
  The value of `num` should be ignored, if the method returned an error

Parameters

  [in] | str | The string to convert
  [out] | num | Pointer to the converted number

Returns
  0 if successful, or a negative integer otherwise (e.g., `-ERANGE` if the value is out of range)

## janus_string_to_uint32()

int janus_string_to_uint32 | ( | const char * | str,
|  | uint32_t * | num )

Helper method to convert a string to a uint32_t.

Note
  The value of `num` should be ignored, if the method returned an error

Parameters

  [in] | str | The string to convert
  [out] | num | Pointer to the converted number

Returns
  0 if successful, or a negative integer otherwise (e.g., `-ERANGE` if the value is out of range)

## janus_string_to_uint8()

int janus_string_to_uint8 | ( | const char * | str,
|  | uint8_t * | num )

Helper method to convert a string to a uint8_t.

Note
  The value of `num` should be ignored, if the method returned an error

Parameters

  [in] | str | The string to convert
  [out] | num | Pointer to the converted number

Returns
  0 if successful, or a negative integer otherwise (e.g., `-ERANGE` if the value is out of range)

## janus_strlcat()

size_t janus_strlcat | ( | char * | dest,
|  | const char * | src,
|  | size_t | dest_size )

Helper method to concatenate strings and log an error if truncation occurred.

Parameters

  [in] | dest | Destination buffer, already containing one nul-terminated string
  [in] | src | Source buffer
  [in] | dest_size | Length of dest buffer in bytes (not length of existing string inside dest)

Returns
  Size of attempted result, if retval >= dest_size, truncation occurred (and an error will be logged).

## janus_strlcat_fast()

int janus_strlcat_fast | ( | char * | dest,
|  | const char * | src,
|  | size_t | dest_size,
|  | size_t * | offset )

Alternative helper method to concatenate strings and log an error if truncation occurred, which uses memccpy instead of g_strlcat and so is supposed to be faster.

Note
  The offset attribute is input/output, and updated any time the method is called

Parameters

  [in] | dest | Destination buffer, already containing one nul-terminated string
  [in] | src | Source buffer
  [in] | dest_size | Length of dest buffer in bytes (not length of existing string inside dest)
  [in] | offset | Offset of where to start appending, in the destination buffer

Returns
  0 in case of success, a negative integer otherwise

## janus_uint64_dup()

guint64 * janus_uint64_dup | ( | guint64 | num | ) |

Helper to generate an allocated copy of a guint64 number.

Note
  While apparently silly, this is needed in order to make sure guint64 values used as keys in GHashTable operations are not lost: using temporary guint64 numbers in a g_hash_table_insert, for instance, will cause the key to contain garbage as soon as the temporary variable is lost, and all opererations on the key to fail

Parameters

  num | The guint64 number to duplicate

Returns
  A pointer to a guint64 number, if successful, NULL otherwise

## janus_uint64_hash()

guint64 janus_uint64_hash | ( | guint64 | num | ) |

Helper to hash a guint64 number to another guint64 number.

Note
  We currently only use for event handlers

Parameters

  num | The guint64 number to hash

Returns
  The hashed number

## janus_vp8_is_keyframe()

gboolean janus_vp8_is_keyframe | ( | const char * | buffer,
|  | int | len )

Helper method to check if a VP8 frame is a keyframe or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_vp8_parse_descriptor()

int janus_vp8_parse_descriptor | ( | char * | buffer,
|  | int | len,
|  | gboolean * | m,
|  | 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).

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload
  [out] | m | Whether the Picture ID is 15 bit or 7 bit
  [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

Returns
  0 in case of success, a negative integer otherwise

## janus_vp8_simulcast_context_reset()

void janus_vp8_simulcast_context_reset | ( | janus_vp8_simulcast_context * | context | ) |

Set (or reset) the context fields to their default values.

Parameters

  [in] | context | The context to (re)set

## janus_vp8_simulcast_descriptor_update()

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.

Parameters

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

## janus_vp9_is_keyframe()

gboolean janus_vp9_is_keyframe | ( | const char * | buffer,
|  | int | len )

Helper method to check if a VP9 frame is a keyframe or not.

Parameters

  [in] | buffer | The RTP payload to process
  [in] | len | The length of the RTP payload

Returns
  TRUE if it's a keyframe, FALSE otherwise

## janus_vp9_parse_svc()

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

Parameters

  [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

Returns
  0 in case of success, a negative integer otherwise