libgpac
Documentation of the core library of GPAC
JSGPACCoreSystem Interface Reference

JSGPACCoreSystem API. More...

import"core.idl";

Public Member Functions

void gc ()
 
void set_arg_used (unsigned int arg_idx, boolean arg_used)
 
DOMString error_string (GF_Err e)
 
DOMString prompt_input ()
 
DOMString prompt_string ()
 
void prompt_echo_off (boolean echo_off)
 
void prompt_code (unsigned long code)
 
WinRect prompt_size ()
 
Array enum_directory (DOMString dir, optional DOMString filter=null, optional bool go_up=false)
 
unsigned long clock_ms ()
 
unsigned long long clock_us ()
 
void sleep (optional unsigned long sleep=0)
 
void exit (optional unsigned long ret_code=0)
 
DOMString fcc_to_str (unsigned long value)
 
void rand_init (optional boolean reset=false)
 
unsigned long rand ()
 
unsigned long long rand64 ()
 
DOMString getenv (DOMString var_name)
 
unsigned long long get_utc ()
 
unsigned long long get_utc (unsigned long year, unsigned long month, unsigned long day, unsigned long hour, unsigned long min, unsigned long sec)
 
unsigned long long get_utc (DOMString date)
 
Fraction get_ntp ()
 
Fraction ntp_shift (Fraction ntp, long microseconds)
 
unsigned long crc32 (ArrayBuffer abuf)
 
unsigned long crc32 (DOMString str)
 
ArrayBuffer sha1 (DOMString fname)
 
ArrayBuffer sha1 (ArrayBuffer abuf)
 
ArrayBuffer load_file (DOMString fname, optional boolean as_utf8=false)
 
ArrayBuffer compress (ArrayBuffer in_data, optional boolean use_gz=false)
 
ArrayBuffer decompress (ArrayBuffer in_data, optional boolean use_gz=false)
 
void rmdir (DOMString dirname)
 
void mkdir (DOMString dirname)
 
boolean dir_exists (DOMString dirname)
 
void dir_clean (DOMString dirname)
 
DOMString basename (DOMString filename)
 
DOMString file_ext (DOMString filename)
 
boolean file_exists (DOMString filename)
 
void del (DOMString filename)
 
unsigned long long mod_time (DOMString filename)
 
void move (DOMString filename, DOMString newname)
 
DOMString get_opt (DOMString secname, DOMString keyname)
 
void set_opt (DOMString secname, DOMString keyname, optional DOMString value=null)
 
void discard_opts ()
 
DOMString base64enc (ArrayBuffer in_data)
 
ArrayBuffer base64enc (DOMString in_data)
 
DOMString base16enc (ArrayBuffer in_data)
 
ArrayBuffer base16enc (DOMString in_data)
 
unsigned long htonl (unsigned long value)
 
unsigned long htons (unsigned long value)
 
unsigned long ntohl (unsigned long value)
 
unsigned long ntohs (unsigned long value)
 
unsigned long pixfmt_size (DOMString pix_fmt, unsigned long width, unsigned long height)
 
boolean pixfmt_transparent (DOMString pix_fmt)
 
boolean pixfmt_yuv (DOMString pix_fmt)
 
boolean pixfmt_depth (DOMString pix_fmt)
 
unsigned long pcmfmt_depth (DOMString pcm_fmt)
 
DOMString color_lerp (double interp, DOMString color1, DOMString color2)
 
double color_component (DOMString color, unsigned long comp_idx)
 
DOMString url_cat (DOMString parent, DOMString URL)
 
Rect rect_union (Rect r1, Rect r2)
 
Rect rect_intersect (Rect r1, Rect r2)
 

Data Fields

attribute Array args
 
attribute readonly unsigned long nb_cores
 
attribute readonly unsigned long sampling_period_duration
 
attribute readonly unsigned long total_cpu_time
 
attribute readonly unsigned long process_cpu_time
 
attribute readonly unsigned long total_cpu_time_diff
 
