Coverage Report

Created: 2026-02-26 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gpac/include/gpac/tools.h
Line
Count
Source
1
/*
2
 *      GPAC - Multimedia Framework C SDK
3
 *
4
 *      Authors: Jean Le Feuvre
5
 *      Copyright (c) Telecom ParisTech 2000-2025
6
 *          All rights reserved
7
 *
8
 *  This file is part of GPAC / common tools sub-project
9
 *
10
 *  GPAC is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU Lesser General Public License as published by
12
 *  the Free Software Foundation; either version 2, or (at your option)
13
 *  any later version.
14
 *
15
 *  GPAC is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Lesser General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Lesser General Public
21
 *  License along with this library; see the file COPYING.  If not, write to
22
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
 *
24
 */
25
26
#ifndef _GF_TOOLS_H_
27
#define _GF_TOOLS_H_
28
29
#ifdef __cplusplus
30
extern "C" {
31
#endif
32
33
#include <gpac/setup.h>
34
#include <gpac/version.h>
35
#include <time.h>
36
37
38
/*!
39
\file "gpac/tools.h"
40
\brief Core definitions and tools of GPAC.
41
42
This file contains basic functions and core definitions of the GPAC framework. This file is
43
usually included by all GPAC header files since it contains the error definitions.
44
*/
45
46
/*!
47
\addtogroup utils_grp Core Tools
48
\brief Core definitions and tools of GPAC.
49
50
You will find in this module the documentation of the core tools used in GPAC.
51
*/
52
53
/*!
54
\addtogroup setup_grp
55
@{
56
 */
57
58
/*!
59
\brief Stringizer
60
\hideinitializer
61
62
Macro transforming its input name into a string
63
*/
64
#define gf_stringizer(x) #x
65
66
/*!
67
\brief 4CC Formatting
68
\hideinitializer
69
70
Macro formatting a 4-character code (or 4CC) "abcd" as 0xAABBCCDD
71
*/
72
#ifndef GF_4CC
73
2.93M
#define GF_4CC(a,b,c,d) ((((u32)a)<<24)|(((u32)b)<<16)|(((u32)c)<<8)|((u32)d))
74
#endif
75
76
/*! Macro formatting 4CC from compiler-constant string of 4 characters
77
\hideinitializer
78
 */
79
0
#define GF_4CC_CSTR(s) GF_4CC(s[0],s[1],s[2],s[3])
80
81
/*! minimum buffer size to hold any 4CC in string format*/
82
0
#define GF_4CC_MSIZE  10
83
84
/*! converts four character code to string
85
\param type a four character code
86
\return a printable form of the code
87
*/
88
const char *gf_4cc_to_str(u32 type);
89
90
/*! converts four character code to string in the provided buffer - thread-safe version of \ref gf_4cc_to_str
91
\param type a four character code
92
\param szType buffer to write the code to
93
\return the onput buffer
94
*/
95
const char *gf_4cc_to_str_safe(u32 type, char szType[GF_4CC_MSIZE]);
96
97
/*! converts a 4CC string to its 32 bits value
98
\param val  four character string
99
\return code value or 0 if error
100
*/
101
u32 gf_4cc_parse(const char *val);
102
103
/*! @} */
104
105
/*!
106
\addtogroup errors_grp
107
\brief Error Types
108
109
This section documents all error codes used in the GPAC framework. Most of the GPAC's functions will use these as
110
 return values, and some of these errors are also used for state communication with the different modules of the framework.
111
112
@{
113
 */
114
115
/*! GPAC Error
116
\hideinitializer
117
118
Positive values are warning and info, 0 means no error and negative values are errors
119
 */
120
typedef enum
121
{
122
  /*!Message from any scripting engine used in the presentation (ECMAScript, MPEG-J, ...) (Info).*/
123
  GF_SCRIPT_INFO                                          = 3,
124
  /*!Indicates a send packet is not dispatched due to pending connections.*/
125
  GF_PENDING_PACKET         = 2,
126
  /*!Indicates the end of a stream or of a file (Info).*/
127
  GF_EOS                = 1,
128
  /*!
129
  \n\n
130
  */
131
  /*!Operation success (no error).*/
132
  GF_OK               = 0,
133
  /*!\n*/
134
  /*!One of the input parameter is not correct or cannot be used in the current operating mode of the framework.*/
135
  GF_BAD_PARAM              = -1,
136
  /*! Memory allocation failure.*/
137
  GF_OUT_OF_MEM             = -2,
138
  /*! Input/Output failure (disk access, system call failures)*/
139
  GF_IO_ERR               = -3,
140
  /*! The desired feature or operation is not supported by the framework*/
141
  GF_NOT_SUPPORTED            = -4,
142
  /*! Input data has been corrupted*/
143
  GF_CORRUPTED_DATA           = -5,
144
  /*! A modification was attempted on a scene node which could not be found*/
145
  GF_SG_UNKNOWN_NODE            = -6,
146
  /*! The PROTO node interface does not match the nodes using it*/
147
  GF_SG_INVALID_PROTO           = -7,
148
  /*! An error occured in the scripting engine*/
149
  GF_SCRIPT_ERROR             = -8,
150
  /*! Buffer is too small to contain decoded data. Decoders shall use this error whenever they need to resize their output memory buffers*/
151
  GF_BUFFER_TOO_SMALL           = -9,
152
  /*! The bitstream is not compliant to the specification it refers to*/
153
  GF_NON_COMPLIANT_BITSTREAM        = -10,
154
  /*! No filter could be found to handle the desired media type*/
155
  GF_FILTER_NOT_FOUND           = -11,
156
  /*! The URL is not properly formatted or cannot be found*/
157
  GF_URL_ERROR              = -12,
158
  /*! An service error has occured at the local side*/
159
  GF_SERVICE_ERROR            = -13,
160
  /*! A service error has occured at the remote (server) side*/
161
  GF_REMOTE_SERVICE_ERROR         = -14,
162
  /*! The desired stream could not be found in the service*/
163
  GF_STREAM_NOT_FOUND           = -15,
164
    /*! The URL no longer exists*/
165
    GF_URL_REMOVED                          = -16,
166
167
  /*! The IsoMedia file is not a valid one*/
168
  GF_ISOM_INVALID_FILE          = -20,
169
  /*! The IsoMedia file is not complete. Either the file is being downloaded, or it has been truncated*/
170
  GF_ISOM_INCOMPLETE_FILE         = -21,
171
  /*! The media in this IsoMedia track is not valid (usually due to a broken stream description)*/
172
  GF_ISOM_INVALID_MEDIA         = -22,
173
  /*! The requested operation cannot happen in the current opening mode of the IsoMedia file*/
174
  GF_ISOM_INVALID_MODE          = -23,
175
  /*! This IsoMedia track refers to media outside the file in an unknown way*/
176
  GF_ISOM_UNKNOWN_DATA_REF        = -24,
177
178
  /*! An invalid MPEG-4 Object Descriptor was found*/
179
  GF_ODF_INVALID_DESCRIPTOR       = -30,
180
  /*! An MPEG-4 Object Descriptor was found or added to a forbidden descriptor*/
181
  GF_ODF_FORBIDDEN_DESCRIPTOR       = -31,
182
  /*! An invalid MPEG-4 BIFS command was detected*/
183
  GF_ODF_INVALID_COMMAND          = -32,
184
  /*! The scene has been encoded using an unknown BIFS version*/
185
  GF_BIFS_UNKNOWN_VERSION         = -33,
186
187
  /*! The remote IP address could not be solved*/
188
  GF_IP_ADDRESS_NOT_FOUND         = -40,
189
  /*! The connection to the remote peer has failed*/
190
  GF_IP_CONNECTION_FAILURE        = -41,
191
  /*! The network operation has failed*/
192
  GF_IP_NETWORK_FAILURE         = -42,
193
  /*! The network connection has been closed*/
194
  GF_IP_CONNECTION_CLOSED         = -43,
195
  /*! The network operation has failed because no data is available*/
196
  GF_IP_NETWORK_EMPTY           = -44,
197
198
  /*! UDP connection did not receive any data at all. Signaled by client services to reconfigure network if possible*/
199
  GF_IP_UDP_TIMEOUT           = -46,
200
201
  /*! Authentication with the remote host has failed*/
202
  GF_AUTHENTICATION_FAILURE       = -50,
203
  /*! Not ready for execution, later retry is needed */
204
  GF_NOT_READY            = -51,
205
  /*! Bad configuration for the current context */
206
  GF_INVALID_CONFIGURATION        = -52,
207
  /*! The element has not been found */
208
  GF_NOT_FOUND              = -53,
209
  /*! Unexpected format of data */
210
  GF_PROFILE_NOT_SUPPORTED        = -54,
211
  /*! filter PID config requires new instance of filter */
212
  GF_REQUIRES_NEW_INSTANCE = -56,
213
  /*! filter PID config cannot be supported by this filter, no use trying to find an alternate input filter chain*/
214
  GF_FILTER_NOT_SUPPORTED = -57,
215
  /*! server does not support range requests: response with status=200 to a request with byte range*/
216
  GF_IO_BYTE_RANGE_NOT_SUPPORTED = -58,
217
} GF_Err;
218
219
/*!
220
\brief Error Printing
221
222
Returns a printable version of a given error
223
\param e Error code requested
224
\return String representing the error
225
*/
226
const char *gf_error_to_string(GF_Err e);
227
228
/*! @} */
229
230
231
/*!
232
\addtogroup mem_grp
233
@{
234
 */
235
236
/*!
237
\brief Memory allocation for a structure
238
\hideinitializer
239
240
Macro allocating memory and zero-ing it
241
*/
242
63.9M
#define GF_SAFEALLOC(__ptr, __struct) {\
243
63.9M
    (__ptr) = (__struct *) gf_malloc(sizeof(__struct));\
244
63.9M
    if (__ptr) {\
245
63.9M
      memset((void *) (__ptr), 0, sizeof(__struct));\
246
63.9M
    }\
247
63.9M
  }
248
249
/*!
250
\brief Memory allocation for an array of n structs
251
\hideinitializer
252
253
Macro allocating memory for n structures and zero-ing it
254
*/
255
37.2k
#define GF_SAFE_ALLOC_N(__ptr, __n, __struct) {\
256
37.2k
    (__ptr) = (__struct *) gf_malloc( __n * sizeof(__struct));\
257
37.2k
    if (__ptr) {\
258
37.2k
      memset((void *) (__ptr), 0, __n * sizeof(__struct));\
259
37.2k
    }\
260
37.2k
  }
261
262
263
/*!
264
\brief dynamic string concatenation
265
266
Dynamic concatenation of string with optional separator
267
\param str pointer to destination string pointer
268
\param to_append string to append
269
\param sep optional separator string to insert before concatenation. If set and initial string is NULL, will not be appended
270
\return error code
271
 */
272
GF_Err gf_dynstrcat(char **str, const char *to_append, const char *sep);
273
274
275
/*!
276
\brief fraction parsing
277
278
Parse a 64 bit fraction from string
279
\param str string to parse
280
\param frac fraction to fill
281
\return GF_TRUE if success, GF_FALSE otherwise ( fraction being set to {0,0} )
282
 */
283
Bool gf_parse_lfrac(const char *str, GF_Fraction64 *frac);
284
285
/*!
286
\brief fraction parsing
287
288
Parse a 32 bit fraction from string
289
\param str string to parse
290
\param frac fraction to fill
291
\return GF_TRUE if success, GF_FALSE otherwise ( fraction being set to {0,0} )
292
 */
293
Bool gf_parse_frac(const char *str, GF_Fraction *frac);
294
295
/*!
296
\brief search string without case
297
298
Search a substring in a string without checking for case
299
\param text text to search
300
\param subtext string to find
301
\param subtext_len length of string to find
302
\return GF_TRUE if success, GF_FALSE otherwise
303
 */
304
Bool gf_strnistr(const char *text, const char *subtext, u32 subtext_len);
305
306
/*!
307
\brief search string in buffer
308
309
Search for a substring in a memory buffer of characters that may not be null-terminated
310
\param data buffer of chars in which to search
311
\param data_size size of data buffer
312
\param pat pattern to search for as a null-terminated string
313
\return a pointer to the first occurrence of pat in data, or null if not found (may not be null-terminated)
314
 */
315
const char* gf_strmemstr(const char *data, u32 data_size, const char *pat);
316
317
/*!
318
\brief safe timestamp rescale
319
320
Rescale a 64 bit timestamp value to new timescale, i.e. performs value * new_timescale / timescale
321
\param value value to rescale. A value of -1 means no timestamp defined and is returned unmodified
322
\param timescale timescale of value. Assumed to be less than 0xFFFFFFFF
323
\param new_timescale new timescale? Assumed to be less than 0xFFFFFFFF
324
\return new value
325
 */
