libgpac
Documentation of the core library of GPAC
tools.h File Reference

Core definitions and tools of GPAC. More...

#include <gpac/setup.h>
#include <gpac/version.h>
#include <time.h>
+ Include dependency graph for tools.h:
+ This graph shows which files directly or indirectly include this file:

Data Structures

struct  GF_Blob
 
struct  GF_SystemRTInfo
 run-time system info object More...
 
struct  GF_FileEnumInfo
 FileEnum info object. More...
 

Macros

#define gf_stringizer(x)
 Stringizer. More...
 
#define GF_4CC(a, b, c, d)   ((((u32)a)<<24)|(((u32)b)<<16)|(((u32)c)<<8)|((u32)d))
 4CC Formatting More...
 
#define GF_4CC_MSIZE   10
 
#define GF_SAFEALLOC(__ptr, __struct)
 Memory allocation for a structure. More...
 
#define GF_SAFE_ALLOC_N(__ptr, __n, __struct)
 Memory allocation for an array of n structs. More...
 
#define GF_LOG(_log_level, _log_tools, __args)
 Message logging. More...
 
#define GF_SHA1_DIGEST_SIZE   20
 
#define GF_ARRAY_LENGTH(a)   (sizeof(a) / sizeof((a)[0]))
 

Typedefs

typedef void(* gf_rmt_user_callback) (void *udta, const char *text)
 
typedef void(* gf_log_cbk) (void *cbck, GF_LOG_Level log_level, GF_LOG_Tool log_tool, const char *fmt, va_list vlist)
 Log Message Callback. More...
 
typedef void(* gf_on_progress_cbk) (const void *cbck, const char *title, u64 done, u64 total)
 Progress Callback. More...
 
typedef Bool(* gf_enum_dir_item) (void *cbck, char *item_name, char *item_path, GF_FileEnumInfo *file_info)
 Directory Enumeration Callback. More...
 
typedef struct __gf_file_io GF_FileIO
 
typedef GF_FileIO *(* gfio_open_proc) (GF_FileIO *fileio_ref, const char *url, const char *mode, GF_Err *out_error)
 
typedef GF_Err(* gfio_seek_proc) (GF_FileIO *fileio, u64 offset, s32 whence)
 
typedef u32(* gfio_read_proc) (GF_FileIO *fileio, u8 *buffer, u32 bytes)
 
typedef u32(* gfio_write_proc) (GF_FileIO *fileio, u8 *buffer, u32 bytes)
 
typedef s64(* gfio_tell_proc) (GF_FileIO *fileio)
 
typedef Bool(* gfio_eof_proc) (GF_FileIO *fileio)
 
typedef int(* gfio_printf_proc) (GF_FileIO *fileio, const char *format, va_list args)
 
typedef struct __sha1_context GF_SHA1Context
 

Enumerations

enum  GF_Err {
  GF_SCRIPT_INFO = 3, GF_PENDING_PACKET = 2, GF_EOS = 1, GF_OK = 0,
  GF_BAD_PARAM = -1, GF_OUT_OF_MEM = -2, GF_IO_ERR = -3, GF_NOT_SUPPORTED = -4,
  GF_CORRUPTED_DATA = -5, GF_SG_UNKNOWN_NODE = -6, GF_SG_INVALID_PROTO = -7, GF_SCRIPT_ERROR = -8,
  GF_BUFFER_TOO_SMALL = -9, GF_NON_COMPLIANT_BITSTREAM = -10, GF_FILTER_NOT_FOUND = -11, GF_URL_ERROR = -12,
  GF_SERVICE_ERROR = -13, GF_REMOTE_SERVICE_ERROR = -14, GF_STREAM_NOT_FOUND = -15, GF_URL_REMOVED = -16,
  GF_ISOM_INVALID_FILE = -20, GF_ISOM_INCOMPLETE_FILE = -21, GF_ISOM_INVALID_MEDIA = -22, GF_ISOM_INVALID_MODE = -23,
  GF_ISOM_UNKNOWN_DATA_REF = -24, GF_ODF_INVALID_DESCRIPTOR = -30, GF_ODF_FORBIDDEN_DESCRIPTOR = -31, GF_ODF_INVALID_COMMAND = -32,
  GF_BIFS_UNKNOWN_VERSION = -33, GF_IP_ADDRESS_NOT_FOUND = -40, GF_IP_CONNECTION_FAILURE = -41, GF_IP_NETWORK_FAILURE = -42,
  GF_IP_CONNECTION_CLOSED = -43, GF_IP_NETWORK_EMPTY = -44, GF_IP_SOCK_WOULD_BLOCK = -45, GF_IP_UDP_TIMEOUT = -46,
  GF_AUTHENTICATION_FAILURE = -50, GF_SCRIPT_NOT_READY = -51, GF_INVALID_CONFIGURATION = -52, GF_NOT_FOUND = -53,
  GF_PROFILE_NOT_SUPPORTED = -54, GF_REQUIRES_NEW_INSTANCE = -56, GF_FILTER_NOT_SUPPORTED = -57
}
 