attribute readonly unsigned long process_cpu_time_diff
 
attribute readonly unsigned long cpu_idle_time
 
attribute readonly unsigned long total_cpu_usage
 
attribute readonly unsigned long process_cpu_usage
 
attribute readonly unsigned long pid
 
attribute readonly unsigned long thread_count
 
attribute readonly unsigned long long process_memory
 
attribute readonly unsigned long long physical_memory
 
attribute readonly unsigned long long physical_memory_avail
 
attribute readonly unsigned long long gpac_memory
 
attribute DOMString last_wdir
 
readonly attribute boolean batteryOn
 
readonly attribute boolean batteryCharging
 
readonly attribute unsigned long batteryPercent
 
readonly attribute unsigned long batteryLifeTime
 
readonly attribute unsigned long batteryFullLifeTime
 
readonly DOMString hostname
 
readonly boolean test_mode
 
readonly boolean old_arch
 
readonly boolean log_color
 
readonly boolean quiet
 
readonly signed int timezone
 
readonly unsigned int nb_files_open
 
readonly DOMString cache_dir
 
readonly DOMString shared_dir
 
readonly DOMString version
 
readonly DOMString version_full
 
readonly DOMString copyright
 
readonly unsigned long version_major
 
readonly unsigned long version_minor
 
readonly unsigned long version_micro
 

Detailed Description

The JSGPACCoreSystem interface has a single instance exposed to the script under the name "Sys". It implements binding to the underlying instance of libgpac.

Member Function Documentation

◆ gc()

void JSGPACCoreSystem::gc ( )

run garbage collection

◆ set_arg_used()

void JSGPACCoreSystem::set_arg_used ( unsigned int  arg_idx,
boolean  arg_used 
)

marks an argument as used (for argument tracking at prompt)

Parameters
arg_idxindex of argument to mark as used
arg_usedif true, argument is marked as used

◆ error_string()

DOMString JSGPACCoreSystem::error_string ( GF_Err  e)

gets string for error

Parameters
ethe error code
Returns
the corresponding string

◆ prompt_input()

DOMString JSGPACCoreSystem::prompt_input ( )

returns character input from prompt, or null if no input (this will be moved soon to core API)

Returns
input char, or NULL if no input

◆ prompt_string()

DOMString JSGPACCoreSystem::prompt_string ( )

wait character input from prompt and returns it

Returns
string entered at prompt

◆ prompt_echo_off()

void JSGPACCoreSystem::prompt_echo_off ( boolean  echo_off)

sets prompt echo off (input characters not visible) or on - see gf_prompt_set_echo_off

Parameters
echo_offif true, echo is disabled

◆ prompt_code()

void JSGPACCoreSystem::prompt_code ( unsigned long  code)

sets stderr color and other code for upcoming strings - see gf_sys_set_console_code

Parameters
codecode to set

◆ prompt_size()

WinRect JSGPACCoreSystem::prompt_size ( )

gets stdin TTY size - see gf_prompt_get_size

Returns
TTY size object, or null if not available

◆ enum_directory()

Array JSGPACCoreSystem::enum_directory ( DOMString  dir,
optional DOMString  filter = null,
optional bool  go_up = false 
)

enumerate directories

Parameters
dirthe directory to enumerate
filterthe filter for file extensions. If "dir", only enumerate directories
go_upif true, enumerate parent directory or root (/).
Returns
array of FileInformation interface

◆ clock_ms()

unsigned long JSGPACCoreSystem::clock_ms ( )

get system clock in milliseconds - see gf_sys_clock

Returns
clock value

◆ clock_us()

unsigned long long JSGPACCoreSystem::clock_us ( )

get system clock in microseconds - see gf_sys_clock_high_res

Returns
clock value

◆ sleep()

void JSGPACCoreSystem::sleep ( optional unsigned long  sleep = 0)

sleep for a given time - see gf_sleep

Parameters
sleepsleep value in milliseconds

◆ exit()

void JSGPACCoreSystem::exit ( optional unsigned long  ret_code = 0)