326
u64 gf_timestamp_rescale(u64 value, u64 timescale, u64 new_timescale);
327
328
/*!
329
\brief safe signed timestamp rescale
330
331
Rescale a 64 bit timestamp value to new timescale, i.e. performs value * new_timescale / timescale
332
\param value value to rescale
333
\param timescale timescale of value. Assumed to be less than 0xFFFFFFFF
334
\param new_timescale new timescale. Assumed to be less than 0xFFFFFFFF
335
\return new value
336
 */
337
s64 gf_timestamp_rescale_signed(s64 value, u64 timescale, u64 new_timescale);
338
339
/*!
340
\brief compare timestamps
341
342
Compares two timestamps
343
\param value1 value to rescale
344
\param timescale1 timescale of value. Assumed to be less than 0xFFFFFFFF
345
\param value2 value to rescale
346
\param timescale2 timescale of value. Assumed to be less than 0xFFFFFFFF
347
\return GF_TRUE if (value1 / timescale1) is stricly less than (value2 / timescale2)
348
 */
349
Bool gf_timestamp_less(u64 value1, u64 timescale1, u64 value2, u64 timescale2);
350
351
/*!
352
\brief compare timestamps
353
354
Compares two timestamps
355
\param value1 value to rescale
356
\param timescale1 timescale of value. Assumed to be less than 0xFFFFFFFF
357
\param value2 value to rescale
358
\param timescale2 timescale of value. Assumed to be less than 0xFFFFFFFF
359
\return GF_TRUE if (value1 / timescale1) is stricly less than or equal to (value2 / timescale2)
360
 */
361
Bool gf_timestamp_less_or_equal(u64 value1, u64 timescale1, u64 value2, u64 timescale2);
362
363
/*!
364
\brief compare timestamps
365
366
Compares two timestamps
367
\param value1 value to rescale
368
\param timescale1 timescale of value. Assumed to be less than 0xFFFFFFFF
369
\param value2 value to rescale
370
\param timescale2 timescale of value. Assumed to be less than 0xFFFFFFFF
371
\return GF_TRUE if (value1 / timescale1) is stricly greater than (value2 / timescale2)
372
 */
373
Bool gf_timestamp_greater(u64 value1, u64 timescale1, u64 value2, u64 timescale2);
374
375
/*!
376
\brief compare timestamps
377
378
Compares two timestamps
379
\param value1 value to rescale
380
\param timescale1 timescale of value. Assumed to be less than 0xFFFFFFFF
381
\param value2 value to rescale
382
\param timescale2 timescale of value. Assumed to be less than 0xFFFFFFFF
383
\return GF_TRUE if (value1 / timescale1) is stricly greater than or equal to (value2 / timescale2)
384
 */
385
Bool gf_timestamp_greater_or_equal(u64 value1, u64 timescale1, u64 value2, u64 timescale2);
386
387
/*!
388
\brief compare timestamps
389
390
Compares two timestamps
391
\param value1 value to rescale
392
\param timescale1 timescale of value. Assumed to be less than 0xFFFFFFFF
393
\param value2 value to rescale
394
\param timescale2 timescale of value. Assumed to be less than 0xFFFFFFFF
395
\return GF_TRUE if (value1 / timescale1) is equal to (value2 / timescale2)
396
 */
397
Bool gf_timestamp_equal(u64 value1, u64 timescale1, u64 value2, u64 timescale2);
398
399
/*!
400
\brief strict convert str into integer
401
402
Validate and parse str into integer
403
\param str text to convert to integer
404
\param ans integer to fill
405
\return GF_TRUE if str represents an integer without any leading space nor extra chars
406
 */
407
Bool gf_strict_atoi(const char* str, s32* ans);
408
409
/*!
410
\brief strict convert str into unsigned integer
411
412
Validate and parse str into integer
413
\param str text to convert to integer
414
\param ans unsigned integer to fill
415
\return GF_TRUE if str represents an unsigned integer without any leading space nor extra chars
416
*/
417
Bool gf_strict_atoui(const char* str, u32* ans);
418
419
/*!
420
\brief formats a duration
421
422
Formats a duration into a string
423
\param dur duration expressed in timescale
424
\param timescale number of ticks per second in duration
425
\param szDur the buffer to format
426
\return the formated input buffer
427
*/
428
const char *gf_format_duration(u64 dur, u32 timescale, char szDur[100]);
429
430
/*!
431
\brief timecode type
432
 */
433
typedef struct
434
{
435
  Float max_fps;
436
  u16 n_frames;
437
  u8 hours, minutes, seconds;
438
  u8 drop_frame, negative;
439
  u8 counting_type;
440
} GF_TimeCode;
441
442
/*!
443
\brief formats a timecode
444
445
Formats a timecode into a string
446
\param tc timecode to format
447
\param szTimecode the buffer to format
448
\return the formated input buffer
449
*/
450
const char* gf_format_timecode(GF_TimeCode *tc, char szTimecode[100]);
451
452
/*!
453
\brief converts a timecode to timestamp
454
455
Converts a timecode to a timestamp in the given timescale
456
\param tc timecode to convert
457
\param timescale timescale to convert to
458
\return the timestamp in the given timescale
459
*/
460
u64 gf_timecode_to_timestamp(GF_TimeCode *tc, u32 timescale);
461
462
/*!
463
\brief compare timecodes
464
465
Compares two timecodes
466
\param value1 value to compare
467
\param value2 value to compare
468
\return GF_TRUE if value1 is stricly less than value2
469
 */
470
Bool gf_timecode_less(GF_TimeCode *value1, GF_TimeCode *value2);
471
472
/*!
473
\brief compare timecodes
474
475
Compares two timecodes
476
\param value1 value to compare
477
\param value2 value to compare
478
\return GF_TRUE if value1 is stricly less than or equal to value2
479
 */
480
Bool gf_timecode_less_or_equal(GF_TimeCode *value1, GF_TimeCode *value2);
481
482
/*!
483
\brief compare timecodes
484
485
Compares two timecodes
486
\param value1 value to compare
487
\param value2 value to compare
488
\return GF_TRUE if value1 is stricly greater than value2
489
 */
490
Bool gf_timecode_greater(GF_TimeCode *value1, GF_TimeCode *value2);
491
492
/*!
493
\brief compare timecodes
494
495
Compares two timecodes
496
\param value1 value to compare
497
\param value2 value to compare
498
\return GF_TRUE if value1 is stricly greater than or equal to value2
499
 */
500
Bool gf_timecode_greater_or_equal(GF_TimeCode *value1, GF_TimeCode *value2);
501
502
/*!
503
\brief compare timecodes
504
505
Compares two timecodes
506
\param value1 value to compare
507
\param value2 value to compare
508
\return GF_TRUE if value1 is equal to value2
509
 */
510
Bool gf_timecode_equal(GF_TimeCode *value1, GF_TimeCode *value2);
511
512
513
/*!
514
\brief Get CENC IV size
515
516
Get CENC IV size from a key info chunk
517
\param key_info CENC key info buffer
518
\param key_info_size CENC key info buffer size
519
\param key_idx index of key for multi-key cases, 0 otherwise
520
\param const_iv_size set to const IV size if const IV is used, otherwise set to 0 - can be NULL
521
\param const_iv set to const IV start in key_info buffer when constant IV is used, otherwise set to NULL - can be NULL
522
\return IV size in bytes if constant IV is not used, otherwise 0
523
 */
524
u8 gf_cenc_key_info_get_iv_size(const u8 *key_info, u32 key_info_size, u32 key_idx, u8 *const_iv_size, const u8 **const_iv);
525
526
/*!
527
\brief validate a CENC key info chunk
528
529
Checks whether a CENC key info chunk is valid or not
530
\param key_info CENC key info buffer
531
\param key_info_size CENC key info buffer size
532
\return GF_TRUE if this chunk looks like a CENC key info buffer, GF_FALSE otherwise
533
*/
534
Bool gf_cenc_validate_key_info(const u8 *key_info, u32 key_info_size);
535
536
/*! @} */
537
538
/*!
539
\addtogroup libsys_grp
540
\brief Library configuration
541
542
These functions are used to initialize, shutdown and configure libgpac.
543
544
The library shall be initialized using \ref gf_sys_init and terminated using gf_sys_close
545
546
The library can usually be configured from command line if your program uses \ref gf_sys_set_args.
547
548
The library can also be configured from your program using \ref gf_opts_set_key and related functions right after initializing the library.
549
550
For more information on configuration options, see \code gpac -hx core \endcode and https://wiki.gpac.io/Filters/core_options
551
552
For more information on filters configuration options, see https://wiki.gpac.io/Filters/Filters
553
554
@{
555
 */
556
557
/*!
558
Selection flags for memory tracker
559
\hideinitializer
560
 */
561
typedef enum
562
{
563
    /*! No memory tracking*/
564
    GF_MemTrackerNone = 0,
565
    /*! Memory tracking without backtrace*/
566
    GF_MemTrackerSimple,
567
    /*! Memory tracking with backtrace*/
568
    GF_MemTrackerBackTrace,
569
} GF_MemTrackerType;
570
571
/*!
572
\brief System setup
573
574
Inits system tools (GPAC global config, high-resolution clock if any, CPU usage manager, random number, ...).
575
576
You MUST call this function before calling any libgpac function, typically only once at startup.
577
578
The profile allows using a different global config file than the default, and may be a name (without / or \\) or point to an existing config file.
579
\note This can be called several times but only the first call will result in system setup.
580
581
\param mem_tracker_type memory tracking mode
582
\param profile name of the profile to load, NULL for default.
583
\return Error code if any
584
 */
585
GF_Err gf_sys_init(GF_MemTrackerType mem_tracker_type, const char *profile);
586
587
/*!
588
\brief System closing
589
590
Closes allocated system resources opened by \ref gf_sys_init.
591
\note This can be called several times but systems resources will be closed when no more users are accounted for.
592
593
When JavaScript APIs are loaded, the JS runtime is destroyed in this function call.
594
If your application needs to reload GPAC a second time after this, you MUST prevent JS runtime destruction otherwise the application will crash due to static JS class definitions refering to freed memory.
595
To prevent destruction, make sure you have called
596
 \code gf_opts_set_key("temp", "static-jsrt", "true"); \endcode
597
598
before calling \ref gf_sys_close. For example:
599
600
\code
601
gf_sys_init(GF_MemTrackerNone, NULL);
602
//run your code, eg a filter session
603
604
//prevent JSRT destruction
605
gf_opts_set_key("temp", "static-jsrt", "true");
606
gf_sys_close();
607
608
//The JSRT is still valid
609
610
gf_sys_init(GF_MemTrackerNone, NULL);
611
//run your code, eg another filter session
612
613
//do NOT prevent JSRT, parent app will exit after this call
614
gf_sys_close();
615
616
\endcode
617
618
 */
619
void gf_sys_close();
620
621
622
#if defined(GPAC_CONFIG_ANDROID)
623
624
/*!
625
\brief Android paths setup
626
627
Sets application data and external storage paths for android, to be called by JNI wrappers BEFORE \ref gf_sys_init is called.
628
If not set, default are:
629
- app_data is /data/data/io.gpac.gpac
630
- ext_storage is /sdcard
631
632
The default profile used on android is located in $ext_storage/GPAC/ if that directory exists, otherwise in $app_data/GPAC
633
634
\param app_data application data path, with no trailing path separator
635
\param ext_storage external storage location, with no trailing path separator
636
*/
637
void gf_sys_set_android_paths(const char *app_data, const char *ext_storage);
638
639
#endif // GPAC_CONFIG_ANDROID
640
641
642
/*!
643
\brief System arguments
644
645
Sets the user app arguments (used by GUI mode)
646
\param argc Number of arguments
647
\param argv Array of arguments - the first string is ignored (considered to be the executable name)
648
\return error code if any, GF_OK otherwise
649
 */
650
GF_Err gf_sys_set_args(s32 argc, const char **argv);
651
652
/*!
653
\brief Get number of args
654
655
Gets the number of argument of the user application if any
656
\return number of argument of the user application
657
 */
658
u32 gf_sys_get_argc();
659
660
/*!
661
\brief Get program arguments
662
663
Gets the arguments of the user application if any
664
\return  argument of the user application
665
 */
666
const char **gf_sys_get_argv();
667
668
/*!
669
\brief Get number of args
670
671
Gets the number of argument of the user application if any
672
\param arg Index of argument to retrieve
673
\return number of argument of the user application
674
 */