enum  GF_MemTrackerType { GF_MemTrackerNone = 0, GF_MemTrackerSimple, GF_MemTrackerBackTrace }
 
enum  GF_ConsoleCodes {
  GF_CONSOLE_RESET =0, GF_CONSOLE_RED, GF_CONSOLE_GREEN, GF_CONSOLE_BLUE,
  GF_CONSOLE_YELLOW, GF_CONSOLE_CYAN, GF_CONSOLE_WHITE, GF_CONSOLE_MAGENTA,
  GF_CONSOLE_CLEAR, GF_CONSOLE_SAVE, GF_CONSOLE_RESTORE, GF_CONSOLE_BOLD = 1<<16,
  GF_CONSOLE_ITALIC = 1<<17, GF_CONSOLE_UNDERLINED = 1<<18, GF_CONSOLE_STRIKE = 1<<19
}
 
enum  GF_LOG_Level {
  GF_LOG_QUIET = 0, GF_LOG_ERROR, GF_LOG_WARNING, GF_LOG_INFO,
  GF_LOG_DEBUG
}
 GPAC Log Levels. More...
 
enum  GF_LOG_Tool {
  GF_LOG_CORE = 0, GF_LOG_CODING, GF_LOG_CONTAINER, GF_LOG_NETWORK,
  GF_LOG_HTTP, GF_LOG_RTP, GF_LOG_CODEC, GF_LOG_PARSER,
  GF_LOG_MEDIA, GF_LOG_SCENE, GF_LOG_SCRIPT, GF_LOG_INTERACT,
  GF_LOG_COMPOSE, GF_LOG_COMPTIME, GF_LOG_CACHE, GF_LOG_MMIO,
  GF_LOG_RTI, GF_LOG_MEMORY, GF_LOG_AUDIO, GF_LOG_MODULE,
  GF_LOG_MUTEX, GF_LOG_CONDITION, GF_LOG_DASH, GF_LOG_FILTER,
  GF_LOG_SCHEDULER, GF_LOG_ROUTE, GF_LOG_CONSOLE, GF_LOG_APP,
  GF_LOG_ALL, GF_LOG_TOOL_MAX = GF_LOG_ALL
}
 GPAC Log tools. More...
 
enum  { GF_BLOB_IN_TRANSFER = 1, GF_BLOB_CORRUPTED = 1<<1 }
 
enum  { GF_RTI_ALL_PROCESSES_TIMES = 1, GF_RTI_PROCESS_MEMORY = 1<<1, GF_RTI_SYSTEM_MEMORY_ONLY = 1<<2 }
 

Functions

const char * gf_4cc_to_str (u32 type)
 
u32 gf_4cc_parse (const char *val)
 
const char * gf_error_to_string (GF_Err e)
 Error Printing. More...
 
GF_Err gf_dynstrcat (char **str, const char *to_append, const char *sep)
 dynamic string concatenation More...
 
Bool gf_parse_lfrac (const char *str, GF_Fraction64 *frac)
 fraction parsing More...
 
Bool gf_parse_frac (const char *str, GF_Fraction *frac)
 fraction parsing More...
 
