PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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