exit gpac process

Parameters
ret_codeexit return code

◆ fcc_to_str()

DOMString JSGPACCoreSystem::fcc_to_str ( unsigned long  value)

convert a 4CC code to its string representation - see gf_4cc_to_str

Parameters
valuethe 4CC code to convert
Returns
string representation

◆ rand_init()

void JSGPACCoreSystem::rand_init ( optional boolean  reset = false)

inits random number - see gf_rand_init

Parameters
resetif true, resets the random seed

◆ rand()

unsigned long JSGPACCoreSystem::rand ( )

gets a random number - see gf_rand

Returns
random 32 bit value

◆ rand64()

unsigned long long JSGPACCoreSystem::rand64 ( )

gets a random number

Returns
random 64 bit value

◆ getenv()

DOMString JSGPACCoreSystem::getenv ( DOMString  var_name)

gets an environment variable

Parameters
var_nameenvironment variable name
Returns
environment variable value, or null if variable is not defined

◆ get_utc() [1/3]

unsigned long long JSGPACCoreSystem::get_utc ( )

gets UTC clock - see gf_net_get_utc

Returns
UTC 64 bit timestamp

◆ get_utc() [2/3]

unsigned long long JSGPACCoreSystem::get_utc ( unsigned long  year,
unsigned long  month,
unsigned long  day,
unsigned long  hour,
unsigned long  min,
unsigned long  sec 
)

gets UTC timestamp for a given date - see gf_net_get_utc_ts

Parameters
yeardate's year
monthdate's month of the year, 0 to 11
daydate's day of the week, 1 to 31
hourdate's hours
mindate's minutes
secdate's seconds
Returns
UTC 64 bit timestamp

◆ get_utc() [3/3]

unsigned long long JSGPACCoreSystem::get_utc ( DOMString  date)

gets UTC clock from a date - see gf_net_parse_date

Parameters
datedate string
Returns
UTC 64 bit timestamp corresponding to the date

◆ get_ntp()

Fraction JSGPACCoreSystem::get_ntp ( )

gets NTP 64-bit timestamp - see gf_net_get_ntp_ts

Returns
NTP 64 bit timestamp as fraction, 'n' continaing seconds, 'd' containing fractional part

◆ ntp_shift()

Fraction JSGPACCoreSystem::ntp_shift ( Fraction  ntp,
long  microseconds 
)

shifts an NTP 64-bit timestamp by the given number of microseconds

Parameters
ntpsource NTP
microsecondsnumber of microseconds to add (positive) or remove (negative)
Returns
adjusted NTP 64 bit timestamp as fraction, 'n' continaing seconds, 'd' containing fractional part

◆ crc32() [1/2]

unsigned long JSGPACCoreSystem::crc32 ( ArrayBuffer  abuf)

gets CRC32 of an arraybuffer - see gf_crc_32

Parameters
abufarray buffer
Returns
CRC32 of the data

◆ crc32() [2/2]

unsigned long JSGPACCoreSystem::crc32 ( DOMString  str)

gets CRC32 of a string - see gf_crc_32

Parameters
strstring buffer
Returns
CRC32 of the string

◆ sha1() [1/2]

ArrayBuffer JSGPACCoreSystem::sha1 ( DOMString  fname)

gets SHA1 digest of an arraybuffer - see gf_sha1_file

Parameters
fnamename of file to hash
Returns
ArrayBuffer containing SHA1 of the file data

◆ sha1() [2/2]

ArrayBuffer JSGPACCoreSystem::sha1 ( ArrayBuffer  abuf)

gets SHA1 digest of a file - see gf_sha1_csum

Parameters
abufarray buffer
Returns
ArrayBuffer containing SHA1 of the data

◆ load_file()

ArrayBuffer JSGPACCoreSystem::load_file ( DOMString  fname,
optional boolean  as_utf8 = false 
)

loads file content into an array buffer - see gf_file_load_data

Parameters
fnamename of file to load
as_utf8load as UTF8 string
Returns
ArrayBuffer containing data of the file or UTF8 string

