Coverage Report

Created: 2025-11-09 07:03

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
0
#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 specfication 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
1.78k
#define GF_SAFEALLOC(__ptr, __struct) {\
243
1.78k
    (__ptr) = (__struct *) gf_malloc(sizeof(__struct));\
244
1.78k
    if (__ptr) {\
245
1.78k
      memset((void *) (__ptr), 0, sizeof(__struct));\
246
1.78k
    }\
247
1.78k
  }
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
0
#define GF_SAFE_ALLOC_N(__ptr, __n, __struct) {\
256
0
    (__ptr) = (__struct *) gf_malloc( __n * sizeof(__struct));\
257
0
    if (__ptr) {\
258
0
      memset((void *) (__ptr), 0, __n * sizeof(__struct));\
259
0
    }\
260
0
  }
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
764
/*!
765
GPAC Log tools
766
\hideinitializer
767
768
Describes the color code for console print
769
 */
770
typedef enum
771
{
772
  /*!reset color*/
773
  GF_CONSOLE_RESET=0,
774
  /*!set text to red*/
775
  GF_CONSOLE_RED,
776
  /*!set text to green*/
777
  GF_CONSOLE_GREEN,
778
  /*!set text to blue*/
779
  GF_CONSOLE_BLUE,
780
  /*!set text to yellow*/
781
  GF_CONSOLE_YELLOW,
782
  /*!set text to cyan*/
783
  GF_CONSOLE_CYAN,
784
  /*!set text to white*/
785
  GF_CONSOLE_WHITE,
786
  /*!set text to magenta*/
787
  GF_CONSOLE_MAGENTA,
788
  /*!reset all console text*/
789
  GF_CONSOLE_CLEAR,
790
  /*!save console state*/
791
  GF_CONSOLE_SAVE,
792
  /*!restore console state*/
793
  GF_CONSOLE_RESTORE,
794
795
  /*!set text to bold modifier*/
796
  GF_CONSOLE_BOLD = 1<<16,
797
  /*!set text to italic*/
798
  GF_CONSOLE_ITALIC = 1<<17,
799
  /*!set text to underlined*/
800
  GF_CONSOLE_UNDERLINED = 1<<18,
801
  /*!set text to strikethrough*/
802
  GF_CONSOLE_STRIKE = 1<<19
803
} GF_ConsoleCodes;
804
805
/*! sets console code
806
\param std the output stream (stderr or stdout)
807
\param code the console code to set
808
*/
809
void gf_sys_set_console_code(FILE *std, GF_ConsoleCodes code);
810
811
812
/*! @} */
813
814
815
/*!
816
\addtogroup log_grp
817
\brief Logging System
818
819
@{
820
*/
821
822
/*!
823
\brief GPAC Log Levels
824
\hideinitializer
825
826
These levels describes messages priority used when filtering logs
827
*/
828
typedef enum
829
{
830
  /*! Disable all Log message*/
831
  GF_LOG_QUIET = 0,
832
  /*! Log message describes an error*/
833
  GF_LOG_ERROR,
834
  /*! Log message describes a warning*/
835
  GF_LOG_WARNING,
836
  /*! Log message is informational (state, etc..)*/
837
  GF_LOG_INFO,
838
  /*! Log message is a debug info*/
839
  GF_LOG_DEBUG
840
} GF_LOG_Level;
841
842
/*!
843
\brief Log exits at first error assignment
844
845
When GF_LOG_ERROR happens, program leaves with instruction exit(1);
846
\param strict strict behavior when encoutering a serious error.
847
\return old value before the call.
848
 */
849
Bool gf_log_set_strict_error(Bool strict);
850
851
/*!
852
\brief gets string-formatted log tools
853
854
Gets the string-formatted log tools and levels. Returned string shall be freed by the caller.
855
\return string-formatted log tools.
856
 */
857
char *gf_log_get_tools_levels(void);
858
859
/*!
860
\brief GPAC Log tools
861
\hideinitializer
862
863
These flags describes which sub-part of GPAC generates the log and are used when filtering logs
864
 */
865
typedef enum
866
{
867
  /*! Log message from the core library (init, threads, network calls, etc)*/
868
  GF_LOG_CORE = 0,
869
  /*! Log message from a raw media parser (BIFS, LASeR, A/V formats)*/
870
  GF_LOG_CODING,
871
  /*! Log message from a bitstream parser (IsoMedia, MPEG-2 TS, OGG, ...)*/
872
  GF_LOG_CONTAINER,
873
  /*! Log message from the network/service stack (messages & co)*/
874
  GF_LOG_NETWORK,
875
  /*! Log message from the HTTP stack*/
876
  GF_LOG_HTTP,
877
  /*! Log message from the RTP/RTCP stack (TS info) and packet structure & hinting (debug)*/
878
  GF_LOG_RTP,
879
  /*! Log message from a codec*/
880
  GF_LOG_CODEC,
881
  /*! Log message from any textual (XML, ...) parser (context loading, etc)*/
882
  GF_LOG_PARSER,
883
  /*! Generic log message from a filter (not from filter core library)*/
884
  GF_LOG_MEDIA,
885
  /*! Log message from the scene graph/scene manager (handling of nodes and attribute modif, DOM core)*/
886
  GF_LOG_SCENE,
887
  /*! Log message from the scripting engine APIs - does not cover alert() in the script code itself*/
888
  GF_LOG_SCRIPT,
889
  /*! Log message from event handling*/
890
  GF_LOG_INTERACT,
891
  /*! Log message from compositor*/
892
  GF_LOG_COMPOSE,
893
  /*! Log message from the compositor, indicating media object state*/
894
  GF_LOG_COMPTIME,
895
  /*! Log for video object cache */
896
  GF_LOG_CACHE,
897
  /*! Log message from multimedia I/O devices (audio/video input/output, ...)*/
898
  GF_LOG_MMIO,
899
  /*! Log for runtime info (times, memory, CPU usage)*/
900
  GF_LOG_RTI,
901
  /*! Log for memory tracker*/
902
  GF_LOG_MEMORY,
903
  /*! Log for audio compositor*/
904
  GF_LOG_AUDIO,
905
  /*! Generic Log for modules*/
906
  GF_LOG_MODULE,
907
  /*! Log for threads and mutexes */
908
  GF_LOG_MUTEX,
909
  /*! Log for threads and condition */
910
  GF_LOG_CONDITION,
911
  /*! Log for all HTTP streaming */
912
  GF_LOG_DASH,
913
  /*! Log for all messages from filter core library (not from a filter) */
914
  GF_LOG_FILTER,
915
  /*! Log for filter scheduler only */
916
  GF_LOG_SCHEDULER,
917
  /*! Log for all ROUTE message */
918
  GF_LOG_ROUTE,
919
  /*! Log for all messages coming from script*/
920
  GF_LOG_CONSOLE,
921
  /*! Log for all messages coming the application, not used by libgpac or the modules*/
922
  GF_LOG_APP,
923
  /*! Log for all info regarding the rmt_ws server and bindings*/
924
  GF_LOG_RMTWS,
925
926
  /*! special value used to set a level for all tools*/
927
  GF_LOG_ALL,
928
  GF_LOG_TOOL_MAX = GF_LOG_ALL,
929
  GF_LOG_TOOL_UNDEFINED
930
} GF_LOG_Tool;
931
932
/*!
933
\brief Log modules assignment
934
935
Sets the tools to be checked for log filtering. By default no logging is performed.
936
\param log_tool the tool to be logged
937
\param log_level the level of logging for this tool
938
 *
939
 */
940
void gf_log_set_tool_level(GF_LOG_Tool log_tool, GF_LOG_Level log_level);
941
942
/*!
943
\brief Log Message Callback
944
945
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
946
\param cbck Opaque user data.
947
\param log_level level of the log. This value is not guaranteed in multi-threaded context.
948
\param log_tool tool emitting the log. This value is not guaranteed in multi-threaded context.
949
\param fmt message log format.
950
\param vlist message log param.
951
 *
952
 */