Bool gf_strnistr (const char *text, const char *subtext, u32 subtext_len)
 search string without case More...
 
u64 gf_timestamp_rescale (u64 value, u64 timescale, u64 new_timescale)
 safe timestamp rescale More...
 
s64 gf_timestamp_rescale_signed (s64 value, u64 timescale, u64 new_timescale)
 safe signed timestamp rescale More...
 
Bool gf_timestamp_less (u64 value1, u64 timescale1, u64 value2, u64 timescale2)
 compare timestamps More...
 
Bool gf_timestamp_less_or_equal (u64 value1, u64 timescale1, u64 value2, u64 timescale2)
 compare timestamps More...
 
Bool gf_timestamp_greater (u64 value1, u64 timescale1, u64 value2, u64 timescale2)
 compare timestamps More...
 
Bool gf_timestamp_greater_or_equal (u64 value1, u64 timescale1, u64 value2, u64 timescale2)
 compare timestamps More...
 
Bool gf_timestamp_equal (u64 value1, u64 timescale1, u64 value2, u64 timescale2)
 compare timestamps More...
 
GF_Err gf_sys_init (GF_MemTrackerType mem_tracker_type, const char *profile)
 System setup. More...
 
void gf_sys_close ()
 System closing. More...
 
GF_Err gf_sys_set_args (s32 argc, const char **argv)
 System arguments. More...
 
u32 gf_sys_get_argc ()
 Get number of args. More...
 
const char ** gf_sys_get_argv ()
 Get program arguments. More...
 
const char * gf_sys_get_arg (u32 arg)
 Get number of args. More...
 
const char * gf_sys_find_global_arg (const char *arg)
 Locate a global filter arg. More...
 
void gf_sys_mark_arg_used (s32 arg_idx, Bool used)
 Mark arg as used. More...
 
Bool gf_sys_is_arg_used (s32 arg_idx)
 Check if arg is marked as used. More...
 
Bool gf_sys_is_test_mode ()
 checks if test mode is enabled More...
 
Bool gf_sys_old_arch_compat ()
 checks if compatibility with old arch is enabled More...
 
u32 gf_sys_is_quiet ()
 checks if running in quiet mode More...
 
const char * gf_sys_features (Bool disabled)
 
GF_Err gf_sys_profiler_set_callback (void *udta, gf_rmt_user_callback rmt_usr_cbk)
 
GF_Err gf_sys_profiler_send (const char *msg)
 
void gf_sys_profiler_enable_sampling (Bool enable)
 
Bool gf_sys_profiler_sampling_enabled ()
 
void gf_sys_set_console_code (FILE *std, GF_ConsoleCodes code)
 
Bool gf_log_set_strict_error (Bool strict)
 Log exits at first error assignment. More...
 
char * gf_log_get_tools_levels (void)
 gets string-formatted log tools More...
 
void gf_log_set_tool_level (GF_LOG_Tool log_tool, GF_LOG_Level log_level)
 Log modules assignment. More...
 
gf_log_cbk gf_log_set_callback (void *usr_cbk, gf_log_cbk cbk)
 Log overwrite. More...
 
Bool gf_log_tool_level_on (GF_LOG_Tool log_tool, GF_LOG_Level log_level)
 Log level checking. More...
 
const char * gf_log_tool_name (GF_LOG_Tool log_tool)
 Log tool name. More...
 
u32 gf_log_get_tool_level (GF_LOG_Tool log_tool)
 Log level getter. More...
 
GF_Err gf_log_set_tools_levels (const char *log_tools_levels, Bool reset_all)
 Set log tools and levels. More...
 
GF_Err gf_log_modify_tools_levels (const char *val)
 Modify log tools and levels. More...
 
Bool gf_log_use_color ()
 Checks if color logs is enabled. More...
 
Bool gf_log_use_file ()
 Checks if logs are stored to file. More...
 
void gf_log_reset_file ()
 Resets log file Resets log file if any log file name was specified, by closing and reopening a new file.
 
void gf_rand_init (Bool Reset)
 PseudoRandom Integer Generation Initialization. More...
 
u32 gf_rand ()
 
void gf_get_user_name (char buf[1024])
 