◆ compress()

ArrayBuffer JSGPACCoreSystem::compress ( ArrayBuffer  in_data,
optional boolean  use_gz = false 
)

compress using deflate() an array buffer

Parameters
in_datainput data to compress
use_gzcompress using gz (adds headers)
Returns
ArrayBuffer containing compressed data

◆ decompress()

ArrayBuffer JSGPACCoreSystem::decompress ( ArrayBuffer  in_data,
optional boolean  use_gz = false 
)

decompress using inflate() an array buffer

Parameters
in_datainput data to decompress
use_gzcompressed payload uses gz (has headers)
Returns
ArrayBuffer containing decompressed data

◆ rmdir()

void JSGPACCoreSystem::rmdir ( DOMString  dirname)

removes directory - cf gf_rmdir

Parameters
dirnamename of directory

◆ mkdir()

void JSGPACCoreSystem::mkdir ( DOMString  dirname)

creates directory - cf gf_mkdir

Parameters
dirnamename of directory

◆ dir_exists()

boolean JSGPACCoreSystem::dir_exists ( DOMString  dirname)

checks if directory exists - cf gf_dir_exists

Parameters
dirnamename of directory
Returns
true if directory exists

◆ dir_clean()

void JSGPACCoreSystem::dir_clean ( DOMString  dirname)

remove files in directory - cf gf_dir_cleanup

Parameters
dirnamename of directory

◆ basename()

DOMString JSGPACCoreSystem::basename ( DOMString  filename)

get basename of file or dir - cf gf_file_basename

Parameters
filenamename of file
Returns
file basename

◆ file_ext()

DOMString JSGPACCoreSystem::file_ext ( DOMString  filename)

get file extension - cf gf_file_ext_start

Parameters
filenamename of file
Returns
file extension or null if none

◆ file_exists()

boolean JSGPACCoreSystem::file_exists ( DOMString  filename)

check if file exists - cf gf_file_exists

Parameters
filenamename of file
Returns
true if directory exists

◆ del()

void JSGPACCoreSystem::del ( DOMString  filename)

deletes a file - cf gf_file_delete

Parameters
filenamename of file

◆ mod_time()

unsigned long long JSGPACCoreSystem::mod_time ( DOMString  filename)

get file modification time - cf gf_file_modification_time

Parameters
filenamename of file
Returns
file modification time

◆ move()

void JSGPACCoreSystem::move ( DOMString  filename,
DOMString  newname 
)

rename/move file - cf gf_file_move

Parameters
filenamename of file
newnamenew name of the file

◆ get_opt()

DOMString JSGPACCoreSystem::get_opt ( DOMString  secname,
DOMString  keyname 
)

get option from GPAC config - cf gf_opts_get_key

Parameters
secnamename of section
keynamename of key
Returns
value of key or null if no key

◆ set_opt()

void JSGPACCoreSystem::set_opt ( DOMString  secname,
DOMString  keyname,
optional DOMString  value = null 
)

get option from GPAC config - cf gf_opts_get_key

Parameters
secnamename of section
keynamename of key
valuenew value of key or null to remove key

◆ discard_opts()

void JSGPACCoreSystem::discard_opts ( )

discard all changes in GPAC config - see gf_opts_discard_changes

◆ base64enc() [1/2]

DOMString JSGPACCoreSystem::base64enc ( ArrayBuffer  in_data)

encodes an arraybuffer to a base64 string

Parameters
in_datainput buffer
Returns
encoded string

◆ base64enc() [2/2]

ArrayBuffer JSGPACCoreSystem::base64enc ( DOMString  in_data)

decodes a base64 string to an arraybuffer

Parameters
in_datainput encoded string
Returns
output decoded buffer

◆ base16enc() [1/2]

DOMString JSGPACCoreSystem::base16enc ( ArrayBuffer  in_data)

encodes an arraybuffer to a base16 string

Parameters
in_datainput buffer
Returns
encoded string

◆ base16enc() [2/2]