675
const char *gf_sys_get_arg(u32 arg);
676
677
/*!
678
\brief Locate a global filter arg
679
680
Looks for a filter option specified as global argument
681
\param arg name of option to search, without "--" or "-+" specififers
682
\return argument value string, empty string for booleans or NULL if not found
683
 */
684
const char *gf_sys_find_global_arg(const char *arg);
685
686
/*!
687
\brief Mark arg as used
688
689
Marks the argument at given index as used. By default all args are marked as not used when assigning args
690
\param arg_idx Index of argument to mark
691
\param used flag to set
692
*/
693
void gf_sys_mark_arg_used(s32 arg_idx, Bool used);
694
695
/*!
696
\brief Check if arg is marked as used
697
698
Marks the argument at given index as used
699
\param arg_idx Index of argument to mark
700
\return used flag of the arg
701
*/
702
Bool gf_sys_is_arg_used(s32 arg_idx);
703
704
/*!
705
\brief checks if test mode is enabled
706
707
Checks if test mode is enabled (no date nor GPAC version should be written).
708
\return GF_TRUE if test mode is enabled, GF_FALSE otherwise.
709
 */
710
Bool gf_sys_is_test_mode();
711
712
/*!
713
\brief checks if compatibility with old arch is enabled
714
715
Checks if compatibility with old arch is enabled - this function will be removed when master will be moved to filters branch
716
\return GF_TRUE if old arch compat is enabled, GF_FALSE otherwise.
717
 */
718
Bool gf_sys_old_arch_compat();
719
720
#ifdef GPAC_ENABLE_COVERAGE
721
/*!
722
\brief checks if coverage tests are enabled
723
724
Checks if coverage tests are enabled
725
\return GF_TRUE if coverage is enabled, GF_FALSE otherwise.
726
 */
727
Bool gf_sys_is_cov_mode();
728
#endif
729
730
/*!
731
\brief checks if running in quiet mode
732
733
Checks if quiet mode is enabled
734
\return 2 if quiet mode is enabled, 1 if quiet mode not enabled but progress is disabled, 0 otherwise.
735
 */
736
u32 gf_sys_is_quiet();
737
738
/*! gets GPAC feature list in this GPAC build
739
\param disabled if GF_TRUE, gets disabled features, otherwise gets enabled features
740
\return the list of features.
741
*/
742
const char *gf_sys_features(Bool disabled);
743
744
/*! solves path starting with replacement keywords:
745
 - $GDOCS: replaced by path to user document , OS-specific
746
   - application document directory for iOS
747
   - EXTERNAL_STORAGE environment variable if present or '/sdcard'  otherwise for Android
748
   - user home directory for other platforms
749
 - $GCFG: replaced by path to GPAC config directory for the current profile
750
751
\param tpl_path url to translate, must start with $GDOCS or $GCFG
752
\param szPath path to store the result
753
\return GF_TRUE if success, GF_FALSE otherwise.
754
*/
755
Bool gf_sys_solve_path(const char *tpl_path, char szPath[GF_MAX_PATH]);
756
757
/*! Enables or disables the rmt websocket monitoring server
758
\param start If true starts the webserver, if false stops it
759
\return GF_OK if success, GF_BAD_PARAM if error, GF_NOT_SUPPORTED if ws server not supported
760
*/
761
GF_Err gf_sys_enable_rmtws(Bool start);
762
763
/*! Enables or disables the rmt websocket user server
764
\param start If true starts the webserver, if false stops it
765
\return GF_OK if success, GF_BAD_PARAM if error, GF_NOT_SUPPORTED if ws server not supported
766
*/
767
GF_Err gf_sys_enable_userws(Bool start);
768
769
/*! Returns the monitoring websocket server handler
770
\return the object to cast to RMT_WS*
771
*/
772
void* gf_sys_get_rmtws();
773
774
/*! Returns the user websocket server handler
775
\return the object to cast to RMT_WS*
776
*/
777
void* gf_sys_get_userws();
778
779
/*!
780
GPAC Log tools
781
\hideinitializer
782
783
Describes the color code for console print
784
 */
785
typedef enum
786
{
787
  /*!reset color*/
788
  GF_CONSOLE_RESET=0,
789
  /*!set text to red*/
790
  GF_CONSOLE_RED,
791
  /*!set text to green*/
792
  GF_CONSOLE_GREEN,
793
  /*!set text to blue*/
794
  GF_CONSOLE_BLUE,
795
  /*!set text to yellow*/
796
  GF_CONSOLE_YELLOW,
797
  /*!set text to cyan*/
798
  GF_CONSOLE_CYAN,
799
  /*!set text to white*/
800
  GF_CONSOLE_WHITE,
801
  /*!set text to magenta*/
802
  GF_CONSOLE_MAGENTA,
803
  /*!reset all console text*/
804
  GF_CONSOLE_CLEAR,
805
  /*!save console state*/
806
  GF_CONSOLE_SAVE,
807
  /*!restore console state*/
808
  GF_CONSOLE_RESTORE,
809
810
  /*!set text to bold modifier*/
811
  GF_CONSOLE_BOLD = 1<<16,
812
  /*!set text to italic*/
813
  GF_CONSOLE_ITALIC = 1<<17,
814
  /*!set text to underlined*/
815
  GF_CONSOLE_UNDERLINED = 1<<18,
816
  /*!set text to strikethrough*/
817
  GF_CONSOLE_STRIKE = 1<<19
818
} GF_ConsoleCodes;
819
820
/*! sets console code
821
\param std the output stream (stderr or stdout)
822
\param code the console code to set
823
*/
824
void gf_sys_set_console_code(FILE *std, GF_ConsoleCodes code);
825
826
827
/*! @} */
828
829
830
/*!
831
\addtogroup log_grp
832
\brief Logging System
833
834
@{
835
*/
836
837
/*!
838
\brief GPAC Log Levels
839
\hideinitializer
840
841
These levels describes messages priority used when filtering logs
842
*/
843
typedef enum
844
{
845
  /*! Disable all Log message*/
846
  GF_LOG_QUIET = 0,
847
  /*! Log message describes an error*/
848
  GF_LOG_ERROR,
849
  /*! Log message describes a warning*/
850
  GF_LOG_WARNING,
851
  /*! Log message is informational (state, etc..)*/
852
  GF_LOG_INFO,
853
  /*! Log message is a debug info*/
854
  GF_LOG_DEBUG
855
} GF_LOG_Level;
856
857
/*!
858
\brief Log exits at first error assignment
859
860
When GF_LOG_ERROR happens, program leaves with instruction exit(1);
861
\param strict strict behavior when encoutering a serious error.
862
\return old value before the call.
863
 */
864
Bool gf_log_set_strict_error(Bool strict);
865
866
/*!
867
\brief gets string-formatted log tools
868
869
Gets the string-formatted log tools and levels. Returned string shall be freed by the caller.
870
\return string-formatted log tools.
871
 */
872
char *gf_log_get_tools_levels(void);
873
874
/*!
875
\brief GPAC Log tools
876
\hideinitializer
877
878
These flags describes which sub-part of GPAC generates the log and are used when filtering logs
879
 */
880
typedef enum
881
{
882
  /*! Log message from the core library (init, threads, network calls, etc)*/
883
  GF_LOG_CORE = 0,
884
  /*! Log message from a raw media parser (BIFS, LASeR, A/V formats)*/
885
  GF_LOG_CODING,
886
  /*! Log message from a bitstream parser (IsoMedia, MPEG-2 TS, OGG, ...)*/
887
  GF_LOG_CONTAINER,
888
  /*! Log message from the network/service stack (messages & co)*/
889
  GF_LOG_NETWORK,
890
  /*! Log message from the HTTP stack*/
891
  GF_LOG_HTTP,
892
  /*! Log message from the RTP/RTCP stack (TS info) and packet structure & hinting (debug)*/
893
  GF_LOG_RTP,
894
  /*! Log message from a codec*/
895
  GF_LOG_CODEC,
896
  /*! Log message from any textual (XML, ...) parser (context loading, etc)*/
897
  GF_LOG_PARSER,
898
  /*! Generic log message from a filter (not from filter core library)*/
899
  GF_LOG_MEDIA,
900
  /*! Log message from the scene graph/scene manager (handling of nodes and attribute modif, DOM core)*/
901
  GF_LOG_SCENE,
902
  /*! Log message from the scripting engine APIs - does not cover alert() in the script code itself*/
903
  GF_LOG_SCRIPT,
904
  /*! Log message from event handling*/
905
  GF_LOG_INTERACT,
906
  /*! Log message from compositor*/
907
  GF_LOG_COMPOSE,
908
  /*! Log message from the compositor, indicating media object state*/
909
  GF_LOG_COMPTIME,
910
  /*! Log for video object cache */
911
  GF_LOG_CACHE,
912
  /*! Log message from multimedia I/O devices (audio/video input/output, ...)*/
913
  GF_LOG_MMIO,
914
  /*! Log for runtime info (times, memory, CPU usage)*/
915
  GF_LOG_RTI,
916
  /*! Log for memory tracker*/
917
  GF_LOG_MEMORY,
918
  /*! Log for audio compositor*/
919
  GF_LOG_AUDIO,
920
  /*! Generic Log for modules*/
921
  GF_LOG_MODULE,
922
  /*! Log for threads and mutexes */
923
  GF_LOG_MUTEX,
924
  /*! Log for threads and condition */
925
  GF_LOG_CONDITION,
926
  /*! Log for all HTTP streaming */
927
  GF_LOG_DASH,
928
  /*! Log for all messages from filter core library (not from a filter) */
929
  GF_LOG_FILTER,
930
  /*! Log for filter scheduler only */
931
  GF_LOG_SCHEDULER,
932
  /*! Log for all ROUTE message */
933
  GF_LOG_ROUTE,
934
  /*! Log for all messages coming from script*/
935
  GF_LOG_CONSOLE,
936
  /*! Log for all messages coming the application, not used by libgpac or the modules*/
937
  GF_LOG_APP,
938
  /*! Log for all info regarding the rmt_ws server and bindings*/
939
  GF_LOG_RMTWS,
940
941
  /*! special value used to set a level for all tools*/
942
  GF_LOG_ALL,
943
  GF_LOG_TOOL_MAX = GF_LOG_ALL,
944
  GF_LOG_TOOL_UNDEFINED
945
} GF_LOG_Tool;
946
947
/*!
948
\brief Log modules assignment
949
950
Sets the tools to be checked for log filtering. By default no logging is performed.
951
\param log_tool the tool to be logged
952
\param log_level the level of logging for this tool
953
 *
954
 */
955
void gf_log_set_tool_level(GF_LOG_Tool log_tool, GF_LOG_Level log_level);
956
957
/*!
958
\brief Log Message Callback
959
960
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 stderr
961
\param cbck Opaque user data.
962
\param log_level level of the log. This value is not guaranteed in multi-threaded context.
963
\param log_tool tool emitting the log. This value is not guaranteed in multi-threaded context.
964
\param fmt message log format.
965
\param vlist message log param.
966
 *
967
 */
