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>
|
|
346 #elif defined(__linux__)
|
|
347 #include <mntent.h>
|
|
348 #endif
|
|
349
|
|
350 +#ifdef __MINGW32__
|
|
351 +#include <sys/timeb.h>
|
|
352 +static void gettimeofday(struct timeval* t,void* timezone){
|
|
353 + struct timeb timebuffer;
|
|
354 + ftime( &timebuffer );
|
|
355 + t->tv_sec=timebuffer.time;
|
|
356 + t->tv_usec=1000*timebuffer.millitm;
|
|
357 +}
|
|
358 +#endif
|
|
359 +
|
|
360 #include "dvd_udf.h"
|
|
361 #include "dvd_input.h"
|
|
362 #include "dvd_reader.h"
|
|
363 @@ -144,6 +158,13 @@
|
|
364 }
|
|
365
|
|
366
|
|
367 +#ifndef HAVE_MPLAYER
|
|
368 + #include "get_path.c"
|
|
369 +#else
|
|
370 + extern char * get_path( char * filename );
|
|
371 +#endif
|
|
372 +
|
|
373 +//extern char * dvdcss_cache_dir;
|
|
374
|
|
375 /**
|
|
376 * Open a DVD image or block device file.
|
|
377 @@ -152,7 +173,17 @@
|
|
378 {
|
|
379 dvd_reader_t *dvd;
|
|
380 dvd_input_t dev;
|
|
381 +
|
|
382 + /* setup cache dir is no longer needed, it's now implemented in libdvdcss.c
|
|
383 + if(!dvdcss_cache_dir){
|
|
384 + dvdcss_cache_dir=get_path( "" );
|
|
385 + if ( dvdcss_cache_dir ) { mkdir( dvdcss_cache_dir,493 ); free( dvdcss_cache_dir ); }
|
|
386 + dvdcss_cache_dir=get_path( "DVDKeys" );
|
|
387 + if(dvdcss_cache_dir) mkdir( dvdcss_cache_dir,493 );
|
|
388 + }
|
|
389 + */
|
|
390
|
|
391 + /* open it */
|
|
392 dev = DVDinput_open( location );
|
|
393 if( !dev ) {
|
|
394 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
|
|
395 @@ -222,7 +253,7 @@
|
|
396 char *new_path;
|
|
397
|
|
398 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
|
|
399 - if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
|
|
400 + if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) )
|
|
401 return (char *) strdup( path );
|
|
402
|
|
403 /* Replace "/dev/" with "/dev/r" */
|
|
404 @@ -242,6 +273,16 @@
|
|
405
|
|
406 if( !path ) return 0;
|
|
407
|
|
408 +#ifdef WIN32
|
|
409 + /* Stat doesn't work on devices under mingwin/cygwin. */
|
|
410 + if( path[0] && path[1] == ':' && path[2] == '\0' )
|
|
411 + {
|
|
412 + /* Don't try to stat the file */
|
|
413 + fileinfo.st_mode = S_IFBLK;
|
|
414 + }
|
|
415 + else
|
|
416 +#endif
|
|
417 + {
|
|
418 ret = stat( path, &fileinfo );
|
|
419 if( ret < 0 ) {
|
|
420 /* If we can't stat the file, give up */
|
|
421 @@ -249,6 +290,7 @@
|
|
422 perror("");
|
|
423 return 0;
|
|
424 }
|
|
425 + }
|
|
426
|
|
427 /* Try to open libdvdcss or fall back to standard functions */
|
|
428 have_css = DVDInputSetup();
|
|
429 @@ -289,7 +331,9 @@
|
|
430 if( cdir >= 0 ) {
|
|
431 chdir( path_copy );
|
|
432 new_path = getcwd( NULL, PATH_MAX );
|
|
433 +#ifndef __MINGW32__
|
|
434 fchdir( cdir );
|
|
435 +#endif
|
|
436 close( cdir );
|
|
437 if( new_path ) {
|
|
438 free( path_copy );
|
|
439 @@ -364,6 +408,9 @@
|
|
440 }
|
|
441 fclose( mntfile );
|
|
442 }
|
|
443 +#elif defined(WIN32)
|
|
444 + dev_name = strdup(path);
|
|
445 + auth_drive = DVDOpenImageFile( path, have_css );
|
|
446 #endif
|
|
447 if( !dev_name ) {
|
|
448 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
|
|
449 @@ -554,8 +601,8 @@
|
|
450 }
|
|
451
|
|
452 if( dvd->css_state == 1 /* Need key init */ ) {
|
|
453 - initAllCSSKeys( dvd );
|
|
454 - dvd->css_state = 2;
|
|
455 +// initAllCSSKeys( dvd );
|
|
456 +// dvd->css_state = 2;
|
|
457 }
|
|
458 /*
|
|
459 if( DVDinput_seek( dvd_file->dvd->dev,
|
|
460 @@ -631,10 +678,9 @@
|
|
461 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
|
|
462 dvd_file->title_devs[ i ] = DVDinput_open( full_path );
|
|
463 dvd_file->filesize += dvd_file->title_sizes[ i ];
|
|
464 + DVDinput_seek( dvd_file->title_devs[ i ], 0, DVDINPUT_SEEK_KEY );
|
|
465 }
|
|
466 - if( dvd_file->title_devs[ 0 ] ) {
|
|
467 - DVDinput_seek( dvd_file->title_devs[ 0 ], 0, DVDINPUT_SEEK_KEY );
|
|
468 - } else {
|
|
469 + if( !dvd_file->title_devs[ 0 ] ) {
|
|
470 free( dvd_file );
|
|
471 return 0;
|
|
472 }
|
|
473 @@ -794,7 +840,10 @@
|
|
474 if( ret < 0 ) return ret;
|
|
475 /* FIXME: This is wrong if i is the last file in the set.
|
|
476 * also error from this read will not show in ret. */
|
|
477 -
|
|
478 +
|
|
479 + /* Does the next part exist? If not then return now. */
|
|
480 + if( !dvd_file->title_devs[ i + 1 ] ) return ret;
|
|
481 +
|
|
482 /* Read part 2 */
|
|
483 off = DVDinput_seek( dvd_file->title_devs[ i + 1 ],
|
|
484 0, DVDINPUT_NOFLAGS );
|
|
485 @@ -846,7 +895,7 @@
|
|
486 return (ssize_t)ret;
|
|
487 }
|
|
488
|
|
489 -int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
|
|
490 +int DVDFileSeek( dvd_file_t *dvd_file, int offset )
|
|
491 {
|
|
492 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
|
|
493 return -1;
|
|
494 --- dvdread/dvd_udf.c 2002-05-06 22:16:31.000000000 +0200
|
|
495 +++ dvd_udf.c 2005-03-01 07:07:46.000000000 +0100
|
|
496 @@ -4,6 +4,9 @@
|
|
497 *
|
|
498 * Modifications by:
|
|
499 * Billy Biggs <vektor@dumbterm.net>.
|
|
500 + * Björn Englund <d4bjorn@dtek.chalmers.se>.
|
|
501 + * Joey Parrish <joey@nicewarrior.org>.
|
|
502 + * - updated from libdvdread 0.9.4 and removed udf caching
|
|
503 *
|
|
504 * dvdudf: parse and read the UDF volume information of a DVD Video
|
|
505 * Copyright (C) 1999 Christian Wolff for convergence integrated media
|
|
506 @@ -30,8 +33,10 @@
|
|
507 #include <stdio.h>
|
|
508 #include <stdlib.h>
|
|
509 #include <string.h>
|
|
510 -#include <assert.h>
|
|
511 +//#include <assert.h>
|
|
512 +#ifndef __MINGW32__
|
|
513 #include <sys/ioctl.h>
|
|
514 +#endif
|
|
515 #include <sys/types.h>
|
|
516 #include <sys/stat.h>
|
|
517 #include <unistd.h>
|
|
518 @@ -93,6 +98,32 @@
|
|
519 uint16_t Partition;
|
|
520 };
|
|
521
|
|
522 +struct extent_ad {
|
|
523 + uint32_t location;
|
|
524 + uint32_t length;
|
|
525 +};
|
|
526 +
|
|
527 +struct avdp_t {
|
|
528 + struct extent_ad mvds;
|
|
529 + struct extent_ad rvds;
|
|
530 +};
|
|
531 +
|
|
532 +struct pvd_t {
|
|
533 + uint8_t VolumeIdentifier[32];
|
|
534 + uint8_t VolumeSetIdentifier[128];
|
|
535 +};
|
|
536 +
|
|
537 +struct lbudf {
|
|
538 + uint32_t lb;
|
|
539 + uint8_t *data;
|
|
540 +};
|
|
541 +
|
|
542 +struct icbmap {
|
|
543 + uint32_t lbn;
|
|
544 + struct AD file;
|
|
545 + uint8_t filetype;
|
|
546 +};
|
|
547 +
|
|
548 /* For direct data access, LSB first */
|
|
549 #define GETN1(p) ((uint8_t)data[p])
|
|
550 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8))
|
|
551 @@ -334,6 +365,67 @@
|
|
552 return 0;
|
|
553 }
|
|
554
|
|
555 +
|
|
556 +static int UDFGetAVDP( dvd_reader_t *device,
|
|
557 + struct avdp_t *avdp)
|
|
558 +{
|
|
559 + uint8_t Anchor[ DVD_VIDEO_LB_LEN ];
|
|
560 + uint32_t lbnum, MVDS_location, MVDS_length;
|
|
561 + uint16_t TagID;
|
|
562 + uint32_t lastsector;
|
|
563 + int terminate;
|
|
564 + struct avdp_t;
|
|
565 +
|
|
566 + /* Find Anchor */
|
|
567 + lastsector = 0;
|
|
568 + lbnum = 256; /* Try #1, prime anchor */
|
|
569 + terminate = 0;
|
|
570 +
|
|
571 + for(;;) {
|
|
572 + if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) {
|
|
573 + UDFDescriptor( Anchor, &TagID );
|
|
574 + } else {
|
|
575 + TagID = 0;
|
|
576 + }
|
|
577 + if (TagID != 2) {
|
|
578 + /* Not an anchor */
|
|
579 + if( terminate ) return 0; /* Final try failed */
|
|
580 +
|
|
581 + if( lastsector ) {
|
|
582 +
|
|
583 + /* We already found the last sector. Try #3, alternative
|
|
584 + * backup anchor. If that fails, don't try again.
|
|
585 + */
|
|
586 + lbnum = lastsector;
|
|
587 + terminate = 1;
|
|
588 + } else {
|
|
589 + /* TODO: Find last sector of the disc (this is optional). */
|
|
590 + if( lastsector ) {
|
|
591 + /* Try #2, backup anchor */
|
|
592 + lbnum = lastsector - 256;
|
|
593 + } else {
|
|
594 + /* Unable to find last sector */
|
|
595 + return 0;
|
|
596 + }
|
|
597 + }
|
|
598 + } else {
|
|
599 + /* It's an anchor! We can leave */
|
|
600 + break;
|
|
601 + }
|
|
602 + }
|
|
603 + /* Main volume descriptor */
|
|
604 + UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location );
|
|
605 + avdp->mvds.location = MVDS_location;
|
|
606 + avdp->mvds.length = MVDS_length;
|
|
607 +
|
|
608 + /* Backup volume descriptor */
|
|
609 + UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location );
|
|
610 + avdp->rvds.location = MVDS_location;
|
|
611 + avdp->rvds.length = MVDS_length;
|
|
612 +
|
|
613 + return 1;
|
|
614 +}
|
|
615 +
|
|
616 /**
|
|
617 * Looks for partition on the disc. Returns 1 if partition found, 0 on error.
|
|
618 * partnum: Number of the partition, starting at 0.
|
|
619 @@ -342,52 +434,21 @@
|
|
620 static int UDFFindPartition( dvd_reader_t *device, int partnum,
|
|
621 struct Partition *part )
|
|
622 {
|
|
623 - uint8_t LogBlock[ DVD_VIDEO_LB_LEN ], Anchor[ DVD_VIDEO_LB_LEN ];
|
|
624 + uint8_t LogBlock[ DVD_VIDEO_LB_LEN ];
|
|
625 uint32_t lbnum, MVDS_location, MVDS_length;
|
|
626 uint16_t TagID;
|
|
627 - uint32_t lastsector;
|
|
628 - int i, terminate, volvalid;
|
|
629 + int i, volvalid;
|
|
630 + struct avdp_t avdp;
|
|
631
|
|
632 - /* Find Anchor */
|
|
633 - lastsector = 0;
|
|
634 - lbnum = 256; /* Try #1, prime anchor */
|
|
635 - terminate = 0;
|
|
636 -
|
|
637 - for(;;) {
|
|
638 - if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) {
|
|
639 - UDFDescriptor( Anchor, &TagID );
|
|
640 - } else {
|
|
641 - TagID = 0;
|
|
642 - }
|
|
643 - if (TagID != 2) {
|
|
644 - /* Not an anchor */
|
|
645 - if( terminate ) return 0; /* Final try failed */
|
|
646 -
|
|
647 - if( lastsector ) {
|
|
648 -
|
|
649 - /* We already found the last sector. Try #3, alternative
|
|
650 - * backup anchor. If that fails, don't try again.
|
|
651 - */
|
|
652 - lbnum = lastsector;
|
|
653 - terminate = 1;
|
|
654 - } else {
|
|
655 - /* TODO: Find last sector of the disc (this is optional). */
|
|
656 - if( lastsector ) {
|
|
657 - /* Try #2, backup anchor */
|
|
658 - lbnum = lastsector - 256;
|
|
659 - } else {
|
|
660 - /* Unable to find last sector */
|
|
661 - return 0;
|
|
662 - }
|
|
663 - }
|
|
664 - } else {
|
|
665 - /* It's an anchor! We can leave */
|
|
666 - break;
|
|
667 - }
|
|
668 +
|
|
669 + if(!UDFGetAVDP(device, &avdp)) {
|
|
670 + return 0;
|
|
671 }
|
|
672 +
|
|
673 /* Main volume descriptor */
|
|
674 - UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location );
|
|
675 -
|
|
676 + MVDS_location = avdp.mvds.location;
|
|
677 + MVDS_length = avdp.mvds.length;
|
|
678 +
|
|
679 part->valid = 0;
|
|
680 volvalid = 0;
|
|
681 part->VolumeDesc[ 0 ] = '\0';
|
|
682 @@ -422,8 +483,9 @@
|
|
683 && ( ( !part->valid ) || ( !volvalid ) ) );
|
|
684
|
|
685 if( ( !part->valid) || ( !volvalid ) ) {
|
|
686 - /* Backup volume descriptor */
|
|
687 - UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location );
|
|
688 + /* Backup volume descriptor */
|
|
689 + MVDS_location = avdp.mvds.location;
|
|
690 + MVDS_length = avdp.mvds.length;
|
|
691 }
|
|
692 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) );
|
|
693
|
|
694 @@ -442,17 +504,18 @@
|
|
695 char tokenline[ MAX_UDF_FILE_NAME_LEN ];
|
|
696 char *token;
|
|
697 uint8_t filetype;
|
|
698 -
|
|
699 +
|
|
700 *filesize = 0;
|
|
701 tokenline[0] = '\0';
|
|
702 strcat( tokenline, filename );
|
|
703
|
|
704 - /* Find partition, 0 is the standard location for DVD Video.*/
|
|
705 - if( !UDFFindPartition( device, 0, &partition ) ) return 0;
|
|
706 -
|
|
707 - /* Find root dir ICB */
|
|
708 - lbnum = partition.Start;
|
|
709 - do {
|
|
710 +
|
|
711 + /* Find partition, 0 is the standard location for DVD Video.*/
|
|
712 + if( !UDFFindPartition( device, 0, &partition ) ) return 0;
|
|
713 +
|
|
714 + /* Find root dir ICB */
|
|
715 + lbnum = partition.Start;
|
|
716 + do {
|
|
717 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) {
|
|
718 TagID = 0;
|
|
719 } else {
|
|
720 @@ -469,19 +532,27 @@
|
|
721 /* Sanity checks. */
|
|
722 if( TagID != 256 ) return 0;
|
|
723 if( RootICB.Partition != 0 ) return 0;
|
|
724 -
|
|
725 +
|
|
726 /* Find root dir */
|
|
727 if( !UDFMapICB( device, RootICB, &filetype, &partition, &File ) ) return 0;
|
|
728 if( filetype != 4 ) return 0; /* Root dir should be dir */
|
|
729
|
|
730 - /* Tokenize filepath */
|
|
731 - token = strtok(tokenline, "/");
|
|
732 - while( token != NULL ) {
|
|
733 - if( !UDFScanDir( device, File, token, &partition, &ICB ) ) return 0;
|
|
734 - if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) return 0;
|
|
735 + {
|
|
736 + /* Tokenize filepath */
|
|
737 + token = strtok(tokenline, "/");
|
|
738 +
|
|
739 + while( token != NULL ) {
|
|
740 +
|
|
741 + if( !UDFScanDir( device, File, token, &partition, &ICB)) {
|
|
742 + return 0;
|
|
743 + }
|
|
744 + if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) {
|
|
745 + return 0;
|
|
746 + }
|
|
747 token = strtok( NULL, "/" );
|
|
748 - }
|
|
749 -
|
|
750 + }
|
|
751 + }
|
|
752 +
|
|
753 /* Sanity check. */
|
|
754 if( File.Partition != 0 ) return 0;
|
|
755
|
|
756 @@ -492,3 +563,81 @@
|
|
757 else
|
|
758 return partition.Start + File.Location;
|
|
759 }
|
|
760 +
|
|
761 +
|
|
762 +
|
|
763 +/**
|
|
764 + * Gets a Descriptor .
|
|
765 + * Returns 1 if descriptor found, 0 on error.
|
|
766 + * id, tagid of descriptor
|
|
767 + * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN).
|
|
768 + */
|
|
769 +static int UDFGetDescriptor( dvd_reader_t *device, int id,
|
|
770 + uint8_t *descriptor, int bufsize)
|
|
771 +{
|
|
772 + uint32_t lbnum, MVDS_location, MVDS_length;
|
|
773 + struct avdp_t avdp;
|
|
774 + uint16_t TagID;
|
|
775 + uint32_t lastsector;
|
|
776 + int i, terminate;
|
|
777 + int desc_found = 0;
|
|
778 + /* Find Anchor */
|
|
779 + lastsector = 0;
|
|
780 + lbnum = 256; /* Try #1, prime anchor */
|
|
781 + terminate = 0;
|
|
782 + if(bufsize < DVD_VIDEO_LB_LEN) {
|
|
783 + return 0;
|
|
784 + }
|
|
785 +
|
|
786 + if(!UDFGetAVDP(device, &avdp)) {
|
|
787 + return 0;
|
|
788 + }
|
|
789 +
|
|
790 + /* Main volume descriptor */
|
|
791 + MVDS_location = avdp.mvds.location;
|
|
792 + MVDS_length = avdp.mvds.length;
|
|
793 +
|
|
794 + i = 1;
|
|
795 + do {
|
|
796 + /* Find Descriptor */
|
|
797 + lbnum = MVDS_location;
|
|
798 + do {
|
|
799 +
|
|
800 + if( DVDReadLBUDF( device, lbnum++, 1, descriptor, 0 ) <= 0 ) {
|
|
801 + TagID = 0;
|
|
802 + } else {
|
|
803 + UDFDescriptor( descriptor, &TagID );
|
|
804 + }
|
|
805 +
|
|
806 + if( (TagID == id) && ( !desc_found ) ) {
|
|
807 + /* Descriptor */
|
|
808 + desc_found = 1;
|
|
809 + }
|
|
810 + } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 )
|
|
811 + / DVD_VIDEO_LB_LEN ) && ( TagID != 8 )
|
|
812 + && ( !desc_found) );
|
|
813 +
|
|
814 + if( !desc_found ) {
|
|
815 + /* Backup volume descriptor */
|
|
816 + MVDS_location = avdp.rvds.location;
|
|
817 + MVDS_length = avdp.rvds.length;
|
|
818 + }
|
|
819 + } while( i-- && ( !desc_found ) );
|
|
820 +
|
|
821 + return desc_found;
|
|
822 +}
|
|
823 +
|
|
824 +
|
|
825 +static int UDFGetPVD(dvd_reader_t *device, struct pvd_t *pvd)
|
|
826 +{
|
|
827 + uint8_t pvd_buf[DVD_VIDEO_LB_LEN];
|
|
828 +
|
|
829 + if(!UDFGetDescriptor( device, 1, pvd_buf, sizeof(pvd_buf))) {
|
|
830 + return 0;
|
|
831 + }
|
|
832 +
|
|
833 + memcpy(pvd->VolumeIdentifier, &pvd_buf[24], 32);
|
|
834 + memcpy(pvd->VolumeSetIdentifier, &pvd_buf[72], 128);
|
|
835 +
|
|
836 + return 1;
|
|
837 +}
|
|
838 --- dvdread/ifo_print.c 2002-05-15 21:35:54.000000000 +0200
|
|
839 +++ ifo_print.c 2005-03-01 07:07:46.000000000 +0100
|
|
840 @@ -23,7 +23,7 @@
|
|
841 #include <inttypes.h>
|
|
842 #include <string.h>
|
|
843 #include <ctype.h>
|
|
844 -#include <assert.h>
|
|
845 +//#include <assert.h>
|
|
846
|
|
847 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
848 #include "ifo_types.h"
|
|
849 --- dvdread/ifo_print.h 2002-04-07 19:52:01.000000000 +0200
|
|
850 +++ ifo_print.h 2005-03-01 07:07:46.000000000 +0100
|
|
851 @@ -20,8 +20,8 @@
|
|
852 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
853 */
|
|
854
|
|
855 -#include <dvdread/ifo_types.h>
|
|
856 -#include <dvdread/dvd_reader.h>
|
|
857 +#include "ifo_types.h"
|
|
858 +#include "dvd_reader.h"
|
|
859
|
|
860 #ifdef __cplusplus
|
|
861 extern "C" {
|
|
862 --- dvdread/ifo_read.c 2002-05-25 21:37:18.000000000 +0200
|
|
863 +++ ifo_read.c 2005-03-01 07:07:46.000000000 +0100
|
|
864 @@ -22,7 +22,7 @@
|
|
865 #include <unistd.h>
|
|
866 #include <inttypes.h>
|
|
867 #include <string.h>
|
|
868 -#include <assert.h>
|
|
869 +//#include <assert.h>
|
|
870
|
|
871 #include "dvd_reader.h"
|
|
872
|
|
873 --- dvdread/ifo_read.h 2002-04-07 19:52:01.000000000 +0200
|
|
874 +++ ifo_read.h 2005-03-01 07:07:46.000000000 +0100
|
|
875 @@ -20,8 +20,8 @@
|
|
876 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
877 */
|
|
878
|
|
879 -#include <dvdread/ifo_types.h>
|
|
880 -#include <dvdread/dvd_reader.h>
|
|
881 +#include "ifo_types.h"
|
|
882 +#include "dvd_reader.h"
|
|
883
|
|
884 #ifdef __cplusplus
|
|
885 extern "C" {
|
|
886 --- dvdread/ifo_types.h 2002-04-07 19:52:01.000000000 +0200
|
|
887 +++ ifo_types.h 2005-03-01 07:07:46.000000000 +0100
|
|
888 @@ -21,7 +21,7 @@
|
|
889 */
|
|
890
|
|
891 #include <inttypes.h>
|
|
892 -#include <dvdread/dvd_reader.h>
|
|
893 +#include "dvd_reader.h"
|
|
894
|
|
895
|
|
896 #undef ATTRIBUTE_PACKED
|
|
897 --- dvdread/nav_print.c 2002-04-07 19:18:06.000000000 +0200
|
|
898 +++ nav_print.c 2005-03-01 07:07:46.000000000 +0100
|
|
899 @@ -25,7 +25,7 @@
|
|
900
|
|
901 #include <stdio.h>
|
|
902 #include <inttypes.h>
|
|
903 -#include <assert.h>
|
|
904 +//#include <assert.h>
|
|
905
|
|
906 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
907 #include "nav_types.h"
|
|
908 --- dvdread/nav_print.h 2002-04-07 20:17:19.000000000 +0200
|
|
909 +++ nav_print.h 2005-03-01 07:07:46.000000000 +0100
|
|
910 @@ -20,7 +20,7 @@
|
|
911 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
912 */
|
|
913
|
|
914 -#include <dvdread/nav_types.h>
|
|
915 +#include "nav_types.h"
|
|
916
|
|
917 #ifdef __cplusplus
|
|
918 extern "C" {
|
|
919 --- dvdread/nav_read.c 2002-04-07 19:52:01.000000000 +0200
|
|
920 +++ nav_read.c 2005-03-01 07:07:46.000000000 +0100
|
|
921 @@ -19,7 +19,7 @@
|
|
922 #include <stdio.h>
|
|
923 #include <string.h>
|
|
924 #include <inttypes.h>
|
|
925 -#include <assert.h>
|
|
926 +//#include <assert.h>
|
|
927
|
|
928 #include "config.h" // Needed for WORDS_BIGENDIAN
|
|
929 #include "bswap.h"
|
|
930 @@ -95,7 +95,9 @@
|
|
931 /* pci hli btnit */
|
|
932 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
|
|
933 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
|
|
934 +#ifdef HAVE_ASSERT_H
|
|
935 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
|
|
936 +#endif
|
|
937 assert(pci->hli.btnit[n].zero1 == 0);
|
|
938 assert(pci->hli.btnit[n].zero2 == 0);
|
|
939 assert(pci->hli.btnit[n].zero3 == 0);
|
|
940 --- dvdread/nav_read.h 2002-04-07 20:17:19.000000000 +0200
|
|
941 +++ nav_read.h 2005-03-01 07:07:46.000000000 +0100
|
|
942 @@ -19,7 +19,7 @@
|
|
943 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
944 */
|
|
945
|
|
946 -#include <dvdread/nav_types.h>
|
|
947 +#include "nav_types.h"
|
|
948
|
|
949 #ifdef __cplusplus
|
|
950 extern "C" {
|
|
951 --- dvdread/nav_types.h 2002-04-07 20:41:59.000000000 +0200
|
|
952 +++ nav_types.h 2005-03-01 07:07:46.000000000 +0100
|
|
953 @@ -30,7 +30,7 @@
|
|
954 */
|
|
955
|
|
956 #include <inttypes.h>
|
|
957 -#include <dvdread/ifo_types.h> // only dvd_time_t, vm_cmd_t and user_ops_t
|
|
958 +#include "ifo_types.h" // only dvd_time_t, vm_cmd_t and user_ops_t
|
|
959
|
|
960
|
|
961 #undef ATTRIBUTE_PACKED
|