2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / common tools sub-project
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
25 #ifndef _GF_TOOLS_H_
\r
26 #define _GF_TOOLS_H_
\r
32 #include <gpac/setup.h>
\r
35 /*! \file "gpac/tools.h"
\r
36 * \brief Base definitions and functions of GPAC.
\r
38 * This file contains basic functions and core definitions of the GPAC framework. This file is
\r
39 * usually included by all GPAC header files since it contains the error definitions.
\r
42 /*! \defgroup utils_grp utils
\r
43 * You will find in this module the documentation of all tools used in GPAC.
\r
46 /*! \addtogroup tools_grp base utils
\r
47 * \ingroup utils_grp
\r
48 * \brief Base definitions and functions of GPAC.
\r
50 * This section documents some very basic functions and core definitions of the GPAC framework.
\r
55 * \brief GPAC Version
\r
58 * Macro giving GPAC version expressed as a printable string
\r
60 /*KEEP SPACE SEPARATORS FOR MAKE / GREP (SEE MAIN MAKEFILE)!!!, and NO SPACE in GPAC_VERSION for proper install*/
\r
61 #define GPAC_VERSION "0.4.6-DEV"
\r
63 #define GPAC_BUILD_NUMBER "1"
\r
64 #define GPAC_FULL_VERSION GPAC_VERSION" (build "GPAC_BUILD_NUMBER")"
\r
67 * \brief GPAC Version
\r
70 * Macro giving GPAC version expressed as an integer, where version X.Y.Z is coded as 0x00XXYYZZ
\r
72 #define GPAC_VERSION_INT 0x00000406
\r
75 * \brief Memory allocation
\r
78 * Macro allocating memory and zero-ing it
\r
80 #define GF_SAFEALLOC(__ptr, __struct) { __ptr = (__struct *) malloc(sizeof(__struct)); if (__ptr) memset((void *) __ptr, 0, sizeof(__struct)); }
\r
83 * \brief 4CC Formatting
\r
86 * Macro formating a 4-character code (or 4CC) "abcd" as 0xAABBCCDD
\r
88 #define GF_4CC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
\r
90 * \brief 4CC Printing
\r
92 * returns a 4CC printable form
\r
94 const char *gf_4cc_to_str(u32 type);
\r
97 * \brief large file opening
\r
99 * Opens a large file (>4GB)
\r
100 * \param file_name Same semantics as fopen
\r
101 * \param mode Same semantics as fopen
\r
102 * \return stream handle of the file object
\r
103 * \note You only need to call this function if you're suspecting the file to be a large one (usually only media files), otherwise use regular stdio.
\r
105 FILE *gf_f64_open(const char *file_name, const char *mode);
\r
107 * \brief large file position query
\r
109 * Queries the current read/write position in a large file
\r
110 * \param f Same semantics as ftell
\r
111 * \return position in the file
\r
112 * \note You only need to call this function if you're suspecting the file to be a large one (usually only media files), otherwise use regular stdio.
\r
114 u64 gf_f64_tell(FILE *f);
\r
116 * \brief large file seeking
\r
118 * Seeks the current read/write position in a large file
\r
119 * \param f Same semantics as fseek
\r
120 * \param pos Same semantics as fseek
\r
121 * \param whence Same semantics as fseek
\r
122 * \return new position in the file
\r
123 * \note You only need to call this function if you're suspecting the file to be a large one (usually only media files), otherwise use regular stdio.
\r
125 u64 gf_f64_seek(FILE *f, s64 pos, s32 whence);
\r
130 /*! \addtogroup errors_grp error codes
\r
131 * \ingroup utils_grp
\r
132 * \brief Errors used in GPAC.
\r
134 * This section documents all error codes used in the GPAC framework. Most of the GPAC's functions will use these as
\r
135 * return values, and some of these errors are also used for state communication with the different modules of the framework.
\r
143 * positive values are warning and info, 0 means no error and negative values are errors
\r
147 /*!Message from any scripting engine used in the presentation (ECMAScript, MPEG-J, ...) (Info).*/
\r
148 GF_SCRIPT_INFO = 3,
\r
149 /*!Indicates an data frame has several AU packed (not MPEG-4 compliant). This is used by decoders to force
\r
150 multiple decoding of the same data frame (Info).*/
\r
151 GF_PACKED_FRAMES = 2,
\r
152 /*!Indicates the end of a stream or of a file (Info).*/
\r
157 /*!Operation success (no error).*/
\r
160 /*!One of the input parameter is not correct or cannot be used in the current operating mode of the framework.*/
\r
162 /*! Memory allocation failure.*/
\r
163 GF_OUT_OF_MEM = -2,
\r
164 /*! Input/Output failure (disk access, system call failures)*/
\r
166 /*! The desired feature or operation is not supported by the framework*/
\r
167 GF_NOT_SUPPORTED = -4,
\r
168 /*! Input data has been corrupted*/
\r
169 GF_CORRUPTED_DATA = -5,
\r
170 /*! A modification was attempted on a scene node which could not be found*/
\r
171 GF_SG_UNKNOWN_NODE = -6,
\r
172 /*! The PROTO node interface does not match the nodes using it*/
\r
173 GF_SG_INVALID_PROTO = -7,
\r
174 /*! An error occured in the scripting engine*/
\r
175 GF_SCRIPT_ERROR = -8,
\r
176 /*! Buffer is too small to contain decoded data. Decoders shall use this error whenever they need to resize their output memory buffers*/
\r
177 GF_BUFFER_TOO_SMALL = -9,
\r
178 /*! Bitstream is not compliant to the specfication it refers to*/
\r
179 GF_NON_COMPLIANT_BITSTREAM = -10,
\r
180 /*! No decoders could be found to handle the desired media type*/
\r
181 GF_CODEC_NOT_FOUND = -11,
\r
182 /*! The URL is not properly formatted or cannot be found*/
\r
183 GF_URL_ERROR = -12,
\r
184 /*! An service error has occured at the local side*/
\r
185 GF_SERVICE_ERROR = -13,
\r
186 /*! A service error has occured at the remote (server) side*/
\r
187 GF_REMOTE_SERVICE_ERROR = -14,
\r
188 /*! The desired stream could not be found in the service*/
\r
189 GF_STREAM_NOT_FOUND = -15,
\r
190 /*! The IsoMedia file is not a valid one*/
\r
191 GF_ISOM_INVALID_FILE = -20,
\r
192 /*! The IsoMedia file is not complete. Either the file is being downloaded, or it has been truncated*/
\r
193 GF_ISOM_INCOMPLETE_FILE = -21,
\r
194 /*! The media in this IsoMedia track is not valid (usually due to a broken stream description)*/
\r
195 GF_ISOM_INVALID_MEDIA = -22,
\r
196 /*! The requested operation cannot happen in the current opening mode of the IsoMedia file*/
\r
197 GF_ISOM_INVALID_MODE = -23,
\r
198 /*! This IsoMedia track refers to media outside the file in an unknown way*/
\r
199 GF_ISOM_UNKNOWN_DATA_REF = -24,
\r
201 /*! An invalid MPEG-4 Object Descriptor was found*/
\r
202 GF_ODF_INVALID_DESCRIPTOR = -30,
\r
203 /*! An MPEG-4 Object Descriptor was found or added to a forbidden descriptor*/
\r
204 GF_ODF_FORBIDDEN_DESCRIPTOR = -31,
\r
205 /*! An invalid MPEG-4 BIFS command was detected*/
\r
206 GF_ODF_INVALID_COMMAND = -32,
\r
207 /*! The scene has been encoded using an unknown BIFS version*/
\r
208 GF_BIFS_UNKNOWN_VERSION = -33,
\r
210 /*! The remote IP address could not be solved*/
\r
211 GF_IP_ADDRESS_NOT_FOUND = -40,
\r
212 /*! The connection to the remote peer has failed*/
\r
213 GF_IP_CONNECTION_FAILURE = -41,
\r
214 /*! The network operation has failed*/
\r
215 GF_IP_NETWORK_FAILURE = -42,
\r
216 /*! The network connection has been closed*/
\r
217 GF_IP_CONNECTION_CLOSED = -43,
\r
218 /*! The network operation has failed because no data is available*/
\r
219 GF_IP_NETWORK_EMPTY = -44,
\r
220 /*! The network operation has been discarded because it would be a blocking one*/
\r
221 GF_IP_SOCK_WOULD_BLOCK = -45,
\r
222 /*! UDP connection did not receive any data at all. Signaled by client services to reconfigure network if possible*/
\r
223 GF_IP_UDP_TIMEOUT = -46,
\r
225 /*! Authentication with the remote host has failed*/
\r
226 GF_AUTHENTICATION_FAILURE = -50,
\r
227 /*! Script not ready for playback */
\r
228 GF_SCRIPT_NOT_READY = -51,
\r
232 * \brief Error Printing
\r
234 * Returns a printable version of a given error
\r
235 * \param e Error code requested
\r
236 * \return String representing the error
\r
238 const char *gf_error_to_string(GF_Err e);
\r
242 /*! \addtogroup log_grp logging tools
\r
243 * \ingroup utils_grp
\r
251 * These levels describes messages priority used when filtering logs
\r
255 /*! Log message describes an error*/
\r
257 /*! Log message describes a warning*/
\r
259 /*! Log message is informational (state, etc..)*/
\r
261 /*! Log message is a debug info*/
\r
266 * \brief Log level assignment
\r
268 * Sets the level used for log filtering. By default no log is performed
\r
269 * \param level log level used.
\r
272 void gf_log_set_level(u32 level);
\r
279 * These flags describes which sub-part of GPAC generates the log and are used when filtering logs
\r
283 /*! Log message from the core library (init, threads, network calls, etc)*/
\r
285 /*! Log message from a raw media parser (BIFS, LASeR, A/V formats)*/
\r
286 GF_LOG_CODING= 1<<1,
\r
287 /*! Log message from a bitstream parser (IsoMedia, MPEG-2 TS, OGG, ...)*/
\r
288 GF_LOG_CONTAINER = 1<<2,
\r
289 /*! Log message from the network/service stack (messages & co)*/
\r
290 GF_LOG_NETWORK = 1<<3,
\r
291 /*! Log message from the RTP/RTCP stack (TS info) and packet structure & hinting (debug)*/
\r
293 /*! Log message from authoring subsystem (file manip, import/export)*/
\r
294 GF_LOG_AUTHOR = 1<<5,
\r
295 /*! Log message from the sync layer of the terminal*/
\r
296 GF_LOG_SYNC = 1<<6,
\r
297 /*! Log message from a codec*/
\r
298 GF_LOG_CODEC = 1<<7,
\r
299 /*! Log message from any XML parser (context loading, etc)*/
\r
300 GF_LOG_PARSER = 1<<8,
\r
301 /*! Log message from the terminal/compositor, indicating media object state*/
\r
302 GF_LOG_MEDIA = 1<<9,
\r
303 /*! Log message from the scene graph/scene manager (handling of nodes and attribute modif, DOM core)*/
\r
304 GF_LOG_SCENE = 1<<10,
\r
305 /*! Log message from the scripting engine*/
\r
306 GF_LOG_SCRIPT = 1<<11,
\r
307 /*! Log message from event handling*/
\r
308 GF_LOG_INTERACT = 1<<12,
\r
309 /*! Log message from compositor*/
\r
310 GF_LOG_COMPOSE = 1<<13,
\r
311 /*! Log for video object cache */
\r
312 GF_LOG_CACHE = 1<<14,
\r
313 /*! Log message from multimedia I/O devices (audio/video input/output, ...)*/
\r
314 GF_LOG_MMIO = 1<<15,
\r
315 /*! Log for runtime info (times, memory, CPU usage)*/
\r
316 GF_LOG_RTI = 1<<16,
\r
317 /*! Log for SMIL timing and animation*/
\r
318 GF_LOG_SMIL = 1<<17,
\r
323 * \brief Log modules assignment
\r
325 * Sets the modules to be checked for log filtering. By default no modules are logged.
\r
326 * \param tools log tools filtered. This is an OR'ed combinaison of log module flags
\r
329 void gf_log_set_tools(u32 tools);
\r
332 * \brief Log Message Callback
\r
334 * The gf_log_cbk type is the type for the callback of the \ref gf_log_set_callback function. By default all logs are redirected to stdout
\r
335 * \param cbck Opaque user data.
\r
336 * \param log_level level of the log. This value is not guaranteed in multi-threaded context.
\r
337 * \param log_tool tool emitting the log. This value is not guaranteed in multi-threaded context.
\r
338 * \param fmt message log format.
\r
339 * \param vlist message log param.
\r
342 typedef void (*gf_log_cbk)(void *cbck, u32 log_level, u32 log_tool, const char* fmt, va_list vlist);
\r
345 * \brief Log overwrite
\r
347 * Assigns a user-defined callback for printing log messages. By default all logs are redirected to stdout
\r
348 * \param usr_cbk Opaque user data
\r
349 * \param cbk callback log function
\r
350 * \return previous callback function
\r
352 gf_log_cbk gf_log_set_callback(void *usr_cbk, gf_log_cbk cbk);
\r
355 \cond DUMMY_DOXY_SECTION
\r
358 #ifndef GPAC_DISABLE_LOG
\r
360 to turn log on, change to GPAC_ENABLE_LOG
\r
361 to turn log off, change to GPAC_DISABLE_LOG
\r
362 this is needed by configure+sed to modify this file directly
\r
364 #define GPAC_ENABLE_LOG
\r
372 /*this is all a bit ugly, but most compilers don't properly handle variadic macros...*/
\r
373 void gf_log(const char *fmt, ...);
\r
374 void gf_log_lt(u32 ll, u32 lt);
\r
376 u32 gf_log_get_level();
\r
377 u32 gf_log_get_tools();
\r
379 #ifdef GPAC_DISABLE_LOG
\r
380 #define GF_LOG(_ll, _lm, __args)
\r
383 * \brief Message logging
\r
386 * Macro for logging messages. Usage is GF_LOG(log_lev, log_module, (fmt, ...)). The log function is only called if log filtering allows it. This avoids fetching logged parameters when the tool is not being logged.
\r
388 #define GF_LOG(_log_level, _log_tools, __args) if ((gf_log_get_level() >= (_log_level)) && (gf_log_get_tools() & (_log_tools))) { gf_log_lt(_log_level, _log_tools); gf_log __args ;}
\r
394 /*! \addtogroup tools_grp
\r
400 * \brief PseudoRandom Integer Generation Initialization
\r
402 * Sets the starting point for generating a series of pseudorandom integers.
\r
403 * \param Reset Re-initializes the random number generator
\r
405 void gf_rand_init(Bool Reset);
\r
407 * \brief PseudoRandom Integer Generation
\r
409 * Returns a pseudorandom integer.
\r
414 * \brief user name
\r
416 * Gets current user (login) name.
\r
418 void gf_get_user_name(char *buf, u32 buf_size);
\r
421 * \brief Directory Enumeration Callback
\r
423 * The gf_enum_dir_item type is the type for the callback of the \ref gf_enum_directory function
\r
424 * \param cbck Opaque user data.
\r
425 * \param item_name File or directory name.
\r
426 * \param item_path File or directory full path and name from filesystem root.
\r
427 * \return 1 to abort enumeration, 0 to continue enumeration.
\r
430 typedef Bool (*gf_enum_dir_item)(void *cbck, char *item_name, char *item_path);
\r
432 * \brief Directory enumeration
\r
434 * Enumerates a directory content. Feedback is provided by the enum_dir_item function
\r
435 * \param dir Directory to enumerate
\r
436 * \param enum_directory If set, only directories will be enumerated, otherwise only files are.
\r
437 * \param enum_dir \ref gf_enum_dir_item callback function for enumeration.
\r
438 * \param cbck Opaque user data passed to callback function.
\r
439 * \param filter optional filter for file extensions. If a file extension without the dot '.' character is not found in the
\r
440 * filter the file will be skipped.
\r
442 GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir, void *cbck, const char *filter);
\r
446 * \brief File Deletion
\r
448 * Deletes a file from the disk.
\r
449 * \param fileName absolute name of the file or name relative to the current working directory.
\r
451 void gf_delete_file(char *fileName);
\r
453 * \brief File Deletion
\r
455 * Creates a new temporary file in binary mode
\r
456 * \return stream handle to the new file ressoucre
\r
458 FILE *gf_temp_file_new();
\r
462 * \brief Progress formatting
\r
464 * Signals progress in GPAC's operations. Note that progress signaling with this function is not thread-safe, the main purpose is to use it for authoring tools only.
\r
465 * \param title title string of the progress, or NULL for no progress
\r
466 * \param done Current amount performed of the action.
\r
467 * \param total Total amount of the action.
\r
469 void gf_set_progress(char *title, u32 done, u32 total);
\r
472 * \brief Progress Callback
\r
474 * The gf_on_progress_cbk type is the type for the callback of the \ref gf_set_progress_callback function
\r
475 * \param cbck Opaque user data.
\r
476 * \param title preogress title.
\r
477 * \param done Current amount performed of the action
\r
478 * \param total Total amount of the action.
\r
481 typedef void (*gf_on_progress_cbk)(void *cbck, char *title, u32 done, u32 total);
\r
484 * \brief Progress overwriting
\r
486 * Iverwrites the progress signaling function by a user-defined one.
\r
487 * \param user_cbk Opaque user data
\r
488 * \param prog_cbk new callback function to use. Passing NULL restore default GPAC stdout notification.
\r
490 void gf_set_progress_callback(void *user_cbk, gf_on_progress_cbk prog_cbk);
\r
494 * \brief Prompt checking
\r
496 * Checks if a character is pending in the prompt buffer.
\r
497 * \return 1 if a character is ready to be fetched, 0 otherwise.
\r
498 * \note Function not available under WindowsCE nor SymbianOS
\r
500 Bool gf_prompt_has_input();
\r
503 * \brief Prompt character flush
\r
505 * Returns the current character entered at prompt if any.
\r
506 * \return value of the character.
\r
507 * \note Function not available under WindowsCE nor SymbianOS
\r
509 char gf_prompt_get_char();
\r
513 * \brief turns prompt echo on/off
\r
515 * Turns the prompt character echo on/off - this is usefull when entering passwords.
\r
516 * \param echo_off indicates whether echo should be turned on or off.
\r
517 * \note Function not available under WindowsCE nor SymbianOS
\r
519 void gf_prompt_set_echo_off(Bool echo_off);
\r
522 *\addtogroup cpu_grp Time tools
\r
523 *\ingroup utils_grp
\r
524 *\brief System time and CPU functions
\r
526 *This section documents time functionalities and CPU management in GPAC.
\r
532 * \brief System setup
\r
534 * Inits the system high-resolution clock if any, and CPU usage manager. It is strongly recommended to call this
\r
535 * function before calling any other GPAC functions, since on some systems (like winCE) it may result in a better memory usage estimation.
\r
536 * \note This can be called several times but only the first call will result in system setup.
\r
538 void gf_sys_init();
\r
540 * \brief System closing
\r
542 * Closes the system high-resolution clock and any CPU associated ressources.
\r
543 * \note This can be called several times but the system will be closed when no more users are counted.
\r
545 void gf_sys_close();
\r
547 * \brief System clock query
\r
549 * Gets the system clock time.
\r
550 * \return System clock value since initialization in milliseconds.
\r
552 u32 gf_sys_clock();
\r
555 * \brief Sleeps thread/process
\r
557 * Locks calling thread/process execution for a given time.
\r
558 * \param ms Amount of time to sleep in milliseconds.
\r
560 void gf_sleep(u32 ms);
\r
563 * \brief CRC32 compute
\r
565 * Computes the CRC32 value of a buffer.
\r
566 * \param data buffer
\r
567 * \param size buffer size
\r
568 * \return computed CRC32
\r
570 u32 gf_crc_32(char *data, u32 size);
\r
573 /*!\brief run-time system info object
\r
575 *The Run-Time Info object is used to get CPU and memory occupation of the calling process.
\r
576 *All time values are expressed in milliseconds (accuracy is not guaranteed).
\r
580 /*!start of the sampling period*/
\r
581 u32 sampling_instant;
\r
582 /*!duration of the sampling period*/
\r
583 u32 sampling_period_duration;
\r
584 /*!total amount of time (User+kernel) spent in CPU for all processes as evaluated at the end of the sampling period*/
\r
585 u32 total_cpu_time;
\r
586 /*!total amount of time (User+kernel) spent in CPU for the calling process as evaluated at the end of the sampling period*/
\r
587 u32 process_cpu_time;
\r
588 /*!amount of time (User+kernel) spent in CPU for all processes during the sampling period*/
\r
589 u32 total_cpu_time_diff;
\r
590 /*!total amount of time (User+kernel) spent in CPU for the calling process during the sampling period*/
\r
591 u32 process_cpu_time_diff;
\r
592 /*!total amount of idle time during the sampling period.*/
\r
594 /*!percentage (from 0 to 100) of CPU usage during the sampling period.*/
\r
595 u32 total_cpu_usage;
\r
596 /*!percentage (from 0 to 100) of the CPU usage by the calling process during the sampling period.*/
\r
597 u32 process_cpu_usage;
\r
598 /*!calling process ID*/
\r
600 /*!calling process thread count if known*/
\r
602 /*!size of calling process allocated heaps*/
\r
603 u64 process_memory;
\r
604 /*!total physical memory in system*/
\r
605 u64 physical_memory;
\r
606 /*!available physical memory in system*/
\r
607 u64 physical_memory_avail;
\r
608 /*!total memory currently allocated by gpac*/
\r
613 * Selection flags for run-time info retrieval
\r
618 /*!Indicates all processes' times must be fetched. If not set, only the current process times will be retrieved, and the
\r
619 thread count and total times won't be available*/
\r
620 GF_RTI_ALL_PROCESSES_TIMES = 1,
\r
621 /*!Indicates the process allocated heap size must be fetch. If not set, only the system physical memory is fetched.
\r
622 Fetching the entire ocess allocated memory can have a large impact on performances*/
\r
623 GF_RTI_PROCESS_MEMORY = 1<<1,
\r
624 /*!Indicates that only system memory should be fetched. When set, all refreshing info is ignored*/
\r
625 GF_RTI_SYSTEM_MEMORY_ONLY = 1<<2,
\r
629 * \brief Gets Run-Time info
\r
631 * Gets CPU and memory usage info for the calling process and the system. Information gathering
\r
632 * is controled through timeout values.
\r
633 * \param refresh_time_ms refresh time period in milliseconds. If the last sampling was done less than this period ago, the run-time info is not refreshed.
\r
634 * \param rti holder to the run-time info structure to update.
\r
635 * \param flags specify which info is to be retrieved.
\r
636 * \return 1 if info has been updated, 0 otherwise.
\r
637 * \note You should not try to use a too small refresh time. Typical values are 500 ms or one second.
\r
639 Bool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags);
\r
642 Bool gf_sys_get_battery_state(Bool *onBattery, u32 *onCharge, u32 *level);
\r
654 #endif /*_GF_CORE_H_*/
\r