968
typedef void (*gf_log_cbk)(void *cbck, GF_LOG_Level log_level, GF_LOG_Tool log_tool, const char* fmt, va_list vlist);
969
970
/*!
971
\brief Log overwrite
972
973
Assigns a user-defined callback for printing log messages. By default all logs are redirected to stderr
974
\param usr_cbk Opaque user data
975
\param cbk     Callback log function
976
\return previous callback function
977
*/
978
gf_log_cbk gf_log_set_callback(void *usr_cbk, gf_log_cbk cbk);
979
980
981
/*!
982
 \cond DUMMY_DOXY_SECTION
983
*/
984
#ifndef GPAC_DISABLE_LOG
985
/*\note
986
  - to turn log on, change to GPAC_ENABLE_LOG
987
  - to turn log off, change to GPAC_DISABLE_LOG
988
  this is needed by configure+sed to modify this file directly
989
*/
990
#define GPAC_ENABLE_LOG
991
#endif
992
993
/*!
994
 \endcond
995
*/
996
997
998
/*! \cond PRIVATE */
999
void gf_log(const char *fmt, ...);
1000
void gf_log_lt(GF_LOG_Level ll, GF_LOG_Tool lt);
1001
void gf_log_va_list(GF_LOG_Level level, GF_LOG_Tool tool, const char *fmt, va_list vl);
1002
/*! \endcond */
1003
1004
/*!
1005
\brief Log level checking
1006
1007
Checks if a given tool is logged for the given level
1008
\param log_tool tool to check
1009
\param log_level level to check
1010
\return 1 if logged, 0 otherwise
1011
*/
1012
Bool gf_log_tool_level_on(GF_LOG_Tool log_tool, GF_LOG_Level log_level);
1013
1014
/*!
1015
\brief Log tool name
1016
1017
Gets log  tool name
1018
\param log_tool tool to check
1019
\return name, or "unknown" if not known
1020
*/
1021
const char *gf_log_tool_name(GF_LOG_Tool log_tool);
1022
1023
/*!
1024
\brief Log level getter
1025
1026
Gets log level of a given tool
1027
\param log_tool tool to check
1028
\return log level of tool
1029
*/
1030
u32 gf_log_get_tool_level(GF_LOG_Tool log_tool);
1031
1032
/*!
1033
\brief Set log tools and levels
1034
1035
Set log tools and levels according to the log_tools_levels string.
1036
\param log_tools_levels string specifying the tools and levels. It is formatted as logToolX\@logLevelX:logToolZ\@logLevelZ:...
1037
\param reset_all if GF_TRUE, all previous log settings are discarded.
1038
\return GF_OK or GF_BAD_PARAM
1039
*/
1040
GF_Err gf_log_set_tools_levels(const char *log_tools_levels, Bool reset_all);
1041
1042
/*!
1043
\brief Modify log tools and levels
1044
1045
Modify log tools and levels according to the log_tools_levels string. Previous log settings are kept.
1046
\param val string specifying the tools and levels. It is formatted as logToolX\@logLevelX:logToolZ\@logLevelZ:...
1047
\return GF_OK or GF_BAD_PARAM
1048
*/
1049
GF_Err gf_log_modify_tools_levels(const char *val);
1050
1051
/*!
1052
\brief Checks if color logs is enabled
1053
1054
Checks if color logs is enabled
1055
\return GF_TRUE if color logs are used
1056
*/
1057
Bool gf_log_use_color();
1058
1059
/*!
1060
\brief Checks if logs are stored to file
1061
1062
Checks if logs are stored to file
1063
\return GF_TRUE if logs are stored to file
1064
*/
1065
Bool gf_log_use_file();
1066
1067
/*!
1068
\brief Parses a log tool
1069
1070
Parses a log tool by name
1071
\param logs the name to parse
1072
\return log tool value
1073
*/
1074
u32 gf_log_parse_tool(const char *logs);
1075
1076
#ifdef GPAC_DISABLE_LOG
1077
void gf_log_check_error(u32 ll, u32 lt);
1078
#define GF_LOG(_ll, _lm, __args) gf_log_check_error(_ll, _lm);
1079
#else
1080
/*!
1081
\brief Message logging
1082
\hideinitializer
1083
1084
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.
1085
*/
1086
23.0M
#define GF_LOG(_log_level, _log_tools, __args) if (gf_log_tool_level_on(_log_tools, _log_level) ) { gf_log_lt(_log_level, _log_tools); gf_log __args ;}
1087
#endif
1088
1089
/*!
1090
\brief Resets log file
1091
Resets log file if any log file name was specified, by closing and reopening a new file.
1092
*/
1093
void gf_log_reset_file();
1094
1095
//! Extra log instructions
1096
typedef struct log_extra
1097
{
1098
  //! number of tools and levels
1099
  u32 nb_tools;
1100
  //! additionnal  tools
1101
  GF_LOG_Tool *tools;
1102
  //! additionnal  levels for the tools
1103
  GF_LOG_Level *levels;
1104
  //! exit if error
1105
  Bool strict;
1106
} GF_LogExtra;
1107
1108
/*! Register a new extra log levels
1109
 \param log extra levels to add - may be NULL but shall be valid until call to \ref gf_log_pop_extra or \ref gf_log_reset_extras or  end of app
1110
*/
1111
void gf_log_push_extra(const GF_LogExtra *log);
1112
/*! Unregister an extra log levels
1113
 \param log extra levels to add - may be NULL
1114
*/
1115
void gf_log_pop_extra(const GF_LogExtra *log);
1116
/*! Unregister all  extra log levels
1117
*/
1118
void gf_log_reset_extras();
1119
1120
/*! @} */
1121
1122
/*!
1123
\addtogroup miscsys_grp
1124
\brief System time CPU
1125
1126
This section documents time functionalities and CPU management in GPAC.
1127
1128
@{
1129
 */
1130
1131
1132
/*!
1133
\brief PseudoRandom Integer Generation Initialization
1134
1135
Sets the starting point for generating a series of pseudorandom integers.
1136
\param Reset Re-initializes the random number generator
1137
*/
1138
void gf_rand_init(Bool Reset);
1139
/*! PseudoRandom integer generation
1140
\return a pseudorandom integer
1141
*/
1142
u32 gf_rand();
1143
1144
/*! gets user name
1145
\param buf buffer set to current user (login) name if available.
1146
*/
1147
void gf_get_user_name(char buf[1024]);
1148
1149
/*!
1150
\brief Progress formatting
1151
1152
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.
1153
\param title title string of the progress, or NULL for no progress
1154
\param done Current amount performed of the action.
1155
\param total Total amount of the action.
1156
 */
1157
void gf_set_progress(const char *title, u64 done, u64 total);
1158
1159
/*!
1160
\brief Progress Callback
1161
1162
The gf_on_progress_cbk type is the type for the callback of the \ref gf_set_progress_callback function
1163
\param cbck Opaque user data.
1164
\param title preogress title.
1165
\param done Current amount performed of the action
1166
\param total Total amount of the action.
1167
 *
1168
 */
1169
typedef void (*gf_on_progress_cbk)(const void *cbck, const char *title, u64 done, u64 total);
1170
1171
/*!
1172
\brief Progress overwriting
1173
Overwrites the progress signaling function by a user-defined one.
1174
\param user_cbk Opaque user data
1175
\param prog_cbk new callback function to use. Passing NULL restore default GPAC stderr notification.
1176
 */
1177
void gf_set_progress_callback(void *user_cbk, gf_on_progress_cbk prog_cbk);
1178
1179
1180
/*!
1181
\brief Prompt checking
1182
1183
Checks if a character is pending in the prompt buffer.
1184
\return 1 if a character is ready to be fetched, 0 otherwise.
1185
\note Function not available under WindowsCE nor SymbianOS
1186
*/
1187
Bool gf_prompt_has_input();
1188
1189
/*!
1190
\brief Prompt character flush
1191
1192
Gets the current character entered at prompt if any.
1193
\return value of the character.
1194
\note Function not available under WindowsCE nor SymbianOS
1195
*/
1196
char gf_prompt_get_char();
1197
1198
/*!
1199
\brief Get prompt TTY size
1200
1201
Gets the stdin prompt size (columns and rows)
1202
\param width set to number of rows in the TTY
1203
\param height set to number of columns in the TTY
1204
\return error if any
1205
*/
1206
GF_Err gf_prompt_get_size(u32 *width, u32 *height);
1207
1208
/*!
1209
\brief turns prompt echo on/off
1210
1211
Turns the prompt character echo on/off - this is useful when entering passwords.
1212
\param echo_off indicates whether echo should be turned on or off.
1213
\note Function not available under WindowsCE nor SymbianOS
1214
*/
1215
void gf_prompt_set_echo_off(Bool echo_off);
1216
1217
/*! @} */
1218
1219
1220
/*! gets battery state
1221
\param onBattery set to GF_TRUE if running on battery
1222
\param onCharge set to GF_TRUE if battery is charging
1223
\param level set to battery charge percent
1224
\param batteryLifeTime set to battery lifetime
1225
\param batteryFullLifeTime set to battery full lifetime
1226
\return GF_TRUE if success
1227
*/
1228
Bool gf_sys_get_battery_state(Bool *onBattery, u32 *onCharge, u32 *level, u32 *batteryLifeTime, u32 *batteryFullLifeTime);
1229
1230
1231
/*!
1232
\brief parses 128 bit from string
1233
1234
Parses 128 bit from string
1235
\param string the string containing the value in hexa. Non alphanum characters are skipped
1236
\param value the value parsed
1237
\return error code if any
1238
 */
1239
GF_Err gf_bin128_parse(const char *string, bin128 value);
1240
1241
1242
/*! blob range status */
1243
typedef enum
1244
{
1245
  /*! blob range is valid */
1246
  GF_BLOB_RANGE_VALID=0,
1247
  /*! blob range is not valid, still in transfer */
1248
  GF_BLOB_RANGE_IN_TRANSFER,
1249
  /*! blob range is not in transfer and is (partially or completely) lost */
1250
  GF_BLOB_RANGE_CORRUPTED,
1251
} GF_BlobRangeStatus;
1252
1253
/*! blob flags*/
1254
enum
1255
{
1256
  /*! blob is in transfer */
1257
    GF_BLOB_IN_TRANSFER = 1,
1258
  /*! blob is corrupted */
1259
    GF_BLOB_CORRUPTED = 1<<1,
1260
  /*! blob is parsable (valid mux format) but had partial repair only (media holes) */
1261
    GF_BLOB_PARTIAL_REPAIR = 1<<2
1262
};
1263
1264
/*!
1265
 * Blob structure used to pass data pointer around
1266
 */
1267
typedef struct __gf_blob
1268
{
1269
  /*! data block of blob */
1270
  u8 *data;
1271
  /*! size of blob */
1272
  u32 size;
1273
    /*! blob flags */
1274
    u32 flags;
1275
#ifdef GPAC_DISABLE_THREADS
1276
    void *mx;
1277
#else
1278
    /*! blob mutex for multi-thread access */
1279
    struct __tag_mutex *mx;
1280
#endif
1281
    /*! last blob modification time (write access) in microsec , 0 if unknown*/
1282
    u64 last_modification_time;
1283
  /*! function used to query if a range of a blob in transfer is valid. If NULL, any range is invalid until transfer is done
1284
  when set this function overrides the blob flags for gf_blob_query_range
1285
  If check_when_complete is true, range will be checked when blob transfer is over; if false, range will either be valid or corrupted for a transferred blob
1286
  size is updated to the maximum number of consecutive bytes starting from the goven offset */
1287
  GF_BlobRangeStatus (*range_valid)(struct __gf_blob *blob, Bool check_when_complete, u64 start, u32 *size);
1288
  /*! private data for range_valid function*/
1289
  void *range_udta;
1290
} GF_Blob;
1291
1292
/*!
1293
 * Retrieves data associated with a blob url. If success, \ref gf_blob_release must be called after this
1294
\param blob_url URL of blob object (ie gmem://%p)
1295
\param out_data if success, set to blob data pointer
1296
\param out_size if success, set to blob data size
1297
\param blob_flags if success, set to blob flags - may be NULL
1298
\return error code
1299
 */
1300
GF_Err gf_blob_get(const char *blob_url, u8 **out_data, u32 *out_size, u32 *blob_flags);
1301
1302
/*!
1303
 * Checks if a given byte range is valid in blob
1304
\param blob  blob object
1305
\param check_when_complete when true, range will be checked when blob transfer is over; when false, range will either be valid or corrupted for a transferred blob)
1306
\param start_offset start offset of data to check in blob
1307
\param size size of data to check in blob
1308
\return blob range status
1309
 */
1310
GF_BlobRangeStatus gf_blob_query_range(GF_Blob *blob, Bool check_when_complete, u64 start_offset, u32 size);
1311
1312
/*!
1313
 * Releases blob data
1314
\param blob_url URL of blob object (ie gmem://%p)
1315
\return error code
1316
 */
1317
GF_Err gf_blob_release(const char *blob_url);
1318
1319
1320
/*!
1321
 * Retrieves data associated with a blob. If success, \ref gf_blob_release_ex must be called after this
1322
\param blob the blob object
1323
\param out_data if success, set to blob data pointer
1324
\param out_size if success, set to blob data size
1325
\param blob_flags if success, set to blob flags - may be NULL
1326
\return error code
1327
 */
1328
GF_Err gf_blob_get_ex(GF_Blob *blob, u8 **out_data, u32 *out_size, u32 *blob_flags);
1329
/*!
1330
 * Releases blob data
1331
\param blob the blob object
1332
\return error code
1333
 */
1334
GF_Err gf_blob_release_ex(GF_Blob *blob);
1335
1336
/*!
1337
 * Registers a new blob
1338
\param blob  blob object
1339
\return URL of blob object (ie gmem://%p), must be freed by user
1340
 */
1341
char *gf_blob_register(GF_Blob *blob);
1342
1343
/*!
1344
 * Unegisters a blob. This must be called before destroying a registered blob
1345
\param blob  blob object
1346
 */
