/xbmc/cores/dvdplayer/DVDInputStreams/dvdnav/dvdnav_internal.h

http://github.com/xbmc/xbmc · C Header · 225 lines · 139 code · 36 blank · 50 comment · 8 complexity · 6de9fa10ea87737f7845aff763a8a11f MD5 · raw file

  1. /*
  2. * Copyright (C) 2001-2004 Rich Wareham <richwareham@users.sourceforge.net>
  3. *
  4. * This file is part of libdvdnav, a DVD navigation library.
  5. *
  6. * libdvdnav 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. * libdvdnav 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 along
  17. * with libdvdnav; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #ifndef LIBDVDNAV_DVDNAV_INTERNAL_H
  21. #define LIBDVDNAV_DVDNAV_INTERNAL_H
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. //#include <unistd.h>
  28. #include <limits.h>
  29. #include <string.h>
  30. #ifdef TARGET_WINDOWS
  31. /* pthread_mutex_* wrapper for win32 */
  32. #ifndef TARGET_POSIX
  33. #include <windows.h>
  34. #include <process.h>
  35. typedef CRITICAL_SECTION pthread_mutex_t;
  36. #define pthread_mutex_init(a, b) InitializeCriticalSection(a)
  37. #define pthread_mutex_lock(a) EnterCriticalSection(a)
  38. #define pthread_mutex_unlock(a) LeaveCriticalSection(a)
  39. #define pthread_mutex_destroy(a) DeleteCriticalSection(a)
  40. #endif // !TARGET_POSIX
  41. #ifndef HAVE_GETTIMEOFDAY
  42. /* replacement gettimeofday implementation */
  43. #include <sys/timeb.h>
  44. static inline int _private_gettimeofday( struct timeval *tv, void *tz )
  45. {
  46. struct timeb t;
  47. ftime( &t );
  48. tv->tv_sec = t.time;
  49. tv->tv_usec = t.millitm * 1000;
  50. return 0;
  51. }
  52. #define gettimeofday(TV, TZ) _private_gettimeofday((TV), (TZ))
  53. #endif
  54. #ifndef TARGET_POSIX
  55. #include <io.h> /* read() */
  56. #define lseek64 _lseeki64
  57. #endif // !TARGET_POSIX
  58. #else
  59. #include <pthread.h>
  60. #endif /* TARGET_WINDOWS */
  61. /* Uncomment for VM command tracing */
  62. /* #define TRACE */
  63. #include "decoder.h"
  64. #include "dvdnav.h"
  65. #include "vm.h"
  66. #include "vmcmd.h"
  67. /* where should libdvdnav write its messages (stdout/stderr) */
  68. #define MSG_OUT stderr
  69. /* Maximum length of an error string */
  70. #define MAX_ERR_LEN 255
  71. /* Use the POSIX PATH_MAX if available */
  72. #ifdef PATH_MAX
  73. #define MAX_PATH_LEN PATH_MAX
  74. #else
  75. #define MAX_PATH_LEN 255 /* Arbitrary */
  76. #endif
  77. #ifndef DVD_VIDEO_LB_LEN
  78. #define DVD_VIDEO_LB_LEN 2048
  79. #endif
  80. typedef struct read_cache_s read_cache_t;
  81. /*
  82. * These are defined here because they are
  83. * not in ifo_types.h, they maybe one day
  84. */
  85. #ifndef audio_status_t
  86. typedef struct {
  87. #ifdef WORDS_BIGENDIAN
  88. unsigned int available : 1;
  89. unsigned int zero1 : 4;
  90. unsigned int stream_number : 3;
  91. uint8_t zero2;
  92. #else
  93. uint8_t zero2;
  94. unsigned int stream_number : 3;
  95. unsigned int zero1 : 4;
  96. unsigned int available : 1;
  97. #endif
  98. } ATTRIBUTE_PACKED audio_status_t;
  99. #endif
  100. #ifndef spu_status_t
  101. typedef struct {
  102. #ifdef WORDS_BIGENDIAN
  103. unsigned int available : 1;
  104. unsigned int zero1 : 2;
  105. unsigned int stream_number_4_3 : 5;
  106. unsigned int zero2 : 3;
  107. unsigned int stream_number_wide : 5;
  108. unsigned int zero3 : 3;
  109. unsigned int stream_number_letterbox : 5;
  110. unsigned int zero4 : 3;
  111. unsigned int stream_number_pan_scan : 5;
  112. #else
  113. unsigned int stream_number_pan_scan : 5;
  114. unsigned int zero4 : 3;
  115. unsigned int stream_number_letterbox : 5;
  116. unsigned int zero3 : 3;
  117. unsigned int stream_number_wide : 5;
  118. unsigned int zero2 : 3;
  119. unsigned int stream_number_4_3 : 5;
  120. unsigned int zero1 : 2;
  121. unsigned int available : 1;
  122. #endif
  123. } ATTRIBUTE_PACKED spu_status_t;
  124. #endif
  125. typedef struct dvdnav_vobu_s {
  126. int32_t vobu_start; /* Logical Absolute. MAX needed is 0x300000 */
  127. int32_t vobu_length;
  128. int32_t blockN; /* Relative offset */
  129. int32_t vobu_next; /* Relative offset */
  130. } dvdnav_vobu_t;
  131. /** The main DVDNAV type **/
  132. struct dvdnav_s {
  133. /* General data */
  134. char path[MAX_PATH_LEN]; /* Path to DVD device/dir */
  135. dvd_file_t *file; /* Currently opened file */
  136. /* Position data */
  137. vm_position_t position_next;
  138. vm_position_t position_current;
  139. dvdnav_vobu_t vobu;
  140. /* NAV data */
  141. pci_t pci;
  142. dsi_t dsi;
  143. uint32_t last_cmd_nav_lbn; /* detects when a command is issued on an already left NAV */
  144. /* Flags */
  145. int skip_still; /* Set when skipping a still */
  146. int sync_wait; /* applications should wait till they are in sync with us */
  147. int sync_wait_skip; /* Set when skipping wait state */
  148. int spu_clut_changed; /* The SPU CLUT changed */
  149. int started; /* vm_start has been called? */
  150. int use_read_ahead; /* 1 - use read-ahead cache, 0 - don't */
  151. int pgc_based; /* positioning works PGC based instead of PG based */
  152. int cur_cell_time; /* time expired since the beginning of the current cell, read from the dsi */
  153. /* VM */
  154. vm_t *vm;
  155. pthread_mutex_t vm_lock;
  156. /* Read-ahead cache */
  157. read_cache_t *cache;
  158. /* Errors */
  159. char err_str[MAX_ERR_LEN];
  160. };
  161. /** HELPER FUNCTIONS **/
  162. /* converts a dvd_time_t to PTS ticks */
  163. int64_t dvdnav_convert_time(dvd_time_t *time);
  164. /* XBMC added functions */
  165. /*
  166. * Get current playback state
  167. */
  168. dvdnav_status_t dvdnav_get_state(dvdnav_t *self, dvd_state_t *save_state);
  169. /*
  170. * Resume playback state
  171. */
  172. dvdnav_status_t dvdnav_set_state(dvdnav_t *self, dvd_state_t *save_state);
  173. /* end XBMC */
  174. /** USEFUL MACROS **/
  175. #ifdef __GNUC__
  176. #define printerrf(format, args...) \
  177. do { if (this) snprintf(this->err_str, MAX_ERR_LEN, format, ## args); } while (0)
  178. #else
  179. #ifdef _MSC_VER
  180. #define printerrf(str) \
  181. do { if (this) snprintf(this->err_str, MAX_ERR_LEN, str); } while (0)
  182. #else
  183. #define printerrf(...) \
  184. do { if (this) snprintf(this->err_str, MAX_ERR_LEN, __VA_ARGS__); } while (0)
  185. #endif /* TARGET_WINDOWS */
  186. #endif
  187. #define printerr(str) \
  188. do { if (this) strncpy(this->err_str, str, MAX_ERR_LEN - 1); } while (0)
  189. #endif /* LIBDVDNAV_DVDNAV_INTERNAL_H */