953
typedef void (*gf_log_cbk)(void *cbck, GF_LOG_Level log_level, GF_LOG_Tool log_tool, const char* fmt, va_list vlist);
954
955
/*!
956
\brief Log overwrite
957
958
Assigns a user-defined callback for printing log messages. By default all logs are redirected to stderr
959
\param usr_cbk Opaque user data
960
\param cbk     Callback log function
961
\return previous callback function
962
*/
963
gf_log_cbk gf_log_set_callback(void *usr_cbk, gf_log_cbk cbk);
964
965
966
/*!
967
 \cond DUMMY_DOXY_SECTION
968
*/
969
#ifndef GPAC_DISABLE_LOG
970
/*\note
971
  - to turn log on, change to GPAC_ENABLE_LOG
972
  - to turn log off, change to GPAC_DISABLE_LOG
973
  this is needed by configure+sed to modify this file directly
974
*/
975
#define GPAC_ENABLE_LOG
976
#endif
977
978
/*!
979
 \endcond
980
*/
981
982
983
/*! \cond PRIVATE */
984
void gf_log(const char *fmt, ...);
985
void gf_log_lt(GF_LOG_Level ll, GF_LOG_Tool lt);
986
void gf_log_va_list(GF_LOG_Level level, GF_LOG_Tool tool, const char *fmt, va_list vl);
987
/*! \endcond */
988
989
/*!
990
\brief Log level checking
991
992
Checks if a given tool is logged for the given level
993
\param log_tool tool to check
994
\param log_level level to check
995
\return 1 if logged, 0 otherwise
996
*/
997
Bool gf_log_tool_level_on(GF_LOG_Tool log_tool, GF_LOG_Level log_level);
998
999
/*!
1000
\brief Log tool name
1001
1002
Gets log  tool name
1003
\param log_tool tool to check
1004
\return name, or "unknown" if not known
1005
*/
1006
const char *gf_log_tool_name(GF_LOG_Tool log_tool);
1007
1008
/*!
1009
\brief Log level getter
1010
1011
Gets log level of a given tool
1012
\param log_tool tool to check
1013
\return log level of tool
1014
*/
1015
u32 gf_log_get_tool_level(GF_LOG_Tool log_tool);
1016
1017
/*!
1018
\brief Set log tools and levels
1019
1020
Set log tools and levels according to the log_tools_levels string.
1021
\param log_tools_levels string specifying the tools and levels. It is formatted as logToolX\@logLevelX:logToolZ\@logLevelZ:...
1022
\param reset_all if GF_TRUE, all previous log settings are discarded.
1023
\return GF_OK or GF_BAD_PARAM
1024
*/
1025
GF_Err gf_log_set_tools_levels(const char *log_tools_levels, Bool reset_all);
1026
1027
/*!
1028
\brief Modify log tools and levels
1029
1030
Modify log tools and levels according to the log_tools_levels string. Previous log settings are kept.
1031
\param val string specifying the tools and levels. It is formatted as logToolX\@logLevelX:logToolZ\@logLevelZ:...
1032
\return GF_OK or GF_BAD_PARAM
1033
*/
1034
GF_Err gf_log_modify_tools_levels(const char *val);
1035
1036
/*!
1037
\brief Checks if color logs is enabled
1038
1039
Checks if color logs is enabled
1040
\return GF_TRUE if color logs are used
1041
*/
1042
Bool gf_log_use_color();
1043
1044
/*!
1045
\brief Checks if logs are stored to file
1046
1047
Checks if logs are stored to file
1048
\return GF_TRUE if logs are stored to file
1049
*/
1050
Bool gf_log_use_file();
1051
1052
/*!
1053
\brief Parses a log tool
1054
1055
Parses a log tool by name
1056
\param logs the name to parse
1057
\return log tool value
1058
*/
1059
u32 gf_log_parse_tool(const char *logs);
1060
1061
#ifdef GPAC_DISABLE_LOG
1062
void gf_log_check_error(u32 ll, u32 lt);
1063
#define GF_LOG(_ll, _lm, __args) gf_log_check_error(_ll, _lm);
1064
#else
1065
/*!
1066
\brief Message logging
1067
\hideinitializer
1068
1069
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.
1070
*/
1071
1.39k
#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 ;}
1072
#endif
1073
1074
/*!
1075
\brief Resets log file
1076
Resets log file if any log file name was specified, by closing and reopening a new file.
1077
*/
1078
void gf_log_reset_file();
1079
1080
//! Extra log instructions
1081
typedef struct log_extra
1082
{
1083
  //! number of tools and levels
1084
  u32 nb_tools;
1085
  //! additionnal  tools
1086
  GF_LOG_Tool *tools;
1087
  //! additionnal  levels for the tools
1088
  GF_LOG_Level *levels;
1089
  //! exit if error
1090
  Bool strict;
1091
} GF_LogExtra;
1092
1093
/*! Register a new extra log levels
1094
 \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
1095
*/
1096
void gf_log_push_extra(const GF_LogExtra *log);
1097
/*! Unregister an extra log levels
1098
 \param log extra levels to add - may be NULL
1099
*/
1100
void gf_log_pop_extra(const GF_LogExtra *log);
1101
/*! Unregister all  extra log levels
1102
*/
1103
void gf_log_reset_extras();
1104
1105
/*! @} */
1106
1107
/*!
1108
\addtogroup miscsys_grp
1109
\brief System time CPU
1110
1111
This section documents time functionalities and CPU management in GPAC.
1112
1113
@{
1114
 */
1115
1116
1117
/*!
1118
\brief PseudoRandom Integer Generation Initialization
1119
1120
Sets the starting point for generating a series of pseudorandom integers.
1121
\param Reset Re-initializes the random number generator
1122
*/
1123
void gf_rand_init(Bool Reset);
1124
/*! PseudoRandom integer generation
1125
\return a pseudorandom integer
1126
*/
1127
u32 gf_rand();
1128
1129
/*! gets user name
1130
\param buf buffer set to current user (login) name if available.
1131
*/
1132
void gf_get_user_name(char buf[1024]);
1133
1134
/*!
1135
\brief Progress formatting
1136
1137
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.
1138
\param title title string of the progress, or NULL for no progress
1139
\param done Current amount performed of the action.
1140
\param total Total amount of the action.
1141
 */
1142
void gf_set_progress(const char *title, u64 done, u64 total);
1143
1144
/*!
1145
\brief Progress Callback
1146
1147
The gf_on_progress_cbk type is the type for the callback of the \ref gf_set_progress_callback function
1148
\param cbck Opaque user data.
1149
\param title preogress title.
1150
\param done Current amount performed of the action
1151
\param total Total amount of the action.
1152
 *
1153
 */
1154
typedef void (*gf_on_progress_cbk)(const void *cbck, const char *title, u64 done, u64 total);
1155
1156
/*!
1157
\brief Progress overwriting
1158
Overwrites the progress signaling function by a user-defined one.
1159
\param user_cbk Opaque user data
1160
\param prog_cbk new callback function to use. Passing NULL restore default GPAC stderr notification.
1161
 */
1162
void gf_set_progress_callback(void *user_cbk, gf_on_progress_cbk prog_cbk);
1163
1164
1165
/*!
1166
\brief Prompt checking
1167
1168
Checks if a character is pending in the prompt buffer.
1169
\return 1 if a character is ready to be fetched, 0 otherwise.
1170
\note Function not available under WindowsCE nor SymbianOS
1171
*/
1172
Bool gf_prompt_has_input();
1173
1174
/*!
1175
\brief Prompt character flush
1176
1177
Gets the current character entered at prompt if any.
1178
\return value of the character.
1179
\note Function not available under WindowsCE nor SymbianOS
1180
*/
1181
char gf_prompt_get_char();
1182
1183
/*!
1184
\brief Get prompt TTY size
1185
1186
Gets the stdin prompt size (columns and rows)
1187
\param width set to number of rows in the TTY
1188
\param height set to number of columns in the TTY
1189
\return error if any
1190
*/
1191
GF_Err gf_prompt_get_size(u32 *width, u32 *height);
1192
1193
/*!
1194
\brief turns prompt echo on/off
1195
1196
Turns the prompt character echo on/off - this is useful when entering passwords.
1197
\param echo_off indicates whether echo should be turned on or off.
1198
\note Function not available under WindowsCE nor SymbianOS
1199
*/
1200
void gf_prompt_set_echo_off(Bool echo_off);
1201
1202
/*! @} */
1203
1204
1205
/*! gets battery state
1206
\param onBattery set to GF_TRUE if running on battery
1207
\param onCharge set to GF_TRUE if battery is charging
1208
\param level set to battery charge percent
1209
\param batteryLifeTime set to battery lifetime
1210
\param batteryFullLifeTime set to battery full lifetime
1211
\return GF_TRUE if success
1212
*/
1213
Bool gf_sys_get_battery_state(Bool *onBattery, u32 *onCharge, u32 *level, u32 *batteryLifeTime, u32 *batteryFullLifeTime);
1214
1215
1216
/*!
1217
\brief parses 128 bit from string
1218
1219
Parses 128 bit from string
1220
\param string the string containing the value in hexa. Non alphanum characters are skipped
1221
\param value the value parsed
1222
\return error code if any
1223
 */