1347
void gf_blob_unregister(GF_Blob *blob);
1348
1349
/*!
1350
\brief Portable getch()
1351
1352
Returns immediately a typed char from stdin
1353
\return the typed char
1354
*/
1355
int gf_getch();
1356
1357
/*!
1358
\brief Reads a line of input from stdin
1359
\param line the buffer to fill
1360
\param maxSize the maximum size of the line to read
1361
\param showContent boolean indicating if the line read should be printed on stderr or not
1362
\return GF_TRUE if some content was read, GF_FALSE otherwise
1363
*/
1364
Bool gf_read_line_input(char * line, int maxSize, Bool showContent);
1365
1366
1367
/*!
1368
\addtogroup time_grp
1369
\brief Time manipulation tools
1370
@{
1371
*/
1372
1373
/*!
1374
\brief System clock query
1375
1376
Gets the system clock time.
1377
\return System clock value since GPAC initialization in milliseconds.
1378
 */
1379
u32 gf_sys_clock();
1380
1381
/*!
1382
\brief High precision system clock query
1383
1384
Gets the hight precision system clock time.
1385
\return System clock value since GPAC initialization in microseconds.
1386
 */
1387
u64 gf_sys_clock_high_res();
1388
1389
/*!
1390
\brief Sleeps thread/process
1391
1392
Locks calling thread/process execution for a given time.
1393
\param ms Amount of time to sleep in milliseconds.
1394
 */
1395
void gf_sleep(u32 ms);
1396
1397
#ifdef WIN32
1398
/*!
1399
\brief WINCE time constant
1400
\hideinitializer
1401
1402
time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds
1403
*/
1404
#define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008)
1405
1406
#endif
1407
1408
/*!
1409
\brief gets UTC time in milliseconds
1410
1411
Gets UTC clock in milliseconds
1412
\return UTC time in milliseconds
1413
 */
1414
u64 gf_net_get_utc();
1415
1416
/*!
1417
\brief converts an ntp timestamp into UTC time in milliseconds
1418
1419
Converts NTP 64-bit timestamp to UTC clock in milliseconds
1420
\param ntp NTP timestamp
1421
\return UTC time in milliseconds
1422
 */
1423
u64 gf_net_ntp_to_utc(u64 ntp);
1424
1425
/*!
1426
\brief parses date
1427
1428
Parses date and gets UTC value for this date. Date format is an XSD dateTime format or any of the supported formats from HTTP 1.1:
1429
  Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
1430
  Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
1431
  Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() formatgets UTC time in milliseconds
1432
1433
\param date string containing the date to parse
1434
\return UTC time in milliseconds
1435
 */
1436
u64 gf_net_parse_date(const char *date);
1437
1438
/*!
1439
\brief returns 64-bit UTC timestamp from year, month, day, hour, min and sec
1440
\param year the year
1441
\param month the month, from 0 to 11
1442
\param day the day
1443
\param hour the hour
1444
\param min the min
1445
\param sec the sec
1446
\return UTC time in milliseconds
1447
 */
1448
u64 gf_net_get_utc_ts(u32 year, u32 month, u32 day, u32 hour, u32 min, u32 sec);
1449
1450
/*!
1451
\brief gets timezone adjustment in seconds
1452
1453
Gets timezone adjustment in seconds, with localtime - timezone = UTC time
1454
\return timezone shift in seconds
1455
 */
1456
s32 gf_net_get_timezone();
1457
1458
/*!
1459
\brief gets timezone daylight saving time status
1460
1461
Gets timezone daylight saving time
1462
\return GF_TRUE if DST is active
1463
 */
1464
Bool gf_net_time_is_dst();
1465
1466
/*!
1467
\brief gets time from UTC timestamp
1468
1469
Gets time from UTC timestamp
1470
\param time timestamp value - see gmtime
1471
\return time description structure - see gmtime
1472
 */
1473
struct tm *gf_gmtime(const time_t *time);
1474
1475
/*! @} */
1476
1477
/*!
1478
\addtogroup thr_grp
1479
\brief Time manipulation tools
1480
@{
1481
*/
1482
1483
/*!
1484
\brief Gets process ID
1485
1486
Gets ID of the process running this gpac instance.
1487
\return the ID of the main process
1488
*/
1489
u32 gf_sys_get_process_id();
1490
1491
1492
/*! lockfile status*/
1493
typedef enum {
1494
  /*! lockfile creation failed*/
1495
  GF_LOCKFILE_FAILED=0,
1496
  /*! lockfile creation succeeded, creating a new lock file*/
1497
  GF_LOCKFILE_NEW,
1498
  /*! lockfile creation succeeded, lock file was already present and created by this process*/
1499
  GF_LOCKFILE_REUSE
1500
} GF_LockStatus;
1501
1502
/*!
1503
\brief Creates a lock file
1504
1505
Creates a lock file for the current process. A lockfile contains a single string giving the creator process ID
1506
If a lock file exists with a process ID no longer running, the lock file will be granted to the caller.
1507
Lock files are removed using \ref gf_file_delete
1508
\param lockfile name of the lockfile
1509
\return return status
1510
*/
1511
GF_LockStatus gf_sys_create_lockfile(const char *lockfile);
1512
1513
/*!
1514
\brief Checks a process is valid
1515
1516
Checks if a process is running by its ID
1517
\param process_id process ID
1518
\return GF_TRUE if process is running, GF_FALSE otherwise
1519
*/
1520
Bool gf_sys_check_process_id(u32 process_id);
1521
1522
1523
/*!\brief run-time system info object
1524
1525
The Run-Time Info object is used to get CPU and memory occupation of the calling process.
1526
All time values are expressed in milliseconds (accuracy is not guaranteed).
1527
*/
1528
typedef struct
1529
{
1530
  /*!start of the sampling period*/
1531
  u32 sampling_instant;
1532
  /*!duration of the sampling period*/
1533
  u32 sampling_period_duration;
1534
  /*!total amount of time (User+kernel) spent in CPU for all processes as evaluated at the end of the sampling period*/
1535
  u32 total_cpu_time;
1536
  /*!total amount of time (User+kernel) spent in CPU for the calling process as evaluated at the end of the sampling period*/
1537
  u32 process_cpu_time;
1538
  /*!amount of time (User+kernel) spent in CPU for all processes during the sampling period*/
1539
  u32 total_cpu_time_diff;
1540
  /*!total amount of time (User+kernel) spent in CPU for the calling process during the sampling period*/
1541
  u32 process_cpu_time_diff;
1542
  /*!total amount of idle time during the sampling period.*/
1543
  u32 cpu_idle_time;
1544
  /*!percentage (from 0 to 100) of CPU usage during the sampling period.*/
1545
  u32 total_cpu_usage;
1546
  /*!percentage (from 0 to 100) of the CPU usage by the calling process during the sampling period.*/
1547
  u32 process_cpu_usage;
1548
  /*!calling process ID*/
1549
  u32 pid;
1550
  /*!calling process thread count if known*/
1551
  u32 thread_count;
1552
  /*!size of calling process allocated heaps*/
1553
  u64 process_memory;
1554
  /*!total physical memory in system*/
1555
  u64 physical_memory;
1556
  /*!available physical memory in system*/
1557
  u64 physical_memory_avail;
1558
  /*!total memory currently allocated by gpac*/
1559
  u64 gpac_memory;
1560
  /*!total number of cores on the system*/
1561
  u32 nb_cores;
1562
} GF_SystemRTInfo;
1563
1564
/*!
1565
Selection flags for run-time info retrieval
1566
\hideinitializer
1567
 */
1568
enum
1569
{
1570
  /*!Indicates all processes' times must be fetched. If not set, only the current process times will be retrieved, and the
1571
  thread count and total times won't be available*/
1572
  GF_RTI_ALL_PROCESSES_TIMES = 1,
1573
  /*!Indicates the process allocated heap size must be fetch. If not set, only the system physical memory is fetched.
1574
  Fetching the entire ocess  allocated memory can have a large impact on performances*/
1575
  GF_RTI_PROCESS_MEMORY = 1<<1,
1576
  /*!Indicates that only system memory should be fetched. When set, all refreshing info is ignored*/
1577
  GF_RTI_SYSTEM_MEMORY_ONLY = 1<<2
1578
};
1579
1580
/*!
1581
\brief Gets Run-Time info
1582
1583
Gets CPU and memory usage info for the calling process and the system. Information gathering is controled through timeout values.
1584
\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.
1585
\param rti holder to the run-time info structure to update.
1586
\param flags specify which info is to be retrieved.
1587
\return 1 if info has been updated, 0 otherwise.
1588
\note You should not try to use a too small refresh time. Typical values are 500 ms or one second.
1589
 */
1590
Bool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags);
1591
1592
/*! @} */
1593
1594
/*!
1595
\addtogroup osfile_grp
1596
\brief File System tools
1597
1598
This section documents file system tools used in GPAC.
1599
1600
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:
1601
\code
1602
//bad design, will fail when using wrapped memory IOs
1603
FILE *t = fopen(url, "rb");
1604
fputs(t, mystring);
1605
fclose(t);
1606
1607
//good design, will work fine when using wrapped memory IOs
1608
FILE *t = gf_fopen(url, "rb");
1609
gf_fputs(t, mystring);
1610
gf_fclose(t);
1611
\endcode
1612
1613
@{
1614
 */
1615
1616
/*!
1617
\brief reads a file into memory
1618
1619
Reads a local file into memory, in binary open mode.
1620
\param file_name path on disk of the file to read
1621
\param out_data pointer to allocted address, to be freed by caller
1622
\param out_size pointer to allocted size
1623
\return error code if any
1624
 */
1625
GF_Err gf_file_load_data(const char *file_name, u8 **out_data, u32 *out_size);
1626
1627
/*!
1628
\brief reads a file into memory
1629
1630
Reads a local file into memory, in binary open mode.
1631
\param file stream object to read (no seek is performed)
1632
\param out_data pointer to allocted address, to be freed by caller
1633
\param out_size pointer to allocted size
1634
\return error code if any
1635
 */
1636
GF_Err gf_file_load_data_filep(FILE *file, u8 **out_data, u32 *out_size);
1637
1638
/*!
1639
\brief Delete Directory
1640
1641
Delete a  dir within the full path.
1642
\param DirPathName the file path name.
1643
\return error if any
1644
 */
1645
GF_Err gf_rmdir(const char *DirPathName);
1646
1647
/*!
1648
\brief Create Directory
1649
1650
Create a directory within the full path.
1651
\param DirPathName the dir path name.
1652
\return error if any
1653
 */
1654
GF_Err gf_mkdir(const char* DirPathName);
1655
1656
/*!
1657
\brief Check Directory Exists
1658
1659
Create a directory within the full path.
1660
\param DirPathName the dir path name.
1661
\return GF_TRUE if directory exists
1662
 */
1663
Bool gf_dir_exists(const char *DirPathName);
1664
1665
/*!
1666
\brief Create Directory
1667
1668
Cleanup a directory within the full path, removing all the files and the directories.
1669
\param DirPathName the dir path name.
1670
\return error if any
1671
 */
1672
GF_Err gf_dir_cleanup(const char* DirPathName);
1673
1674
1675
/**
1676
Gets a globally allocated string containing the default cache directory.
1677
The caller shall not free the string.
1678
\return a fully qualified path to the default cache directory
1679
 */
1680
const char * gf_get_default_cache_directory();
1681
1682
/**
1683
Gets the number of open file handles (gf_fopen/gf_fclose only).
1684
\return  number of open file handles
1685
 */
