xine-lib 1.2.13-20230125hg15249
xineutils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2000-2022 the xine project
3 *
4 * This file is part of xine, a free video player.
5 *
6 * xine is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * xine is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 */
20#ifndef XINEUTILS_H
21#define XINEUTILS_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdlib.h>
28#include <string.h>
29#include <stdarg.h>
30#include <stddef.h>
31#include <pthread.h>
32
33#include <time.h>
34#ifdef WIN32
35#else
36# include <sys/time.h>
37#endif
38#include <xine/os_types.h>
39#include <xine/attributes.h>
40#include <xine/compat.h>
41#include <xine/xmlparser.h>
42#include <xine/xine_buffer.h>
43#include <xine/configfile.h>
44#include <xine/list.h>
45#include <xine/array.h>
46#include <xine/sorted_array.h>
47
48#include <stdio.h>
49#include <string.h>
50
51/*
52 * Mark exported data symbols for link engine library clients with older
53 * Win32 compilers
54 */
55#if defined(WIN32) && !defined(XINE_LIBRARY_COMPILE)
56# define DL_IMPORT __declspec(dllimport)
57# define extern DL_IMPORT extern
58#endif
59
60
61/* Amiga style doubly linked lists, taken from TJtools.
62 * Most compilers will support the straightforward aliasing safe version.
63 * For others, try that "volatile" hack. */
64
65typedef struct dnode_st {
66 struct dnode_st *next, *prev;
68
69#ifdef HAVE_NAMELESS_STRUCT_IN_UNION
70# define DLIST_H(l) (&(l)->h)
71# define DLIST_T(l) (&(l)->t)
72typedef union {
73 struct { dnode_t *head, *null, *tail; };
74 struct { dnode_t h; dnode_t *dummy1; };
75 struct { dnode_t *dummy2; dnode_t t; };
76} dlist_t;
77#else
78# define DLIST_H(l) ((void *)(&(l)->head))
79# define DLIST_T(l) ((void *)(&(l)->null))
80typedef struct {
81 dnode_t * volatile head;
83 dnode_t * volatile tail;
84} dlist_t;
85#endif
86
87#define DLIST_IS_EMPTY(l) ((l)->head == DLIST_T(l))
88
89#define DLIST_REMOVE(n) { \
90 dnode_t *dl_rm_this = n; \
91 dnode_t *dl_rm_prev = dl_rm_this->prev; \
92 dnode_t *dl_rm_next = dl_rm_this->next; \
93 dl_rm_next->prev = dl_rm_prev; \
94 dl_rm_prev->next = dl_rm_next; \
95}
96
97#define DLIST_ADD_HEAD(n,l) { \
98 dlist_t *dl_ah_list = l; \
99 dnode_t *dl_ah_node = n; \
100 dnode_t *dl_ah_head = dl_ah_list->head; \
101 dl_ah_node->next = dl_ah_head; \
102 dl_ah_node->prev = DLIST_H(dl_ah_list); \
103 dl_ah_list->head = dl_ah_node; \
104 dl_ah_head->prev = dl_ah_node; \
105}
106
107#define DLIST_ADD_TAIL(n,l) { \
108 dlist_t *dl_at_list = l; \
109 dnode_t *dl_at_node = n; \
110 dnode_t *dl_at_tail = dl_at_list->tail; \
111 dl_at_node->next = DLIST_T(dl_at_list); \
112 dl_at_node->prev = dl_at_tail; \
113 dl_at_tail->next = dl_at_node; \
114 dl_at_list->tail = dl_at_node; \
115}
116
117#define DLIST_INSERT(n,h) { \
118 dnode_t *dl_i_node = n; \
119 dnode_t *dl_i_here = h; \
120 dnode_t *dl_i_prev = dl_i_here->prev; \
121 dl_i_prev->next = dl_i_node; \
122 dl_i_here->prev = dl_i_node; \
123 dl_i_node->next = dl_i_here; \
124 dl_i_node->prev = dl_i_prev; \
125}
126
127#define DLIST_INIT(l) { \
128 dlist_t *dl_in_list = l; \
129 dl_in_list->head = DLIST_T(dl_in_list); \
130 dl_in_list->null = NULL; \
131 dl_in_list->tail = DLIST_H(dl_in_list); }
132
133
134 /*
135 * debugable mutexes
136 */
137
138 typedef struct {
139 pthread_mutex_t mutex;
140 char id[80];
142 } xine_mutex_t;
143
144 int xine_mutex_init (xine_mutex_t *mutex, const pthread_mutexattr_t *mutexattr,
145 const char *id) XINE_PROTECTED;
146
147 int xine_mutex_lock (xine_mutex_t *mutex, const char *who) XINE_PROTECTED;
148 int xine_mutex_unlock (xine_mutex_t *mutex, const char *who) XINE_PROTECTED;
150
151
152
153 /* CPU Acceleration */
154
155/*
156 * The type of an value that fits in an MMX register (note that long
157 * long constant values MUST be suffixed by LL and unsigned long long
158 * values by ULL, lest they be truncated by the compiler)
159 */
160
161/* generic accelerations */
162#define MM_ACCEL_MLIB 0x00000001
163
164/* x86 accelerations */
165#define MM_ACCEL_X86_MMX 0x80000000
166#define MM_ACCEL_X86_3DNOW 0x40000000
167#define MM_ACCEL_X86_MMXEXT 0x20000000
168#define MM_ACCEL_X86_SSE 0x10000000
169#define MM_ACCEL_X86_SSE2 0x08000000
170#define MM_ACCEL_X86_SSE3 0x04000000
171#define MM_ACCEL_X86_SSSE3 0x02000000
172#define MM_ACCEL_X86_SSE4 0x01000000
173#define MM_ACCEL_X86_SSE42 0x00800000
174#define MM_ACCEL_X86_AVX 0x00400000
175
176/* powerpc accelerations and features */
177#define MM_ACCEL_PPC_ALTIVEC 0x04000000
178#define MM_ACCEL_PPC_CACHE32 0x02000000
179
180/* SPARC accelerations */
181
182#define MM_ACCEL_SPARC_VIS 0x01000000
183#define MM_ACCEL_SPARC_VIS2 0x00800000
184
185/* x86 compat defines */
186#define MM_MMX MM_ACCEL_X86_MMX
187#define MM_3DNOW MM_ACCEL_X86_3DNOW
188#define MM_MMXEXT MM_ACCEL_X86_MMXEXT
189#define MM_SSE MM_ACCEL_X86_SSE
190#define MM_SSE2 MM_ACCEL_X86_SSE2
191
193
195
196
197 /* Optimized/fast memcpy */
198
199extern void *(* xine_fast_memcpy)(void *to, const void *from, size_t len) XINE_PROTECTED;
200
201/* len (usually) < 500, but not a build time constant. */
202#define xine_small_memcpy(xsm_to,xsm_from,xsm_len) memcpy (xsm_to, xsm_from, xsm_len)
203
204#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
205# if defined(ARCH_X86)
206# undef xine_small_memcpy
207static inline void *xine_small_memcpy (void *to, const void *from, size_t len) {
208 void *t2 = to;
209 size_t l2 = len;
210# if !defined(__clang__) && !defined(__cplusplus)
211 __asm__ __volatile__ (
212 "cld\n\trep movsb"
213 : "=S" (from), "=D" (t2), "=c" (l2), "=m" (*(struct {char foo[len];} *)to)
214 : "0" (from), "1" (t2), "2" (l2)
215 : "cc"
216 );
217# else /* clang dislikes virtual variable size struct */
218 __asm__ __volatile__ (
219 "cld\n\trep movsb"
220 : "=S" (from), "=D" (t2), "=c" (l2)
221 : "0" (from), "1" (t2), "2" (l2)
222 : "cc", "memory"
223 );
224# endif
225 (void)from;
226 (void)t2;
227 (void)l2;
228 return to;
229}
230# endif
231#endif
232
233/*
234 * Debug stuff
235 */
236/*
237 * profiling (unworkable in non DEBUG isn't defined)
238 */
240int xine_profiler_allocate_slot (const char *label) XINE_PROTECTED;
244
245/*
246 * xine_container_of()
247 * calculate struct pointer from field pointer
248 */
249
250#if defined(__GNUC__)
251# define xine_container_of(ptr, type, member) \
252 ({ \
253 const typeof(((type *)0)->member) *__mptr = (ptr); \
254 (type *)(void *)((char *)__mptr - offsetof(type, member)); \
255 })
256#else
257# define xine_container_of(ptr, type, member) \
258 ((type *)(void *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member)))
259#endif
260
261/*
262 * Allocate and clean memory size_t 'size', then return the pointer
263 * to the allocated memory.
264 */
266
267void *xine_xcalloc(size_t nmemb, size_t size) XINE_MALLOC XINE_PROTECTED;
268
269/*
270 * Free allocated memory and set pointer to NULL
271 * @param ptr Pointer to the pointer to the memory block which should be freed.
272 */
273static inline void _x_freep(void *ptr) {
274 void **p = (void **)ptr;
275 free (*p);
276 *p = NULL;
277}
278
279static inline void _x_freep_wipe_string(char **pp) {
280 char *p = *pp;
281 while (p && *p)
282 *p++ = 0;
283 _x_freep(pp);
284}
285
286/*
287 * Copy blocks of memory.
288 */
289void *xine_memdup (const void *src, size_t length) XINE_PROTECTED;
290void *xine_memdup0 (const void *src, size_t length) XINE_PROTECTED;
291
296#ifndef XINE_MEM_ALIGN
297# define XINE_MEM_ALIGN 32
298#endif
299
302void xine_free_aligned (void *ptr) XINE_PROTECTED;
303void *xine_realloc_aligned (void *ptr, size_t size) XINE_PROTECTED;
304#define xine_freep_aligned(xinefreepptr) do {xine_free_aligned (*(xinefreepptr)); *(xinefreepptr) = NULL; } while (0)
305
314size_t xine_base64_encode (uint8_t *from, char *to, size_t size) XINE_PROTECTED;
321size_t xine_base64_decode (const char *from, uint8_t *to) XINE_PROTECTED;
322
326uint32_t xine_crc32_ieee (uint32_t crc, const uint8_t *data, size_t len) XINE_PROTECTED;
327uint32_t xine_crc16_ansi (uint32_t crc, const uint8_t *data, size_t len) XINE_PROTECTED;
328
329/*
330 * Get user home directory.
331 */
332const char *xine_get_homedir(void) XINE_PROTECTED;
333
334#if defined(WIN32) || defined(__CYGWIN__)
335/*
336 * Get other xine directories.
337 */
338const char *xine_get_pluginroot(void) XINE_PROTECTED;
339const char *xine_get_plugindir(void) XINE_PROTECTED;
340const char *xine_get_fontdir(void) XINE_PROTECTED;
341const char *xine_get_localedir(void) XINE_PROTECTED;
342#endif
343
344/*
345 * Clean a string (remove spaces and '=' at the begin,
346 * and '\n', '\r' and spaces at the end.
347 */
348char *xine_chomp (char *str) XINE_PROTECTED;
349
350/*
351 * A thread-safe usecond sleep
352 */
353void xine_usec_sleep(unsigned usec) XINE_PROTECTED;
354
355/* compatibility macros */
356#define xine_strpbrk(S, ACCEPT) strpbrk((S), (ACCEPT))
357#define xine_strsep(STRINGP, DELIM) strsep((STRINGP), (DELIM))
358#define xine_setenv(NAME, VAL, XX) setenv((NAME), (VAL), (XX))
359
365char *xine_strcat_realloc (char **dest, const char *append) XINE_PROTECTED;
366
373char *_x_asprintf(const char *format, ...) XINE_PROTECTED XINE_MALLOC XINE_FORMAT_PRINTF(1, 2);
374
379int xine_open_cloexec(const char *name, int flags) XINE_PROTECTED;
380
385int xine_create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED;
386
391int xine_socket_cloexec(int domain, int type, int protocol) XINE_PROTECTED;
392
393/*
394 * Color Conversion Utility Functions
395 * The following data structures and functions facilitate the conversion
396 * of RGB images to packed YUV (YUY2) images. There are also functions to
397 * convert from YUV9 -> YV12. All of the meaty details are written in
398 * color.c.
399 */
400
401typedef struct yuv_planes_s {
402
403 unsigned char *y;
404 unsigned char *u;
405 unsigned char *v;
406 unsigned int row_width; /* frame width */
407 unsigned int row_count; /* frame height */
408
410
412void init_yuv_planes(yuv_planes_t *yuv_planes, int width, int height) XINE_PROTECTED;
414
415extern void (*yuv444_to_yuy2)
416 (const yuv_planes_t *yuv_planes, unsigned char *yuy2_map, int pitch) XINE_PROTECTED;
417extern void (*yuv9_to_yv12)
418 (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
419 const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
420 const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
421 int width, int height) XINE_PROTECTED;
422extern void (*yuv411_to_yv12)
423 (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
424 const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
425 const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
426 int width, int height) XINE_PROTECTED;
427extern void (*yv12_to_yuy2)
428 (const unsigned char *y_src, int y_src_pitch,
429 const unsigned char *u_src, int u_src_pitch,
430 const unsigned char *v_src, int v_src_pitch,
431 unsigned char *yuy2_map, int yuy2_pitch,
432 int width, int height, int progressive) XINE_PROTECTED;
433extern void (*yuy2_to_yv12)
434 (const unsigned char *yuy2_map, int yuy2_pitch,
435 unsigned char *y_dst, int y_dst_pitch,
436 unsigned char *u_dst, int u_dst_pitch,
437 unsigned char *v_dst, int v_dst_pitch,
438 int width, int height) XINE_PROTECTED;
439
440
441/* convert full range rgb to mpeg range yuv */
442#define SCALESHIFT 16
443#define SCALEFACTOR (1<<SCALESHIFT)
444#define CENTERSAMPLE 128
445
446/* new fast and more accurate macros. Simply recompile to use them */
447#define COMPUTE_Y(r, g, b) \
448 (unsigned char) \
449 ((y_r_table[r] + y_g_table[g] + y_b_table[b]) >> SCALESHIFT)
450#define COMPUTE_U(r, g, b) \
451 (unsigned char) \
452 ((u_r_table[r] + u_g_table[g] + uv_br_table[b]) >> SCALESHIFT)
453#define COMPUTE_V(r, g, b) \
454 (unsigned char) \
455 ((uv_br_table[r] + v_g_table[g] + v_b_table[b]) >> SCALESHIFT)
456
457/* Binaries using these old ones keep working,
458 and get the full vs mpeg range bug fixed transparently as well.
459#define COMPUTE_Y(r, g, b) \
460 (unsigned char) \
461 ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR)
462#define COMPUTE_U(r, g, b) \
463 (unsigned char) \
464 ((u_r_table[r] + u_g_table[g] + u_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
465#define COMPUTE_V(r, g, b) \
466 (unsigned char) \
467 ((v_r_table[r] + v_g_table[g] + v_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
468*/
469
470#define UNPACK_BGR15(packed_pixel, r, g, b) \
471 b = (packed_pixel & 0x7C00) >> 7; \
472 g = (packed_pixel & 0x03E0) >> 2; \
473 r = (packed_pixel & 0x001F) << 3;
474
475#define UNPACK_BGR16(packed_pixel, r, g, b) \
476 b = (packed_pixel & 0xF800) >> 8; \
477 g = (packed_pixel & 0x07E0) >> 3; \
478 r = (packed_pixel & 0x001F) << 3;
479
480#define UNPACK_RGB15(packed_pixel, r, g, b) \
481 r = (packed_pixel & 0x7C00) >> 7; \
482 g = (packed_pixel & 0x03E0) >> 2; \
483 b = (packed_pixel & 0x001F) << 3;
484
485#define UNPACK_RGB16(packed_pixel, r, g, b) \
486 r = (packed_pixel & 0xF800) >> 8; \
487 g = (packed_pixel & 0x07E0) >> 3; \
488 b = (packed_pixel & 0x001F) << 3;
489
490extern int y_r_table[256] XINE_PROTECTED;
491extern int y_g_table[256] XINE_PROTECTED;
492extern int y_b_table[256] XINE_PROTECTED;
493
494extern int uv_br_table[256] XINE_PROTECTED;
495
496extern int u_r_table[256] XINE_PROTECTED;
497extern int u_g_table[256] XINE_PROTECTED;
498extern int u_b_table[256] XINE_PROTECTED;
499
500extern int v_r_table[256] XINE_PROTECTED;
501extern int v_g_table[256] XINE_PROTECTED;
502extern int v_b_table[256] XINE_PROTECTED;
503
504/* TJ. direct sliced rgb -> yuy2 conversion */
505typedef struct rgb2yuy2_s rgb2yuy2_t;
506extern rgb2yuy2_t *rgb2yuy2_alloc (int color_matrix, const char *format) XINE_PROTECTED;
507extern void rgb2yuy2_free (rgb2yuy2_t *rgb2yuy2) XINE_PROTECTED;
508extern void rgb2yuy2_slice (rgb2yuy2_t *rgb2yuy2, const uint8_t *in, int ipitch, uint8_t *out, int opitch,
509 int width, int height) XINE_PROTECTED;
510extern void rgb2yuy2_palette (rgb2yuy2_t *rgb2yuy2, const uint8_t *pal, int num_colors, int bits_per_pixel)
512
513extern void rgb2yv12_slice (rgb2yuy2_t *rgb2yuy2, const uint8_t *src, int src_stride,
514 uint8_t *y_dst, int y_pitch,
515 uint8_t *u_dst, int u_pitch,
516 uint8_t *v_dst, int v_pitch,
517 int width, int height) XINE_PROTECTED;
518
519/* frame copying functions */
520extern void yv12_to_yv12
521 (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch,
522 const unsigned char *u_src, int u_src_pitch, unsigned char *u_dst, int u_dst_pitch,
523 const unsigned char *v_src, int v_src_pitch, unsigned char *v_dst, int v_dst_pitch,
524 int width, int height) XINE_PROTECTED;
525extern void yuy2_to_yuy2
526 (const unsigned char *src, int src_pitch,
527 unsigned char *dst, int dst_pitch,
528 int width, int height) XINE_PROTECTED;
529
530void _x_nv12_to_yv12(const uint8_t *y_src, int y_src_pitch,
531 const uint8_t *uv_src, int uv_src_pitch,
532 uint8_t *y_dst, int y_dst_pitch,
533 uint8_t *u_dst, int u_dst_pitch,
534 uint8_t *v_dst, int v_dst_pitch,
535 int width, int height) XINE_PROTECTED;
536void _x_yv12_to_nv12(const uint8_t *y_src, int y_src_pitch,
537 const uint8_t *u_src, int u_src_pitch,
538 const uint8_t *v_src, int v_src_pitch,
539 uint8_t *y_dst, int y_dst_pitch,
540 uint8_t *uv_dst, int uv_dst_pitch,
541 int width, int height) XINE_PROTECTED;
542void _x_yuy2_to_nv12(const uint8_t *src_yuy2_map, int yuy2_pitch,
543 uint8_t *y_dst, int y_dst_pitch,
544 uint8_t *uv_dst, int uv_dst_pitch,
545 int width, int height) XINE_PROTECTED;
546
547
548/* print a hexdump of the given data */
549void xine_hexdump (const void *buf, int length) XINE_PROTECTED;
550
551/*
552 * Optimization macros for conditions
553 * Taken from the FIASCO L4 microkernel sources
554 */
555#if !defined(__GNUC__) || __GNUC__ < 3
556# define EXPECT_TRUE(x) (x)
557# define EXPECT_FALSE(x) (x)
558#else
559# define EXPECT_TRUE(x) __builtin_expect((x),1)
560# define EXPECT_FALSE(x) __builtin_expect((x),0)
561#endif
562
563#ifdef NDEBUG
564#define _x_assert(exp) \
565 do { \
566 if (!(exp)) \
567 fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
568 __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
569 } while(0)
570#else
571#define _x_assert(exp) \
572 do { \
573 if (!(exp)) { \
574 fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
575 __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
576 abort(); \
577 } \
578 } while(0)
579#endif
580
581XINE_DEPRECATED static inline void _x_abort_is_deprecated(void) {}
582#define _x_abort() \
583 do { \
584 fprintf(stderr, "abort: %s:%d: %s: Aborting.\n", \
585 __FILE__, __LINE__, __XINE_FUNCTION__); \
586 abort(); \
587 _x_abort_is_deprecated(); \
588 } while(0)
589
590
591/****** logging with xine **********************************/
592
593#ifndef LOG_MODULE
594 #define LOG_MODULE __FILE__
595#endif /* LOG_MODULE */
596
597#define LOG_MODULE_STRING printf("%s: ", LOG_MODULE );
598
599#ifdef LOG_VERBOSE
600 #define LONG_LOG_MODULE_STRING \
601 printf("%s: (%s:%d) ", LOG_MODULE, __XINE_FUNCTION__, __LINE__ );
602#else
603 #define LONG_LOG_MODULE_STRING LOG_MODULE_STRING
604#endif /* LOG_VERBOSE */
605
606#ifdef LOG
607 #if defined(__GNUC__) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
608 #define lprintf(fmt, args...) \
609 do { \
610 LONG_LOG_MODULE_STRING \
611 printf(fmt, ##args); \
612 fflush(stdout); \
613 } while(0)
614 #else /* __GNUC__ */
615 #ifdef _MSC_VER
616 #define lprintf(fmtargs) \
617 do { \
618 LONG_LOG_MODULE_STRING \
619 printf("%s", fmtargs); \
620 fflush(stdout); \
621 } while(0)
622 #else /* _MSC_VER */
623 #define lprintf(...) \
624 do { \
625 LONG_LOG_MODULE_STRING \
626 printf(__VA_ARGS__); \
627 fflush(stdout); \
628 } while(0)
629 #endif /* _MSC_VER */
630 #endif /* __GNUC__ */
631#else /* LOG */
632 #if defined(DEBUG) && defined(XINE_COMPILE)
633XINE_FORMAT_PRINTF(1, 2) static inline void lprintf(const char * fmt, ...) { (void)fmt; }
634 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
635 #define lprintf(...) do {} while(0)
636 #elif defined(__GNUC__)
637 #define lprintf(fmt, args...) do {} while(0)
638 #elif defined(_MSC_VER)
639void __inline lprintf(const char * fmt, ...) {}
640 #else
641 #define lprintf(...) do {} while(0)
642 #endif
643#endif /* LOG */
644
645#if defined(__GNUC__) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
646 #define llprintf(cat, fmt, args...) \
647 do{ \
648 if(cat){ \
649 LONG_LOG_MODULE_STRING \
650 printf( fmt, ##args ); \
651 } \
652 }while(0)
653#else
654#ifdef _MSC_VER
655 #define llprintf(cat, fmtargs) \
656 do{ \
657 if(cat){ \
658 LONG_LOG_MODULE_STRING \
659 printf( "%s", fmtargs ); \
660 } \
661 }while(0)
662#else
663 #define llprintf(cat, ...) \
664 do{ \
665 if(cat){ \
666 LONG_LOG_MODULE_STRING \
667 printf( __VA_ARGS__ ); \
668 } \
669 }while(0)
670#endif /* _MSC_VER */
671#endif /* __GNUC__ */
672
673#if defined(__GNUC__) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
674 #define xprintf(xine, verbose, fmt, args...) \
675 do { \
676 if((xine) && (xine)->verbosity >= verbose){ \
677 xine_log(xine, XINE_LOG_TRACE, fmt, ##args); \
678 } \
679 } while(0)
680#else
681#ifdef _MSC_VER
682void xine_xprintf(xine_t *xine, int verbose, const char *fmt, ...);
683 #define xprintf xine_xprintf
684#else
685 #define xprintf(xine, verbose, ...) \
686 do { \
687 if((xine) && (xine)->verbosity >= verbose){ \
688 xine_log(xine, XINE_LOG_TRACE, __VA_ARGS__); \
689 } \
690 } while(0)
691#endif /* _MSC_VER */
692#endif /* __GNUC__ */
693
694/* time measuring macros for profiling tasks */
695
696#ifdef DEBUG
697# define XINE_PROFILE(function) \
698 do { \
699 struct timeval current_time; \
700 double dtime; \
701 gettimeofday(&current_time, NULL); \
702 dtime = -(current_time.tv_sec + (current_time.tv_usec / 1000000.0)); \
703 function; \
704 gettimeofday(&current_time, NULL); \
705 dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
706 printf("%s: (%s:%d) took %lf seconds\n", \
707 LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
708 } while(0)
709# define XINE_PROFILE_ACCUMULATE(function) \
710 do { \
711 struct timeval current_time; \
712 static double dtime = 0; \
713 gettimeofday(&current_time, NULL); \
714 dtime -= current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
715 function; \
716 gettimeofday(&current_time, NULL); \
717 dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
718 printf("%s: (%s:%d) took %lf seconds\n", \
719 LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
720 } while(0)
721#else
722# define XINE_PROFILE(function) function
723# define XINE_PROFILE_ACCUMULATE(function) function
724#endif /* DEBUG */
725
730
731/*
732 * guess default encoding for the subtitles
733 */
735
736/*
737 * use the best clock reference (API compatible with gettimeofday)
738 * note: it will be a monotonic clock, if available.
739 */
740struct timezone;
741int xine_monotonic_clock(struct timeval *tv, struct timezone *tz) XINE_PROTECTED;
742
746void _x_report_video_fourcc (xine_t *, const char *module, uint32_t) XINE_PROTECTED;
747void _x_report_audio_format_tag (xine_t *, const char *module, uint32_t) XINE_PROTECTED;
748
753#define XINE_FAST_STRING 1
755size_t xine_fast_string_need (size_t max_strlen) XINE_PROTECTED;
757size_t xine_fast_string_max (char *fast_string) XINE_PROTECTED;
759char *xine_fast_string_init (char *buf, size_t bsize) XINE_PROTECTED;
763char *xine_fast_string_set (char *fast_string, const char *text, size_t tsize) XINE_PROTECTED;
767int xine_fast_string_cmp (char *fast_string1, char *fast_string2);
769void xine_fast_string_free (char **fast_string) XINE_PROTECTED;
770
771#define XINE_REF_STRING 1
774char *xine_ref_string_ref (const char *s, int len) XINE_PROTECTED;
776size_t xine_ref_string_len (const char *s) XINE_PROTECTED;
779
782#define XINE_PTS_QUEUE 1
789void xine_pts_queue_put (xine_pts_queue_t *queue, size_t bytes, int64_t pts) XINE_PROTECTED;
794
796#define XINE_TS 1
807int xine_ts_from_string (struct timespec *ts, const char *string) XINE_PROTECTED;
809void xine_ts_add (struct timespec *a, const struct timespec *b) XINE_PROTECTED;
811void xine_ts_sub (struct timespec *a, const struct timespec *b) XINE_PROTECTED;
813int64_t xine_ts_to_timebase (const struct timespec *ts, uint32_t timebase) XINE_PROTECTED;
814
816#define XINE_RATS 1
817typedef struct {
818 int64_t num, den;
822
823/* don't harm following code */
824#ifdef extern
825# undef extern
826#endif
827
828#ifdef __cplusplus
829}
830#endif
831
832#endif
unsigned int height
Definition gfontrle.c:5
unsigned int width
Definition gfontrle.c:4
#define XINE_DEPRECATED
Definition attributes.h:87
#define XINE_MALLOC
Definition attributes.h:141
#define XINE_PROTECTED
Definition attributes.h:75
#define XINE_FORMAT_PRINTF(fmt, var)
Definition attributes.h:129
#define XINE_CONST
Definition attributes.h:153
Definition xineutils.h:80
dnode_t *volatile head
Definition xineutils.h:81
dnode_t *volatile tail
Definition xineutils.h:83
dnode_t * null
Definition xineutils.h:82
Definition xineutils.h:65
struct dnode_st * next
Definition xineutils.h:66
struct dnode_st * prev
Definition xineutils.h:66
Definition color.c:1752
int fmt
Definition color.c:1758
Definition xineutils.h:138
char * locked_by
Definition xineutils.h:141
pthread_mutex_t mutex
Definition xineutils.h:139
Definition utils.c:1521
int64_t pts
Definition utils.c:1526
uint32_t num
Definition utils.c:1534
uint32_t bytes
Definition utils.c:1533
Definition xineutils.h:817
int64_t den
Definition xineutils.h:818
Definition xine_internal.h:80
Definition xineutils.h:401
unsigned char * u
Definition xineutils.h:404
unsigned int row_width
Definition xineutils.h:406
unsigned int row_count
Definition xineutils.h:407
unsigned char * y
Definition xineutils.h:403
unsigned char * v
Definition xineutils.h:405
const char * name
Definition xine.c:1575
_xine_arg_type_t type
Definition xine.c:1574
NULL
Definition xine_plugin.c:78
enable disable number of frames of telecine pattern sync required before mode change make frames evenly spaced for film mode(24 fps)" ) PARAM_ITEM( POST_PARAM_TYPE_BOOL
void free_yuv_planes(yuv_planes_t *yuv_planes)
Definition color.c:140
void xine_profiler_stop_count(int id)
Definition monitor.c:98
void rgb2yv12_slice(rgb2yuy2_t *rgb2yuy2, const uint8_t *src, int src_stride, uint8_t *y_dst, int y_pitch, uint8_t *u_dst, int u_pitch, uint8_t *v_dst, int v_pitch, int width, int height)
Definition color.c:2231
void init_yuv_conversion(void)
Definition color.c:1686
char * xine_fast_string_init(char *buf, size_t bsize)
Definition utils.c:1174
struct yuv_planes_s yuv_planes_t
size_t xine_fast_string_need(size_t max_strlen)
Definition utils.c:1169
void * xine_xmalloc(size_t size) XINE_DEPRECATED
Allocate and clean memory size_t 'size', then return the pointer to the allocated memory.
Definition utils.c:271
size_t xine_base64_encode(uint8_t *from, char *to, size_t size)
Definition utils.c:918
struct dnode_st dnode_t
int64_t xine_ts_to_timebase(const struct timespec *ts, uint32_t timebase)
Definition utils.c:1991
void xine_profiler_init(void)
Definition monitor.c:47
void xine_pts_queue_delete(xine_pts_queue_t **queue)
Definition utils.c:1614
char int xine_open_cloexec(const char *name, int flags)
Definition utils.c:815
char * xine_strcat_realloc(char **dest, const char *append)
Definition utils.c:775
uint32_t xine_crc32_ieee(uint32_t crc, const uint8_t *data, size_t len)
Definition utils.c:998
void xine_fast_string_free(char **fast_string)
Definition utils.c:1277
int xine_mutex_unlock(xine_mutex_t *mutex, const char *who)
Definition xine_mutex.c:71
char * _x_asprintf(const char *format,...) XINE_FORMAT_PRINTF(1
void _x_report_video_fourcc(xine_t *, const char *module, uint32_t)
Definition buffer_types.c:615
char * xine_get_system_encoding(void)
Definition utils.c:646
void xine_hexdump(const void *buf, int length)
Definition utils.c:576
int xine_ref_string_unref(char **s)
Definition utils.c:1489
int xine_cpu_count(void) XINE_CONST
Definition cpu_accel.c:496
void xine_ts_sub(struct timespec *a, const struct timespec *b)
Definition utils.c:1980
void xine_pts_queue_reset(xine_pts_queue_t *queue)
Definition utils.c:1544
void _x_nv12_to_yv12(const uint8_t *y_src, int y_src_pitch, const uint8_t *uv_src, int uv_src_pitch, uint8_t *y_dst, int y_dst_pitch, uint8_t *u_dst, int u_dst_pitch, uint8_t *v_dst, int v_dst_pitch, int width, int height)
int y_g_table[256]
Definition color.c:79
int xine_create_cloexec(const char *name, int flags, mode_t mode)
Definition utils.c:826
void xine_profiler_start_count(int id)
Definition monitor.c:90
void init_yuv_planes(yuv_planes_t *yuv_planes, int width, int height)
Definition color.c:122
const char * xine_guess_spu_encoding(void)
Definition utils.c:694
int y_r_table[256]
Definition color.c:78
int xine_mutex_destroy(xine_mutex_t *mutex)
Definition xine_mutex.c:78
int v_r_table[256]
Definition color.c:90
int64_t xine_pts_queue_get(xine_pts_queue_t *queue, size_t bytes)
Definition utils.c:1577
size_t xine_ref_string_len(const char *s)
Definition utils.c:1481
void * xine_xcalloc(size_t nmemb, size_t size)
Wrapper around calloc() function.
Definition utils.c:296
void(* yv12_to_yuy2)(const unsigned char *y_src, int y_src_pitch, const unsigned char *u_src, int u_src_pitch, const unsigned char *v_src, int v_src_pitch, unsigned char *yuy2_map, int yuy2_pitch, int width, int height, int progressive)
Definition color.c:104
int v_g_table[256]
Definition color.c:87
static void _x_freep(void *ptr)
Definition xineutils.h:273
void * xine_memdup0(const void *src, size_t length)
Definition utils.c:317
static void _x_freep_wipe_string(char **pp)
Definition xineutils.h:279
rgb2yuy2_t * rgb2yuy2_alloc(int color_matrix, const char *format)
Definition color.c:1768
int xine_fast_string_cmp(char *fast_string1, char *fast_string2)
Definition utils.c:1250
xine_pts_queue_t * xine_pts_queue_new(void)
Definition utils.c:1539
int xine_socket_cloexec(int domain, int type, int protocol)
Definition utils.c:837
void * xine_memdup(const void *src, size_t length)
Definition utils.c:308
uint32_t xine_crc16_ansi(uint32_t crc, const uint8_t *data, size_t len)
Definition utils.c:1071
char * xine_fast_string_set(char *fast_string, const char *text, size_t tsize)
Definition utils.c:1202
const char * xine_get_homedir(void)
Definition utils.c:380
void(* yuy2_to_yv12)(const unsigned char *yuy2_map, int yuy2_pitch, unsigned char *y_dst, int y_dst_pitch, unsigned char *u_dst, int u_dst_pitch, unsigned char *v_dst, int v_dst_pitch, int width, int height)
Definition color.c:110
void xine_pts_queue_put(xine_pts_queue_t *queue, size_t bytes, int64_t pts)
Definition utils.c:1550
int xine_mutex_lock(xine_mutex_t *mutex, const char *who)
Definition xine_mutex.c:46
size_t xine_fast_string_max(char *fast_string)
Definition utils.c:1192
void * xine_malloc_aligned(size_t size)
Definition utils.c:869
int xine_ts_from_string(struct timespec *ts, const char *string)
Definition utils.c:1623
void xine_free_aligned(void *ptr)
Definition utils.c:882
void(* yuv9_to_yv12)(const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch, const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch, const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch, int width, int height)
Definition color.c:94
int uv_br_table[256]
Definition color.c:82
void rgb2yuy2_free(rgb2yuy2_t *rgb2yuy2)
Definition color.c:1943
int v_b_table[256]
Definition color.c:86
void * xine_realloc_aligned(void *ptr, size_t size)
Definition utils.c:890
void xine_rats_shorten(xine_rats_t *value)
Definition utils.c:2004
int xine_mutex_init(xine_mutex_t *mutex, const pthread_mutexattr_t *mutexattr, const char *id)
Definition xine_mutex.c:33
void yuy2_to_yuy2(const unsigned char *src, int src_pitch, unsigned char *dst, int dst_pitch, int width, int height)
Definition copy.c:59
void yv12_to_yv12(const unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch, const unsigned char *u_src, int u_src_pitch, unsigned char *u_dst, int u_dst_pitch, const unsigned char *v_src, int v_src_pitch, unsigned char *v_dst, int v_dst_pitch, int width, int height)
Definition copy.c:48
#define xine_small_memcpy(xsm_to, xsm_from, xsm_len)
Definition xineutils.h:202
void xine_profiler_print_results(void)
Definition monitor.c:107
void _x_yuy2_to_nv12(const uint8_t *src_yuy2_map, int yuy2_pitch, uint8_t *y_dst, int y_dst_pitch, uint8_t *uv_dst, int uv_dst_pitch, int width, int height)
Definition copy.c:120
char * xine_ref_string_ref(const char *s, int len)
Definition utils.c:1453
void _x_yv12_to_nv12(const uint8_t *y_src, int y_src_pitch, const uint8_t *u_src, int u_src_pitch, const uint8_t *v_src, int v_src_pitch, uint8_t *y_dst, int y_dst_pitch, uint8_t *uv_dst, int uv_dst_pitch, int width, int height)
Definition copy.c:88
int y_b_table[256]
Definition color.c:80
void rgb2yuy2_slice(rgb2yuy2_t *rgb2yuy2, const uint8_t *in, int ipitch, uint8_t *out, int opitch, int width, int height)
int xine_profiler_allocate_slot(const char *label)
Definition monitor.c:53
int u_r_table[256]
Definition color.c:84
void(* yuv411_to_yv12)(const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch, const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch, const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch, int width, int height)
Definition color.c:99
int u_b_table[256]
Definition color.c:89
void xine_ts_add(struct timespec *a, const struct timespec *b)
Definition utils.c:1969
uint32_t xine_mm_accel(void) XINE_CONST
Definition cpu_accel.c:390
size_t xine_base64_decode(const char *from, uint8_t *to)
Definition utils.c:943
int u_g_table[256]
Definition color.c:85
#define lprintf(...)
Definition xineutils.h:641
void xine_usec_sleep(unsigned usec)
Definition utils.c:546
void rgb2yuy2_palette(rgb2yuy2_t *rgb2yuy2, const uint8_t *pal, int num_colors, int bits_per_pixel)
Definition color.c:1947
static XINE_DEPRECATED void _x_abort_is_deprecated(void)
Definition xineutils.h:581
char * xine_chomp(char *str)
Definition utils.c:525
void * xine_mallocz_aligned(size_t size)
Definition utils.c:856
int xine_monotonic_clock(struct timeval *tv, struct timezone *tz)
Definition utils.c:727
void _x_report_audio_format_tag(xine_t *, const char *module, uint32_t)
Definition buffer_types.c:627
void(* yuv444_to_yuy2)(const yuv_planes_t *yuv_planes, unsigned char *yuy2_map, int pitch)
Definition color.c:92