1224
GF_Err gf_bin128_parse(const char *string, bin128 value);
1225
1226
1227
/*! blob range status */
1228
typedef enum
1229
{
1230
  /*! blob range is valid */
1231
  GF_BLOB_RANGE_VALID=0,
1232
  /*! blob range is not valid, still in transfer */
1233
  GF_BLOB_RANGE_IN_TRANSFER,
1234
  /*! blob range is not in transfer and is (partially or completely) lost */
1235
  GF_BLOB_RANGE_CORRUPTED,
1236
} GF_BlobRangeStatus;
1237
1238
/*! blob flags*/
1239
enum
1240
{
1241
  /*! blob is in transfer */
1242
    GF_BLOB_IN_TRANSFER = 1,
1243
  /*! blob is corrupted */
1244
    GF_BLOB_CORRUPTED = 1<<1,
1245
  /*! blob is parsable (valid mux format) but had partial repair only (media holes) */
1246
    GF_BLOB_PARTIAL_REPAIR = 1<<2
1247
};
1248
1249
/*!
1250
 * Blob structure used to pass data pointer around
1251
 */
1252
typedef struct __gf_blob
1253
{
1254
  /*! data block of blob */
1255
  u8 *data;
1256
  /*! size of blob */
1257
  u32 size;
1258
    /*! blob flags */
1259
    u32 flags;
1260
#ifdef GPAC_DISABLE_THREADS
1261
    void *mx;
1262
#else
1263
    /*! blob mutex for multi-thread access */
1264
    struct __tag_mutex *mx;
1265
#endif
1266
    /*! last blob modification time (write access) in microsec , 0 if unknown*/
1267
    u64 last_modification_time;
1268
  /*! function used to query if a range of a blob in transfer is valid. If NULL, any range is invalid until transfer is done
1269
  when set this function overrides the blob flags for gf_blob_query_range
1270
  size is updated to the maximum number of consecutive bytes starting from the goven offset */
1271
  GF_BlobRangeStatus (*range_valid)(struct __gf_blob *blob, u64 start, u32 *size);
1272
  /*! private data for range_valid function*/
1273
  void *range_udta;
1274
} GF_Blob;
1275
1276
/*!
1277
 * Retrieves data associated with a blob url. If success, \ref gf_blob_release must be called after this
1278
\param blob_url URL of blob object (ie gmem://%p)
1279
\param out_data if success, set to blob data pointer
1280
\param out_size if success, set to blob data size
1281
\param blob_flags if success, set to blob flags - may be NULL
1282
\return error code
1283
 */
1284
GF_Err gf_blob_get(const char *blob_url, u8 **out_data, u32 *out_size, u32 *blob_flags);
1285
1286
/*!
1287
 * Checks if a given byte range is valid in blob
1288
\param blob  blob object
1289
\param start_offset start offset of data to check in blob
1290
\param size size of data to check in blob
1291
\return blob range status
1292
 */
1293
GF_BlobRangeStatus gf_blob_query_range(GF_Blob *blob, u64 start_offset, u32 size);
1294
1295
/*!
1296
 * Releases blob data
1297
\param blob_url URL of blob object (ie gmem://%p)
1298
\return error code
1299
 */
1300
GF_Err gf_blob_release(const char *blob_url);
1301
1302
1303
/*!
1304
 * Retrieves data associated with a blob. If success, \ref gf_blob_release_ex must be called after this
1305
\param blob the blob object
1306
\param out_data if success, set to blob data pointer
1307
\param out_size if success, set to blob data size
1308
\param blob_flags if success, set to blob flags - may be NULL
1309
\return error code
1310
 */
1311
GF_Err gf_blob_get_ex(GF_Blob *blob, u8 **out_data, u32 *out_size, u32 *blob_flags);
1312
/*!
1313
 * Releases blob data
1314
\param blob the blob object
1315
\return error code
1316
 */
1317
GF_Err gf_blob_release_ex(GF_Blob *blob);
1318
1319
/*!
1320
 * Registers a new blob
1321
\param blob  blob object
1322
\return URL of blob object (ie gmem://%p), must be freed by user
1323
 */
1324
char *gf_blob_register(GF_Blob *blob);
1325
1326
/*!
1327
 * Unegisters a blob. This must be called before destroying a registered blob
1328
\param blob  blob object
1329
 */
1330
void gf_blob_unregister(GF_Blob *blob);
1331
1332
/*!
1333
\brief Portable getch()
1334
1335
Returns immediately a typed char from stdin
1336
\return the typed char
1337
*/
1338
int gf_getch();
1339
1340
/*!
1341
\brief Reads a line of input from stdin
1342
\param line the buffer to fill
1343
\param maxSize the maximum size of the line to read
1344
\param showContent boolean indicating if the line read should be printed on stderr or not
1345
\return GF_TRUE if some content was read, GF_FALSE otherwise
1346
*/
1347
Bool gf_read_line_input(char * line, int maxSize, Bool showContent);
1348
1349
1350
/*!
1351
\addtogroup time_grp
1352
\brief Time manipulation tools
1353
@{
1354
*/
1355
1356
/*!
1357
\brief System clock query
1358
1359
Gets the system clock time.
1360
\return System clock value since GPAC initialization in milliseconds.
1361
 */
1362
u32 gf_sys_clock();
1363
1364
/*!
1365
\brief High precision system clock query
1366
1367
Gets the hight precision system clock time.
1368
\return System clock value since GPAC initialization in microseconds.
1369
 */
1370
u64 gf_sys_clock_high_res();
1371
1372
/*!
1373
\brief Sleeps thread/process
1374
1375
Locks calling thread/process execution for a given time.
1376
\param ms Amount of time to sleep in milliseconds.
1377
 */
1378
void gf_sleep(u32 ms);
1379
1380
#ifdef WIN32
1381
/*!
1382
\brief WINCE time constant
1383
\hideinitializer
1384
1385
time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds
1386
*/
1387
#define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008)
1388
1389
#endif
1390
1391
/*!
1392
\brief gets UTC time in milliseconds
1393
1394
Gets UTC clock in milliseconds
1395
\return UTC time in milliseconds
1396
 */
1397
u64 gf_net_get_utc();
1398
1399
/*!
1400
\brief converts an ntp timestamp into UTC time in milliseconds
1401
1402
Converts NTP 64-bit timestamp to UTC clock in milliseconds
1403
\param ntp NTP timestamp
1404
\return UTC time in milliseconds
1405
 */
1406
u64 gf_net_ntp_to_utc(u64 ntp);
1407
1408
/*!
1409
\brief parses date
1410
1411
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:
1412
  Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
1413
  Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
1414
  Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() formatgets UTC time in milliseconds
1415
1416
\param date string containing the date to parse
1417
\return UTC time in milliseconds
1418
 */
1419
u64 gf_net_parse_date(const char *date);
1420
1421
/*!
1422
\brief returns 64-bit UTC timestamp from year, month, day, hour, min and sec
1423
\param year the year
1424
\param month the month, from 0 to 11
1425
\param day the day
1426
\param hour the hour
1427
\param min the min
1428
\param sec the sec
1429
\return UTC time in milliseconds
1430
 */
1431
u64 gf_net_get_utc_ts(u32 year, u32 month, u32 day, u32 hour, u32 min, u32 sec);
1432
1433
/*!
1434
\brief gets timezone adjustment in seconds
1435
1436
Gets timezone adjustment in seconds, with localtime - timezone = UTC time
1437
\return timezone shift in seconds
1438
 */
1439
s32 gf_net_get_timezone();
1440
1441
/*!
1442
\brief gets timezone daylight saving time status
1443
1444
Gets timezone daylight saving time
1445
\return GF_TRUE if DST is active
1446
 */
1447
Bool gf_net_time_is_dst();
1448
1449
/*!
1450
\brief gets time from UTC timestamp
1451
1452
Gets time from UTC timestamp
1453
\param time timestamp value - see gmtime
1454
\return time description structure - see gmtime
1455
 */
