xine-lib 1.2.13-20230125hg15249
Data Structures | Macros | Enumerations | Functions | Variables
utils.c File Reference
#include <xine/xineutils.h>
#include <xine/xineintl.h>
#include "xine_private.h"
#include "../xine-engine/bswap.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>

Data Structures

struct  lang_locale_t
 
struct  xine_fast_text_s
 
struct  _xine_ref_string_head_t
 
struct  xine_pts_queue_s
 

Macros

#define _POSIX_PTHREAD_SEMANTICS   1 /* for 5-arg getpwuid_r on solaris */
 
#define O_CLOEXEC   0
 
#define BUFSIZ   256
 
#define XINE_MEM_ALIGN   32
 
#define XINE_MEM_ADD   (sizeof (size_t) + XINE_MEM_ALIGN)
 
#define XINE_MEM_MASK   ((uintptr_t)XINE_MEM_ALIGN - 1)
 
#define rr   128 /* repeat */
 
#define ss   64 /* stop */
 
#define rev32(n)   (((n) << 24) | (((n) << 8) & 0xff0000) | (((n) >> 8) & 0xff00) | ((n) >> 24))
 
#define rev16(n)   ((((n) << 8) | ((n) >> 8)) & 0xffff)
 
#define XFST_ALIGN   (16)
 
#define XFST_MIN_SIZE   ((XFST_ALIGN + 2 + XFST_ALIGN - 1) & ~(XFST_ALIGN - 1))
 
#define XPQ_BACKLOG_LD   3
 
#define XPQ_BACKLOG_SIZE   (1 << XPQ_BACKLOG_LD)
 
#define XPQ_BACKLOG_MASK   (XPQ_BACKLOG_SIZE - 1)
 
#define _DC_DIGIT   1
 
#define _DC_SPACE   2
 
#define _DC_Tt   4
 
#define _DC_Zz   8
 
#define _DC_PLUS   16
 
#define _DC_MINUS   32
 
#define _DC_DOT   64
 
#define _DC_END   128
 
#define _DV_HAVE_DATE   1
 
#define _DV_HAVE_TIME   2
 
#define _DV_HAVE_ZONE   4
 
#define _DV_HAVE_JTIME   16
 

Enumerations

enum  xine_pts_queue_action_t {
  XPQ_A_NONE = 0 , XPQ_A_STALL , XPQ_A_PUT , XPQ_A_READY ,
  XPQ_A_GET
}
 

Functions

void * xine_xmalloc (size_t size)
 Allocate and clean memory size_t 'size', then return the pointer to the allocated memory.
 
void * xine_xcalloc (size_t nmemb, size_t size)
 Wrapper around calloc() function.
 
void * xine_memdup (const void *src, size_t length)
 
void * xine_memdup0 (const void *src, size_t length)
 
const char * xine_get_homedir (void)
 
char * xine_chomp (char *str)
 
void xine_usec_sleep (unsigned usec)
 
void xine_hexdump (const void *buf_gen, int length)
 
static const lang_locale_t_get_first_lang_locale (const char *lcal)
 
static char * _get_lang (void)
 
char * xine_get_system_encoding (void)
 
const char * xine_guess_spu_encoding (void)
 
int xine_monotonic_clock (struct timeval *tv, struct timezone *tz)
 
char * xine_strcat_realloc (char **dest, const char *append)
 
char * _x_asprintf (const char *format,...)
 
int _x_set_file_close_on_exec (int fd)
 Make file descriptors and sockets uninheritable.
 
int _x_set_socket_close_on_exec (int s)
 
int xine_open_cloexec (const char *name, int flags)
 
int xine_create_cloexec (const char *name, int flags, mode_t mode)
 
int xine_socket_cloexec (int domain, int type, int protocol)
 
void * xine_mallocz_aligned (size_t size)
 
void * xine_malloc_aligned (size_t size)
 
void xine_free_aligned (void *ptr)
 
void * xine_realloc_aligned (void *ptr, size_t size)
 
size_t xine_base64_encode (uint8_t *from, char *to, size_t size)
 
size_t xine_base64_decode (const char *from, uint8_t *to)
 
uint32_t xine_crc32_ieee (uint32_t crc, const uint8_t *data, size_t len)
 
