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