1686
u32 gf_file_handles_count();
1687
1688
/*!
1689
\brief file writing helper
1690
1691
Wrapper to properly handle calls to fwrite(), ensuring proper error handling is invoked when it fails.
1692
\param ptr data buffer to write
1693
\param nb_bytes number of bytes to write
1694
\param stream stream object
1695
\return number of bytes to written
1696
*/
1697
size_t gf_fwrite(const void *ptr, size_t nb_bytes, FILE *stream);
1698
1699
/*!
1700
\brief file reading helper
1701
1702
Wrapper to properly handle calls to fread()
1703
\param ptr data buffer to read
1704
\param nbytes number of bytes to read
1705
\param stream stream object
1706
\return number of bytes read
1707
*/
1708
size_t gf_fread(void *ptr, size_t nbytes, FILE *stream);
1709
1710
/*!
1711
\brief file reading helper
1712
1713
Wrapper to properly handle calls to fgets()
1714
\param buf same as fgets
1715
\param size same as fgets
1716
\param stream same as fgets
1717
\return same as fgets
1718
*/
1719
char *gf_fgets(char *buf, size_t size, FILE *stream);
1720
/*!
1721
\brief file reading helper
1722
1723
Wrapper to properly handle calls to fgetc()
1724
\param stream same as fgetc
1725
\return same as fgetc
1726
*/
1727
int gf_fgetc(FILE *stream);
1728
/*!
1729
\brief file writing helper
1730
1731
Wrapper to properly handle calls to fputc()
1732
\param val same as fputc
1733
\param stream same as fputc
1734
\return same as fputc
1735
*/
1736
int gf_fputc(int val, FILE *stream);
1737
/*!
1738
\brief file writing helper
1739
1740
Wrapper to properly handle calls to fputs()
1741
\param buf same as fputs
1742
\param stream same as fputs
1743
\return same as fputs
1744
*/
1745
int gf_fputs(const char *buf, FILE *stream);
1746
/*!
1747
\brief file writing helper
1748
1749
Wrapper to properly handle calls to fprintf()
1750
\param stream same as fprintf
1751
\param format same as fprintf
1752
\return same as fprintf
1753
*/
1754
int gf_fprintf(FILE *stream, const char *format, ...);
1755
1756
/*!
1757
\brief file writing helper
1758
1759
Wrapper to properly handle calls to vfprintf()
1760
\param stream same as vfprintf
1761
\param format same as vfprintf
1762
\param args same as vfprintf
1763
\return same as fprintf
1764
*/
1765
int gf_vfprintf(FILE *stream, const char *format, va_list args);
1766
1767
/*!
1768
\brief file flush helper
1769
1770
Wrapper to properly handle calls to fflush()
1771
\param stream same as fflush
1772
\return same as fflush
1773
*/
1774
int gf_fflush(FILE *stream);
1775
/*!
1776
\brief end of file helper
1777
1778
Wrapper to properly handle calls to feof()
1779
\param stream same as feof
1780
\return same as feof
1781
*/
1782
int gf_feof(FILE *stream);
1783
/*!
1784
\brief file error helper
1785
1786
Wrapper to properly handle calls to ferror()
1787
\param stream same as ferror
1788
\return same as ferror
1789
*/
1790
int gf_ferror(FILE *stream);
1791
1792
/*!
1793
\brief file size helper
1794
1795
Gets the file size given a FILE object. The FILE object position will be reset to 0 after this call
1796
\param fp FILE object to check
1797
\return file size in bytes
1798
*/
1799
u64 gf_fsize(FILE *fp);
1800
1801
/*!
1802
\brief file size helper for a file descriptor
1803
1804
Gets the file size given a file descriptor.
1805
\param fd file descriptor to check
1806
\return file size in bytes
1807
*/
1808
u64 gf_fd_fsize(int fd);
1809
1810
/*!
1811
\brief file IO checker
1812
1813
Checks if the given FILE object is a native FILE or a GF_FileIO wrapper.
1814
\param fp FILE object to check
1815
\return GF_TRUE if the FILE object is a wrapper to GF_FileIO
1816
*/
1817
Bool gf_fileio_check(FILE *fp);
1818
1819
/*! FileIO write state*/
1820
typedef enum
1821
{
1822
  /*! FileIO object is ready for write operations*/
1823
  GF_FIO_WRITE_READY=0,
1824
  /*! FileIO object is not yet ready for write operations*/
1825
  GF_FIO_WRITE_WAIT,
1826
  /*! FileIO object has been canceled*/
1827
  GF_FIO_WRITE_CANCELED,
1828
} GF_FileIOWriteState;
1829
/*!
1830
\brief file IO write checker
1831
1832
Checks if the given FILE object is ready for write.
1833
\param fp FILE object to check
1834
\return write state of GF_FileIO object, GF_FIO_WRITE_READY if not a GF_FileIO object
1835
*/
1836
GF_FileIOWriteState gf_fileio_write_ready(FILE *fp);
1837
1838
/*!
1839
\brief file opening
1840
1841
Opens a file, potentially bigger than 4GB. if filename identifies a blob (gmem://), the blob will be opened
1842
\param file_name same as fopen
1843
\param mode same as fopen
1844
\return stream handle of the file object
1845
*/
1846
FILE *gf_fopen(const char *file_name, const char *mode);
1847
1848
/*!
1849
\brief file opening
1850
1851
Opens a file, potentially using file IO if the parent URL is a File IO wrapper
1852
1853
\note If a parent GFIO file is used and file_name was obtained without using \ref gf_url_concatenate on the parent GFIO, make sur to call \ref gf_fileio_open_url in "url" mode to prevent further concatenations by the GFIO handler.
1854
1855
\param file_name same as fopen
1856
\param parent_url URL of parent file. If not a file io wrapper (gfio://), the function is equivalent to gf_fopen
1857
\param 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)
1858
\param no_warn if GF_TRUE, do not throw log message if failure
1859
\return stream habdle of the file or file IO object*/
1860
FILE *gf_fopen_ex(const char *file_name, const char *parent_url, const char *mode, Bool no_warn);
1861
1862
/*!
1863
\brief file closing
1864
1865
Closes a file
1866
\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.
1867
\param file file to close
1868
\return same as flcose
1869
*/
1870
s32 gf_fclose(FILE *file);
1871
1872
/*!
1873
\brief large file position query
1874
1875
Queries the current read/write position in a large file
1876
\param f Same semantics as gf_ftell
1877
\return position in the file
1878
\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.
1879
*/
1880
u64 gf_ftell(FILE *f);
1881
/*!
1882
\brief large file seeking
1883
1884
Seeks the current read/write position in a large file
1885
\param f Same semantics as fseek
1886
\param pos Same semantics as fseek
1887
\param whence Same semantics as fseek
1888
\return 0 if success, -1 if error
1889
\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.
1890
*/
1891
s32 gf_fseek(FILE *f, s64 pos, s32 whence);
1892
1893
1894
/*! gets basename from filename/path
1895
\param filename Path of the file, can be an absolute path
1896
\return a pointer to the start of a filepath basename or null
1897
*/
1898
char* gf_file_basename(const char* filename);
1899
1900
/*! gets extension from filename
1901
\param filename Path of the file, can be an absolute path
1902
\return a pointer to the start of a filepath extension or null
1903
*/
1904
char* gf_file_ext_start(const char* filename);
1905
1906
/*!\brief FileEnum info object
1907
1908
The FileEnumInfo object is used to get file attributes upon enumeration of a directory.
1909
*/
1910
typedef struct
1911
{
1912
  /*!File is marked as hidden*/
1913
  Bool hidden;
1914
  /*!File is a directory*/
1915
  Bool directory;
1916
  /*!File is a drive mountpoint*/
1917
  Bool drive;
1918
  /*!File is a system file*/
1919
  Bool system;
1920
  /*!File size in bytes*/
1921
  u64 size;
1922
  /*!File last modif time in UTC seconds*/
1923
  u64 last_modified;
1924
} GF_FileEnumInfo;
1925
1926
/*!
1927
\brief Directory Enumeration Callback
1928
1929
The gf_enum_dir_item type is the type for the callback of the \ref gf_enum_directory function
1930
\param cbck Opaque user data.
1931
\param item_name File or directory name.
1932
\param item_path File or directory full path and name from filesystem root.
1933
\param file_info information for the file or directory.
1934
\return 1 to abort enumeration, 0 to continue enumeration.
1935
 *
1936
 */
1937
typedef Bool (*gf_enum_dir_item)(void *cbck, char *item_name, char *item_path, GF_FileEnumInfo *file_info);
1938
/*!
1939
\brief Directory enumeration
1940
1941
Enumerates a directory content. Feedback is provided by the enum_dir_item function
1942
\param dir Directory to enumerate
1943
\param enum_directory If set, only directories will be enumerated, otherwise only files are.
1944
\param enum_dir gf_enum_dir_item callback function for enumeration.
1945
\param cbck Opaque user data passed to callback function.
1946
\param filter optional filter for file extensions. If a file extension without the dot '.' character is not found in the
1947
 *  filter the file will be skipped.
1948
\return error if any
1949
 */
1950
GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir, void *cbck, const char *filter);
1951
1952
1953
/*!
1954
\brief File Deletion
1955
1956
Deletes a file from the disk.
1957
\param fileName absolute name of the file or name relative to the current working directory.
1958
\return error if any
1959
*/
1960
GF_Err gf_file_delete(const char *fileName);
1961
1962
/*!
1963
\brief File Move
1964
1965
Moves or renames a file or directory.
1966
\param fileName absolute path of the file / directory to move or rename
1967
\param newFileName absolute new path/name of the file / directory
1968
\return error if any
1969
*/
1970
GF_Err gf_file_move(const char *fileName, const char *newFileName);
1971
1972
/*!
1973
\brief Temporary File Creation
1974
1975
Creates a new temporary file in binary mode
1976
\param fileName if not NULL, strdup() of the temporary filename when created by GPAC (NULL otherwise as the system automatically removes its own tmp files)
1977
\return stream handle to the new file ressoucre
1978
 */
1979
FILE *gf_file_temp(char ** const fileName);
1980
1981
1982
/*!
1983
\brief File Modification Time
1984
1985
Gets the UTC modification time of the given file in microseconds
1986
\param filename file to check
1987
\return modification time of the file
1988
 */
1989
u64 gf_file_modification_time(const char *filename);
1990
1991
/*!
1992
\brief File existence check
1993
1994
Checks if file with given name exists
1995
\param fileName path of the file to check
1996
\return GF_TRUE if file exists */
1997
Bool gf_file_exists(const char *fileName);
1998
1999
/*!
2000
\brief File existence check
2001
2002
Checks if file with given name exists, for regular files or File IO wrapper
2003
\param file_name path of the file to check
2004
\param par_name  name of the parent file
2005
\return GF_TRUE if file exists */
2006
Bool gf_file_exists_ex(const char *file_name, const char *par_name);
2007
2008
/*!
2009
\brief Open file descriptor
2010
2011
Opens a file descriptor - this is simply a wrapper aroun open taking care of UTF8 for windows
2012
\param file_name path of the file to check
2013
\param oflags same parameters as open flags for open
2014
\param pflags same parameters as permission flags for open
2015
\return file descriptor, -1 if error*/
2016
s32 gf_fd_open(const char *file_name, u32 oflags, u32 pflags);
2017
2018
/*! File IO wrapper object*/
2019
typedef struct __gf_file_io GF_FileIO;
2020
2021
2022
/*! open proc for memory file IO
2023
\param fileio_ref reference file_io. A file can be opened multiple times for the same reference, your code must handle this
2024
\param url target file name.
2025
\param mode opening mode of file, same as fopen mode. The following additional modes are defined:
2026
  - "ref": indicates this FileIO object is used by some part of the code and must not be destroyed upon closing of the file. Associated URL is null
2027
  - "unref": indicates this FileIO object is not used by some part of the code and may be destroyed if no more references to this object are set. Associated URL is null
2028
  - "url": indicates to create a new FileIO object for the given URL without opening the output file. The resulting FileIO object must be garbage collected by the app in case it is never used by the callers
2029
  - "probe": checks if the file exists, but no need to open the file. The function should return NULL in this case. If file does not exist, set out_error to GF_URL_ERROR
2030
  - "close": indicates the fileIO object is being closed (fclose)
2031
\param out_error must be set to error code if any (never NULL)
2032
\return the opened GF_FileIO if success, or NULL otherwise
2033
 */
2034
typedef GF_FileIO *(*gfio_open_proc)(GF_FileIO *fileio_ref, const char *url, const char *mode, GF_Err *out_error);
2035
2036
/*! seek proc for memory file IO
2037
\param fileio target file IO object
2038
\param offset offset in file
2039
\param whence position from offset, same as fseek
2040
\return error if any
2041
 */
2042
typedef GF_Err (*gfio_seek_proc)(GF_FileIO *fileio, u64 offset, s32 whence);
2043
2044
/*! read proc for memory file IO
2045
\param fileio target file IO object
2046
\param buffer buffer to read.
2047
\param bytes number of bytes to read.
2048
\return number of bytes read, 0 if error.
2049
 */
2050
typedef u32 (*gfio_read_proc)(GF_FileIO *fileio, u8 *buffer, u32 bytes);
2051
2052
/*! write proc for memory file IO
2053
\param fileio target file IO object
2054
\param buffer buffer to write.
2055
\param bytes number of bytes to write. If 0, acts as fflush
2056
\return number of bytes write, 0 if error
2057
 */
2058
typedef u32 (*gfio_write_proc)(GF_FileIO *fileio, u8 *buffer, u32 bytes);
2059
2060
/*! positon tell proc for memory file IO
2061
\param fileio target file IO object
2062
\return position in bytes from file start
2063
 */
