libgpac
Documentation of the core library of GPAC
|
Data Structures | |
struct | GF_FileEnumInfo |
FileEnum info object. More... | |
Typedefs | |
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) |
Enumerations | |
enum | GF_FileIOWriteState { GF_FIO_WRITE_READY =0 , GF_FIO_WRITE_WAIT , GF_FIO_WRITE_CANCELED } |
enum | GF_FileIOCacheState { GF_FILEIO_CACHE_IN_PROGRESS =0 , GF_FILEIO_CACHE_DONE , GF_FILEIO_NO_CACHE } |
Functions | |
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 checker More... | |
GF_FileIOWriteState | gf_fileio_write_ready (FILE *fp) |
file IO write checker 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_FileIO * | gf_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) |
GF_FileIO * | gf_fileio_from_mem (const char *URL, const u8 *data, u32 size) |
void | gf_fileio_set_stats (GF_FileIO *fileio, u64 bytes_done, u64 file_size, GF_FileIOCacheState cache_state, u32 bytes_per_sec) |
Bool | gf_fileio_get_stats (GF_FileIO *fileio, u64 *bytes_done, u64 *file_size, GF_FileIOCacheState *cache_state, u32 *bytes_per_sec) |
void | gf_fileio_set_write_state (GF_FileIO *fileio, GF_FileIOWriteState write_state) |
GF_FileIO * | gf_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_FileIO * | gf_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) |
This section documents file system tools used in GPAC.
FILE objects are wrapped in GPAC for direct memory or callback operations. All file functions not using stderr/stdout must use the gf_ prefixed versions, eg:
struct GF_FileEnumInfo |
The FileEnumInfo object is used to get file attributes upon enumeration of a directory.
Data Fields | ||
---|---|---|
Bool | hidden |
File is marked as hidden |
Bool | directory |
File is a directory |
Bool | drive |
File is a drive mountpoint |
Bool | system |
File is a system file |
u64 | size |
File size in bytes |
u64 | last_modified |
File last modif time in UTC seconds |
typedef Bool(* gf_enum_dir_item) (void *cbck, char *item_name, char *item_path, GF_FileEnumInfo *file_info) |
The gf_enum_dir_item type is the type for the callback of the gf_enum_directory function
cbck | Opaque user data. |
item_name | File or directory name. |
item_path | File or directory full path and name from filesystem root. |
file_info | information for the file or directory. |
typedef GF_FileIO*(* gfio_open_proc) (GF_FileIO *fileio_ref, const char *url, const char *mode, GF_Err *out_error) |
open proc for memory file IO
fileio_ref | reference file_io. A file can be opened multiple times for the same reference, your code must handle this |
url | target file name. |
mode | opening mode of file, same as fopen mode. The following additional modes are defined:
|
out_error | must be set to error code if any (never NULL) |
seek proc for memory file IO
fileio | target file IO object |
offset | offset in file |
whence | position from offset, same as fseek |
read proc for memory file IO
fileio | target file IO object |
buffer | buffer to read. |
bytes | number of bytes to read. |
write proc for memory file IO
fileio | target file IO object |
buffer | buffer to write. |
bytes | number of bytes to write. If 0, acts as fflush |
positon tell proc for memory file IO
fileio | target file IO object |
end of file proc for memory file IO
fileio | target file IO object |
printf proc for memory file IO
fileio | target file IO object |
format | format string to use |
args | variable argument list for printf, already initialized (va_start called) |
enum GF_FileIOWriteState |
enum GF_FileIOCacheState |
Reads a local file into memory, in binary open mode.
file_name | path on disk of the file to read |
out_data | pointer to allocted address, to be freed by caller |
out_size | pointer to allocted size |
Reads a local file into memory, in binary open mode.
file | stream object to read (no seek is performed) |
out_data | pointer to allocted address, to be freed by caller |
out_size | pointer to allocted size |
GF_Err gf_rmdir | ( | const char * | DirPathName | ) |
Delete a dir within the full path.
DirPathName | the file path name. |
GF_Err gf_mkdir | ( | const char * | DirPathName | ) |
Create a directory within the full path.
DirPathName | the dir path name. |
Bool gf_dir_exists | ( | const char * | DirPathName | ) |
Create a directory within the full path.
DirPathName | the dir path name. |
GF_Err gf_dir_cleanup | ( | const char * | DirPathName | ) |
Cleanup a directory within the full path, removing all the files and the directories.
DirPathName | the dir path name. |
const char* gf_get_default_cache_directory | ( | ) |
Gets a newly allocated string containing the default cache directory. It is the responsibility of the caller to free the string.
u32 gf_file_handles_count | ( | ) |
Gets the number of open file handles (gf_fopen/gf_fclose only).
size_t gf_fwrite | ( | const void * | ptr, |
size_t | nb_bytes, | ||
FILE * | stream | ||
) |
Wrapper to properly handle calls to fwrite(), ensuring proper error handling is invoked when it fails.
ptr | data buffer to write |
nb_bytes | number of bytes to write |
stream | stream object |
size_t gf_fread | ( | void * | ptr, |
size_t | nbytes, | ||
FILE * | stream | ||
) |
Wrapper to properly handle calls to fread()
ptr | data buffer to read |
nbytes | number of bytes to read |
stream | stream object |
char* gf_fgets | ( | char * | buf, |
size_t | size, | ||
FILE * | stream | ||
) |
Wrapper to properly handle calls to fgets()
buf | same as fgets |
size | same as fgets |
stream | same as fgets |
int gf_fgetc | ( | FILE * | stream | ) |
Wrapper to properly handle calls to fgetc()
stream | same as fgetc |
int gf_fputc | ( | int | val, |
FILE * | stream | ||
) |
Wrapper to properly handle calls to fputc()
val | same as fputc |
stream | same as fputc |
int gf_fputs | ( | const char * | buf, |
FILE * | stream | ||
) |
Wrapper to properly handle calls to fputs()
buf | same as fputs |
stream | same as fputs |
int gf_fprintf | ( | FILE * | stream, |
const char * | format, | ||
... | |||
) |
Wrapper to properly handle calls to fprintf()
stream | same as fprintf |
format | same as fprintf |
int gf_vfprintf | ( | FILE * | stream, |
const char * | format, | ||
va_list | args | ||
) |
Wrapper to properly handle calls to vfprintf()
stream | same as vfprintf |
format | same as vfprintf |
args | same as vfprintf |
int gf_fflush | ( | FILE * | stream | ) |
Wrapper to properly handle calls to fflush()
stream | same as fflush |
int gf_feof | ( | FILE * | stream | ) |
Wrapper to properly handle calls to feof()
stream | same as feof |
int gf_ferror | ( | FILE * | stream | ) |
Wrapper to properly handle calls to ferror()
stream | same as ferror |
u64 gf_fsize | ( | FILE * | fp | ) |
Gets the file size given a FILE object. The FILE object position will be reset to 0 after this call
fp | FILE object to check |
Bool gf_fileio_check | ( | FILE * | fp | ) |
Checks if the given FILE object is a native FILE or a GF_FileIO wrapper.
fp | FILE object to check |
GF_FileIOWriteState gf_fileio_write_ready | ( | FILE * | fp | ) |
Checks if the given FILE object is ready for write.
fp | FILE object to check |
FILE* gf_fopen | ( | const char * | file_name, |
const char * | mode | ||
) |
Opens a file, potentially bigger than 4GB. if filename identifies a blob (gmem://), the blob will be opened
file_name | same as fopen |
mode | same as fopen |
FILE* gf_fopen_ex | ( | const char * | file_name, |
const char * | parent_url, | ||
const char * | mode, | ||
Bool | no_warn | ||
) |
Opens a file, potentially using file IO if the parent URL is a File IO wrapper
file_name | same as fopen |
parent_url | URL of parent file. If not a file io wrapper (gfio://), the function is equivalent to gf_fopen |
mode | same as fopen - value "mkdir" checks if parent dir(s) need to be created, create them if needed and returns NULL (no file open) |
no_warn | if GF_TRUE, do not throw log message if failure |
s32 gf_fclose | ( | FILE * | file | ) |
Closes a file
file | file to close |
u64 gf_ftell | ( | FILE * | f | ) |
Queries the current read/write position in a large file
f | Same semantics as gf_ftell |
Seeks the current read/write position in a large file
f | Same semantics as fseek |
pos | Same semantics as fseek |
whence | Same semantics as fseek |
char* gf_file_basename | ( | const char * | filename | ) |
gets basename from filename/path
filename | Path of the file, can be an absolute path |
char* gf_file_ext_start | ( | const char * | filename | ) |
gets extension from filename
filename | Path of the file, can be an absolute path |
GF_Err gf_enum_directory | ( | const char * | dir, |
Bool | enum_directory, | ||
gf_enum_dir_item | enum_dir, | ||
void * | cbck, | ||
const char * | filter | ||
) |
Enumerates a directory content. Feedback is provided by the enum_dir_item function
dir | Directory to enumerate |
enum_directory | If set, only directories will be enumerated, otherwise only files are. |
enum_dir | gf_enum_dir_item callback function for enumeration. |
cbck | Opaque user data passed to callback function. |
filter | optional filter for file extensions. If a file extension without the dot '.' character is not found in the filter the file will be skipped. |
GF_Err gf_file_delete | ( | const char * | fileName | ) |
Deletes a file from the disk.
fileName | absolute name of the file or name relative to the current working directory. |
GF_Err gf_file_move | ( | const char * | fileName, |
const char * | newFileName | ||
) |
Moves or renames a file or directory.
fileName | absolute path of the file / directory to move or rename |
newFileName | absolute new path/name of the file / directory |
FILE* gf_file_temp | ( | char **const | fileName | ) |
Creates a new temporary file in binary mode
fileName | if not NULL, strdup() of the temporary filename when created by GPAC (NULL otherwise as the system automatically removes its own tmp files) |
u64 gf_file_modification_time | ( | const char * | filename | ) |
Gets the UTC modification time of the given file in microseconds
filename | file to check |
Bool gf_file_exists | ( | const char * | fileName | ) |
Checks if file with given name exists
fileName | path of the file to check |
Bool gf_file_exists_ex | ( | const char * | file_name, |
const char * | par_name | ||
) |
Checks if file with given name exists, for regular files or File IO wrapper
file_name | path of the file to check |
par_name | name of the parent file |
GF_FileIO* gf_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 | ||
) |
Creates a new file IO object
There is no guarantee that the corresponding resource will be opened by the framework, it is therefore the caller responsibility to track objects created by gf_fileio_new or as a response to open with mode "url".
url | the original URL this file IO object wraps |
udta | opaque data for caller |
open | open proc for IO, must not be NULL |
seek | seek proc for IO, must not be NULL |
read | read proc for IO - if NULL the file is considered write only |
write | write proc for IO - if NULL the file is considered read only |
tell | tell proc for IO, must not be NULL |
eof | eof proc for IO, must not be NULL |
printf | printf proc for IO, may be NULL |
void gf_fileio_del | ( | GF_FileIO * | fileio | ) |
Deletes a new fileIO object
fileio | the File IO object to delete |
void* gf_fileio_get_udta | ( | GF_FileIO * | fileio | ) |
Gets associated user data of a fileIO object
fileio | target file IO object |
const char* gf_fileio_url | ( | GF_FileIO * | fileio | ) |
Gets URL of a fileIO object. The url uses the protocol scheme "gfio://"
fileio | target file IO object |
Gets a fileIO object from memory - the resulting fileIO can only be opened once at any time but can be closed/reopen.
URL | of source data, may be null |
data | memory, must be valid until next close |
size | memory size |
void gf_fileio_set_stats | ( | GF_FileIO * | fileio, |
u64 | bytes_done, | ||
u64 | file_size, | ||
GF_FileIOCacheState | cache_state, | ||
u32 | bytes_per_sec | ||
) |
Sets statistics on a fileIO object.
fileio | target file IO object |
bytes_done | number of bytes fetched for this file |
file_size | total size of this file, 0 if unknown |
cache_state | if GF_TRUE, means the file is completely available |
bytes_per_sec | reception bytes per second, 0 if unknown |
Bool gf_fileio_get_stats | ( | GF_FileIO * | fileio, |
u64 * | bytes_done, | ||
u64 * | file_size, | ||
GF_FileIOCacheState * | cache_state, | ||
u32 * | bytes_per_sec | ||
) |
Gets statistics on a fileIO object.
fileio | target file IO object |
bytes_done | number of bytes fetched for this file (may be NULL) |
file_size | total size of this file, 0 if unknown (may be NULL) |
cache_state | set to caching state for this object (may be NULL) |
bytes_per_sec | reception bytes per second, 0 if unknown (may be NULL) |
void gf_fileio_set_write_state | ( | GF_FileIO * | fileio, |
GF_FileIOWriteState | write_state | ||
) |
Sets write state of a fileIO object.
fileio | target file IO object |
write_state | the state to set |
GF_FileIO* gf_fileio_open_url | ( | GF_FileIO * | fileio, |
const char * | url, | ||
const char * | mode, | ||
GF_Err * | out_err | ||
) |
Checks if a FileIO object can write
fileio | target file IO object |
url | the original resource URL to open |
mode | the desired open mode |
out_err | set to error code if any, must not be NULL |
Tags a FileIO object to be accessed from main thread only
fileio | target file IO object |
Bool gf_fileio_is_main_thread | ( | const char * | url | ) |
Check if a FileIO object is to be accessed from main thread only
url | target url |
GF_FileIO* gf_fileio_from_url | ( | const char * | url | ) |
Gets GF_FileIO object from its URL The url uses the protocol scheme "gfio://"
url | the URL of the File IO object |
const char* gf_fileio_factory | ( | GF_FileIO * | fileio, |
const char * | new_res_url | ||
) |
Constructs a new GF_FileIO object from a URL The url can be absolute or relative to the parent GF_FileIO. This is typcically needed by filters (dash input, dasher, NHML/NHNT writers...) generating or consuming additional files associated with the main file IO object but being written or read by other filters. The function will not open the associated resource, only create the file IO wrapper for later usage If you need to create a new fileIO to be opened immediately, use gf_fopen_ex.
fileio | parent file IO object |
new_res_url | the original URL of the new object to create |
const char* gf_fileio_translate_url | ( | const char * | url | ) |
const char* gf_fileio_resource_url | ( | GF_FileIO * | fileio | ) |
Gets a FileIO original resource URL
fileio | target file IO object |
Checks if a FileIO object can read
fileio | target file IO object |