14937
|
1 --- dvdread/bswap.h 2002-04-07 19:52:00.000000000 +0200
|
|
2 +++ bswap.h 2005-03-01 07:07:45.000000000 +0100
|
|
3 @@ -20,8 +20,6 @@
|
|
4 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
5 */
|
|
6
|
|
7 -#include <config.h>
|
|
8 -
|
|
9 #if defined(WORDS_BIGENDIAN)
|
|
10 /* All bigendian systems are fine, just ignore the swaps. */
|
|
11 #define B2N_16(x) (void)(x)
|
|
12 @@ -48,13 +46,51 @@
|
|
13 #define B2N_32(x) x = swap32(x)
|
|
14 #define B2N_64(x) x = swap64(x)
|
|
15
|
|
16 +#elif defined(ARCH_X86)
|
|
17 +inline static unsigned short bswap_16(unsigned short x)
|
|
18 +{
|
|
19 + __asm("xchgb %b0,%h0" :
|
|
20 + "=q" (x) :
|
|
21 + "0" (x));
|
|
22 + return x;
|
|
23 +}
|
|
24 +#define B2N_16(x) x = bswap_16(x)
|
|
25 +
|
|
26 +inline static unsigned int bswap_32(unsigned int x)
|
|
27 +{
|
|
28 + __asm(
|
|
29 +#if __CPU__ > 386
|
|
30 + "bswap %0":
|
|
31 + "=r" (x) :
|
|
32 +#else
|
|
33 + "xchgb %b0,%h0\n"
|
|
34 + " rorl $16,%0\n"
|
|
35 + " xchgb %b0,%h0":
|
|
36 + "=q" (x) :
|
|
37 +#endif
|
|
38 + "0" (x));
|
|
39 + return x;
|
|
40 +}
|
|
41 +#define B2N_32(x) x = bswap_32(x)
|
|
42 +
|
|
43 +inline static unsigned long long int bswap_64(unsigned long long int x)
|
|
44 +{
|
|
45 + register union { __extension__ uint64_t __ll;
|
|
46 + uint32_t __l[2]; } __x;
|
|
47 + asm("xchgl %0,%1":
|
|
48 + "=r"(__x.__l[0]),"=r"(__x.__l[1]):
|
|
49 + "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
|
|
50 + return __x.__ll;
|
|
51 +}
|
|
52 +#define B2N_64(x) x = bswap_64(x)
|
|
53 +
|
|
54 /* This is a slow but portable implementation, it has multiple evaluation
|
|
55 * problems so beware.
|
|
56 * FreeBSD and Solaris don't have <byteswap.h> or any other such
|
|
57 * functionality!
|
|
58 */
|
|
59
|
|
60 -#elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__)
|
|
61 +#elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__)
|
|
62 #define B2N_16(x) \
|
|
63 x = ((((x) & 0xff00) >> 8) | \
|
|
64 (((x) & 0x00ff) << 8))
|
|
65 --- dvdread/dvd_input.c 2002-05-09 23:32:46.000000000 +0200
|
|
66 +++ dvd_input.c 2005-03-01 07:07:46.000000000 +0100
|
|
67 @@ -21,13 +21,11 @@
|
|
68 #include <stdlib.h>
|
|
69 #include <fcntl.h>
|
|
70 #include <unistd.h>
|
|
71 -#include <dlfcn.h>
|
|
72
|
|
73 #include "dvd_reader.h"
|
|
74 #include "dvd_input.h"
|
|
75
|
|
76 -/* For libdvdcss */
|
|
77 -typedef struct dvdcss_s *dvdcss_handle;
|
|
78 +#include "dvdcss.h"
|
|
79
|
|
80 dvdcss_handle (*DVDcss_open) (const char *);
|
|
81 int (*DVDcss_close) (dvdcss_handle);
|
|
82 @@ -36,6 +34,12 @@
|
|
83 int (*DVDcss_read) (dvdcss_handle, void *, int, int);
|
|
84 char * (*DVDcss_error) (dvdcss_handle);
|
|
85
|
|
86 +dvd_input_t (*DVDinput_open) (const char *);
|
|
87 +int (*DVDinput_close) (dvd_input_t);
|
|
88 +int (*DVDinput_seek) (dvd_input_t, int, int);
|
|
89 +int (*DVDinput_title) (dvd_input_t, int);
|
|
90 +int (*DVDinput_read) (dvd_input_t, void *, int, int);
|
|
91 +char * (*DVDinput_error) (dvd_input_t);
|
|
92
|
|
93 /* The DVDinput handle, add stuff here for new input methods. */
|
|
94 struct dvd_input_s {
|
|
95 @@ -55,7 +59,7 @@
|
|
96 dvd_input_t dev;
|
|
97
|
|
98 /* Allocate the handle structure */
|
|
99 - dev = (dvd_input_t) malloc(sizeof(dvd_input_t));
|
|
100 + dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s));
|
|
101 if(dev == NULL) {
|
|
102 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
|
|
103 return NULL;
|
|
104 @@ -123,176 +127,26 @@
|
|
105
|
|
106
|
|
107
|
|
108 -
|
|
109 -
|
|
110 -
|
|
111 -/**
|
|
112 - * initialize and open a DVD device or file.
|
|
113 - */
|
|
114 -static dvd_input_t file_open(const char *target)
|
|
115 -{
|
|
116 - dvd_input_t dev;
|
|
117 -
|
|
118 - /* Allocate the library structure */
|
|
119 - dev = (dvd_input_t) malloc(sizeof(dvd_input_t));
|
|
120 - if(dev == NULL) {
|
|
121 - fprintf(stderr, "libdvdread: Could not allocate memory.\n");
|
|
122 - return NULL;
|
|
123 - }
|
|
124 -
|
|
125 - /* Open the device */
|
|
126 - dev->fd = open(target, O_RDONLY);
|
|
127 - if(dev->fd < 0) {
|
|
128 - perror("libdvdread: Could not open input");
|
|
129 - free(dev);
|
|
130 - return NULL;
|
|
131 - }
|
|
132 -
|
|
133 - return dev;
|
|
134 -}
|
|
135 -
|
|
136 -/**
|
|
137 - * return the last error message
|
|
138 - */
|
|
139 -static char *file_error(dvd_input_t dev)
|
|
140 -{
|
|
141 - /* use strerror(errno)? */
|
|
142 - return "unknown error";
|
|
143 -}
|
|
144 -
|
|
145 -/**
|
|
146 - * seek into the device.
|
|
147 - */
|
|
148 -static int file_seek(dvd_input_t dev, int blocks, int flags)
|
|
149 -{
|
|
150 - off_t pos;
|
|
151 -
|
|
152 - pos = lseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
|
|
153 - if(pos < 0) {
|
|
154 - return pos;
|
|
155 - }
|
|
156 - /* assert pos % DVD_VIDEO_LB_LEN == 0 */
|
|
157 - return (int) (pos / DVD_VIDEO_LB_LEN);
|
|
158 -}
|
|
159 -
|
|
160 -/**
|
|
161 - * set the block for the begining of a new title (key).
|
|
162 - */
|
|
163 -static int file_title(dvd_input_t dev, int block)
|
|
164 -{
|
|
165 - return -1;
|
|
166 -}
|
|
167 -
|
|
168 -/**
|
|
169 - * read data from the device.
|
|
170 - */
|
|
171 -static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags)
|
|
172 -{
|
|
173 - size_t len;
|
|
174 - ssize_t ret;
|
|
175 -
|
|
176 - len = (size_t)blocks * DVD_VIDEO_LB_LEN;
|
|
177 -
|
|
178 - while(len > 0) {
|
|
179 -
|
|
180 - ret = read(dev->fd, buffer, len);
|
|
181 -
|
|
182 - if(ret < 0) {
|
|
183 - /* One of the reads failed, too bad. We won't even bother
|
|
184 - * returning the reads that went ok, and as in the posix spec
|
|
185 - * the file postition is left unspecified after a failure. */
|
|
186 - return ret;
|
|
187 - }
|
|
188 -
|
|
189 - if(ret == 0) {
|
|
190 - /* Nothing more to read. Return the whole blocks, if any, that we got.
|
|
191 - and adjust the file possition back to the previous block boundary. */
|
|
192 - size_t bytes = (size_t)blocks * DVD_VIDEO_LB_LEN - len;
|
|
193 - off_t over_read = -(bytes % DVD_VIDEO_LB_LEN);
|
|
194 - /*off_t pos =*/ lseek(dev->fd, over_read, SEEK_CUR);
|
|
195 - /* should have pos % 2048 == 0 */
|
|
196 - return (int) (bytes / DVD_VIDEO_LB_LEN);
|
|
197 - }
|
|
198 -
|
|
199 - len -= ret;
|
|
200 - }
|
|
201 -
|
|
202 - return blocks;
|
|
203 -}
|
|
204 -
|
|
205 -/**
|
|
206 - * close the DVD device and clean up.
|
|
207 - */
|
|
208 -static int file_close(dvd_input_t dev)
|
|
209 -{
|
|
210 - int ret;
|
|
211 -
|
|
212 - ret = close(dev->fd);
|
|
213 -
|
|
214 - if(ret < 0)
|
|
215 - return ret;
|
|
216 -
|
|
217 - free(dev);
|
|
218 -
|
|
219 - return 0;
|
|
220 -}
|
|
221 -
|
|
222 -
|
|
223 /**
|
|
224 * Setup read functions with either libdvdcss or minimal DVD access.
|
|
225 */
|
|
226 int DVDInputSetup(void)
|
|
227 {
|
|
228 - void *dvdcss_library = NULL;
|
|
229 - char **dvdcss_version = NULL;
|
|
230 -
|
|
231 - dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY);
|
|
232 -
|
|
233 - if(dvdcss_library != NULL) {
|
|
234 -#if defined(__OpenBSD__) && !defined(__ELF__)
|
|
235 -#define U_S "_"
|
|
236 -#else
|
|
237 -#define U_S
|
|
238 -#endif
|
|
239 - DVDcss_open = (dvdcss_handle (*)(const char*))
|
|
240 - dlsym(dvdcss_library, U_S "dvdcss_open");
|
|
241 - DVDcss_close = (int (*)(dvdcss_handle))
|
|
242 - dlsym(dvdcss_library, U_S "dvdcss_close");
|
|
243 - DVDcss_title = (int (*)(dvdcss_handle, int))
|
|
244 - dlsym(dvdcss_library, U_S "dvdcss_title");
|
|
245 - DVDcss_seek = (int (*)(dvdcss_handle, int, int))
|
|
246 - dlsym(dvdcss_library, U_S "dvdcss_seek");
|
|
247 - DVDcss_read = (int (*)(dvdcss_handle, void*, int, int))
|
|
248 - dlsym(dvdcss_library, U_S "dvdcss_read");
|
|
249 - DVDcss_error = (char* (*)(dvdcss_handle))
|
|
250 - dlsym(dvdcss_library, U_S "dvdcss_error");
|
|
251 + DVDcss_open = dvdcss_open;
|
|
252 + DVDcss_close = dvdcss_close;
|
|
253 + DVDcss_title = dvdcss_title;
|
|
254 + DVDcss_seek = dvdcss_seek;
|
|
255 + DVDcss_read = dvdcss_read;
|
|
256 + DVDcss_error = dvdcss_error;
|
|
257
|
|
258 - dvdcss_version = (char **)dlsym(dvdcss_library, U_S "dvdcss_interface_2");
|
|
259 -
|
|
260 - if(dlsym(dvdcss_library, U_S "dvdcss_crack")) {
|
|
261 - fprintf(stderr,
|
|
262 - "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n"
|
|
263 - "libdvdread: You should get the latest version from "
|
|
264 - "http://www.videolan.org/\n" );
|
|
265 - dlclose(dvdcss_library);
|
|
266 - dvdcss_library = NULL;
|
|
267 - } else if(!DVDcss_open || !DVDcss_close || !DVDcss_title || !DVDcss_seek
|
|
268 - || !DVDcss_read || !DVDcss_error || !dvdcss_version) {
|
|
269 - fprintf(stderr, "libdvdread: Missing symbols in libdvdcss.so.2, "
|
|
270 - "this shouldn't happen !\n");
|
|
271 - dlclose(dvdcss_library);
|
|
272 - }
|
|
273 - }
|
|
274 -
|
|
275 - if(dvdcss_library != NULL) {
|
|
276 /*
|
|
277 char *psz_method = getenv( "DVDCSS_METHOD" );
|
|
278 char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
|
|
279 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method);
|
|
280 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
|
|
281 */
|
|
282 - fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n",
|
|
283 - *dvdcss_version);
|
|
284 +// fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n",
|
|
285 +// *dvdcss_version);
|
|
286
|
|
287 /* libdvdcss wraper functions */
|
|
288 DVDinput_open = css_open;
|
|
289 @@ -303,16 +157,4 @@
|
|
290 DVDinput_error = css_error;
|
|
291 return 1;
|
|
292
|
|
293 - } else {
|
|
294 - fprintf(stderr, "libdvdread: Encrypted DVD support unavailable.\n");
|
|
295 -
|
|
296 - /* libdvdcss replacement functions */
|
|
297 - DVDinput_open = file_open;
|
|
298 - DVDinput_close = file_close;
|
|
299 - DVDinput_seek = file_seek;
|
|
300 - DVDinput_title = file_title;
|
|
301 - DVDinput_read = file_read;
|
|
302 - DVDinput_error = file_error;
|
|
303 - return 0;
|
|
304 - }
|
|
305 }
|
|
306 --- dvdread/dvd_input.h 2002-05-09 23:21:20.000000000 +0200
|
|
307 +++ dvd_input.h 2005-03-01 07:07:46.000000000 +0100
|
|
308 @@ -36,12 +36,12 @@
|
|
309 /**
|
|
310 * Pointers which will be filled either the input meathods functions.
|
|
311 */
|
|
312 -dvd_input_t (*DVDinput_open) (const char *);
|
|
313 -int (*DVDinput_close) (dvd_input_t);
|
|
314 -int (*DVDinput_seek) (dvd_input_t, int, int);
|
|
315 -int (*DVDinput_title) (dvd_input_t, int);
|
|
316 -int (*DVDinput_read) (dvd_input_t, void *, int, int);
|
|
317 -char * (*DVDinput_error) (dvd_input_t);
|
|
318 +extern dvd_input_t (*DVDinput_open) (const char *);
|
|
319 +extern int (*DVDinput_close) (dvd_input_t);
|
|
320 +extern int (*DVDinput_seek) (dvd_input_t, int, int);
|
|
321 +extern int (*DVDinput_title) (dvd_input_t, int);
|
|
322 +extern int (*DVDinput_read) (dvd_input_t, void *, int, int);
|
|
323 +extern char * (*DVDinput_error) (dvd_input_t);
|
|
324
|
|
325 /**
|
|
326 * Setup function accessed by dvd_reader.c. Returns 1 if there is CSS support.
|
|
327 --- dvdread/dvd_reader.c 2002-05-19 17:48:41.000000000 +0200
|
|
328 +++ dvd_reader.c 2005-03-01 07:07:46.000000000 +0100
|
|
329 @@ -17,6 +17,8 @@
|
|
330 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
|
331 */
|
|
332
|
|
333 +#include "config.h"
|
|
334 +
|
|
335 #include <sys/types.h>
|
|
336 #include <sys/stat.h>
|
|
337 #include <sys/time.h> /* For the timing of dvdcss_title crack. */
|
|
338 @@ -35,12 +37,24 @@
|
|
339
|
|
340 #if defined(__sun)
|
|
341 #include <sys/mnttab.h>
|
|
342 +#elif defined(hpux)
|
|
343 +#include </usr/conf/h/mnttab.h>
|
|
344 #elif defined(SYS_BSD)
|
|
345 #include <fstab.h>
|
15535
|
346 -#elif defined(__linux__)
|
|
347 +#elif defined(__linux__) || defined(__CYGWIN__)
|
14937
|
348 #include <mntent.h>
|
|
349 #endif
|
|
350
|
|
351 +#ifdef __MINGW32__
|
|
352 +#include <sys/timeb.h>
|
|
353 +static void gettimeofday(struct timeval* t,void* timezone){
|
|
354 + struct timeb timebuffer;
|
|
355 + ftime( &timebuffer );
|
|
356 + t->tv_sec=timebuffer.time;
|
|
357 + t->tv_usec=1000*timebuffer.millitm;
|
|
358 +}
|
|
359 +#endif
|
|
360 +
|
|
361 #include "dvd_udf.h"
|
|
362 #include "dvd_input.h"
|
|
363 #include "dvd_reader.h"
|
|
364 @@ -144,6 +158,13 @@
|
|
365 }
|
|
366
|
|
367
|
|
368 +#ifndef HAVE_MPLAYER
|
|
369 + #include "get_path.c"
|
|
370 +#else
|
|
371 + extern char * get_path( char * filename );
|
|
372 +#endif
|
|
373 +
|
|
374 +//extern char * dvdcss_cache_dir;
|
|
375
|
|
376 /**
|
|
377 * Open a DVD image or block device file.
|
|
378 @@ -152,7 +173,17 @@
|
|
379 {
|
|
380 dvd_reader_t *dvd;
|
|
381 dvd_input_t dev;
|
|
382 +
|
|
383 + /* setup cache dir is no longer needed, it's now implemented in libdvdcss.c
|
|
384 + if(!dvdcss_cache_dir){
|
|
385 + dvdcss_cache_dir=get_path( "" );
|
|
386 + if ( dvdcss_cache_dir ) { mkdir( dvdcss_cache_dir,493 ); free( dvdcss_cache_dir ); }
|
|
387 + dvdcss_cache_dir=get_path( "DVDKeys" );
|
|
388 + if(dvdcss_cache_dir) mkdir( dvdcss_cache_dir,493 );
|
|
389 + }
|
|
390 + */
|
|
391
|
|
392 + /* open it */
|
|
393 dev = DVDinput_open( location );
|
|
394 if( !dev ) {
|
|
395 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
|
|
396 @@ -222,7 +253,7 @@
|
|
397 char *new_path;
|
|
398
|
|
399 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
|
|
400 - if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
|
|
401 + if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) )
|
|
402 return (char *) strdup( path );
|
|
403
|
|
404 /* Replace "/dev/" with "/dev/r" */
|
|
405 @@ -242,6 +273,16 @@
|
|
406
|
|
407 if( !path ) return 0;
|
|
408
|
|
409 +#ifdef WIN32
|
|
410 + /* Stat doesn't work on devices under mingwin/cygwin. */
|
|
411 + if( path[0] && path[1] == ':' && path[2] == '\0' )
|
|
412 + {
|
|
413 + /* Don't try to stat the file */
|
|
414 + fileinfo.st_mode = S_IFBLK;
|
|
415 + }
|
|
416 + else
|
|
417 +#endif
|
|
418 + {
|
|
419 ret = stat( path, &fileinfo );
|
|
420 if( ret < 0 ) {
|
|
421 /* If we can't stat the file, give up */
|
|
422 @@ -249,6 +290,7 @@
|
|
423 perror("");
|
|
424 return 0;
|
|
425 }
|
|
426 + }
|
|
427
|
|
428 /* Try to open libdvdcss or fall back to standard functions */
|
|
429 have_css = DVDInputSetup();
|
15535
|
430 @@ -274,7 +320,7 @@
|
|
431 char *path_copy;
|
|
432 #if defined(SYS_BSD)
|
|
433 struct fstab* fe;
|
|
434 -#elif defined(__sun) || defined(__linux__)
|
|
435 +#elif defined(__sun) || defined(__linux__) || defined(__CYGWIN__)
|
|
436 FILE *mntfile;
|
|
437 #endif
|
|
438
|
14937
|
439 @@ -289,7 +331,9 @@
|
|
440 if( cdir >= 0 ) {
|
|
441 chdir( path_copy );
|
|
442 new_path = getcwd( NULL, PATH_MAX );
|
|
443 +#ifndef __MINGW32__
|
|
444 fchdir( cdir );
|
|
445 +#endif
|
|
446 close( cdir );
|
|
447 if( new_path ) {
|
|
448 free( path_copy );
|
15535
|
449 @@ -345,7 +393,7 @@
|
|
450 }
|
|
451 fclose( mntfile );
|
|
452 }
|
|
453 -#elif defined(__linux__)
|
|
454 +#elif defined(__linux__) || defined(__CYGWIN__)
|
|
455 mntfile = fopen( MOUNTED, "r" );
|
|
456 if( mntfile ) {
|
|
457 struct mntent *me;
|
14937
|
458 @@ -364,6 +408,9 @@
|
|
459 }
|
|
460 fclose( mntfile );
|
|
461 }
|
15535
|
462 +#elif defined(__MINGW32__)
|
14937
|
463 + dev_name = strdup(path);
|
|
464 + auth_drive = DVDOpenImageFile( path, have_css );
|
|
465 #endif
|
|
466 if( !dev_name ) {
|
|
467 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
|
|
468 @@ -554,8 +601,8 @@
|
|
469 }
|
|
470
|
|
471 if( dvd->css_state == 1 /* Need key init */ ) {
|
|
472 - initAllCSSKeys( dvd );
|
|
473 - dvd->css_state = 2;
|
|
474 +// initAllCSSKeys( dvd );
|
|
475 +// dvd->css_state = 2;
|
|
476 }
|
|
477 /*
|
|
478 if( DVDinput_seek( dvd_file->dvd->dev,
|
|
479 @@ -631,10 +678,9 @@
|
|
480 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
|
|
481 dvd_file->title_devs[ i ] = DVDinput_open( full_path );
|
|
482 dvd_file->filesize += dvd_file->title_sizes[ i ];
|
|
483 + DVDinput_seek( dvd_file->title_devs[ i ], 0, DVDINPUT_SEEK_KEY );
|
|
484 }
|
|
485 - if( dvd_file->title_devs[ 0 ] ) {
|
|
486 - DVDinput_seek( dvd_file->title_devs[ 0 ], 0, DVDINPUT_SEEK_KEY );
|
|
487 - } else {
|
|
488 + if( !dvd_file->title_devs[ 0 ] ) {
|
|
489 free( dvd_file );
|
|
490 return 0;
|
|
491 }
|
|
492 @@ -794,7 +840,10 @@
|
|
493 if( ret < 0 ) return ret;
|
|
494 /* FIXME: This is wrong if i is the last file in the set.
|
|
495 * also error from this read will not show in ret. */
|
|
496 -
|
|
497 +
|
|
498 + /* Does the next part exist? If not then return now. */
|
|
499 + if( !dvd_file->title_devs[ i + 1 ] ) return ret;
|
|
500 +
|
|
501 /* Read part 2 */
|
|
502 off = DVDinput_seek( dvd_file->title_devs[ i + 1 ],
|
|
503 0, DVDINPUT_NOFLAGS );
|
|
504 @@ -846,7 +895,7 @@
|
|
505 return (ssize_t)ret;
|
|
506 }
|
|
507
|
|
508 -int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
|
|
509 +int DVDFileSeek( dvd_file_t *dvd_file, int offset )
|
|
510 {
|
|
511 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
|
|
512 return -1;
|
|
513 --- dvdread/dvd_udf.c 2002-05-06 22:16:31.000000000 +0200
|
|
514 +++ dvd_udf.c 2005-03-01 07:07:46.000000000 +0100
|
|
515 @@ -4,6 +4,9 @@
|
|
516 *
|
|
517 * Modifications by:
|
|
518 * Billy Biggs <vektor@dumbterm.net>.
|
|
519 + * Björn Englund <d4bjorn@dtek.chalmers.se>.
|
|
520 + * Joey Parrish <joey@nicewarrior.org>.
|
|
521 + * - updated from libdvdread 0.9.4 and removed udf caching
|
|
522 *
|
|
523 * dvdudf: parse and read the UDF volume information of a DVD Video
|
|
524 * Copyright (C) 1999 Christian Wolff for convergence integrated media
|
|
525 @@ -30,8 +33,10 @@
|
|
526 #include <stdio.h>
|
|
527 #include <stdlib.h>
|
|
528 #include <string.h>
|
|
529 -#include <assert.h>
|
|
530 +//#include <assert.h>
|
|
531 +#ifndef __MINGW32__
|
|
532 #include <sys/ioctl.h>
|
|
533 +#endif
|
|
534 #include <sys/types.h>
|
|
535 #include <sys/stat.h>
|
|
536 #include <unistd.h>
|
|
537 @@ -93,6 +98,32 @@
|
|
538 uint16_t Partition;
|
|
539 };
|
|
540
|
|
541 +struct extent_ad {
|
|
542 + uint32_t location;
|
|
543 + uint32_t length;
|
|
544 +};
|
|
545 +
|
|
546 +struct avdp_t {
|
|
547 + struct extent_ad mvds;
|
|
548 + struct extent_ad rvds;
|
|
549 +};
|
|
550 +
|
|
551 +struct pvd_t {
|
|
552 + uint8_t VolumeIdentifier[32];
|
|
553 + uint8_t VolumeSetIdentifier[128];
|
|
554 +};
|
|
555 +
|
|
556 +struct lbudf {
|
|
557 + uint32_t lb;
|
|
558 + uint8_t *data;
|
|
559 +};
|
|
560 +
|
|
561 +struct icbmap {
|
|
562 + uint32_t lbn;
|
|
563 + struct AD file;
|
|
564 + uint8_t filetype;
|
|
565 +};
|
|
566 +
|
|
567 /* For direct data access, LSB first */
|
|
568 #define GETN1(p) ((uint8_t)data[p])
|
|
569 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8))
|
|
570 @@ -334,6 +365,67 @@
|
|
571 return 0;
|
|
572 }
|
|
573
|
|
574 +
|
|
575 +static int UDFGetAVDP( dvd_reader_t *device,
|
|
576 + struct avdp_t *avdp)
|
|
577 +{
|
|
578 + uint8_t Anchor[ DVD_VIDEO_LB_LEN ];
|
|
579 + uint32_t lbnum, MVDS_location, MVDS_length;
|
|
580 + uint16_t TagID;
|
|
581 + uint32_t lastsector;
|
|
582 + int terminate;
|
|
583 + struct avdp_t;
|
|
584 +
|
|
585 + /* Find Anchor */
|
|
586 + lastsector = 0;
|
|
587 + lbnum = 256; /* Try #1, prime anchor */
|
|
588 + terminate = 0;
|
|
589 +
|
|
590 + for(;;) {
|
|
591 + if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) {
|
|
592 + UDFDescriptor( Anchor, &TagID );
|
|
593 + } else {
|
|
594 + TagID = 0;
|
|
595 + }
|
|
596 + if (TagID != 2) {
|
|
597 + /* Not an anchor */
|
|
598 + if( terminate ) return 0; /* Final try failed */
|
|
599 +
|
|
600 + if( lastsector ) {
|
|
601 +
|
|
602 + /* We already found the last sector. Try #3, alternative
|
|
603 + * backup anchor. If that fails, don't try again.
|
|
604 + */
|
|
605 + lbnum = lastsector;
|
|
606 + terminate = 1;
|
|
607 + } else {
|
|
608 + /* TODO: Find last sector of the disc (this is optional). */
|
|
609 + if( lastsector ) {
|
|
610 + /* Try #2, backup anchor */
|
|
611 + lbnum = lastsector - 256;
|
|
612 + } else {
|
|
613 + /* Unable to find last sector */
|
|
614 + return 0;
|
|
615 + }
|
|
616 + }
|
|
617 + } else {
|
|
618 + /* It's an anchor! We can leave */
|
|
619 + break;
|
|
620 + }
|
|
621 + }
|
|
622 + /* Main volume descriptor */
|
|
623 + UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location );
|
|
624 + avdp->mvds.location = MVDS_location;
|
|
625 + avdp->mvds.length = MVDS_length;
|
|
626 +
|
|
627 + /* Backup volume descriptor */
|
|
628 + UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location );
|
|
629 + avdp->rvds.location = MVDS_location;
|
|
630 + avdp->rvds.length = MVDS_length;
|
|
631 +
|
|
632 + return 1;
|
|
633 +}
|
|
634 +
|
|
635 /**
|
|
636 * Looks for partition on the disc. Returns 1 if partition found, 0 on error.
|
|
637 * partnum: Number of the partition, starting at 0.
|
|
638 @@ -342,52 +434,21 @@
|
|
639 static int UDFFindPartition( dvd_reader_t *device, int partnum,
|
|
640 struct Partition *part )
|
|
641 {
|
|
642 - uint8_t LogBlock[ DVD_VIDEO_LB_LEN ], Anchor[ DVD_VIDEO_LB_LEN ];
|
|
643 + uint8_t LogBlock[ DVD_VIDEO_LB_LEN ];
|
|
644 uint32_t lbnum, MVDS_location, MVDS_length;
|
|
645 uint16_t TagID;
|
|
646 - uint32_t lastsector;
|
|
647 - int i, terminate, volvalid;
|
|
648 + int i, volvalid;
|
|
649 + struct avdp_t avdp;
|
|
650
|
|
651 - /* Find Anchor */
|
|
652 - lastsector = 0;
|
|
653 - lbnum = 256; /* Try #1, prime anchor */
|
|
654 - terminate = 0;
|
|
655 -
|
|
656 - for(;;) {
|
|
657 - if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) {
|
|
658 - UDFDescriptor( Anchor, &TagID );
|
|
659 - } else {
|
|
660 - TagID = 0;
|
|
661 - }
|
|
662 - if (TagID != 2) {
|
|
663 - /* Not an anchor */
|
|
664 - if( terminate ) return 0; /* Final try failed */
|
|
665 -
|
|
666 - if( lastsector ) {
|
|
667 -
|
|
668 - /* We already found the last sector. Try #3, alternative
|
|
669 - * backup anchor. If that fails, don't try again.
|
|
670 - */
|
|
671 - lbnum = lastsector;
|
|
672 - terminate = 1;
|
|
673 - } else {
|
|
674 - /* TODO: Find last sector of the disc (this is optional). */
|
|
675 - if( lastsector ) {
|
|
676 - /* Try #2, backup anchor */
|
|
677 - lbnum = lastsector - 256;
|
|
678 - } else {
|
|
679 - /* Unable to find last sector */
|
|
680 - return 0;
|
|
681 - }
|
|
682 - }
|
|
683 - } else {
|
|
684 - /* It's an anchor! We can leave */
|
|
685 - break;
|
|
686 - }
|
|
687 +
|
|
688 + if(!UDFGetAVDP(device, &avdp)) {
|
|
689 + return 0;
|
|
690 }
|
|
691 +
|
|
692 /* Main volume descriptor */
|
|
693 - UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location );
|
|
694 -
|
|
695 + MVDS_location = avdp.mvds.location;
|
|
696 + MVDS_length = avdp.mvds.length;
|
|
697 +
|
|
698 part->valid = 0;
|
|
699 volvalid = 0;
|
|
700 part->VolumeDesc[ 0 ] = '\0';
|
|
701 @@ -422,8 +483,9 @@
|
|
702 && ( ( !part->valid ) || ( !volvalid ) ) );
|
|
703
|
|
704 if( ( !part->valid) || ( !volvalid ) ) {
|
|
705 - /* Backup volume descriptor */
|
|
706 - UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location );
|
|
707 + /* Backup volume descriptor */
|
|
708 + MVDS_location = avdp.mvds.location;
|
|
709 + MVDS_length = avdp.mvds.length;
|
|
710 }
|
|
711 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) );
|
|
712
|
|
713 @@ -442,17 +504,18 @@
|
|
714 char tokenline[ MAX_UDF_FILE_NAME_LEN ];
|
|
715 char *token;
|
|
716 uint8_t filetype;
|
|
717 -
|
|
718 +
|
|
719 *filesize = 0;
|
|
720 tokenline[0] = '\0';
|
|
721 strcat( tokenline, filename );
|
|
722
|
|
723 - /* Find partition, 0 is the standard location for DVD Video.*/
|
|
724 - if( !UDFFindPartition( device, 0, &partition ) ) return 0;
|
|
725 -
|
|
726 - /* Find root dir ICB */
|
|
727 - lbnum = partition.Start;
|
|
728 - do {
|
|
729 +
|
|
730 + /* Find partition, 0 is the standard location for DVD Video.*/
|
|
731 + if( !UDFFindPartition( device, 0, &partition ) ) return 0;
|
|
732 +
|
|
733 + /* Find root dir ICB */
|
|
734 + lbnum = partition.Start;
|
|
735 + do {
|
|
736 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) {
|
|
737 TagID = 0;
|
|
738 } else {
|
|
739 @@ -469,19 +532,27 @@
|
|
740 /* Sanity checks. */
|
|
741 if( TagID != 256 ) return 0;
|
|
742 if( RootICB.Partition != 0 ) return 0;
|
|
743 -
|
|
744 +
|
|
745 /* Find root dir */
|
|
746 if( !UDFMapICB( device, RootICB, &filetype, &partition, &File ) ) return 0;
|
|
747 if( filetype != 4 ) return 0; /* Root dir should be dir */
|
|
748
|
|
749 - /* Tokenize filepath */
|
|
750 - token = strtok(tokenline, "/");
|
|
751 - while( token != NULL ) {
|
|
752 - if( !UDFScanDir( device, File, token, &partition, &ICB ) ) return 0;
|
|
753 - if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) return 0;
|
|
754 + {
|
|
755 + /* Tokenize filepath */
|
|
756 + token = strtok(tokenline, "/");
|
|
757 +
|
|
758 + while( token != NULL ) {
|
|
759 +
|
|
760 + if( !UDFScanDir( device, File, token, &partition, &ICB)) {
|
|
761 + return 0;
|
|
762 + }
|
|
763 + if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) {
|
|
764 + return 0;
|
|
765 + }
|
|
766 token = strtok( NULL, "/" );
|
|
767 - }
|
|
768 -
|
|
769 + }
|
|
770 + }
|
|
771 +
|
|
772 /* Sanity check. */
|
|
773 if( File.Partition != 0 ) return 0;
|
|
774
|
|
775 @@ -492,3 +563,81 @@
|
|
776 else
|
|
777 return partition.Start + File.Location;
|
|
778 }
|
|
779 +
|
|
780 +
|
|
781 +
|
|
782 +/**
|
|
783 + * Gets a Descriptor .
|
|
784 + * Returns 1 if descriptor found, 0 on error.
|
|
785 + * id, tagid of descriptor
|
|
786 + * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN).
|
|
787 + */
|
|
788 +static int UDFGetDescriptor( dvd_reader_t *device, int id,
|
|
789 + uint8_t *descriptor, int bufsize)
|
|
790 +{
|
|
791 + uint32_t lbnum, MVDS_location, MVDS_length;
|
|
792 + struct avdp_t avdp;
|
|
793 + uint16_t TagID;
|
|
794 + uint32_t lastsector;
|
|
795 + int i, terminate;
|
|
796 + int desc_found = 0;
|
|
797 + /* Find Anchor */
|
|
798 + lastsector = 0;
|
|
799 + lbnum = 256; /* Try #1, prime anchor */
|
|
800 + terminate = 0;
|
|
801 + if(bufsize < DVD_VIDEO_LB_LEN) {
|
|
802 + return 0;
|
|
803 + }
|
|
804 +
|
|
805 + if(!UDFGetAVDP(device, &avdp)) {
|
|
806 + return 0;
|
|
807 + }
|
|
808 +
|
|
809 + /* Main volume descriptor */
|
|
810 + MVDS_location = avdp.mvds.location;
|
|
811 + MVDS_length = avdp.mvds.length;
|
|
812 +
|
|
813 + i = 1;
|
|
814 + do {
|
|
815 + /* Find Descriptor */
|
|
816 + lbnum = MVDS_location;
|
|
817 + do {
|
|
818 +
|
|
819 + if( DVDReadLBUDF( device, lbnum++, 1, descriptor, 0 ) <= 0 ) {
|
|
820 + TagID = 0;
|
|
821 + } else {
|
|
822 + UDFDescriptor( descriptor, &TagID );
|
|
823 + }
|
|
824 +
|
|
825 + if( (TagID == id) && ( !desc_found ) ) {
|
|
826 + /* Descriptor */
|
|
827 + desc_found = 1;
|
|
828 + }
|
|
829 + } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 )
|
|
830 + / DVD_VIDEO_LB_LEN ) && ( TagID != 8 )
|
|
831 + && ( !desc_found) );
|
|
832 +
|
|
833 + if( !desc_found ) {
|
|
834 + /* Backup volume descriptor */
|
|
835 + MVDS_location = avdp.rvds.location;
|
|
836 + MVDS_length = avdp.rvds.length;
|
|
837 + }
|
|
838 + } while( i-- && ( !desc_found ) );
|
|
839 +
|
|
840 + return desc_found;
|
|
841 +}
|
|
842 +
|
|
843 +
|
|
844 +static int UDFGetPVD(dvd_reader_t *device, struct pvd_t *pvd)
|
|
845 +{
|
|
846 + uint8_t pvd_buf[DVD_VIDEO_LB_LEN];
|
|
847 +
|
|
848 + if(!UDFGetDescriptor( device, 1, pvd_buf, sizeof(pvd_buf))) {
|
|
849 + return 0;
|
|
850 + }
|
|
851 +
|
|
852 + memcpy(pvd->VolumeIdentifier, &pvd_buf[24], 32);
|
|
853 + memcpy(pvd->VolumeSetIdentifier, &pvd_buf[72], 128);
|
|
854 +
|
|
855 + return 1;
|
|
856 +}
|
|
857 --- dvdread/ifo_print.c 2002-05-15 21:35:54.000000000 +0200
|
|
858 +++ ifo_print.c 2005-03-01 07:07:46.000000000 +0100
|
|
859 @@ -23,7 +23,7 @@
|
|
860 #include <inttypes.h>
|
|
861 #include <string.h>
|
|
862 #include <ctype.h>
|
|
863 -#include <assert.h>
|
|
864 +//#include <assert.h>
|
|
865
|
|
866 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
867 #include "ifo_types.h"
|
|
868 --- dvdread/ifo_print.h 2002-04-07 19:52:01.000000000 +0200
|
|
869 +++ ifo_print.h 2005-03-01 07:07:46.000000000 +0100
|
|
870 @@ -20,8 +20,8 @@
|
|
871 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
872 */
|
|
873
|
|
874 -#include <dvdread/ifo_types.h>
|
|
875 -#include <dvdread/dvd_reader.h>
|
|
876 +#include "ifo_types.h"
|
|
877 +#include "dvd_reader.h"
|
|
878
|
|
879 #ifdef __cplusplus
|
|
880 extern "C" {
|
|
881 --- dvdread/ifo_read.c 2002-05-25 21:37:18.000000000 +0200
|
|
882 +++ ifo_read.c 2005-03-01 07:07:46.000000000 +0100
|
|
883 @@ -22,7 +22,7 @@
|
|
884 #include <unistd.h>
|
|
885 #include <inttypes.h>
|
|
886 #include <string.h>
|
|
887 -#include <assert.h>
|
|
888 +//#include <assert.h>
|
|
889
|
|
890 #include "dvd_reader.h"
|
|
891
|
|
892 --- dvdread/ifo_read.h 2002-04-07 19:52:01.000000000 +0200
|
|
893 +++ ifo_read.h 2005-03-01 07:07:46.000000000 +0100
|
|
894 @@ -20,8 +20,8 @@
|
|
895 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
896 */
|
|
897
|
|
898 -#include <dvdread/ifo_types.h>
|
|
899 -#include <dvdread/dvd_reader.h>
|
|
900 +#include "ifo_types.h"
|
|
901 +#include "dvd_reader.h"
|
|
902
|
|
903 #ifdef __cplusplus
|
|
904 extern "C" {
|
|
905 --- dvdread/ifo_types.h 2002-04-07 19:52:01.000000000 +0200
|
|
906 +++ ifo_types.h 2005-03-01 07:07:46.000000000 +0100
|
|
907 @@ -21,7 +21,7 @@
|
|
908 */
|
|
909
|
|
910 #include <inttypes.h>
|
|
911 -#include <dvdread/dvd_reader.h>
|
|
912 +#include "dvd_reader.h"
|
|
913
|
|
914
|
|
915 #undef ATTRIBUTE_PACKED
|
|
916 --- dvdread/nav_print.c 2002-04-07 19:18:06.000000000 +0200
|
|
917 +++ nav_print.c 2005-03-01 07:07:46.000000000 +0100
|
|
918 @@ -25,7 +25,7 @@
|
|
919
|
|
920 #include <stdio.h>
|
|
921 #include <inttypes.h>
|
|
922 -#include <assert.h>
|
|
923 +//#include <assert.h>
|
|
924
|
|
925 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
926 #include "nav_types.h"
|
|
927 --- dvdread/nav_print.h 2002-04-07 20:17:19.000000000 +0200
|
|
928 +++ nav_print.h 2005-03-01 07:07:46.000000000 +0100
|
|
929 @@ -20,7 +20,7 @@
|
|
930 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
931 */
|
|
932
|
|
933 -#include <dvdread/nav_types.h>
|
|
934 +#include "nav_types.h"
|
|
935
|
|
936 #ifdef __cplusplus
|
|
937 extern "C" {
|
|
938 --- dvdread/nav_read.c 2002-04-07 19:52:01.000000000 +0200
|
|
939 +++ nav_read.c 2005-03-01 07:07:46.000000000 +0100
|
|
940 @@ -19,7 +19,7 @@
|
|
941 #include <stdio.h>
|
|
942 #include <string.h>
|
|
943 #include <inttypes.h>
|
|
944 -#include <assert.h>
|
|
945 +//#include <assert.h>
|
|
946
|
|
947 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
948 #include "bswap.h"
|
|
949 @@ -95,7 +95,9 @@
|
|
950 /* pci hli btnit */
|
|
951 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
|
|
952 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
|
|
953 +#ifdef HAVE_ASSERT_H
|
|
954 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
|
|
955 +#endif
|
|
956 assert(pci->hli.btnit[n].zero1 == 0);
|
|
957 assert(pci->hli.btnit[n].zero2 == 0);
|
|
958 assert(pci->hli.btnit[n].zero3 == 0);
|
|
959 --- dvdread/nav_read.h 2002-04-07 20:17:19.000000000 +0200
|
|
960 +++ nav_read.h 2005-03-01 07:07:46.000000000 +0100
|
|
961 @@ -19,7 +19,7 @@
|
|
962 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
963 */
|
|
964
|
|
965 -#include <dvdread/nav_types.h>
|
|
966 +#include "nav_types.h"
|
|
967
|
|
968 #ifdef __cplusplus
|
|
969 extern "C" {
|
|
970 --- dvdread/nav_types.h 2002-04-07 20:41:59.000000000 +0200
|
|
971 +++ nav_types.h 2005-03-01 07:07:46.000000000 +0100
|
|
972 @@ -30,7 +30,7 @@
|
|
973 */
|
|
974
|
|
975 #include <inttypes.h>
|
|
976 -#include <dvdread/ifo_types.h> // only dvd_time_t, vm_cmd_t and user_ops_t
|
|
977 +#include "ifo_types.h" // only dvd_time_t, vm_cmd_t and user_ops_t
|
|
978
|
|
979
|
|
980 #undef ATTRIBUTE_PACKED
|