1456
struct tm *gf_gmtime(const time_t *time);
1457
1458
/*! @} */
1459
1460
/*!
1461
\addtogroup thr_grp
1462
\brief Time manipulation tools
1463
@{
1464
*/
1465
1466
/*!
1467
\brief Gets process ID
1468
1469
Gets ID of the process running this gpac instance.
1470
\return the ID of the main process
1471
*/
1472
u32 gf_sys_get_process_id();
1473
1474
1475
/*! lockfile status*/
1476
typedef enum {
1477
  /*! lockfile creation failed*/
1478
  GF_LOCKFILE_FAILED=0,
1479
  /*! lockfile creation succeeded, creating a new lock file*/
1480
  GF_LOCKFILE_NEW,
1481
  /*! lockfile creation succeeded, lock file was already present and created by this process*/
1482
  GF_LOCKFILE_REUSE
1483
} GF_LockStatus;
1484
1485
/*!
1486
\brief Creates a lock file
1487
1488
Creates a lock file for the current process. A lockfile contains a single string giving the creator process ID
1489
If a lock file exists with a process ID no longer running, the lock file will be granted to the caller.
1490
Lock files are removed using \ref gf_file_delete
1491
\param lockfile name of the lockfile
1492
\return return status
1493
*/
1494
GF_LockStatus gf_sys_create_lockfile(const char *lockfile);
1495
1496
/*!
1497
\brief Checks a process is valid
1498
1499
Checks if a process is running by its ID
1500
\param process_id process ID
1501
\return GF_TRUE if process is running, GF_FALSE otherwise
1502
*/
1503
Bool gf_sys_check_process_id(u32 process_id);
1504
1505
1506
/*!\brief run-time system info object
1507
1508
The Run-Time Info object is used to get CPU and memory occupation of the calling process.
1509
All time values are expressed in milliseconds (accuracy is not guaranteed).
1510
*/
1511
typedef struct
1512
{
1513
  /*!start of the sampling period*/
1514
  u32 sampling_instant;
1515
  /*!duration of the sampling period*/
1516
  u32 sampling_period_duration;
1517
  /*!total amount of time (User+kernel) spent in CPU for all processes as evaluated at the end of the sampling period*/
1518
  u32 total_cpu_time;
1519
  /*!total amount of time (User+kernel) spent in CPU for the calling process as evaluated at the end of the sampling period*/
1520
  u32 process_cpu_time;
1521
  /*!amount of time (User+kernel) spent in CPU for all processes during the sampling period*/
1522
  u32 total_cpu_time_diff;
1523
  /*!total amount of time (User+kernel) spent in CPU for the calling process during the sampling period*/
1524
  u32 process_cpu_time_diff;
1525
  /*!total amount of idle time during the sampling period.*/
1526
  u32 cpu_idle_time;
1527
  /*!percentage (from 0 to 100) of CPU usage during the sampling period.*/
1528
  u32 total_cpu_usage;
1529
  /*!percentage (from 0 to 100) of the CPU usage by the calling process during the sampling period.*/
1530
  u32 process_cpu_usage;
1531
  /*!calling process ID*/
1532
  u32 pid;
1533
  /*!calling process thread count if known*/
1534
  u32 thread_count;
1535
  /*!size of calling process allocated heaps*/
1536
  u64 process_memory;
1537
  /*!total physical memory in system*/
1538
  u64 physical_memory;
1539
  /*!available physical memory in system*/
1540
  u64 physical_memory_avail;
1541
  /*!total memory currently allocated by gpac*/
1542
  u64 gpac_memory;
1543
  /*!total number of cores on the system*/
1544
  u32 nb_cores;
1545
} GF_SystemRTInfo;
1546
1547
/*!
1548
Selection flags for run-time info retrieval
1549
\hideinitializer
1550
 */
1551
enum
1552
{
1553
  /*!Indicates all processes' times must be fetched. If not set, only the current process times will be retrieved, and the
1554
  thread count and total times won't be available*/
1555
  GF_RTI_ALL_PROCESSES_TIMES = 1,
1556
  /*!Indicates the process allocated heap size must be fetch. If not set, only the system physical memory is fetched.
1557
  Fetching the entire ocess  allocated memory can have a large impact on performances*/
1558
  GF_RTI_PROCESS_MEMORY = 1<<1,
1559
  /*!Indicates that only system memory should be fetched. When set, all refreshing info is ignored*/
1560
  GF_RTI_SYSTEM_MEMORY_ONLY = 1<<2
1561
};
1562
1563
/*!
1564
\brief Gets Run-Time info
1565
1566
Gets CPU and memory usage info for the calling process and the system. Information gathering is controled through timeout values.
1567
\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.
1568
\param rti holder to the run-time info structure to update.
1569
\param flags specify which info is to be retrieved.
1570
\return 1 if info has been updated, 0 otherwise.
1571
\note You should not try to use a too small refresh time. Typical values are 500 ms or one second.
1572
 */
1573
Bool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags);
1574
1575
/*! @} */
1576
1577
/*!
1578
\addtogroup osfile_grp
1579
\brief File System tools
1580
1581
This section documents file system tools used in GPAC.
1582
1583
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:
1584
\code
1585
//bad design, will fail when using wrapped memory IOs
1586
FILE *t = fopen(url, "rb");
1587
fputs(t, mystring);
1588
fclose(t);
1589
1590
//good design, will work fine when using wrapped memory IOs
1591
FILE *t = gf_fopen(url, "rb");
1592
gf_fputs(t, mystring);
1593
gf_fclose(t);
1594
\endcode
1595
1596
@{
1597
 */
1598
1599
/*!
1600
\brief reads a file into memory
1601
1602
Reads a local file into memory, in binary open mode.
1603
\param file_name path on disk of the file to read
1604
\param out_data pointer to allocted address, to be freed by caller
1605
\param out_size pointer to allocted size
1606
\return error code if any
1607
 */
1608
GF_Err gf_file_load_data(const char *file_name, u8 **out_data, u32 *out_size);
1609
1610
/*!
1611
\brief reads a file into memory
1612
1613
Reads a local file into memory, in binary open mode.
1614
\param file stream object to read (no seek is performed)
1615
\param out_data pointer to allocted address, to be freed by caller
1616
\param out_size pointer to allocted size
1617
\return error code if any
1618
 */
1619
GF_Err gf_file_load_data_filep(FILE *file, u8 **out_data, u32 *out_size);
1620
1621
/*!
1622
\brief Delete Directory
1623
1624
Delete a  dir within the full path.
1625
\param DirPathName the file path name.
1626
\return error if any
1627
 */
1628
GF_Err gf_rmdir(const char *DirPathName);
1629
1630
/*!
1631
\brief Create Directory
1632
1633
Create a directory within the full path.
1634
\param DirPathName the dir path name.
1635
\return error if any
1636
 */
1637
GF_Err gf_mkdir(const char* DirPathName);
1638
1639
/*!
1640
\brief Check Directory Exists
1641
1642
Create a directory within the full path.
1643
\param DirPathName the dir path name.
1644
\return GF_TRUE if directory exists
1645
 */
1646
Bool gf_dir_exists(const char *DirPathName);
1647
1648
/*!
1649
\brief Create Directory
1650
1651
Cleanup a directory within the full path, removing all the files and the directories.
1652
\param DirPathName the dir path name.
1653
\return error if any
1654
 */
1655
GF_Err gf_dir_cleanup(const char* DirPathName);
1656
1657
1658
/**
1659
Gets a newly allocated string containing the default cache directory.
1660
It is the responsibility of the caller to free the string.
1661
\return a fully qualified path to the default cache directory
1662
 */
1663
const char * gf_get_default_cache_directory();
1664
1665
/**
1666
Gets the number of open file handles (gf_fopen/gf_fclose only).
1667
\return  number of open file handles
1668
 */