2064
typedef s64 (*gfio_tell_proc)(GF_FileIO *fileio);
2065
/*! end of file proc for memory file IO
2066
\param fileio target file IO object
2067
\return GF_TRUE if end of file, GF_FALSE otherwise
2068
 */
2069
typedef Bool (*gfio_eof_proc)(GF_FileIO *fileio);
2070
/*! printf proc for memory file IO
2071
\param fileio target file IO object
2072
\param format format string to use
2073
\param args variable argument list for printf, already initialized (va_start called)
2074
\return same as vfprint
2075
 */
2076
typedef int (*gfio_printf_proc)(GF_FileIO *fileio, const char *format, va_list args);
2077
2078
/*! Creates a new file IO object
2079
2080
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
2081
gf_fileio_new or as a response to open with mode "url".
2082
2083
\param url the original URL this file IO object wraps
2084
\param udta opaque data for caller
2085
\param open open proc for IO, must not be NULL
2086
\param seek seek proc for IO, must not be NULL
2087
\param read read proc for IO - if NULL the file is considered write only
2088
\param write write proc for IO - if NULL the file is considered read only
2089
\param tell tell proc for IO, must not be NULL
2090
\param eof eof proc for IO, must not be NULL
2091
\param printf printf proc for IO, may be NULL
2092
\return the newly created file IO wrapper
2093
 */
2094
GF_FileIO *gf_fileio_new(char *url, void *udta,
2095
  gfio_open_proc open,
2096
  gfio_seek_proc seek,
2097
  gfio_read_proc read,
2098
  gfio_write_proc write,
2099
  gfio_tell_proc tell,
2100
  gfio_eof_proc eof,
2101
  gfio_printf_proc printf);
2102
2103
/*! Deletes a new fileIO object
2104
\param fileio the File IO object to delete
2105
*/
2106
void gf_fileio_del(GF_FileIO *fileio);
2107
2108
/*! Gets associated user data of a fileIO object
2109
\param fileio target file IO object
2110
\return the associated user data
2111
*/
2112
void *gf_fileio_get_udta(GF_FileIO *fileio);
2113
2114
/*! Gets URL of a fileIO object.
2115
 The url uses the protocol scheme "gfio://"
2116
\param fileio target file IO object
2117
\return the file IO url to use
2118
*/
2119
const char * gf_fileio_url(GF_FileIO *fileio);
2120
2121
/*! Gets a fileIO object from memory - the resulting fileIO can be reopen multiple times but cannot be re-open once closed. Any URL concatenation against this object will fail (no dynamic creation of fileio from mem).
2122
\param URL of source data, may be null
2123
\param data memory, must be valid until next close
2124
\param size memory size
2125
\return new file IO - use gf_fclose() on this object to close it
2126
*/
2127
GF_FileIO *gf_fileio_from_mem(const char *URL, const u8 *data, u32 size);
2128
2129
/*! Cache state for file IO object*/
2130
typedef enum
2131
{
2132
  /*! File caching is in progress*/
2133
  GF_FILEIO_CACHE_IN_PROGRESS=0,
2134
  /*! File caching is done */
2135
  GF_FILEIO_CACHE_DONE,
2136
  /*! No file caching (file is not stored to disk)) */
2137
  GF_FILEIO_NO_CACHE,
2138
} GF_FileIOCacheState;
2139
2140
2141
/*! Sets statistics on a fileIO object.
2142
\param fileio target file IO object
2143
\param bytes_done number of bytes fetched for this file
2144
\param file_size total size of this file, 0 if unknown
2145
\param cache_state if GF_TRUE, means the file is completely available
2146
\param bytes_per_sec reception bytes per second, 0 if unknown
2147
*/
2148
void gf_fileio_set_stats(GF_FileIO *fileio, u64 bytes_done, u64 file_size, GF_FileIOCacheState cache_state, u32 bytes_per_sec);
2149
2150
/*! Gets statistics on a fileIO object.
2151
\param fileio target file IO object
2152
\param bytes_done number of bytes fetched for this file (may be NULL)
2153
\param file_size total size of this file, 0 if unknown (may be NULL)
2154
\param cache_state set to caching state for this object (may be NULL)
2155
\param bytes_per_sec reception bytes per second, 0 if unknown (may be NULL)
2156
\return GF_TRUE if success, GF_FALSE otherwise
2157
*/
2158
Bool gf_fileio_get_stats(GF_FileIO *fileio, u64 *bytes_done, u64 *file_size, GF_FileIOCacheState *cache_state, u32 *bytes_per_sec);
2159
2160
/*! Sets write state of a  fileIO object.
2161
\param fileio target file IO object
2162
\param write_state the state to set
2163
*/
2164
void gf_fileio_set_write_state(GF_FileIO *fileio, GF_FileIOWriteState write_state);
2165
2166
/*! Checks if a FileIO object can write
2167
\param fileio target file IO object
2168
\param url the original resource URL to open
2169
\param mode the desired open mode
2170
\param out_err set to error code if any, must not be NULL
2171
\return file IO object for this resource
2172
*/
2173
GF_FileIO *gf_fileio_open_url(GF_FileIO *fileio, const char *url, const char *mode, GF_Err *out_err);
2174
2175
2176
/*! Tags a FileIO object to be accessed from main thread only
2177
\param fileio target file IO object
2178
\return error if any
2179
*/
2180
GF_Err gf_fileio_tag_main_thread(GF_FileIO *fileio);
2181
2182
/*! Check if a FileIO object is to be accessed from main thread only
2183
2184
 \note Filters accessing FileIO objects by other means that a filter option must manually tag themselves as main thread, potentially rescheduling a configure call to next process. Not doing so can result in binding crashes in multi-threaded mode.
2185
2186
\param url target url
2187
\return GF_TRUE if object is tagged for main thread, GF_FALSE otherwise
2188
*/
2189
Bool gf_fileio_is_main_thread(const char *url);
2190
2191
/*! Gets GF_FileIO object from its URL
2192
 The url uses the protocol scheme "gfio://"
2193
\param url the URL of  the File IO object
2194
\return the file IO object
2195
*/
2196
GF_FileIO *gf_fileio_from_url(const char *url);
2197
2198
/*! Constructs a new GF_FileIO object from a URL
2199
 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.
2200
 The function will not open the associated resource, only create the file IO wrapper for later usage
2201
 If you need to create a new fileIO to be opened immediately, use \ref gf_fopen_ex.
2202
2203
\param fileio parent file IO object
2204
\param new_res_url the original URL of  the new object to create
2205
\return the url (gfio://) of the created file IO object, NULL otherwise
2206
*/
2207
const char *gf_fileio_factory(GF_FileIO *fileio, const char *new_res_url);
2208
2209
/*! Translates a FileIO object URL into the original resource URL
2210
\param url the URL of  the File IO object
2211
\return the original resource URL associated with the file IO object
2212
*/
2213
const char * gf_fileio_translate_url(const char *url);
2214
/*! Gets a FileIO  original resource URL
2215
\param fileio target file IO object
2216
\return the original resource URL associated with the file IO object
2217
*/
2218
const char * gf_fileio_resource_url(GF_FileIO *fileio);
2219
2220
/*! Checks if a FileIO object can read
2221
\param fileio target file IO object
2222
\return GF_TRUE if read is enabled on this object
2223
*/
2224
Bool gf_fileio_read_mode(GF_FileIO *fileio);
2225
/*! Checks if a FileIO object can write
2226
\param fileio target file IO object
2227
\return GF_TRUE if write is enabled on this object
2228
*/
2229
Bool gf_fileio_write_mode(GF_FileIO *fileio);
2230
2231
/*! Function callback for GF_FileIO delete events. The callback is NOT thread-safe in GPAC, applications should take care of ensuring safety
2232
2233
\note Applications must make sure that the underlying gfio objects are defined as GPAC does not track allocated gfio objects.
2234
2235
 \param url a gfio:// url to be deleted or a regular  name if parent_gfio_url is NULL.
2236
 \param parent_gfio_url the parent GFIO associated with the URL string, or NULL if url is a gfio url
2237
 \return error code if any, GF_EOS if this callback is not handling this specific gfio
2238
*/
2239
typedef GF_Err (*gfio_delete_proc)(const char *url, const char *parent_gfio_url);
2240
2241
/*! Register a GF_FileIO delete callback. This function is NOT threadsafe, applications should take care of ensuring safety
2242
\param del_proc the calback to register. It MUST be valid until unregistered
2243
\return error if any
2244
*/
2245
GF_Err gf_fileio_register_delete_proc(gfio_delete_proc del_proc);
2246
2247
/*! Unregister a GF_FileIO delete callback. This function is NOT threadsafe, applications should take care of ensuring safety
2248
\param del_proc the calback to unregister.
2249
*/
2250
void gf_fileio_unregister_delete_proc(gfio_delete_proc del_proc);
2251
2252
/*! @} */
2253
2254
/*!
2255
\addtogroup hash_grp
2256
\brief Data hashing, integrity and generic compression
2257
2258
This section documents misc data functions such as integrity and parsing such as SHA-1 hashing CRC checksum, 128 bit ID parsing...
2259
2260
@{
2261
 */
2262
2263
2264
/*!
2265
\brief CRC32 compute
2266
2267
Computes the CRC32 value of a buffer.
2268
\param data buffer
2269
\param size buffer size
2270
\return computed CRC32
2271
 */
2272
u32 gf_crc_32(const u8 *data, u32 size);
2273
2274
2275
/**
2276
Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.
2277
\param data pointer to the data buffer to be compressed
2278
\param data_len length of the data buffer to be compressed
2279
\param out_size pointer for output buffer size
2280
\return error if any
2281
 */
2282
GF_Err gf_gz_compress_payload(u8 **data, u32 data_len, u32 *out_size);
2283
2284
/**
2285
Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.
2286
\param data pointer to the data buffer to be compressed
2287
\param data_len length of the data buffer to be compressed
2288
\param out_size pointer for output buffer size
2289
\param data_offset offset in source buffer - the input payload size is data_len - data_offset
2290
\param skip_if_larger if GF_TRUE, will not override source buffer if compressed version is larger than input data
2291
\param out_comp_data if not NULL, the compressed result is set in this pointer rather than doing inplace compression
2292
\param use_gz if true, GZ header is present
2293
\return error if any
2294
 */
2295
GF_Err gf_gz_compress_payload_ex(u8 **data, u32 data_len, u32 *out_size, u8 data_offset, Bool skip_if_larger, u8 **out_comp_data, Bool use_gz);
2296
2297
/**
2298
Decompresses a data buffer using zlib/inflate.
2299
\param data data buffer to be decompressed
2300
\param data_len length of the data buffer to be decompressed
2301
\param uncompressed_data pointer to the uncompressed data buffer. The resulting buffer is NULL-terminated. It is the responsibility of the caller to free this buffer.
2302
\param out_size size of the uncompressed buffer
2303
\return error if any
2304
 */
2305
GF_Err gf_gz_decompress_payload(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size);
2306
2307
/**
2308
Decompresses a data buffer using zlib/inflate.
2309
\param data data buffer to be decompressed
2310
\param data_len length of the data buffer to be decompressed
2311
\param uncompressed_data pointer to the uncompressed data buffer. The resulting buffer is NULL-terminated. It is the responsibility of the caller to free this buffer.
2312
\param out_size size of the uncompressed buffer
2313
\param use_gz if true, gz header is present
2314
\return error if any
2315
 */
2316
GF_Err gf_gz_decompress_payload_ex(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size, Bool use_gz);
2317
2318
2319
/**
2320
Compresses a data buffer in place using LZMA. Buffer may be reallocated in the process.
2321
\param data pointer to the data buffer to be compressed
2322
\param data_len length of the data buffer to be compressed
2323
\param out_size pointer for output buffer size
2324
\return error if any
2325
 */
2326
GF_Err gf_lz_compress_payload(u8 **data, u32 data_len, u32 *out_size);
2327
2328
/**
2329
Decompresses a data buffer using LZMA.
2330
\param data data buffer to be decompressed
2331
\param data_len length of the data buffer to be decompressed
2332
\param uncompressed_data pointer to the uncompressed data buffer. It is the responsibility of the caller to free this buffer.
2333
\param out_size size of the uncompressed buffer
2334
\return error if any
2335
 */