void gf_set_progress (const char *title, u64 done, u64 total)
 Progress formatting. More...
 
void gf_set_progress_callback (void *user_cbk, gf_on_progress_cbk prog_cbk)
 Progress overwriting Overwrites the progress signaling function by a user-defined one. More...
 
Bool gf_prompt_has_input ()
 Prompt checking. More...
 
char gf_prompt_get_char ()
 Prompt character flush. More...
 
GF_Err gf_prompt_get_size (u32 *width, u32 *height)
 Get prompt TTY size. More...
 
void gf_prompt_set_echo_off (Bool echo_off)
 turns prompt echo on/off More...
 
Bool gf_sys_get_battery_state (Bool *onBattery, u32 *onCharge, u32 *level, u32 *batteryLifeTime, u32 *batteryFullLifeTime)
 
GF_Err gf_bin128_parse (const char *string, bin128 value)
 parses 128 bit from string More...
 
GF_Err gf_blob_get (const char *blob_url, u8 **out_data, u32 *out_size, u32 *blob_flags)
 
GF_Err gf_blob_release (const char *blob_url)
 
int gf_getch ()
 Portable getch() More...
 
u32 gf_read_line_input (char *line, int maxSize, Bool showContent)
 Reads a line of input from stdin. More...
 
u32 gf_sys_clock ()
 System clock query. More...
 
u64 gf_sys_clock_high_res ()
 High precision system clock query. More...
 
void gf_sleep (u32 ms)
 Sleeps thread/process. More...
 
u64 gf_net_get_utc ()
 gets UTC time in milliseconds More...
 
u64 gf_net_ntp_to_utc (u64 ntp)
 converts an ntp timestamp into UTC time in milliseconds More...
 
u64 gf_net_parse_date (const char *date)
 parses date More...
 
u64 gf_net_get_utc_ts (u32 year, u32 month, u32 day, u32 hour, u32 min, u32 sec)
 returns 64-bit UTC timestamp from year, month, day, hour, min and sec More...
 
s32 gf_net_get_timezone ()
 gets timezone adjustment in seconds More...
 
Bool gf_net_time_is_dst ()
 gets timezone daylight saving time status More...
 
struct tm * gf_gmtime (const time_t *time)
 gets time from UTC timestamp More...
 
u32 gf_sys_get_process_id ()
 Gets process ID. More...
 
Bool gf_sys_get_rti (u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags)
 Gets Run-Time info. More...
 
GF_Err gf_file_load_data (const char *file_name, u8 **out_data, u32 *out_size)
 reads a file into memory More...
 
GF_Err gf_file_load_data_filep (FILE *file, u8 **out_data, u32 *out_size)
 reads a file into memory More...
 
GF_Err gf_rmdir (const char *DirPathName)
 Delete Directory. More...
 
GF_Err gf_mkdir (const char *DirPathName)
 Create Directory. More...
 
Bool gf_dir_exists (const char *DirPathName)
 Check Directory Exists. More...
 
GF_Err gf_dir_cleanup (const char *DirPathName)
 Create Directory. More...
 
const char * gf_get_default_cache_directory ()
 
u32 gf_file_handles_count ()
 
size_t gf_fwrite (const void *ptr, size_t nb_bytes, FILE *stream)
 file writing helper More...
 
size_t gf_fread (void *ptr, size_t nbytes, FILE *stream)
 file reading helper More...
 
char * gf_fgets (char *buf, size_t size, FILE *stream)
 file reading helper More...
 
int gf_fgetc (FILE *stream)
 file reading helper More...
 
int gf_fputc (int val, FILE *stream)
 file writing helper More...
 
int gf_fputs (const char *buf, FILE *stream)
 file writing helper More...
 
int gf_fprintf (FILE *stream, const char *format,...)
 file writing helper More...
 
int gf_vfprintf (FILE *stream, const char *format, va_list args)
 file writing helper More...
 
int gf_fflush (FILE *stream)
 file flush helper More...
 
int gf_feof (FILE *stream)
 end of file helper More...
 
int gf_ferror (FILE *stream)
 file error helper More...
 