1669
u32 gf_file_handles_count();
1670
1671
/*!
1672
\brief file writing helper
1673
1674
Wrapper to properly handle calls to fwrite(), ensuring proper error handling is invoked when it fails.
1675
\param ptr data buffer to write
1676
\param nb_bytes number of bytes to write
1677
\param stream stream object
1678
\return number of bytes to written
1679
*/
1680
size_t gf_fwrite(const void *ptr, size_t nb_bytes, FILE *stream);
1681
1682
/*!
1683
\brief file reading helper
1684
1685
Wrapper to properly handle calls to fread()
1686
\param ptr data buffer to read
1687
\param nbytes number of bytes to read
1688
\param stream stream object
1689
\return number of bytes read
1690
*/
1691
size_t gf_fread(void *ptr, size_t nbytes, FILE *stream);
1692
1693
/*!
1694
\brief file reading helper
1695
1696
Wrapper to properly handle calls to fgets()
1697
\param buf same as fgets
1698
\param size same as fgets
1699
\param stream same as fgets
1700
\return same as fgets
1701
*/
1702
char *gf_fgets(char *buf, size_t size, FILE *stream);
1703
/*!
1704
\brief file reading helper
1705
1706
Wrapper to properly handle calls to fgetc()
1707
\param stream same as fgetc
1708
\return same as fgetc
1709
*/
1710
int gf_fgetc(FILE *stream);
1711
/*!
1712
\brief file writing helper
1713
1714
Wrapper to properly handle calls to fputc()
1715
\param val same as fputc
1716
\param stream same as fputc
1717
\return same as fputc
1718
*/
1719
int gf_fputc(int val, FILE *stream);
1720
/*!
1721
\brief file writing helper
1722
1723
Wrapper to properly handle calls to fputs()
1724
\param buf same as fputs
1725
\param stream same as fputs
1726
\return same as fputs
1727
*/
1728
int gf_fputs(const char *buf, FILE *stream);
1729
/*!
1730
\brief file writing helper
1731
1732
Wrapper to properly handle calls to fprintf()
1733
\param stream same as fprintf
1734
\param format same as fprintf
1735
\return same as fprintf
1736
*/
1737
int gf_fprintf(FILE *stream, const char *format, ...);
1738
1739
/*!
1740
\brief file writing helper
1741
1742
Wrapper to properly handle calls to vfprintf()
1743
\param stream same as vfprintf
1744
\param format same as vfprintf
1745
\param args same as vfprintf
1746
\return same as fprintf
1747
*/
1748
int gf_vfprintf(FILE *stream, const char *format, va_list args);
1749
1750
/*!
1751
\brief file flush helper
1752
1753
Wrapper to properly handle calls to fflush()
1754
\param stream same as fflush
1755
\return same as fflush
1756
*/
1757
int gf_fflush(FILE *stream);
1758
/*!
1759
\brief end of file helper
1760
1761
Wrapper to properly handle calls to feof()
1762
\param stream same as feof
1763
\return same as feof
1764
*/
1765
int gf_feof(FILE *stream);
1766
/*!
1767
\brief file error helper
1768
1769
Wrapper to properly handle calls to ferror()
1770
\param stream same as ferror
1771
\return same as ferror
1772
*/
1773
int gf_ferror(FILE *stream);
1774
1775
/*!
1776
\brief file size helper
1777
1778
Gets the file size given a FILE object. The FILE object position will be reset to 0 after this call
1779
\param fp FILE object to check
1780
\return file size in bytes
1781
*/
1782
u64 gf_fsize(FILE *fp);
1783
1784
/*!
1785
\brief file size helper for a file descriptor
1786
1787
Gets the file size given a file descriptor.
1788
\param fd file descriptor to check
1789
\return file size in bytes
1790
*/
1791
u64 gf_fd_fsize(int fd);
1792
1793
/*!
1794
\brief file IO checker
1795
1796
Checks if the given FILE object is a native FILE or a GF_FileIO wrapper.
1797
\param fp FILE object to check
1798
\return GF_TRUE if the FILE object is a wrapper to GF_FileIO
1799
*/
1800
Bool gf_fileio_check(FILE *fp);
1801
1802
/*! FileIO write state*/
1803
typedef enum
1804
{
1805
  /*! FileIO object is ready for write operations*/
1806
  GF_FIO_WRITE_READY=0,
1807
  /*! FileIO object is not yet ready for write operations*/
1808
  GF_FIO_WRITE_WAIT,
1809
  /*! FileIO object has been canceled*/
1810
  GF_FIO_WRITE_CANCELED,
1811
} GF_FileIOWriteState;
1812
/*!
1813
\brief file IO write checker
1814
1815
Checks if the given FILE object is ready for write.
1816
\param fp FILE object to check
1817
\return write state of GF_FileIO object, GF_FIO_WRITE_READY if not a GF_FileIO object
1818
*/
1819
GF_FileIOWriteState gf_fileio_write_ready(FILE *fp);
1820
1821
/*!
1822
\brief file opening
1823
1824
Opens a file, potentially bigger than 4GB. if filename identifies a blob (gmem://), the blob will be opened
1825
\param file_name same as fopen
1826
\param mode same as fopen
1827
\return stream handle of the file object
1828
*/
1829
FILE *gf_fopen(const char *file_name, const char *mode);
1830
1831
/*!
1832
\brief file opening
1833
1834
Opens a file, potentially using file IO if the parent URL is a File IO wrapper
1835
1836
\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.
1837
1838
\param file_name same as fopen
1839
\param parent_url URL of parent file. If not a file io wrapper (gfio://), the function is equivalent to gf_fopen
1840
\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)
1841
\param no_warn if GF_TRUE, do not throw log message if failure
1842
\return stream habdle of the file or file IO object*/
1843
FILE *gf_fopen_ex(const char *file_name, const char *parent_url, const char *mode, Bool no_warn);
1844
1845
/*!
1846
\brief file closing
1847
1848
Closes a file
1849
\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.
1850
\param file file to close
1851
\return same as flcose
1852
*/
1853
s32 gf_fclose(FILE *file);
1854
1855
/*!
1856
\brief large file position query
1857
1858
Queries the current read/write position in a large file
1859
\param f Same semantics as gf_ftell
1860
\return position in the file
1861
\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.
1862
*/
1863
u64 gf_ftell(FILE *f);
1864
/*!
1865
\brief large file seeking
1866
1867
Seeks the current read/write position in a large file
1868
\param f Same semantics as fseek
1869
\param pos Same semantics as fseek
1870
\param whence Same semantics as fseek
1871
\return 0 if success, -1 if error
1872
\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.
1873
*/
1874
s32 gf_fseek(FILE *f, s64 pos, s32 whence);
1875
1876
1877
/*! gets basename from filename/path
1878
\param filename Path of the file, can be an absolute path
1879
\return a pointer to the start of a filepath basename or null
1880
*/
1881
char* gf_file_basename(const char* filename);
1882
1883
/*! gets extension from filename
1884
\param filename Path of the file, can be an absolute path
1885
\return a pointer to the start of a filepath extension or null
1886
*/
1887
char* gf_file_ext_start(const char* filename);
1888
1889
/*!\brief FileEnum info object
1890
1891
The FileEnumInfo object is used to get file attributes upon enumeration of a directory.
1892
*/
1893
typedef struct
1894
{
1895
  /*!File is marked as hidden*/
1896
  Bool hidden;
1897
  /*!File is a directory*/
1898
  Bool directory;
1899
  /*!File is a drive mountpoint*/
1900
  Bool drive;
1901
  /*!File is a system file*/
1902
  Bool system;
1903
  /*!File size in bytes*/
1904
  u64 size;
1905
  /*!File last modif time in UTC seconds*/
1906
  u64 last_modified;
1907
} GF_FileEnumInfo;
1908
1909
/*!
1910
\brief Directory Enumeration Callback
1911
1912
The gf_enum_dir_item type is the type for the callback of the \ref gf_enum_directory function
1913
\param cbck Opaque user data.
1914
\param item_name File or directory name.
1915
\param item_path File or directory full path and name from filesystem root.
1916
\param file_info information for the file or directory.
1917
\return 1 to abort enumeration, 0 to continue enumeration.
1918
 *
1919
 */
1920
typedef Bool (*gf_enum_dir_item)(void *cbck, char *item_name, char *item_path, GF_FileEnumInfo *file_info);
1921
/*!
1922
\brief Directory enumeration
1923
1924
Enumerates a directory content. Feedback is provided by the enum_dir_item function
1925
\param dir Directory to enumerate
1926
\param enum_directory If set, only directories will be enumerated, otherwise only files are.
1927
\param enum_dir gf_enum_dir_item callback function for enumeration.
1928
\param cbck Opaque user data passed to callback function.
1929
\param filter optional filter for file extensions. If a file extension without the dot '.' character is not found in the
1930
 *  filter the file will be skipped.
1931
\return error if any
1932
 */
1933
GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir, void *cbck, const char *filter);
1934
1935
1936
/*!
1937
\brief File Deletion
1938
1939
Deletes a file from the disk.
1940
\param fileName absolute name of the file or name relative to the current working directory.
1941
\return error if any
1942
*/
1943
GF_Err gf_file_delete(const char *fileName);
1944
1945
/*!
1946
\brief File Move
1947
1948
Moves or renames a file or directory.
1949
\param fileName absolute path of the file / directory to move or rename
1950
\param newFileName absolute new path/name of the file / directory
1951
\return error if any
1952
*/
1953
GF_Err gf_file_move(const char *fileName, const char *newFileName);
1954
1955
/*!
1956
\brief Temporary File Creation
1957
1958
Creates a new temporary file in binary mode
1959
\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)
1960
\return stream handle to the new file ressoucre
1961
 */
1962
FILE *gf_file_temp(char ** const fileName);
1963
1964
1965
/*!
1966
\brief File Modification Time
1967
1968
Gets the UTC modification time of the given file in microseconds
1969
\param filename file to check
1970
\return modification time of the file
1971
 */
1972
u64 gf_file_modification_time(const char *filename);
1973
1974
/*!
1975
\brief File existence check
1976
1977
Checks if file with given name exists
1978
\param fileName path of the file to check
1979
\return GF_TRUE if file exists */
1980
Bool gf_file_exists(const char *fileName);
1981
1982
/*!
1983
\brief File existence check
1984
1985
Checks if file with given name exists, for regular files or File IO wrapper
1986
\param file_name path of the file to check
1987
\param par_name  name of the parent file
1988
\return GF_TRUE if file exists */
1989
Bool gf_file_exists_ex(const char *file_name, const char *par_name);
1990
1991
/*!
1992
\brief Open file descriptor
1993
1994
Opens a file descriptor - this is simply a wrapper aroun open taking care of UTF8 for windows
1995
\param file_name path of the file to check
1996
\param oflags same parameters as open flags for open
1997
\param pflags same parameters as permission flags for open
1998
\return file descriptor, -1 if error*/
1999
s32 gf_fd_open(const char *file_name, u32 oflags, u32 pflags);
2000
2001
/*! File IO wrapper object*/
2002
typedef struct __gf_file_io GF_FileIO;
2003
2004
2005
/*! open proc for memory file IO
2006
\param fileio_ref reference file_io. A file can be opened multiple times for the same reference, your code must handle this
2007
\param url target file name.
2008
\param mode opening mode of file, same as fopen mode. The following additional modes are defined:
2009
  - "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
2010
  - "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
2011
  - "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
2012
  - "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
2013
  - "close": indicates the fileIO object is being closed (fclose)
2014
\param out_error must be set to error code if any (never NULL)
2015
\return the opened GF_FileIO if success, or NULL otherwise
2016
 */