ArrayBuffer JSGPACCoreSystem::base16enc ( DOMString  in_data)

decodes a base16 string to an arraybuffer

Parameters
in_datainput encoded string
Returns
output decoded buffer

◆ htonl()

unsigned long JSGPACCoreSystem::htonl ( unsigned long  value)

converts 32 bit value from host to network byte order

Parameters
valuevalue to convert
Returns
converted value

◆ htons()

unsigned long JSGPACCoreSystem::htons ( unsigned long  value)

converts 16 bit value from host to network byte order

Parameters
valuevalue to convert
Returns
converted value

◆ ntohl()

unsigned long JSGPACCoreSystem::ntohl ( unsigned long  value)

converts 32 bit value from network to host byte order

Parameters
valuevalue to convert
Returns
converted value

◆ ntohs()

unsigned long JSGPACCoreSystem::ntohs ( unsigned long  value)

converts 16 bit value from network to host byte order

Parameters
valuevalue to convert
Returns
converted value

◆ pixfmt_size()

unsigned long JSGPACCoreSystem::pixfmt_size ( DOMString  pix_fmt,
unsigned long  width,
unsigned long  height 
)

gets size in bytes of an image of given size and pixel format

Parameters
pix_fmtpixel format name
widthimage width in pixels
heightimage height in pixels
Returns
size in bytes

◆ pixfmt_transparent()

boolean JSGPACCoreSystem::pixfmt_transparent ( DOMString  pix_fmt)

checks if pixel format is potentially transparent (uses alpha)

Parameters
pix_fmtpixel format name
Returns
true if transparent, false otherwise

◆ pixfmt_yuv()

boolean JSGPACCoreSystem::pixfmt_yuv ( DOMString  pix_fmt)

checks if pixel format is YUV

Parameters
pix_fmtpixel format name
Returns
true if YUV, false otherwise

◆ pixfmt_depth()

boolean JSGPACCoreSystem::pixfmt_depth ( DOMString  pix_fmt)

checks bit depth of component in pixel format

Parameters
pix_fmtpixel format name
Returns
number of bits per component

◆ pcmfmt_depth()

unsigned long JSGPACCoreSystem::pcmfmt_depth ( DOMString  pcm_fmt)

gets size in bytes of an audio sample in the given format

Parameters
pcm_fmtPCM format name
Returns
size in bytes

◆ color_lerp()

DOMString JSGPACCoreSystem::color_lerp ( double  interp,
DOMString  color1,
DOMString  color2 
)

interpolates colors

Parameters
interpinterpolation fraction between 0 and 1
color1first color to use
color2second color to use
Returns
component-wise interpolated color, i.e.
color1.COMP * (1-interp) + color2.comp * interp

◆ color_component()

double JSGPACCoreSystem::color_component ( DOMString  color,
unsigned long  comp_idx 
)

gets color component

Parameters
colorcolor to use
comp_idxcomponent idx, 0 for alpha, 1 for red, 2 for green 3 for blue
Returns
the component value normalized between 0 and 1

◆ url_cat()

DOMString JSGPACCoreSystem::url_cat ( DOMString  parent,
DOMString  URL 
)

concatenates URLs

Parameters
parentparent URL
URLURL to concatenate
Returns
the resolved URL

◆ rect_union()

Rect JSGPACCoreSystem::rect_union ( Rect  r1,
Rect  r2 
)

gets union of two rectangles

Parameters
r1first rectangle
r2second rectangle
Returns
union rectangle

◆ rect_intersect()

Rect JSGPACCoreSystem::rect_intersect ( Rect  r1,
Rect  r2 
)

gets intersection of two rectangles

Parameters
r1first rectangle
r2second rectangle
Returns
intersection rectangle

Field Documentation

◆ args

attribute Array JSGPACCoreSystem::args

launch arguments

◆ nb_cores

attribute readonly unsigned long JSGPACCoreSystem::nb_cores

number of cores

◆ sampling_period_duration