u64 gf_fsize (FILE *fp)
 file size helper More...
 
Bool gf_fileio_check (FILE *fp)
 file IO helper More...
 
FILE * gf_fopen (const char *file_name, const char *mode)
 file opening More...
 
FILE * gf_fopen_ex (const char *file_name, const char *parent_url, const char *mode, Bool no_warn)
 file opening More...
 
s32 gf_fclose (FILE *file)
 file closing More...
 
u64 gf_ftell (FILE *f)
 large file position query More...
 
s32 gf_fseek (FILE *f, s64 pos, s32 whence)
 large file seeking More...
 
char * gf_file_basename (const char *filename)
 
char * gf_file_ext_start (const char *filename)
 
GF_Err gf_enum_directory (const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir, void *cbck, const char *filter)
 Directory enumeration. More...
 
GF_Err gf_file_delete (const char *fileName)
 File Deletion. More...
 
GF_Err gf_file_move (const char *fileName, const char *newFileName)
 File Move. More...
 
FILE * gf_file_temp (char **const fileName)
 Temporary File Creation. More...
 
u64 gf_file_modification_time (const char *filename)
 File Modification Time. More...
 
Bool gf_file_exists (const char *fileName)
 File existence check. More...
 
Bool gf_file_exists_ex (const char *file_name, const char *par_name)
 File existence check. More...
 
GF_FileIOgf_fileio_new (char *url, void *udta, gfio_open_proc open, gfio_seek_proc seek, gfio_read_proc read, gfio_write_proc write, gfio_tell_proc tell, gfio_eof_proc eof, gfio_printf_proc printf)
 
void gf_fileio_del (GF_FileIO *fileio)
 
void * gf_fileio_get_udta (GF_FileIO *fileio)
 
const char * gf_fileio_url (GF_FileIO *fileio)
 
void gf_fileio_set_stats (GF_FileIO *fileio, u64 bytes_done, u64 file_size, Bool cache_complete, u32 bytes_per_sec)
 
Bool gf_fileio_get_stats (GF_FileIO *fileio, u64 *bytes_done, u64 *file_size, Bool *cache_complete, u32 *bytes_per_sec)
 
GF_FileIOgf_fileio_open_url (GF_FileIO *fileio, const char *url, const char *mode, GF_Err *out_err)
 
GF_Err gf_fileio_tag_main_thread (GF_FileIO *fileio)
 
Bool gf_fileio_is_main_thread (const char *url)
 
GF_FileIOgf_fileio_from_url (const char *url)
 
const char * gf_fileio_factory (GF_FileIO *fileio, const char *new_res_url)
 
const char * gf_fileio_translate_url (const char *url)
 
const char * gf_fileio_resource_url (GF_FileIO *fileio)
 
Bool gf_fileio_read_mode (GF_FileIO *fileio)
 
Bool gf_fileio_write_mode (GF_FileIO *fileio)
 
u32 gf_crc_32 (const u8 *data, u32 size)
 CRC32 compute. More...
 
GF_Err gf_gz_compress_payload (u8 **data, u32 data_len, u32 *out_size)
 
GF_Err gf_gz_compress_payload_ex (u8 **data, u32 data_len, u32 *out_size, u8 data_offset, Bool skip_if_larger, u8 **out_comp_data)
 
GF_Err gf_gz_decompress_payload (u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size)
 
GF_Err gf_lz_compress_payload (u8 **data, u32 data_len, u32 *out_size)
 
GF_Err gf_lz_decompress_payload (u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size)
 
u64 gf_gzseek (void *file, u64 offset, int whence)
 
u64 gf_gztell (void *file)
 
s64 gf_gzrewind (void *file)
 
int gf_gzeof (void *file)
 
int gf_gzclose (void *file)
 
const char * gf_gzerror (void *file, int *errnum)
 
void gf_gzclearerr (void *file)
 
void * gf_gzopen (const char *path, const char *mode)
 
int gf_gzread (void *file, void *buf, unsigned len)
 
int gf_gzdirect (void *file)
 
int gf_gzgetc (void *file)
 
char * gf_gzgets (void *file, char *buf, int len)
 