2017
typedef GF_FileIO *(*gfio_open_proc)(GF_FileIO *fileio_ref, const char *url, const char *mode, GF_Err *out_error);
2018
2019
/*! seek proc for memory file IO
2020
\param fileio target file IO object
2021
\param offset offset in file
2022
\param whence position from offset, same as fseek
2023
\return error if any
2024
 */
2025
typedef GF_Err (*gfio_seek_proc)(GF_FileIO *fileio, u64 offset, s32 whence);
2026
2027
/*! read proc for memory file IO
2028
\param fileio target file IO object
2029
\param buffer buffer to read.
2030
\param bytes number of bytes to read.
2031
\return number of bytes read, 0 if error.
2032
 */
2033
typedef u32 (*gfio_read_proc)(GF_FileIO *fileio, u8 *buffer, u32 bytes);
2034
2035
/*! write proc for memory file IO
2036
\param fileio target file IO object
2037
\param buffer buffer to write.
2038
\param bytes number of bytes to write. If 0, acts as fflush
2039
\return number of bytes write, 0 if error
2040
 */
2041
typedef u32 (*gfio_write_proc)(GF_FileIO *fileio, u8 *buffer, u32 bytes);
2042
2043
/*! positon tell proc for memory file IO
2044
\param fileio target file IO object
2045
\return position in bytes from file start
2046
 */
2047
typedef s64 (*gfio_tell_proc)(GF_FileIO *fileio);
2048
/*! end of file proc for memory file IO
2049
\param fileio target file IO object
2050
\return GF_TRUE if end of file, GF_FALSE otherwise
2051
 */
2052
typedef Bool (*gfio_eof_proc)(GF_FileIO *fileio);
2053
/*! printf proc for memory file IO
2054
\param fileio target file IO object
2055
\param format format string to use
2056
\param args variable argument list for printf, already initialized (va_start called)
2057
\return same as vfprint
2058
 */
2059
typedef int (*gfio_printf_proc)(GF_FileIO *fileio, const char *format, va_list args);
2060
2061
/*! Creates a new file IO object
2062
2063
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
2064
gf_fileio_new or as a response to open with mode "url".
2065
2066
\param url the original URL this file IO object wraps
2067
\param udta opaque data for caller
2068
\param open open proc for IO, must not be NULL
2069
\param seek seek proc for IO, must not be NULL
2070
\param read read proc for IO - if NULL the file is considered write only
2071
\param write write proc for IO - if NULL the file is considered read only
2072
\param tell tell proc for IO, must not be NULL
2073
\param eof eof proc for IO, must not be NULL
2074
\param printf printf proc for IO, may be NULL
2075
\return the newly created file IO wrapper
2076
 */
2077
GF_FileIO *gf_fileio_new(char *url, void *udta,
2078
  gfio_open_proc open,
2079
  gfio_seek_proc seek,
2080
  gfio_read_proc read,
2081
  gfio_write_proc write,
2082
  gfio_tell_proc tell,
2083
  gfio_eof_proc eof,
2084
  gfio_printf_proc printf);
2085
2086
/*! Deletes a new fileIO object
2087
\param fileio the File IO object to delete
2088
*/
2089
void gf_fileio_del(GF_FileIO *fileio);
2090
2091
/*! Gets associated user data of a fileIO object
2092
\param fileio target file IO object
2093
\return the associated user data
2094
*/
2095
void *gf_fileio_get_udta(GF_FileIO *fileio);
2096
2097
/*! Gets URL of a fileIO object.
2098
 The url uses the protocol scheme "gfio://"
2099
\param fileio target file IO object
2100
\return the file IO url to use
2101
*/
2102
const char * gf_fileio_url(GF_FileIO *fileio);
2103
2104
/*! Gets a fileIO object from memory - the resulting fileIO can only be opened once at any time but can be closed/reopen.
2105
\param URL of source data, may be null
2106
\param data memory, must be valid until next close
2107
\param size memory size
2108
\return new file IO - use gf_fclose() on this object to close it
2109
*/
2110
GF_FileIO *gf_fileio_from_mem(const char *URL, const u8 *data, u32 size);
2111
2112
/*! Cache state for file IO object*/
2113
typedef enum
2114
{
2115
  /*! File caching is in progress*/
2116
  GF_FILEIO_CACHE_IN_PROGRESS=0,
2117
  /*! File caching is done */
2118
  GF_FILEIO_CACHE_DONE,
2119
  /*! No file caching (file is not stored to disk)) */
2120
  GF_FILEIO_NO_CACHE,
2121
} GF_FileIOCacheState;
2122
2123
2124
/*! Sets statistics on a fileIO object.
2125
\param fileio target file IO object
2126
\param bytes_done number of bytes fetched for this file
2127
\param file_size total size of this file, 0 if unknown
2128
\param cache_state if GF_TRUE, means the file is completely available
2129
\param bytes_per_sec reception bytes per second, 0 if unknown
2130
*/
2131
void gf_fileio_set_stats(GF_FileIO *fileio, u64 bytes_done, u64 file_size, GF_FileIOCacheState cache_state, u32 bytes_per_sec);
2132
2133
/*! Gets statistics on a fileIO object.
2134
\param fileio target file IO object
2135
\param bytes_done number of bytes fetched for this file (may be NULL)
2136
\param file_size total size of this file, 0 if unknown (may be NULL)
2137
\param cache_state set to caching state for this object (may be NULL)
2138
\param bytes_per_sec reception bytes per second, 0 if unknown (may be NULL)
2139
\return GF_TRUE if success, GF_FALSE otherwise
2140
*/
2141
Bool gf_fileio_get_stats(GF_FileIO *fileio, u64 *bytes_done, u64 *file_size, GF_FileIOCacheState *cache_state, u32 *bytes_per_sec);
2142
2143
/*! Sets write state of a  fileIO object.
2144
\param fileio target file IO object
2145
\param write_state the state to set
2146
*/
2147
void gf_fileio_set_write_state(GF_FileIO *fileio, GF_FileIOWriteState write_state);
2148
2149
/*! Checks if a FileIO object can write
2150
\param fileio target file IO object
2151
\param url the original resource URL to open
2152
\param mode the desired open mode
2153
\param out_err set to error code if any, must not be NULL
2154
\return file IO object for this resource
2155
*/
2156
GF_FileIO *gf_fileio_open_url(GF_FileIO *fileio, const char *url, const char *mode, GF_Err *out_err);
2157
2158
2159
/*! Tags a FileIO object to be accessed from main thread only
2160
\param fileio target file IO object
2161
\return error if any
2162
*/
2163
GF_Err gf_fileio_tag_main_thread(GF_FileIO *fileio);
2164
2165
/*! Check if a FileIO object is to be accessed from main thread only
2166
2167
 \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.
2168
2169
\param url target url
2170
\return GF_TRUE if object is tagged for main thread, GF_FALSE otherwise
2171
*/
2172
Bool gf_fileio_is_main_thread(const char *url);
2173
2174
/*! Gets GF_FileIO object from its URL
2175
 The url uses the protocol scheme "gfio://"
2176
\param url the URL of  the File IO object
2177
\return the file IO object
2178
*/
2179
GF_FileIO *gf_fileio_from_url(const char *url);
2180
2181
/*! Constructs a new GF_FileIO object from a URL
2182
 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.
2183
 The function will not open the associated resource, only create the file IO wrapper for later usage
2184
 If you need to create a new fileIO to be opened immediately, use \ref gf_fopen_ex.
2185
2186
\param fileio parent file IO object
2187
\param new_res_url the original URL of  the new object to create
2188
\return the url (gfio://) of the created file IO object, NULL otherwise
2189
*/
2190
const char *gf_fileio_factory(GF_FileIO *fileio, const char *new_res_url);
2191
2192
/*! Translates a FileIO object URL into the original resource URL
2193
\param url the URL of  the File IO object
2194
\return the original resource URL associated with the file IO object
2195
*/
2196
const char * gf_fileio_translate_url(const char *url);
2197
/*! Gets a FileIO  original resource URL
2198
\param fileio target file IO object
2199
\return the original resource URL associated with the file IO object
2200
*/
2201
const char * gf_fileio_resource_url(GF_FileIO *fileio);
2202
2203
/*! Checks if a FileIO object can read
2204
\param fileio target file IO object
2205
\return GF_TRUE if read is enabled on this object
2206
*/
2207
Bool gf_fileio_read_mode(GF_FileIO *fileio);
2208
/*! Checks if a FileIO object can write
2209
\param fileio target file IO object
2210
\return GF_TRUE if write is enabled on this object
2211
*/
2212
Bool gf_fileio_write_mode(GF_FileIO *fileio);
2213
2214
/*! Function callback for GF_FileIO delete events. The callback is NOT thread-safe in GPAC, applications should take care of ensuring safety
2215
2216
\note Applications must make sure that the underlying gfio objects are defined as GPAC does not track allocated gfio objects.
2217
2218
 \param url a gfio:// url to be deleted or a regular  name if parent_gfio_url is NULL.
2219
 \param parent_gfio_url the parent GFIO associated with the URL string, or NULL if url is a gfio url
2220
 \return error code if any, GF_EOS if this callback is not handling this specific gfio
2221
*/
2222
typedef GF_Err (*gfio_delete_proc)(const char *url, const char *parent_gfio_url);
2223
2224
/*! Register a GF_FileIO delete callback. This function is NOT threadsafe, applications should take care of ensuring safety
2225
\param del_proc the calback to register. It MUST be valid until unregistered
2226
\return error if any
2227
*/
2228
GF_Err gf_fileio_register_delete_proc(gfio_delete_proc del_proc);
2229
2230
/*! Unregister a GF_FileIO delete callback. This function is NOT threadsafe, applications should take care of ensuring safety
2231
\param del_proc the calback to unregister.
2232
*/
2233
void gf_fileio_unregister_delete_proc(gfio_delete_proc del_proc);
2234
2235
/*! @} */
2236
2237
/*!
2238
\addtogroup hash_grp
2239
\brief Data hashing, integrity and generic compression
2240
2241
This section documents misc data functions such as integrity and parsing such as SHA-1 hashing CRC checksum, 128 bit ID parsing...
2242
2243
@{
2244
 */