uint32_t xine_crc16_ansi (uint32_t crc, const uint8_t *data, size_t len)
 
size_t xine_fast_string_need (size_t max_strlen)
 
char * xine_fast_string_init (char *buf, size_t bsize)
 
size_t xine_fast_string_max (char *fast_string)
 
char * xine_fast_string_set (char *fast_string, const char *text, size_t tsize)
 
int xine_fast_string_cmp (char *fast_string1, char *fast_string2)
 
void xine_fast_string_free (char **fast_string)
 
xine_fast_text_txine_fast_text_load (const char *filename, size_t max_size)
 
char * xine_fast_text_line (xine_fast_text_t *xft, size_t *linesize)
 
void xine_fast_text_unload (xine_fast_text_t **xft)
 
static _xine_ref_string_head_t_xine_ref_string_head (char *s)
 
char * xine_ref_string_ref (const char *s, int len)
 
size_t xine_ref_string_len (const char *s)
 
int xine_ref_string_unref (char **s)
 
xine_pts_queue_txine_pts_queue_new (void)
 
void xine_pts_queue_reset (xine_pts_queue_t *q)
 
void xine_pts_queue_put (xine_pts_queue_t *q, size_t bytes, int64_t pts)
 
int64_t xine_pts_queue_get (xine_pts_queue_t *q, size_t bytes)
 
void xine_pts_queue_delete (xine_pts_queue_t **q)
 
int xine_ts_from_string (struct timespec *ts, const char *s)
 
void xine_ts_add (struct timespec *a, const struct timespec *b)
 
void xine_ts_sub (struct timespec *a, const struct timespec *b)
 
int64_t xine_ts_to_timebase (const struct timespec *ts, uint32_t timebase)
 
void xine_rats_shorten (xine_rats_t *value)
 

Variables

static const lang_locale_t lang_locales []
 
static uint32_t tab_crc32_ieee [1280] = {0, 0,}
 
static uint16_t tab_crc16_ansi [768] = {0, 0,}
 
union { 
 
   uint8_t   z [4] 
 
