blob: d1ef49f9263a1cb1b01b9057450e45e675056d17 [file] [edit]
/*
\file
\brief silence !
*/
typedef char *DOMString;
/*!
\defgroup core_grp JS Core API for libgpac
\ingroup jsapi_grp
\brief JavaScript API for libgpac core tools.
This section documents the JavaScript API used to query and control libgpac.
Errors are handled through exceptions.
@{
*/
/*! global context property representing the one and only JSGPACCoreSystem object attached to the loaded script*/
attribute JSGPACCoreSystem Sys;
/*!\brief JSGPACCoreSystem API
The JSGPACCoreSystem interface has a single instance exposed to the script under the name "Sys".
It implements binding to the underlying instance of libgpac.
*/
interface JSGPACCoreSystem {
/*! launch arguments*/
attribute Array args;
/*! run garbage collection*/
void gc();
/*! marks an argument as used (for argument tracking at prompt)
\param arg_idx index of argument to mark as used
\param arg_used if true, argument is marked as used
*/
void set_arg_used(unsigned int arg_idx, boolean arg_used);
/*! gets string for error
\param e the error code
\return the corresponding string*/
DOMString error_string(GF_Err e);
/*! returns character input from prompt, or null if no input (this will be moved soon to core API)
\return input char, or NULL if no input
*/
DOMString prompt_input();
/*! wait character input from prompt and returns it
\return string entered at prompt
*/
DOMString prompt_string();
/*! sets prompt echo off (input characters not visible) or on - see \ref gf_prompt_set_echo_off
\param echo_off if true, echo is disabled
*/
void prompt_echo_off(boolean echo_off);
/*! sets stderr color and other code for upcoming strings - see \ref gf_sys_set_console_code
\param code code to set
*/
void prompt_code(unsigned long code);
/*! gets stdin TTY size - see \ref gf_prompt_get_size
\return TTY size object, or null if not available
*/
WinRect prompt_size();
/*! enumerate directories
\param dir the directory to enumerate
\param filter the filter for file extensions. If "dir", only enumerate directories
\param go_up if true, enumerate parent directory or root (/).
\return array of FileInformation interface*/
Array enum_directory(DOMString dir, optional DOMString filter=null, optional bool go_up=false);
/*! get system clock in milliseconds - see \ref gf_sys_clock
\return clock value
*/
unsigned long clock_ms();
/*! get system clock in microseconds - see \ref gf_sys_clock_high_res
\return clock value
*/
unsigned long long clock_us();
/*! sleep for a given time - see \ref gf_sleep
\param sleep sleep value in milliseconds
*/
void sleep(optional unsigned long sleep = 0);
/*! exit gpac process
\param ret_code exit return code
*/
void exit(optional unsigned long ret_code = 0);
/*! convert a 4CC code to its string representation - see \ref gf_4cc_to_str
\param value the 4CC code to convert
\return string representation
*/
DOMString fcc_to_str(unsigned long value);
/*! inits random number - see \ref gf_rand_init
\param reset if true, resets the random seed
*/
void rand_init(optional boolean reset=false);
/*! gets a random number - see \ref gf_rand
\return random 32 bit value
*/
unsigned long rand();
/*! gets a random number
\return random 64 bit value
*/
unsigned long long rand64();
/*! gets an environment variable
\param var_name environment variable name
\return environment variable value, or null if variable is not defined
*/
DOMString getenv(DOMString var_name);
/*! gets UTC clock - see \ref gf_net_get_utc
\return UTC 64 bit timestamp
*/
unsigned long long get_utc();
/*! gets UTC timestamp for a given date - see \ref gf_net_get_utc_ts
\param year date's year
\param month date's month of the year, 0 to 11
\param day date's day of the week, 1 to 31
\param hour date's hours
\param min date's minutes
\param sec date's seconds
\return UTC 64 bit timestamp
*/
unsigned long long get_utc(unsigned long year, unsigned long month, unsigned long day, unsigned long hour, unsigned long min, unsigned long sec);
/*! gets UTC clock from a date - see \ref gf_net_parse_date
\param date date string
\return UTC 64 bit timestamp corresponding to the date
*/
unsigned long long get_utc(DOMString date);
/*! gets NTP 64-bit timestamp - see \ref gf_net_get_ntp_ts
\return NTP 64 bit timestamp as fraction, 'n' continaing seconds, 'd' containing fractional part
*/
Fraction get_ntp();
/*! shifts an NTP 64-bit timestamp by the given number of microseconds
\param ntp source NTP
\param microseconds number of microseconds to add (positive) or remove (negative)
\return adjusted NTP 64 bit timestamp as fraction, 'n' continaing seconds, 'd' containing fractional part
*/
Fraction ntp_shift(Fraction ntp, long microseconds);
/*! gets CRC32 of an arraybuffer - see \ref gf_crc_32
\param abuf array buffer
\return CRC32 of the data
*/
unsigned long crc32(ArrayBuffer abuf);
/*! gets CRC32 of a string - see \ref gf_crc_32
\param str string buffer
\return CRC32 of the string
*/
unsigned long crc32(DOMString str);
/*! gets SHA1 digest of an arraybuffer - see \ref gf_sha1_file
\param fname name of file to hash
\return ArrayBuffer containing SHA1 of the file data
*/
ArrayBuffer sha1(DOMString fname);
/*! gets SHA1 digest of a file - see \ref gf_sha1_csum
\param abuf array buffer
\return ArrayBuffer containing SHA1 of the data
*/
ArrayBuffer sha1(ArrayBuffer abuf);
/*! loads file content into an array buffer - see \ref gf_file_load_data
\param fname name of file to load
\param as_utf8 load as UTF8 string
\return ArrayBuffer containing data of the file or UTF8 string
*/
ArrayBuffer load_file(DOMString fname, optional boolean as_utf8=false);
/*! compress using deflate() an array buffer
\param in_data input data to compress
\param use_gz compress using gz (adds headers)
\return ArrayBuffer containing compressed data
*/
ArrayBuffer compress(ArrayBuffer in_data, optional boolean use_gz=false);
/*! decompress using inflate() an array buffer
\param in_data input data to decompress
\param use_gz compressed payload uses gz (has headers)
\return ArrayBuffer containing decompressed data
*/
ArrayBuffer decompress(ArrayBuffer in_data, optional boolean use_gz=false);
/*! removes directory - cf \ref gf_rmdir
\param dirname name of directory
*/
void rmdir(DOMString dirname);
/*! creates directory - cf \ref gf_mkdir
\param dirname name of directory
*/
void mkdir(DOMString dirname);
/*! checks if directory exists - cf \ref gf_dir_exists
\param dirname name of directory
\return true if directory exists
*/
boolean dir_exists(DOMString dirname);
/*! remove files in directory - cf \ref gf_dir_cleanup
\param dirname name of directory
*/
void dir_clean(DOMString dirname);
/*! get basename of file or dir - cf \ref gf_file_basename
\param filename name of file
\return file basename
*/
DOMString basename(DOMString filename);
/*! get file extension - cf \ref gf_file_ext_start
\param filename name of file
\return file extension or null if none
*/
DOMString file_ext(DOMString filename);
/*! check if file exists - cf \ref gf_file_exists
\param filename name of file
\return true if directory exists
*/
boolean file_exists(DOMString filename);
/*! deletes a file - cf \ref gf_file_delete
\param filename name of file
*/
void del(DOMString filename);
/*! get file modification time - cf \ref gf_file_modification_time
\param filename name of file
\return file modification time
*/
unsigned long long mod_time(DOMString filename);
/*! rename/move file - cf \ref gf_file_move
\param filename name of file
\param newname new name of the file
*/
void move(DOMString filename, DOMString newname);
/*! get option from GPAC config - cf \ref gf_opts_get_key
\param secname name of section
\param keyname name of key
\return value of key or null if no key
*/
DOMString get_opt(DOMString secname, DOMString keyname);
/*! get option from GPAC config - cf \ref gf_opts_get_key
\param secname name of section
\param keyname name of key
\param value new value of key or null to remove key
*/
void set_opt(DOMString secname, DOMString keyname, optional DOMString value=null);
/*! discard all changes in GPAC config - see \ref gf_opts_discard_changes*/
void discard_opts();
/*! encodes an arraybuffer to a base64 string
\param in_data input buffer
\return encoded string*/
DOMString base64enc(ArrayBuffer in_data);
/*! decodes a base64 string to an arraybuffer
\param in_data input encoded string
\return output decoded buffer*/
ArrayBuffer base64enc(DOMString in_data);
/*! encodes an arraybuffer to a base16 string
\param in_data input buffer
\return encoded string*/
DOMString base16enc(ArrayBuffer in_data);
/*! decodes a base16 string to an arraybuffer
\param in_data input encoded string
\return output decoded buffer*/
ArrayBuffer base16enc(DOMString in_data);
/*! converts 32 bit value from host to network byte order
\param value value to convert
\return converted value
*/
unsigned long htonl(unsigned long value);
/*! converts 16 bit value from host to network byte order
\param value value to convert
\return converted value
*/
unsigned long htons(unsigned long value);
/*! converts 32 bit value from network to host byte order
\param value value to convert
\return converted value
*/
unsigned long ntohl(unsigned long value);
/*! converts 16 bit value from network to host byte order
\param value value to convert
\return converted value
*/
unsigned long ntohs(unsigned long value);
/*! gets size in bytes of an image of given size and pixel format
\param pix_fmt pixel format name
\param width image width in pixels
\param height image height in pixels
\return size in bytes
*/
unsigned long pixfmt_size(DOMString pix_fmt, unsigned long width, unsigned long height);
/*! checks if pixel format is potentially transparent (uses alpha)
\param pix_fmt pixel format name
\return true if transparent, false otherwise
*/
boolean pixfmt_transparent(DOMString pix_fmt);
/*! checks if pixel format is YUV
\param pix_fmt pixel format name
\return true if YUV, false otherwise
*/
boolean pixfmt_yuv(DOMString pix_fmt);
/*! checks bit depth of component in pixel format
\param pix_fmt pixel format name
\return number of bits per component
*/
boolean pixfmt_depth(DOMString pix_fmt);
/*! gets size in bytes of an audio sample in the given format
\param pcm_fmt PCM format name
\return size in bytes
*/
unsigned long pcmfmt_depth(DOMString pcm_fmt);
/*! interpolates colors
\param interp interpolation fraction between 0 and 1
\param color1 first color to use
\param color2 second color to use
\return component-wise interpolated color, i.e. \code color1.COMP * (1-interp) + color2.comp * interp \endcode
*/
DOMString color_lerp(double interp, DOMString color1, DOMString color2);
/*! gets color component
\param color color to use
\param comp_idx component idx, 0 for alpha, 1 for red, 2 for green 3 for blue
\return the component value normalized between 0 and 1
*/
double color_component(DOMString color, unsigned long comp_idx);
/*! concatenates URLs
\param parent parent URL
\param URL URL to concatenate
\return the resolved URL
*/
DOMString url_cat(DOMString parent, DOMString URL);
/*! gets union of two rectangles
\param r1 first rectangle
\param r2 second rectangle
\return union rectangle
*/
Rect rect_union(Rect r1, Rect r2);
/*! gets intersection of two rectangles
\param r1 first rectangle
\param r2 second rectangle
\return intersection rectangle
*/
Rect rect_intersect(Rect r1, Rect r2);
/*! enables websocket monitoring server - see \ref gf_sys_enable_rmtws
*
* define the \ref rmt_on_new_client attribute to set callbacks
* \param enable (default: true) will enable the server if true, stop it if false
*/
void enable_rmtws(bool enable);
/*! enables user websocket server - see \ref gf_sys_enable_userws
*
* define the \ref userws_on_new_client attribute to set callbacks
* \param enable (default: true) will enable the server if true, stop it if false
*/
void enable_userws(bool enable);
/*! get the log tools and levels - see \ref gf_log_get_tools_levels
\param original_logs if set to true, return the logs set by the application, otherwise current logs as possibly modified by JS
\return the log-level string
*/
DOMString get_logs(bool original_logs=GF_FALSE);
/*! set the log tools and levels - see \ref gf_log_set_tools_levels
\param logs string describing logs and levels. Using null will reset logs to original value before modified by JS
\param reset reset all tools if true, otherwise only modify specified tools
*/
void set_logs(DOMString logs, bool reset=false);
/*! set the callback function when new clients connect to the monitoring websocket server
* the function shall take one parameter of type \ref JS_RMTClient
*/
optional attribute function rmt_on_new_client;
/*! set the callback function when new clients connect to the user websocket server
* the function shall take one parameter of type \ref JS_RMTClient
*/
optional attribute function userws_on_new_client;
/*! number of cores */
attribute readonly unsigned long nb_cores;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long sampling_period_duration;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long total_cpu_time;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long process_cpu_time;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long total_cpu_time_diff;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long process_cpu_time_diff;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long cpu_idle_time;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long total_cpu_usage;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long process_cpu_usage;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long pid;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long thread_count;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long long process_memory;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long long physical_memory;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long long physical_memory_avail;
/*! see \ref GF_SystemRTInfo */
attribute readonly unsigned long long gpac_memory;
/*! last working directory */
attribute DOMString last_wdir;
/*! indicates if running on battery or with power charge*/
readonly attribute boolean batteryOn;
/*! indicates if battery is charging*/
readonly attribute boolean batteryCharging;
/*! battery percent (0 to 100)*/
readonly attribute unsigned long batteryPercent;
/*! estimated battery lifetime - see \ref gf_sys_get_battery_state*/
readonly attribute unsigned long batteryLifeTime;
/*! estimated battery lifetime in full charge - see \ref gf_sys_get_battery_state*/
readonly attribute unsigned long batteryFullLifeTime;
/*! host name*/
readonly DOMString hostname;
/*! test mode - see \ref gf_sys_is_test_mode */
readonly boolean test_mode;
/*! old arch compatibility mode - see \ref gf_sys_old_arch_compat */
readonly boolean old_arch;
/*! check if logs use color - see \ref gf_log_use_color */
readonly boolean log_color;
/*! quiet mode - see \ref gf_sys_is_quiet */
readonly boolean quiet;
/*! timezone - see \ref gf_net_get_timezone */
readonly signed int timezone;
/*! number of opened file handles - see \ref gf_file_handles_count */
readonly unsigned int nb_files_open;
/*! default cache directory - see \ref gf_get_default_cache_directory */
readonly DOMString cache_dir;
/*! default shared directory (containing gui, shaders, etc) - see \ref gf_opts_default_shared_directory */
readonly DOMString shared_dir;
/*! GPAC version string */
readonly DOMString version;
/*! GPAC full version string, including GIT rev */
readonly DOMString version_full;
/*! GPAC copyright string */
readonly DOMString copyright;
/*! GPAC version major */
readonly unsigned long version_major;
/*! GPAC version minor */
readonly unsigned long version_minor;
/*! GPAC version micro */
readonly unsigned long version_micro;
/*! get/set extended log mode status*/
boolean use_logx;
/*! set the callback function for logs, or disable log callback and reset tools to original value if null.
* - For regular mode, the callback function is of form log(DOMString tool, unsigned int level, DOMString message).
* - For extended mode, the callback function is of form log(DOMString tool, unsigned int level, DOMString message, unsigned int thread_id, Object caller), with object either a FilterSession, a Filter or null.
*/
optional attribute function on_log;
};
/*! object used for TTY size info - cannot be created through constructor*/
interface WinRect {
/*! width of TTY in characters*/
attribute readonly unsigned long w;
/*! height of TTY in characters*/
attribute readonly unsigned long h;
};
/*! object used for file enumeration - cannot be created through constructor*/
interface FileInformation {
/*! file name*/
DOMString name;
/*! file path*/
DOMString path;
/*! true if directory*/
boolean directory;
/*! true if drive root (local HDD, USB or other mount points)*/
boolean drive;
/*! true if hidden file*/
boolean hidden;
/*! true if system file*/
boolean system;
/*! file size in bytes*/
unsigned long long size;
/*! last modification UTC time in microseconds*/
unsigned long long last_modified;
};
/*! SHA1 hasher object*/
interface SHA1 {
/*! constructor*/
SHA1();
/*! push data to hasher - see \ref gf_sha1_update
\param buffer data to be hashed*/
void push(ArrayBuffer buffer);
/*! get final hash - the hash context is reset after this call - see \ref gf_sha1_finish
\return the hash message*/
ArrayBuffer get();
};
/*! FILE object*/
interface File {
/*! constructor for a temporary file*/
File();
/*! constructor for a file - see \ref gf_fopen
\param name name of file to open
\param mode read/write mode, same as fopen
\param parent_fileio parent GF_FileIO name - see \ref gf_fopen_ex
*/
File(DOMString name, DOMString mode, optional DOMString parent_fileio=null);
/*! flush file - see \ref gf_fflush*/
void flush();
/*! close file, underlying FILE object is destroyed and any futher calls to the file object will fail - see \ref gf_fclose*/
void close();
/*! read bytes in an array buffer - see \ref gf_fread
\param buf array buffer to read bytes into
\param nb_bytes number of bytes to read - if 0, uses array buffer size. If more than array buffer size, truncated to array buffer size
\return the number of bytes read
*/
unsigned long read(ArrayBuffer buf, optional unsigned long nb_bytes=0);
/*! seek into file - see \ref gf_fseek
\param offset offset in file
\param whence seek origin
\return -1 if error, 0 otherwise
*/
long seek(unsigned long long offset, long whence);
/*! get a string from a file, stopping at first new line character found - see \ref gf_fgets
\return string read
*/
DOMString gets();
/*! read a character from file - see \ref gf_fgetc
\return string containing a single character
*/
DOMString getc(DOMString char);
/*! write bytes of an array buffer to file - see \ref gf_fwrite
\param buf array buffer to read bytes from
\param nb_bytes number of bytes to write - if 0, uses array buffer size. If more than array buffer size, truncated to array buffer size
\return the number of bytes written
*/
unsigned long write(ArrayBuffer buf, optional unsigned long nb_bytes=0);
/*! put string to file - see \ref gf_fputs
\param string string to write
*/
void puts(DOMString string);
/*! put character to file - see \ref gf_fputc
\param value character to write (only first char of string is used)
*/
void putc(DOMString value);
/*! put character to file - see \ref gf_fputc
\param value integer value to write
*/
void putc(unsigned long value);
/*! read/write position in file - see \ref gf_ftell and \ref gf_fseek*/
attribute unsigned long long pos;
/*! EOF flag on file - see \ref gf_feof */
attribute readonly boolean eof;
/*! error code on file, 0 if no error - see \ref gf_ferror */
attribute readonly unsigned long error;
/*! file size - see \ref gf_fsize */
attribute readonly unsigned long long size;
/*! set to true if file is a GFIO wrapper - see \ref gf_fileio_check */
attribute readonly boolean gfio;
};
/*! Bitstream object*/
interface Bitstream {
/*! constructor for a dynamic allocated write bitstream*/
Bitstream();
/*! constructor for a static allocated bitstream
\param buffer the array buffer to use for bitstream operations
\param write_mode if set to true, the bitstream is created in write mode, otherwise in read mode
*/
Bitstream(ArrayBuffer buffer, optional boolean write_mode=false);
/*! constructor for a bitstream wrapping a file - see \ref gf_bs_from_file
\param file the File object to use for bitstream operations
\param write_mode if set to true, the bitstream is created in write mode, otherwise in read mode. This mode shall be compatible with the file open mode
*/
Bitstream(File file, optional boolean write_mode=false);
/*! get 8-bits unsigned integer, byte-aligned
\return value read*/
unsigned long get_u8();
/*! get 8-bits signed integer, byte-aligned
\return value read*/
unsigned long get_s8();
/*! get 16-bits unsigned integer, byte-aligned, big-endian
\return value read*/
unsigned long get_u16();
/*! get 16-bits unsigned integer, byte-aligned, little-endian
\return value read*/
unsigned long get_u16_le();
/*! get 16-bits signed integer, byte-aligned, big-endian
\return value read*/
unsigned long get_s16();
/*! get 24-bits unsigned integer, byte-aligned, big-endian
\return value read*/
unsigned long get_u24();
/*! get 32-bits unsigned integer, byte-aligned, big-endian
\return value read*/
unsigned long get_u32();
/*! get 32-bits unsigned integer, byte-aligned, little-endian
\return value read*/
unsigned long get_u32_le();
/*! get 32-bits signed integer, byte-aligned, big-endian
\return value read*/
unsigned long get_s32();
/*! get 64-bits unsigned integer, byte-aligned, big-endian
\return value read*/
unsigned long get_u64();
/*! get 64-bits unsigned integer, byte-aligned, little-endian
\return value read*/
unsigned long get_u64_le();
/*! get 64-bits signed integer, byte-aligned, big-endian
\return value read*/
unsigned long get_s64();
/*! get n-bits unsigned integer, big-endian
\param nb_bits number of bits to read
\return value read*/
unsigned long get_bits(unsigned long nb_bits);
/*! get float 32 bits value
\return value read*/
double get_float();
/*! get float 64 bits value
\return value read*/
double get_double();
/*! reads bytes in an array buffer
\param buffer target read buffer
\param nb_bytes number of bytes to read - if 0, uses array buffer size. If more than array buffer size, truncated to array buffer size
\return number of bytes read*/
unsigned long get_data(ArrayBuffer buffer, optional unsigned long nb_bytes=0);
/*! get utf8 string
\return value read*/
DOMString get_string();
/*! reads 4CC
\return four-character code read
*/
DOMString get_4cc();
/*! write 8-bit unsigned value
\param value value to write*/
void put_u8(unsigned long value);
/*! write 8-bit signed value
\param value value to write*/
void put_s8(signed long value);
/*! write 16-bit unsigned value, big-endian
\param value value to write*/
void put_u16(unsigned long value);
/*! write 8-bit unsigned value, little-endian
\param value value to write*/
void put_u16_le(unsigned long value);
/*! write 16-bit signed value, big-endian
\param value value to write*/
void put_s16(signed long value);
/*! write 24-bit unsigned value
\param value value to write*/
void put_u24(unsigned long value);
/*! write 32-bit unsigned value, big-endian
\param value value to write*/
void put_u32(unsigned long value);
/*! write 32-bit unsigned value, little-endian
\param value value to write*/
void put_u32_le(unsigned long value);
/*! write 32-bit signed value, big-endian
\param value value to write*/
void put_s32(signed long value);
/*! write 64-bit unsigned value, big-endian
\param value value to write*/
void put_u64(unsigned long long value);
/*! write 64-bit unsigned value, little-endian
\param value value to write*/
void put_u64_le(unsigned long long value);
/*! write 64-bit signed value, big-endian
\param value value to write*/
void put_s64(signed long long value);
/*! write n-bit unsigned value
\param value value to write
\param nb_bits number of bits to use when writing
*/
void put_bits(unsigned long long value, unsigned long nb_bits);
/*! write 32-bit float value
\param value value to write*/
void put_float(double value);
/*! write 64-bit float value
\param value value to write*/
void put_double(double value);
/*! write data
\param buffer source of data to write
\param nb_bytes number of bytes to write - if 0, uses array buffer size. If more than array buffer size, truncated to array buffer size
\return number of bytes written
*/
unsigned long put_data(ArrayBuffer buffer, optional unsigned long nb_bytes=0);
/*! write 4CC
\param fcc four-character code to write
*/
void put_4cc(DOMString fcc);
/*! write UTF-8 string
\param str string to write
*/
void put_string(DOMString str);
/*! write 64-bit float value
\param buffer buffer to write
\param nb_bytes number of bytes to write - if 0, uses array buffer size. If more than array buffer size, truncated to array buffer size
\param offset byte offset at which data must be inserted
*/
void insert_data(ArrayBuffer buffer, optional unsigned long nb_bytes=0, optional unsigned long offset=0);
/*! check if bitsream is byte-aligned - see \ref gf_bs_is_align
\return true if aligned*/
boolean is_align();
/*! set bitsream byte-aligned - see \ref gf_bs_align*/
void align();
/*! truncate bitsream - see \ref gf_bs_truncate*/
void truncate();
/*! get content of the bitstream - see \ref gf_bs_get_content
\return ArrayBuffer containing the bitstream content*/
ArrayBuffer get_content();
/*! transfer bitstream into another - see \ref gf_bs_transfer
\param src_bs source bitstream for bytes to transfer
\param keep_src if true, the source bitstream will not be reset
*/
void transfer(Bitstream *src_bs, optional boolean keep_src=false);
/*! peek bits without changing bitstream state - see \ref gf_bs_peek_bits
\param nb_bits the number of bits to peek
\param byte_offset the position of the first byte after the current position to start peek
\return value peeked*/
unsigned long peek(unsigned long nb_bits, optional unsigned long byte_offset=0);
/*! skips given amount of bytes
\param nb_bytes number of bytes to skip*/
void skip(unsigned long nb_bytes);
/*! flush underlying file object if any*/
void flush();
/*! enable emulation preventio byte removal - see \ref gf_bs_enable_emulation_byte_removal
\param enable if true, EPB is removed in read operations*/
void epb_mode(boolean enable);
/*! position of bitstream - see \ref gf_bs_get_position and \ref gf_bs_seek*/
attribute unsigned long long pos;
/*! check if bytes are available for read/write - see \ref gf_bs_available */
attribute readonly unsigned long long available;
/*! size of bitstream - see \ref gf_bs_get_size */
attribute readonly unsigned long long size;
/*! bit offset in bitstream - see \ref gf_bs_get_bit_offset */
attribute readonly unsigned long bit_offset;
/*! bit position in bitstream - see \ref gf_bs_get_bit_position */
attribute readonly unsigned long bit_position;
/*! bit available till end of byte - see \ref gf_bs_bits_available */
attribute readonly unsigned long bits_available;
/*! gets refreshed size of bitstream - see \ref gf_bs_get_refreshed_size */
attribute readonly unsigned long long refreshed_size;
/*! checks if bitstream read has overflown - see \ref gf_bs_is_overflow */
attribute readonly boolean overflow;
}
/*! fraction object*/
interface Fraction {
/*! numerator*/
long n;
/*! denumerator*/
unsigned long d;
};
/*! FileIO object
A FileIO object wraps calls to file IO, allowing the script to feed GPAC files not present on disk, or have GPAC create files in JS memory.
Whenever a file is opened, a new JS object of type FileIO is created and passed as "this" in the specified open, close, read, write, seek, tell, eof callbacks.
Any URL relative to the reference URL provided will be solved against the parent FileIO, resulting in additionnals open() calls.
Warning: this is work in progress
*/
interface FileIO {
/*! constructor for a FileIO
\param reference_url the base URL this FileIO wraps
\param open the open function callback, shall not be NULL. The callback is "boolean open(DOMString url, DOMString mode); ", with mode a fopen mode and the return value true indicates success
\param close the close function callback, shall not be NULL. The callback is "close();"
\param write the write function callback, shall not be NULL if read is NULL. The callback is "unsigned long write(ArrayBuffer ab);", where ab is the buffer to write and the return value the number of bytes written
\param read the read function callback, shall not be NULL if write is NULL. The callback is "unsigned long read(ArrayBuffer ab);", where ab is the buffer to fill and the return value the number of bytes read
\param seek the seek function callback, shall not be NULL. The callback is "unsigned long seek(unsigned long long pos, unsigned long whence);", as in \ref gf_fseek
\param tell the seek function callback, shall not be NULL. The callback is "unsigned long long tell();", as in \ref gf_ftell
\param eof the end of file function callback, shall not be NULL. The callback is "boolean eof();", as in \ref gf_feof
\param exists the file existence probing function callback, shall not be NULL. The callback is "boolean exists(DOMString URL);", returns true if file exists (for read access). The "this" object is the constructed FileIO on this callback.
*/
File(DOMString reference_url, function open, function close, function write, function read, function seek, function tell, function eof, function exists);
/*! protects the FileIO factory, preventing it to be deleted until destroy is called
This is needded in case a FileIO URL is used several time in a session (re-injecting a source), as libgpac will otherwise destroy the
underlying FileIO factory when no more files are associated with it
*/
void protect();
/*! destroy the underlying FileIO, if not already destroyed. If \ref protect is used, this function MUST be called before exiting gpac*/
void destroy();
/*! get the gfio:// URL associated with the fileIO object */
attribute readonly DOMString url;
/*! get the underlying resource URL associated with the fileIO object */
attribute readonly DOMString resource_url;
/*! the parent FileIO object (the one constructed by the script) for this FileIO instance*/
attribute readonly FileIO parent;
};
/*! Object representing a monitoring websocket client
*
* will be passed to the session \ref rmt_on_new_client callback
* and to \ref userws_on_new_client if the user websocket server is enabled
*/
interface JS_RMTClient {
/*! a callback called when the client receives data
*
* the function shall be of type function(data)
* where data will be either of type string (for utf8 data) or arraybuffer (for binary data)
*/
optional attribute function on_data;
/*! a callback called when the client disconnects or is deleted */
optional attribute function on_close;
/*! a string of format ip:port representing the client */
readonly attribute string peer_address;
/*! sends data to the client on the websocket
\param data the data to send as a utf8 string
*/
void send(string data);
/*! sends data to the client on the websocket
\param data the data to send as a binary arraybuffer
*/
void send(arraybuffer data);
}
/*! @} */