2245
2246
2247
/*!
2248
\brief CRC32 compute
2249
2250
Computes the CRC32 value of a buffer.
2251
\param data buffer
2252
\param size buffer size
2253
\return computed CRC32
2254
 */
2255
u32 gf_crc_32(const u8 *data, u32 size);
2256
2257
2258
/**
2259
Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.
2260
\param data pointer to the data buffer to be compressed
2261
\param data_len length of the data buffer to be compressed
2262
\param out_size pointer for output buffer size
2263
\return error if any
2264
 */
2265
GF_Err gf_gz_compress_payload(u8 **data, u32 data_len, u32 *out_size);
2266
2267
/**
2268
Compresses a data buffer in place using zlib/deflate. Buffer may be reallocated in the process.
2269
\param data pointer to the data buffer to be compressed
2270
\param data_len length of the data buffer to be compressed
2271
\param out_size pointer for output buffer size
2272
\param data_offset offset in source buffer - the input payload size is data_len - data_offset
2273
\param skip_if_larger if GF_TRUE, will not override source buffer if compressed version is larger than input data
2274
\param out_comp_data if not NULL, the compressed result is set in this pointer rather than doing inplace compression
2275
\param use_gz if true, GZ header is present
2276
\return error if any
2277
 */
2278
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);
2279
2280
/**
2281
Decompresses a data buffer using zlib/inflate.
2282
\param data data buffer to be decompressed
2283
\param data_len length of the data buffer to be decompressed
2284
\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.
2285
\param out_size size of the uncompressed buffer
2286
\return error if any
2287
 */
2288
GF_Err gf_gz_decompress_payload(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size);
2289
2290
/**
2291
Decompresses a data buffer using zlib/inflate.
2292
\param data data buffer to be decompressed
2293
\param data_len length of the data buffer to be decompressed
2294
\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.
2295
\param out_size size of the uncompressed buffer
2296
\param use_gz if true, gz header is present
2297
\return error if any
2298
 */
2299
GF_Err gf_gz_decompress_payload_ex(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size, Bool use_gz);
2300
2301
2302
/**
2303
Compresses a data buffer in place using LZMA. Buffer may be reallocated in the process.
2304
\param data pointer to the data buffer to be compressed
2305
\param data_len length of the data buffer to be compressed
2306
\param out_size pointer for output buffer size
2307
\return error if any
2308
 */
2309
GF_Err gf_lz_compress_payload(u8 **data, u32 data_len, u32 *out_size);
2310
2311
/**
2312
Decompresses a data buffer using LZMA.
2313
\param data data buffer to be decompressed
2314
\param data_len length of the data buffer to be decompressed
2315
\param uncompressed_data pointer to the uncompressed data buffer. It is the responsibility of the caller to free this buffer.
2316
\param out_size size of the uncompressed buffer
2317
\return error if any
2318
 */
2319
GF_Err gf_lz_decompress_payload(u8 *data, u32 data_len, u8 **uncompressed_data, u32 *out_size);
2320
2321
2322
#ifndef GPAC_DISABLE_ZLIB
2323
/*! Wrapper around gzseek, same parameters
2324
\param file target gzfile
2325
\param offset offset in file
2326
\param whence same as gzseek
2327
\return same as gzseek
2328
*/
2329
u64 gf_gzseek(void *file, u64 offset, int whence);
2330
/*! Wrapper around gf_gztell, same parameters
2331
 \param file target gzfile
2332
 \return postion in file
2333
 */
2334
u64 gf_gztell(void *file);
2335
/*! Wrapper around gzrewind, same parameters
2336
 \param file target gzfile
2337
 \return same as gzrewind
2338
 */
2339
s64 gf_gzrewind(void *file);
2340
/*! Wrapper around gzeof, same parameters
2341
 \param file target gzfile
2342
 \return same as gzeof
2343
 */
2344
int gf_gzeof(void *file);
2345
/*! Wrapper around gzclose, same parameters
2346
\param file target gzfile
2347
\return same as gzclose
2348
*/
2349
int gf_gzclose(void *file);
2350
/*! Wrapper around gzerror, same parameters
2351
\param file target gzfile
2352
\param errnum same as gzerror
2353
\return same as gzerror
2354
 */
2355
const char * gf_gzerror (void *file, int *errnum);
2356
/*! Wrapper around gzclearerr, same parameters
2357
 \param file target gzfile
2358
 */
2359
void gf_gzclearerr(void *file);
2360
/*! Wrapper around gzopen, same parameters
2361
\param path the file name to open
2362
\param mode the file open mode
2363
\return open file
2364
 */
2365
void *gf_gzopen(const char *path, const char *mode);
2366
/*! Wrapper around gzread, same parameters
2367
 \param file target gzfile
2368
 \param buf same as gzread
2369
 \param len same as gzread
2370
 \return same as gzread
2371
 */
2372
int gf_gzread(void *file, void *buf, unsigned len);
2373
/*! Wrapper around gzdirect, same parameters
2374
 \param file target gzfile
2375
 \return same as gzdirect
2376
 */
2377
int gf_gzdirect(void *file);
2378
/*! Wrapper around gzgetc, same parameters
2379
 \param file target gzfile
2380
 \return same as gzgetc
2381
 */
2382
int gf_gzgetc(void *file);
2383
/*! Wrapper around gzgets, same parameters
2384
 \param file target gzfile
2385
 \param buf same as gzread
2386
 \param len same as gzread
2387
 \return same as gzgets
2388
*/
2389
char * gf_gzgets(void *file, char *buf, int len);
2390
#endif
2391
2392
2393
/*! SHA1 context*/
2394
typedef struct __sha1_context GF_SHA1Context;
2395
2396
/*! SHA1 message size */
2397
0
#define GF_SHA1_DIGEST_SIZE   20
2398
2399
/*! create SHA-1 context
2400
\return the SHA1 context*/
2401
GF_SHA1Context *gf_sha1_starts();
2402
/*! adds byte to the SHA-1 context
2403
\param ctx the target SHA1 context
2404
\param input data to hash
2405
\param length size of data in bytes
2406
*/
2407
void gf_sha1_update(GF_SHA1Context *ctx, u8 *input, u32 length);
2408
/*! generates SHA-1 of all bytes ingested
2409
\param ctx the target SHA1 context
2410
\param digest buffer to store message digest
2411
*/
2412
void gf_sha1_finish(GF_SHA1Context *ctx, u8 digest[GF_SHA1_DIGEST_SIZE] );
2413
2414
/*! gets SHA1 message digest of a file
2415
\param filename name of file to hash
2416
\param digest buffer to store message digest
2417
\return error if any
2418
*/
2419
GF_Err gf_sha1_file(const char *filename, u8 digest[GF_SHA1_DIGEST_SIZE]);
2420
2421
/*! gets SHA1 message digest of a opened file
2422
\param file  handle to open file
2423
\param digest buffer to store message digest
2424
\return error if any
2425
*/
2426
GF_Err gf_sha1_file_ptr(FILE *file, u8 digest[GF_SHA1_DIGEST_SIZE] );
2427
2428
/*! gets SHA-1 of input buffer
2429
\param buf input buffer to hash
2430
\param buflen size of input buffer in bytes
2431
\param digest buffer to store message digest
2432
 */