GF_SHA1Contextgf_sha1_starts ()
 
void gf_sha1_update (GF_SHA1Context *ctx, u8 *input, u32 length)
 
void gf_sha1_finish (GF_SHA1Context *ctx, u8 digest[GF_SHA1_DIGEST_SIZE])
 
GF_Err gf_sha1_file (const char *filename, u8 digest[GF_SHA1_DIGEST_SIZE])
 
GF_Err gf_sha1_file_ptr (FILE *file, u8 digest[GF_SHA1_DIGEST_SIZE])
 
void gf_sha1_csum (u8 *buf, u32 buflen, u8 digest[GF_SHA1_DIGEST_SIZE])
 
const char * gf_opts_get_key (const char *secName, const char *keyName)
 
GF_Err gf_opts_set_key (const char *secName, const char *keyName, const char *keyValue)
 
void gf_opts_del_section (const char *secName)
 
u32 gf_opts_get_section_count ()
 
const char * gf_opts_get_section_name (u32 secIndex)
 
u32 gf_opts_get_key_count (const char *secName)
 
const char * gf_opts_get_key_name (const char *secName, u32 keyIndex)
 
Bool gf_opts_get_bool (const char *secName, const char *keyName)
 
u32 gf_opts_get_int (const char *secName, const char *keyName)
 
const char * gf_opts_get_key_restricted (const char *secName, const char *keyName)
 
GF_Err gf_opts_discard_changes ()
 
GF_Err gf_opts_save ()
 
const char * gf_opts_get_filename ()
 
Bool gf_opts_default_shared_directory (char *path_buffer)
 

Detailed Description

This file contains basic functions and core definitions of the GPAC framework. This file is usually included by all GPAC header files since it contains the error definitions.


Data Structure Documentation

◆ GF_Blob

struct GF_Blob

Blob structure used to pass data pointer around

Data Fields
u8 * data

data block of blob

u32 size

size of blob

u32 flags

blob flags

struct __tag_mutex * mx

blob mutex for multi-thread access

Macro Definition Documentation

◆ GF_ARRAY_LENGTH

#define GF_ARRAY_LENGTH (   a)    (sizeof(a) / sizeof((a)[0]))

macros to get the size of an array of struct

Function Documentation

◆ gf_sys_get_battery_state()

Bool gf_sys_get_battery_state ( Bool onBattery,
u32 onCharge,
u32 level,
u32 batteryLifeTime,
u32 batteryFullLifeTime 
)

gets battery state

Parameters
onBatteryset to GF_TRUE if running on battery
onChargeset to GF_TRUE if battery is charging
levelset to battery charge percent
batteryLifeTimeset to battery lifetime
batteryFullLifeTimeset to battery full lifetime
Returns
GF_TRUE if success

◆ gf_bin128_parse()

GF_Err gf_bin128_parse ( const char *  string,
bin128  value 
)

Parses 128 bit from string

Parameters
stringthe string containing the value in hexa. Non alphanum characters are skipped
valuethe value parsed
Returns
error code if any

◆ gf_blob_get()

GF_Err gf_blob_get ( const char *  blob_url,
u8 **  out_data,
u32 out_size,
u32 blob_flags 
)

Retrieves data associated with a blob url. If success, gf_blob_release must be called after this

Parameters
blob_urlURL of blob object (ie gmem://p)
out_dataif success, set to blob data pointer
out_sizeif success, set to blob data size
blob_flagsif success, set to blob flags - may be NULL
Returns
error code

◆ gf_blob_release()

GF_Err gf_blob_release ( const char *  blob_url)

Releases blob data

Parameters
blob_urlURL of blob object (ie gmem://p)
Returns
error code

◆ gf_getch()

int gf_getch ( )

Returns immediately a typed char from stdin

Returns
the typed char

◆ gf_read_line_input()

u32 gf_read_line_input ( char *  line,
int  maxSize,
Bool  showContent 
)
Parameters
linethe buffer to fill
maxSizethe maximum size of the line to read
showContentboolean indicating if the line read should be printed on stderr or not
Returns
GF_TRUE if some content was read, GF_FALSE otherwise