2336
GF_Err gf_lz_decompress_payload(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size);
2337
2338
2339
#ifndef GPAC_DISABLE_ZLIB
2340
/*! Wrapper around gzseek, same parameters
2341
\param file target gzfile
2342
\param offset offset in file
2343
\param whence same as gzseek
2344
\return same as gzseek
2345
*/
2346
u64 gf_gzseek(void *file, u64 offset, int whence);
2347
/*! Wrapper around gf_gztell, same parameters
2348
 \param file target gzfile
2349
 \return postion in file
2350
 */
2351
u64 gf_gztell(void *file);
2352
/*! Wrapper around gzrewind, same parameters
2353
 \param file target gzfile
2354
 \return same as gzrewind
2355
 */
2356
s64 gf_gzrewind(void *file);
2357
/*! Wrapper around gzeof, same parameters
2358
 \param file target gzfile
2359
 \return same as gzeof
2360
 */
2361
int gf_gzeof(void *file);
2362
/*! Wrapper around gzclose, same parameters
2363
\param file target gzfile
2364
\return same as gzclose
2365
*/
2366
int gf_gzclose(void *file);
2367
/*! Wrapper around gzerror, same parameters
2368
\param file target gzfile
2369
\param errnum same as gzerror
2370
\return same as gzerror
2371
 */
2372
const char * gf_gzerror (void *file, int *errnum);
2373
/*! Wrapper around gzclearerr, same parameters
2374
 \param file target gzfile
2375
 */
2376
void gf_gzclearerr(void *file);
2377
/*! Wrapper around gzopen, same parameters
2378
\param path the file name to open
2379
\param mode the file open mode
2380
\return open file
2381
 */
2382
void *gf_gzopen(const char *path, const char *mode);
2383
/*! Wrapper around gzread, same parameters
2384
 \param file target gzfile
2385
 \param buf same as gzread
2386
 \param len same as gzread
2387
 \return same as gzread
2388
 */
2389
int gf_gzread(void *file, void *buf, unsigned len);
2390
/*! Wrapper around gzdirect, same parameters
2391
 \param file target gzfile
2392
 \return same as gzdirect
2393
 */
2394
int gf_gzdirect(void *file);
2395
/*! Wrapper around gzgetc, same parameters
2396
 \param file target gzfile
2397
 \return same as gzgetc
2398
 */
2399
int gf_gzgetc(void *file);
2400
/*! Wrapper around gzgets, same parameters
2401
 \param file target gzfile
2402
 \param buf same as gzread
2403
 \param len same as gzread
2404
 \return same as gzgets
2405
*/
2406
char * gf_gzgets(void *file, char *buf, int len);
2407
#endif
2408
2409
2410
/*! SHA1 context*/
2411
typedef struct __sha1_context GF_SHA1Context;
2412
2413
/*! SHA1 message size */
2414
0
#define GF_SHA1_DIGEST_SIZE   20
2415
2416
/*! create SHA-1 context
2417
\return the SHA1 context*/
2418
GF_SHA1Context *gf_sha1_starts();
2419
/*! adds byte to the SHA-1 context
2420
\param ctx the target SHA1 context
2421
\param input data to hash
2422
\param length size of data in bytes
2423
*/
2424
void gf_sha1_update(GF_SHA1Context *ctx, u8 *input, u32 length);
2425
/*! generates SHA-1 of all bytes ingested
2426
\param ctx the target SHA1 context
2427
\param digest buffer to store message digest
2428
*/
2429
void gf_sha1_finish(GF_SHA1Context *ctx, u8 digest[GF_SHA1_DIGEST_SIZE] );
2430
2431
/*! gets SHA1 message digest of a file
2432
\param filename name of file to hash
2433
\param digest buffer to store message digest
2434
\return error if any
2435
*/
2436
GF_Err gf_sha1_file(const char *filename, u8 digest[GF_SHA1_DIGEST_SIZE]);
2437
2438
/*! gets SHA1 message digest of a opened file
2439
\param file  handle to open file
2440
\param digest buffer to store message digest
2441
\return error if any
2442
*/
2443
GF_Err gf_sha1_file_ptr(FILE *file, u8 digest[GF_SHA1_DIGEST_SIZE] );
2444
2445
/*! gets SHA-1 of input buffer
2446
\param buf input buffer to hash
2447
\param buflen size of input buffer in bytes
2448
\param digest buffer to store message digest
2449
 */
2450
void gf_sha1_csum(u8 *buf, u32 buflen, u8 digest[GF_SHA1_DIGEST_SIZE]);
2451
/*! @} */
2452
2453
/*! checksum size for SHA-256*/
2454
0
#define GF_SHA256_DIGEST_SIZE 32
2455
/*! gets SHA-256 of input buffer
2456
\param buf input buffer to hash
2457
\param buflen size of input buffer in bytes
2458
\param digest buffer to store message digest
2459
 */
2460
void gf_sha256_csum(const void *buf, u64 buflen, u8 digest[GF_SHA256_DIGEST_SIZE]);
2461
2462
2463
/*! checksum size for MD5*/
2464
0
#define GF_MD5_DIGEST_SIZE  16
2465
2466
/*! gets MD5 of input buffer
2467
\param buf input buffer to hash
2468
\param buflen size of input buffer in bytes
2469
\param digest buffer to store message digest
2470
 */
2471
void gf_md5_csum(const void *buf, u32 buflen, u8 digest[GF_MD5_DIGEST_SIZE]);
2472
2473
/*!
2474
\addtogroup libsys_grp
2475
@{
2476
*/
2477
2478
/*! gets a global config key value from its section and name.
2479
\param secName the desired key parent section name
2480
\param keyName the desired key name
2481
\return the desired key value if found, NULL otherwise.
2482
*/
2483
const char *gf_opts_get_key(const char *secName, const char *keyName);
2484
2485
/*! sets a global config key value from its section and name.
2486
\param secName the desired key parent section name
2487
\param keyName the desired key name
2488
\param keyValue the desired key value
2489
\note this will also create both section and key if they are not found in the configuration file
2490
\return error if any
2491
*/
2492
GF_Err gf_opts_set_key(const char *secName, const char *keyName, const char *keyValue);
2493
2494
/*! removes all entries in the given section of the global config
2495
\param secName the target section
2496
*/
2497
void gf_opts_del_section(const char *secName);
2498
/*! gets the number of sections in the global config
2499
\return the number of sections
2500
*/
2501
u32 gf_opts_get_section_count();
2502
/*! gets a section name based on its index in the global config
2503
\param secIndex 0-based index of the section to query
2504
\return the section name if found, NULL otherwise
2505
*/
2506
const char *gf_opts_get_section_name(u32 secIndex);
2507
2508
/*! gets the number of keys in a section of the global config
2509
\param secName the target section
2510
\return the number of keys in the section
2511
*/
2512
u32 gf_opts_get_key_count(const char *secName);
2513
/*! gets the number of keys in a section of the global config
2514
\param secName the target section
2515
\param keyIndex 0-based index of the key in the section
2516
\return the key name if found, NULL otherwise
2517
*/
2518
const char *gf_opts_get_key_name(const char *secName, u32 keyIndex);
2519
2520
/*! gets a global config boolean value from its section and name.
2521
\param secName the desired key parent section name
2522
\param keyName the desired key name
2523
\return the desired key value if found, GF_FALSE otherwise.
2524
*/
2525
Bool gf_opts_get_bool(const char *secName, const char *keyName);
2526
2527
/*! gets a global config integer value from its section and name.
2528
\param secName the desired key parent section name
2529
\param keyName the desired key name
2530
\return the desired key value if found, 0 otherwise.
2531
*/
2532
u32 gf_opts_get_int(const char *secName, const char *keyName);
2533
2534
/*! gets a global config key value from its section and name.
2535
\param secName the desired key parent section name
2536
\param keyName the desired key name
2537
\return the desired key value if found and if the key is not restricted, NULL otherwise.
2538
*/
2539
const char *gf_opts_get_key_restricted(const char *secName, const char *keyName);
2540
2541
/*!
2542
 * Do not save modification to global options
2543
\return error code
2544
 */
2545
GF_Err gf_opts_discard_changes();
2546
2547
/*!
2548
 * Force immediate write of config
2549
\return error code
2550
 */
2551
GF_Err gf_opts_save();
2552
2553
/*!
2554
 * Returns file name of global config
2555
\return file name of global config or NULL if libgpac is not initialized
2556
 */
2557
const char *gf_opts_get_filename();
2558
2559
/*!
2560
 * Gets GPAC shared directory (gui, shaders, etc ..)
2561
\param path_buffer GF_MAX_PATH buffer to store output
2562
\return GF_TRUE if success, GF_FALSE otherwise
2563
 */
2564
Bool gf_opts_default_shared_directory(char *path_buffer);
2565
2566
2567
/*!
2568
 * Checks given user and password are valid
2569
\param username user name
2570
\param password password
2571
\return GF_OK if success, GF_NOT_FOUND if no such user or GF_AUTHENTICATION_FAILURE if wrong password
2572
 */
2573
GF_Err gf_creds_check_password(const char *username, char *password);
2574
2575
/*!
2576
 * Checks given user belongs to list of users or groups.
2577
\param username user name
2578
\param users comma-seprated list of users to check, may be NULL
2579
\param groups comma-seprated list of groups to check, may be NULL
2580
\return GF_TRUE if success, GF_FALSE otherwise
2581
 */
2582
Bool gf_creds_check_membership(const char *username, const char *users, const char *groups);
2583
2584
/*! @} */
2585
2586
2587
//! @cond Doxygen_Suppress
2588
2589
#ifdef GPAC_DISABLE_RMTWS
2590
#define RMT_ENABLED 0
2591
#endif
2592
2593
#include <gpac/rmt_ws.h>
2594
2595
//! @endcond
2596
2597
2598
/* \cond dummy */
2599
2600
/*to call whenever the OpenGL library is opened - this function is needed to load OpenGL extensions on windows
2601
not exported, and not included in src/compositor/gl_inc.h since it may be needed even when no OpenGL
2602
calls are made by the caller*/
2603
void gf_opengl_init();
2604
2605
typedef enum
2606
{
2607
  //pbo not enabled
2608
  GF_GL_PBO_NONE=0,
2609
  //pbo enabled, both push and glTexImage textures are done in gf_gl_txw_upload
2610
  GF_GL_PBO_BOTH,
2611
  //push only is done in gf_gl_txw_upload
2612
  GF_GL_PBO_PUSH,
2613
  // glTexImage textures only is done in gf_gl_txw_upload
2614
  GF_GL_PBO_TEXIMG,
2615
} GF_GLPBOState;
2616
2617
typedef struct _gl_texture_wrap
2618
{
2619
  u32 textures[4];
2620
  u32 PBOs[4];
2621
2622
  u32 nb_textures;
2623
  u32 width, height, pix_fmt, stride, uv_stride;
2624
  Bool is_yuv;
2625
  u32 bit_depth, uv_w, uv_h;
2626
  u32 scale_10bit;
2627
  u32 init_active_texture;
2628
2629
  u32 gl_format;
2630
  u32 bytes_per_pix;
2631
  Bool has_alpha;
2632
  Bool internal_textures;
2633
  Bool uniform_setup;
2634
  u32 memory_format;
2635
  struct _gf_filter_frame_interface *frame_ifce;
2636
  Bool first_tx_load;
2637
2638
  //PBO state - must be managed by caller, especially if using separated push and texImg steps through gf_gl_txw_setup calls
2639
  GF_GLPBOState pbo_state;
2640
  Bool flip;
2641
  //YUV is full video range
2642
  Bool fullrange;
2643
  s32 mx_cicp;
2644
2645
  u32 last_program;
2646
} GF_GLTextureWrapper;
2647
2648
Bool gf_gl_txw_insert_fragment_shader(u32 pix_fmt, const char *tx_name, char **f_source, Bool y_flip);
2649
Bool gf_gl_txw_setup(GF_GLTextureWrapper *tx, u32 pix_fmt, u32 width, u32 height, u32 stride, u32 uv_stride, Bool linear_interp, struct _gf_filter_frame_interface *frame_ifce, Bool full_range, s32 matrix_coef_or_neg);
2650
Bool gf_gl_txw_upload(GF_GLTextureWrapper *tx, const u8 *data, struct _gf_filter_frame_interface *frame_ifce);
2651
Bool gf_gl_txw_bind(GF_GLTextureWrapper *tx, const char *tx_name, u32 gl_program, u32 texture_unit);
2652
void gf_gl_txw_reset(GF_GLTextureWrapper *tx);
2653
2654
/* \endcond */
2655
2656
2657
/*! macros to get the size of an array of struct*/
2658
115k
#define GF_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
2659
2660
#ifdef __cplusplus
2661
}
2662
#endif
2663
2664
2665
#endif    /*_GF_CORE_H_*/