   uint32_t   v 
 
_xine_fast_string_mask [8] 
 

Macro Definition Documentation

◆ _DC_DIGIT

#define _DC_DIGIT   1

◆ _DC_DOT

#define _DC_DOT   64

◆ _DC_END

#define _DC_END   128

◆ _DC_MINUS

#define _DC_MINUS   32

◆ _DC_PLUS

#define _DC_PLUS   16

◆ _DC_SPACE

#define _DC_SPACE   2

◆ _DC_Tt

#define _DC_Tt   4

◆ _DC_Zz

#define _DC_Zz   8

◆ _DV_HAVE_DATE

#define _DV_HAVE_DATE   1

◆ _DV_HAVE_JTIME

#define _DV_HAVE_JTIME   16

◆ _DV_HAVE_TIME

#define _DV_HAVE_TIME   2

◆ _DV_HAVE_ZONE

#define _DV_HAVE_ZONE   4

◆ _POSIX_PTHREAD_SEMANTICS

#define _POSIX_PTHREAD_SEMANTICS   1 /* for 5-arg getpwuid_r on solaris */

◆ BUFSIZ

#define BUFSIZ   256

Referenced by xine_get_homedir().

◆ O_CLOEXEC

#define O_CLOEXEC   0

◆ rev16

#define rev16 ( n)    ((((n) << 8) | ((n) >> 8)) & 0xffff)

Referenced by xine_crc16_ansi().

◆ rev32

#define rev32 ( n)    (((n) << 24) | (((n) << 8) & 0xff0000) | (((n) >> 8) & 0xff00) | ((n) >> 24))

Referenced by xine_crc32_ieee().

◆ rr

#define rr   128 /* repeat */

◆ ss

#define ss   64 /* stop */

◆ XFST_ALIGN

#define XFST_ALIGN   (16)

◆ XFST_MIN_SIZE

#define XFST_MIN_SIZE   ((XFST_ALIGN + 2 + XFST_ALIGN - 1) & ~(XFST_ALIGN - 1))

Referenced by xine_fast_string_init().

◆ XINE_MEM_ADD

#define XINE_MEM_ADD   (sizeof (size_t) + XINE_MEM_ALIGN)

◆ XINE_MEM_ALIGN

#define XINE_MEM_ALIGN   32

◆ XINE_MEM_MASK

#define XINE_MEM_MASK   ((uintptr_t)XINE_MEM_ALIGN - 1)

◆ XPQ_BACKLOG_LD

#define XPQ_BACKLOG_LD   3

◆ XPQ_BACKLOG_MASK

#define XPQ_BACKLOG_MASK   (XPQ_BACKLOG_SIZE - 1)

◆ XPQ_BACKLOG_SIZE

#define XPQ_BACKLOG_SIZE   (1 << XPQ_BACKLOG_LD)

Referenced by xine_pts_queue_get().

Enumeration Type Documentation

◆ xine_pts_queue_action_t

Enumerator
XPQ_A_NONE 
XPQ_A_STALL 
XPQ_A_PUT 
XPQ_A_READY 
XPQ_A_GET 

Function Documentation

◆ _get_first_lang_locale()

static const lang_locale_t * _get_first_lang_locale ( const char * lcal)
static

◆ _get_lang()

static char * _get_lang ( void )
static

◆ _x_asprintf()

char * _x_asprintf ( const char * format,
... )

◆ _x_set_file_close_on_exec()

int _x_set_file_close_on_exec ( int fd)

Make file descriptors and sockets uninheritable.

Referenced by xine_create_cloexec(), and xine_open_cloexec().

◆ _x_set_socket_close_on_exec()

int _x_set_socket_close_on_exec ( int s)

◆ _xine_ref_string_head()

static _xine_ref_string_head_t * _xine_ref_string_head ( char * s)
static

◆ xine_base64_decode()

size_t xine_base64_decode ( const char * from,
uint8_t * to )

Base64 decoder. from: pointer to input string or line formatted / indented, null terminated text. to: pointer to output buffer. ret: length of output in bytes.

References rr, ss, and v.

Referenced by config_register_serialized_entry(), sdpplin_parse(), and sdpplin_parse_stream().

◆ xine_base64_encode()

size_t xine_base64_encode ( uint8_t * from,
char * to,
size_t size )

Base64 encoder. from: pointer to binary input. to: pointer to output string buffer. size: byte length of input. ret: length of output string (without \0). Note that both buffers need 4 writable padding bytes.

References _X_BE_24, and v.

Referenced by _cdda_cdindex(), config_get_serialized_entry(), http_plugin_basicauth(), and rtsp_basicauth().

◆ xine_chomp()

char * xine_chomp ( char * str)

◆ xine_crc16_ansi()

uint32_t xine_crc16_ansi ( uint32_t crc,
const uint8_t * data,
size_t len )

References rev16, tab_crc16_ansi, and v.

Referenced by xine_a52_parse_data().

◆ xine_crc32_ieee()

uint32_t xine_crc32_ieee ( uint32_t crc,
const uint8_t * data,
size_t len )

Checksum calculator.

References rev32, tab_crc32_ieee, and v.

Referenced by demux_ts_parse_pat(), demux_ts_parse_pmt(), and ts_rewrite_packets().

◆ xine_create_cloexec()

int xine_create_cloexec ( const char * name,
int flags,
mode_t mode )

creates a file, ensuring that the descriptor will be closed automatically after a fork/execute.

References _x_set_file_close_on_exec(), mode(), name, and O_CLOEXEC.

Referenced by ao_file_open(), do_record(), open_plugin(), and pvr_break_rec_page().

◆ xine_fast_string_cmp()

int xine_fast_string_cmp ( char * fast_string1,
char * fast_string2 )

fast strcmp (). BTW: XINE_PROTECTED does not link on some systems when doing xine_sarray_new (size, (xine_sarray_comparator_t)xine_fast_string_cmp);.

References _xine_fast_string_mask, and v.

Referenced by _config_fat_entry_cmp(), and _fat_node_file_cmp().

◆ xine_fast_string_free()

void xine_fast_string_free ( char ** fast_string)

free a fast string if it is not application supplied.

References NULL.

◆ xine_fast_string_init()

char * xine_fast_string_init ( char * buf,
size_t bsize )

set up a fast string inside an application supplied buffer.

References NULL, XFST_ALIGN, and XFST_MIN_SIZE.

Referenced by _config_fat_entry_cmp(), _x_scan_plugins(), config_insert(), and load_plugin_list().

◆ xine_fast_string_max()

size_t xine_fast_string_max ( char * fast_string)

return the actual max strlen.

◆ xine_fast_string_need()

size_t xine_fast_string_need ( size_t max_strlen)

return the byte size needed for an application supplied buffer.

References XFST_ALIGN.

◆ xine_fast_string_set()

char * xine_fast_string_set ( char * fast_string,
const char * text,
size_t tsize )

set or change the contents of a fast string. fast_text may be NULL, to allocate a new one. you can even edit the string manually, then apply the new size with text == NULL.

References _xine_fast_string_mask, NULL, v, and XFST_ALIGN.

Referenced by _config_fat_entry_cmp(), collect_plugins(), config_insert(), and load_plugin_list().

◆ xine_fast_text_line()

char * xine_fast_text_line ( xine_fast_text_t * xft,
size_t * linesize )

get next line. you may modify return[0] ... return[filesize]. it all stays valid until xine_fast_text_unload ().

References xine_fast_text_s::dummy, xine_fast_text_s::flags, xine_fast_text_s::line_start, NULL, xine_fast_text_s::scan_here, xine_fast_text_s::text_len, and v.

Referenced by load_plugin_list(), and xine_config_load().

◆ xine_fast_text_load()

xine_fast_text_t * xine_fast_text_load ( const char * filename,
size_t max_size )

◆ xine_fast_text_unload()

void xine_fast_text_unload ( xine_fast_text_t ** xft)

free the text.

References NULL.

Referenced by load_plugin_list(), and xine_config_load().

◆ xine_free_aligned()

void xine_free_aligned ( void * ptr)

◆ xine_get_homedir()

const char * xine_get_homedir ( void )

◆ xine_get_system_encoding()

char * xine_get_system_encoding ( void )

get encoding of current locale

References _get_first_lang_locale(), _get_lang(), lang_locale_t::encoding, and NULL.

Referenced by _meta_info_set_encoding(), and osd_set_encoding().

◆ xine_guess_spu_encoding()

const char * xine_guess_spu_encoding ( void )

◆ xine_hexdump()

void xine_hexdump ( const void * buf_gen,
int length )

◆ xine_malloc_aligned()

void * xine_malloc_aligned ( size_t size)

◆ xine_mallocz_aligned()

void * xine_mallocz_aligned ( size_t size)

◆ xine_memdup()

void * xine_memdup ( const void * src,
size_t length )

References NULL, and xine_fast_memcpy.

Referenced by rmff_new_mdpr().

◆ xine_memdup0()

void * xine_memdup0 ( const void * src,
size_t length )

References NULL, and xine_fast_memcpy.

◆ xine_monotonic_clock()

int xine_monotonic_clock ( struct timeval * tv,
struct timezone * tz )

◆ xine_open_cloexec()

int xine_open_cloexec ( const char * name,
int flags )

◆ xine_pts_queue_delete()

void xine_pts_queue_delete ( xine_pts_queue_t ** queue)

you no longer need the queue.

References NULL.

Referenced by ff_audio_dispose().

◆ xine_pts_queue_get()

int64_t xine_pts_queue_get ( xine_pts_queue_t * queue,
size_t bytes )

◆ xine_pts_queue_new()

xine_pts_queue_t * xine_pts_queue_new ( void )

create a new instance.

Referenced by ff_audio_open_plugin().

◆ xine_pts_queue_put()

void xine_pts_queue_put ( xine_pts_queue_t * queue,
size_t bytes,
int64_t pts )

◆ xine_pts_queue_reset()

void xine_pts_queue_reset ( xine_pts_queue_t * queue)

reset after a stream seek.

Referenced by ff_audio_open_codec(), and ff_audio_reset().

◆ xine_rats_shorten()

void xine_rats_shorten ( xine_rats_t * value)

xine rational numbers, taken from TJtools.

References xine_rats_t::den, and xine_rats_t::num.

Referenced by mpd_set_start_time().

◆ xine_realloc_aligned()

void * xine_realloc_aligned ( void * ptr,
size_t size )

◆ xine_ref_string_len()

size_t xine_ref_string_len ( const char * s)

fast if s is a xine reference counted string.

References _xine_ref_string_head(), and _xine_ref_string_head_t::len.

Referenced by config_get_serialized_entry().

◆ xine_ref_string_ref()

char * xine_ref_string_ref ( const char * s,
int len )

create or reuse a xine reference counted string, whose contents shall remain unchanged. use len == -1 if not kown.

References _xine_ref_string_head(), _xine_ref_string_head_t::len, _xine_ref_string_head_t::magic, NULL, _xine_ref_string_head_t::refs, and v.

Referenced by _x_scan_plugins(), config_register_key(), and config_register_serialized_entry().

◆ xine_ref_string_unref()

int xine_ref_string_unref ( char ** s)

same as x_freep if s is _not a xine reference counted string.

References _xine_ref_string_head(), NULL, and _xine_ref_string_head_t::refs.

Referenced by _x_dispose_plugins(), and config_reset_value().

◆ xine_socket_cloexec()

int xine_socket_cloexec ( int domain,
int type,
int protocol )

creates a socket, ensuring that the descriptor will be closed automatically after a fork/execute.

References _x_set_socket_close_on_exec(), and type.

Referenced by _x_init_broadcaster(), _x_io_tcp_handshake_connect(), host_connect_attempt(), and vdr_plugin_open_socket().

◆ xine_strcat_realloc()

char * xine_strcat_realloc ( char ** dest,
const char * append )

append to a string, reallocating normally, updates & returns *dest on error, *dest is unchanged & NULL is returned.

◆ xine_ts_add()

void xine_ts_add ( struct timespec * a,
const struct timespec * b )

XINE_TS >= 1: a += b.

Referenced by mpd_set_frag_index().

◆ xine_ts_from_string()

int xine_ts_from_string ( struct timespec * ts,
const char * s )

◆ xine_ts_sub()

void xine_ts_sub ( struct timespec * a,
const struct timespec * b )

XINE_TS >= 1: a -= b.

Referenced by mpd_set_frag_index(), and mpd_set_start_time().

◆ xine_ts_to_timebase()

int64_t xine_ts_to_timebase ( const struct timespec * ts,
uint32_t timebase )

XINE_TS >= 1: ts * timebase.

Referenced by mpd_set_frag_index(), and mpd_set_start_time().

◆ xine_usec_sleep()

void xine_usec_sleep ( unsigned usec)

◆ xine_xcalloc()

void * xine_xcalloc ( size_t nmemb,
size_t size )

Wrapper around calloc() function.

Parameters
nmembNumber of elements to allocate
sizeSize of each element to allocate

This is a simple wrapper around calloc(), the only thing it does more than calloc() is outputting an error if the calloc fails (returning NULL).

References __XINE_FUNCTION__, and NULL.

Referenced by open_film_file(), open_mve_file(), open_tta_file(), and parse_vbri_header().

◆ xine_xmalloc()

void * xine_xmalloc ( size_t size)

Allocate and clean memory size_t 'size', then return the pointer to the allocated memory.

Parameters
sizeSize of the memory area to allocate.
Returns
A pointer to the allocated memory area, or NULL in case of error.

The behaviour of this function differs from standard malloc() as xine_xmalloc(0) will not return a NULL pointer, but rather a pointer to a memory area of size 1 byte.

The NULL value is only ever returned in case of an error in malloc(), and is reported to stderr stream.

Deprecated
This function has been deprecated, as the behaviour of allocating a 1 byte memory area on zero size is almost never desired, and the function is thus mostly misused.

References __XINE_FUNCTION__, and NULL.

Referenced by fooviz_init_plugin().

Variable Documentation

◆ [union]

const union { ... } _xine_fast_string_mask[8]
Initial value:
= {
{{0xff, 0xff, 0xff, 0xff}},
{{0x00, 0xff, 0xff, 0xff}},
{{0x00, 0x00, 0xff, 0xff}},
{{0x00, 0x00, 0x00, 0xff}},
{{0x00, 0x00, 0x00, 0x00}},
{{0xff, 0x00, 0x00, 0x00}},
{{0xff, 0xff, 0x00, 0x00}},
{{0xff, 0xff, 0xff, 0x00}}
}

Referenced by xine_fast_string_cmp(), and xine_fast_string_set().

◆ lang_locales

const lang_locale_t lang_locales[]
static

Referenced by _get_first_lang_locale().

◆ tab_crc16_ansi

uint16_t tab_crc16_ansi[768] = {0, 0,}
static

Referenced by xine_crc16_ansi().

◆ tab_crc32_ieee

uint32_t tab_crc32_ieee[1280] = {0, 0,}
static

Referenced by xine_crc32_ieee().

◆ v

uint32_t v

Referenced by _get_hex(), _mad_fixed_2_db(), _mad_scale(), _ogl2_fmt2str(), _ogl2_str2hex(), _vdec_hw_h264_unescape(), _video_overlay_clip_trans(), _vovl_event_free_get(), _x_clut_yuv2rgb(), _x_spu_dvb_opacity(), _x_url_parse2(), _xine_ref_string_head(), _xine_str2secs(), _xine_stree_load_json(), _xine_stree_load_xml(), XineOpenGLView::acceptsFirstResponder, ao_esd_set_property(), ao_oss_get_property(), ao_oss_set_property(), asmrp_set_id(), audio_filter_equalize(), bebf_get(), bebf_skip(), bebf_sniff(), bebf_sync(), bits_read(), bits_set_buf(), bits_valid_left(), build_frame_table(), clut_to_argb(), config_update_string_e(), convert_yv12(), create_lut(), demux_qt_load_fragment_index(), demux_ts_parse_pat(), demux_ts_parse_pes_header(), demux_ts_parse_pmt(), detect_ts(), downmix_lfe_2(), draw_ifs(), dvd_parse_mrl(), faad_decode_audio(), fade(), fade_out_yuv(), ff_aac_mode_parse(), ff_audio_decode(), ff_audio_decode_data(), find_embedded_atoms(), flac_get_frame(), flac_init_frame_head(), flac_parse_frame_head(), flac_test_frame_head(), float_to_int(), frametype_h264(), frametype_h265(), frametype_mpeg(), frametype_vc1(), hexstr2uint32(), hls_bump_find(), hscale_chroma_line(), http_plugin_open(), iatan(), ifs_update(), init_plugin(), isqr(), lineNoise_C(), load_plugin_list(), mad_decode_data(), mpd_input_open(), mpeg1_read_pts(), mpeg2_read_pts(), mpeg_get_pts(), opengl2_open_plugin(), pgx64_overlay_key_blend(), process_alt_CLUT_segment(), process_CLUT_definition_segment(), put32le(), recalculate_trans(), rgb2yuy2_palette(), rgb2yuy2_slice(), saturate(), scale_int_do(), sha160_final(), simplify(), str2uint32(), str2uint32(), str2uint32(), str2uint64(), str2uint64(), str2usec(), tdaan_downmix16_4(), tdaan_levels_get(), test_make(), uint64_2str(), uint_sqrt(), unescape(), unixscr_adjust(), unixscr_get_current(), unixscr_init(), unixscr_set_pivot(), unixscr_set_speed(), unixscr_start(), vdec_hw_h264_put_frame(), vo_get_property(), vo_set_property(), vo_update_max_frame_rate(), vobsub_parse_palette(), w32v_decode_data(), x11osd_blend(), xcbosd_blend(), xine_base64_decode(), xine_base64_encode(), xine_crc16_ansi(), xine_crc32_ieee(), xine_fast_string_cmp(), xine_fast_string_set(), xine_fast_text_line(), xine_find_byte(), xine_gl_extensions_load(), xine_init(), xine_int32_2str(), xine_ref_string_ref(), xine_refs_add(), xine_refs_get(), xine_refs_sub(), xine_str2int32(), xine_str2uint32(), xine_str2uint64(), xine_stree_find(), xine_string_unampersand(), xine_string_unbackslash(), xine_string_unpercent(), xine_ts_from_string(), xine_uint32_2str(), xine_uint64_2str(), xml_parser_get_property_bool(), xml_parser_get_property_int(), yuv2rgb_single_pixel_16(), yuv2rgb_single_pixel_24_bgr(), yuv2rgb_single_pixel_24_rgb(), yuv2rgb_single_pixel_32(), yuv2rgb_single_pixel_8(), yuv2rgb_single_pixel_gray(), yuv2rgb_single_pixel_palette(), and yuv444_to_yuy2_c().

◆ z

uint8_t z[4]