2433
void gf_sha1_csum(u8 *buf, u32 buflen, u8 digest[GF_SHA1_DIGEST_SIZE]);
2434
/*! @} */
2435
2436
/*! checksum size for SHA-256*/
2437
0
#define GF_SHA256_DIGEST_SIZE 32
2438
/*! gets SHA-256 of input buffer
2439
\param buf input buffer to hash
2440
\param buflen size of input buffer in bytes
2441
\param digest buffer to store message digest
2442
 */
2443
void gf_sha256_csum(const void *buf, u64 buflen, u8 digest[GF_SHA256_DIGEST_SIZE]);
2444
2445
2446
/*! checksum size for MD5*/
2447
0
#define GF_MD5_DIGEST_SIZE  16
2448
2449
/*! gets MD5 of input buffer
2450
\param buf input buffer to hash
2451
\param buflen size of input buffer in bytes
2452
\param digest buffer to store message digest
2453
 */
2454
void gf_md5_csum(const void *buf, u32 buflen, u8 digest[GF_MD5_DIGEST_SIZE]);
2455
2456
/*!
2457
\addtogroup libsys_grp
2458
@{
2459
*/
2460
2461
/*! gets a global config key value from its section and name.
2462
\param secName the desired key parent section name
2463
\param keyName the desired key name
2464
\return the desired key value if found, NULL otherwise.
2465
*/
2466
const char *gf_opts_get_key(const char *secName, const char *keyName);
2467
2468
/*! sets a global config key value from its section and name.
2469
\param secName the desired key parent section name
2470
\param keyName the desired key name
2471
\param keyValue the desired key value
2472
\note this will also create both section and key if they are not found in the configuration file
2473
\return error if any
2474
*/
2475
GF_Err gf_opts_set_key(const char *secName, const char *keyName, const char *keyValue);
2476
2477
/*! removes all entries in the given section of the global config
2478
\param secName the target section
2479
*/
2480
void gf_opts_del_section(const char *secName);
2481
/*! gets the number of sections in the global config
2482
\return the number of sections
2483
*/
2484
u32 gf_opts_get_section_count();
2485
/*! gets a section name based on its index in the global config
2486
\param secIndex 0-based index of the section to query
2487
\return the section name if found, NULL otherwise
2488
*/
2489
const char *gf_opts_get_section_name(u32 secIndex);
2490
2491
/*! gets the number of keys in a section of the global config
2492
\param secName the target section
2493
\return the number of keys in the section
2494
*/
2495
u32 gf_opts_get_key_count(const char *secName);
2496
/*! gets the number of keys in a section of the global config
2497
\param secName the target section
2498
\param keyIndex 0-based index of the key in the section
2499
\return the key name if found, NULL otherwise
2500
*/
2501
const char *gf_opts_get_key_name(const char *secName, u32 keyIndex);
2502
2503
/*! gets a global config boolean value from its section and name.
2504
\param secName the desired key parent section name
2505
\param keyName the desired key name
2506
\return the desired key value if found, GF_FALSE otherwise.
2507
*/
2508
Bool gf_opts_get_bool(const char *secName, const char *keyName);
2509
2510
/*! gets a global config integer value from its section and name.
2511
\param secName the desired key parent section name
2512
\param keyName the desired key name
2513
\return the desired key value if found, 0 otherwise.
2514
*/
2515
u32 gf_opts_get_int(const char *secName, const char *keyName);
2516
2517
/*! gets a global config key value from its section and name.
2518
\param secName the desired key parent section name
2519
\param keyName the desired key name
2520
\return the desired key value if found and if the key is not restricted, NULL otherwise.
2521
*/
2522
const char *gf_opts_get_key_restricted(const char *secName, const char *keyName);
2523
2524
/*!
2525
 * Do not save modification to global options
2526
\return error code
2527
 */
2528
GF_Err gf_opts_discard_changes();
2529
2530
/*!
2531
 * Force immediate write of config
2532
\return error code
2533
 */
2534
GF_Err gf_opts_save();
2535
2536
/*!
2537
 * Returns file name of global config
2538
\return file name of global config or NULL if libgpac is not initialized
2539
 */
2540
const char *gf_opts_get_filename();
2541
2542
/*!
2543
 * Gets GPAC shared directory (gui, shaders, etc ..)
2544
\param path_buffer GF_MAX_PATH buffer to store output
2545
\return GF_TRUE if success, GF_FALSE otherwise
2546
 */
2547
Bool gf_opts_default_shared_directory(char *path_buffer);
2548
2549
2550
/*!
2551
 * Checks given user and password are valid
2552
\param username user name
2553
\param password password
2554
\return GF_OK if success, GF_NOT_FOUND if no such user or GF_AUTHENTICATION_FAILURE if wrong password
2555
 */
2556
GF_Err gf_creds_check_password(const char *username, char *password);
2557
2558
/*!
2559
 * Checks given user belongs to list of users or groups.
2560
\param username user name
2561
\param users comma-seprated list of users to check, may be NULL
2562
\param groups comma-seprated list of groups to check, may be NULL
2563
\return GF_TRUE if success, GF_FALSE otherwise
2564
 */
2565
Bool gf_creds_check_membership(const char *username, const char *users, const char *groups);
2566
2567
/*! @} */
2568
2569
2570
//! @cond Doxygen_Suppress
2571
2572
#ifdef GPAC_DISABLE_RMTWS
2573
#define RMT_ENABLED 0
2574
#endif
2575
2576
#include <gpac/rmt_ws.h>
2577
2578
//! @endcond
2579
2580
2581
/* \cond dummy */
2582
2583
/*to call whenever the OpenGL library is opened - this function is needed to load OpenGL extensions on windows
2584
not exported, and not included in src/compositor/gl_inc.h since it may be needed even when no OpenGL
2585
calls are made by the caller*/
2586
void gf_opengl_init();
2587
2588
typedef enum
2589
{
2590
  //pbo not enabled
2591
  GF_GL_PBO_NONE=0,
2592
  //pbo enabled, both push and glTexImage textures are done in gf_gl_txw_upload
2593
  GF_GL_PBO_BOTH,
2594
  //push only is done in gf_gl_txw_upload
2595
  GF_GL_PBO_PUSH,
2596
  // glTexImage textures only is done in gf_gl_txw_upload
2597
  GF_GL_PBO_TEXIMG,
2598
} GF_GLPBOState;
2599
2600
typedef struct _gl_texture_wrap
2601
{
2602
  u32 textures[4];
2603
  u32 PBOs[4];
2604
2605
  u32 nb_textures;
2606
  u32 width, height, pix_fmt, stride, uv_stride;
2607
  Bool is_yuv;
2608
  u32 bit_depth, uv_w, uv_h;
2609
  u32 scale_10bit;
2610
  u32 init_active_texture;
2611
2612
  u32 gl_format;
2613
  u32 bytes_per_pix;
2614
  Bool has_alpha;
2615
  Bool internal_textures;
2616
  Bool uniform_setup;
2617
  u32 memory_format;
2618
  struct _gf_filter_frame_interface *frame_ifce;
2619
  Bool first_tx_load;
2620
2621
  //PBO state - must be managed by caller, especially if using separated push and texImg steps through gf_gl_txw_setup calls
2622
  GF_GLPBOState pbo_state;
2623
  Bool flip;
2624
  //YUV is full video range
2625
  Bool fullrange;
2626
  s32 mx_cicp;
2627
2628
  u32 last_program;
2629
} GF_GLTextureWrapper;
2630
2631
Bool gf_gl_txw_insert_fragment_shader(u32 pix_fmt, const char *tx_name, char **f_source, Bool y_flip);
2632
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);
2633
Bool gf_gl_txw_upload(GF_GLTextureWrapper *tx, const u8 *data, struct _gf_filter_frame_interface *frame_ifce);
2634
Bool gf_gl_txw_bind(GF_GLTextureWrapper *tx, const char *tx_name, u32 gl_program, u32 texture_unit);
2635
void gf_gl_txw_reset(GF_GLTextureWrapper *tx);
2636
2637
/* \endcond */
2638
2639
2640
/*! macros to get the size of an array of struct*/
2641
0
#define GF_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
2642
2643
#ifdef __cplusplus
2644
}
2645
#endif
2646
2647
2648
#endif    /*_GF_CORE_H_*/