attribute readonly unsigned long JSGPACCoreSystem::sampling_period_duration

◆ total_cpu_time

attribute readonly unsigned long JSGPACCoreSystem::total_cpu_time

◆ process_cpu_time

attribute readonly unsigned long JSGPACCoreSystem::process_cpu_time

◆ total_cpu_time_diff

attribute readonly unsigned long JSGPACCoreSystem::total_cpu_time_diff

◆ process_cpu_time_diff

attribute readonly unsigned long JSGPACCoreSystem::process_cpu_time_diff

◆ cpu_idle_time

attribute readonly unsigned long JSGPACCoreSystem::cpu_idle_time

◆ total_cpu_usage

attribute readonly unsigned long JSGPACCoreSystem::total_cpu_usage

◆ process_cpu_usage

attribute readonly unsigned long JSGPACCoreSystem::process_cpu_usage

◆ pid

attribute readonly unsigned long JSGPACCoreSystem::pid

◆ thread_count

attribute readonly unsigned long JSGPACCoreSystem::thread_count

◆ process_memory

attribute readonly unsigned long long JSGPACCoreSystem::process_memory

◆ physical_memory

attribute readonly unsigned long long JSGPACCoreSystem::physical_memory

◆ physical_memory_avail

attribute readonly unsigned long long JSGPACCoreSystem::physical_memory_avail

◆ gpac_memory

attribute readonly unsigned long long JSGPACCoreSystem::gpac_memory

◆ last_wdir

attribute DOMString JSGPACCoreSystem::last_wdir

last working directory

◆ batteryOn

readonly attribute boolean JSGPACCoreSystem::batteryOn

indicates if running on battery or with power charge

◆ batteryCharging

readonly attribute boolean JSGPACCoreSystem::batteryCharging

indicates if battery is charging

◆ batteryPercent

readonly attribute unsigned long JSGPACCoreSystem::batteryPercent

battery percent (0 to 100)

◆ batteryLifeTime

readonly attribute unsigned long JSGPACCoreSystem::batteryLifeTime

estimated battery lifetime - see gf_sys_get_battery_state

◆ batteryFullLifeTime

readonly attribute unsigned long JSGPACCoreSystem::batteryFullLifeTime

estimated battery lifetime in full charge - see gf_sys_get_battery_state

◆ hostname

readonly DOMString JSGPACCoreSystem::hostname

host name

◆ test_mode

readonly boolean JSGPACCoreSystem::test_mode

test mode - see gf_sys_is_test_mode

◆ old_arch

readonly boolean JSGPACCoreSystem::old_arch

old arch compatibility mode - see gf_sys_old_arch_compat

◆ log_color

readonly boolean JSGPACCoreSystem::log_color

check if logs use color - see gf_log_use_color

◆ quiet

readonly boolean JSGPACCoreSystem::quiet

quiet mode - see gf_sys_is_quiet

◆ timezone

readonly signed int JSGPACCoreSystem::timezone

timezone - see gf_net_get_timezone

◆ nb_files_open

readonly unsigned int JSGPACCoreSystem::nb_files_open

number of opened file handles - see gf_file_handles_count

◆ cache_dir

readonly DOMString JSGPACCoreSystem::cache_dir

default cache directory - see gf_get_default_cache_directory

◆ shared_dir

readonly DOMString JSGPACCoreSystem::shared_dir

default shared directory (containing gui, shaders, etc) - see gf_opts_default_shared_directory

◆ version

readonly DOMString JSGPACCoreSystem::version

GPAC version string

◆ version_full

readonly DOMString JSGPACCoreSystem::version_full

GPAC full version string, including GIT rev

◆ copyright

readonly DOMString JSGPACCoreSystem::copyright

GPAC copyright string

◆ version_major

readonly unsigned long JSGPACCoreSystem::version_major

GPAC version major

◆ version_minor

readonly unsigned long JSGPACCoreSystem::version_minor

GPAC version minor

◆ version_micro

readonly unsigned long JSGPACCoreSystem::version_micro

GPAC version micro