Mercurial > mplayer.hg
annotate libmpdvdkit2/dvd_reader.c @ 16317:458c83408fd7
How to build MPlayerOSX
author | gpoirier |
---|---|
date | Tue, 30 Aug 2005 16:32:45 +0000 |
parents | 483e955893b8 |
children | 881e136ebf1a |
rev | line source |
---|---|
7029 | 1 /* |
15874 | 2 * Copyright (C) 2001, 2002, 2003 Billy Biggs <vektor@dumbterm.net>, |
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>, | |
4 * Björn Englund <d4bjorn@dtek.chalmers.se> | |
7029 | 5 * |
14938
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
6 * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
7 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
8 * $Id$ |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
9 * |
7029 | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or (at | |
13 * your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, but | |
16 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
23 */ | |
24 | |
7033 | 25 #include "config.h" |
26 | |
7029 | 27 #include <sys/types.h> |
28 #include <sys/stat.h> | |
29 #include <sys/time.h> /* For the timing of dvdcss_title crack. */ | |
30 #include <fcntl.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <errno.h> | |
34 #include <string.h> | |
35 #include <unistd.h> | |
36 #include <limits.h> | |
37 #include <dirent.h> | |
38 | |
15566 | 39 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__)|| defined(__DARWIN__) || defined(__DragonFly__) |
7029 | 40 #define SYS_BSD 1 |
41 #endif | |
42 | |
43 #if defined(__sun) | |
44 #include <sys/mnttab.h> | |
7423
ad967766679a
hpux DVD support fixes by Martin Gansser <mgansser@ngi.de>
arpi
parents:
7358
diff
changeset
|
45 #elif defined(hpux) |
ad967766679a
hpux DVD support fixes by Martin Gansser <mgansser@ngi.de>
arpi
parents:
7358
diff
changeset
|
46 #include </usr/conf/h/mnttab.h> |
7029 | 47 #elif defined(SYS_BSD) |
48 #include <fstab.h> | |
15534 | 49 #elif defined(__linux__) || defined(__CYGWIN__) |
7029 | 50 #include <mntent.h> |
51 #endif | |
52 | |
10825 | 53 #ifdef __MINGW32__ |
54 #include <sys/timeb.h> | |
55 static void gettimeofday(struct timeval* t,void* timezone){ | |
56 struct timeb timebuffer; | |
57 ftime( &timebuffer ); | |
58 t->tv_sec=timebuffer.time; | |
59 t->tv_usec=1000*timebuffer.millitm; | |
60 } | |
61 #endif | |
62 | |
7029 | 63 #include "dvd_udf.h" |
64 #include "dvd_input.h" | |
65 #include "dvd_reader.h" | |
15874 | 66 #include "md5.h" |
67 | |
68 #define DEFAULT_UDF_CACHE_LEVEL 0 | |
7029 | 69 |
70 struct dvd_reader_s { | |
71 /* Basic information. */ | |
72 int isImageFile; | |
73 | |
74 /* Hack for keeping track of the css status. | |
75 * 0: no css, 1: perhaps (need init of keys), 2: have done init */ | |
76 int css_state; | |
15874 | 77 int css_title; /* Last title that we have called dvdinpute_title for. */ |
7029 | 78 |
79 /* Information required for an image file. */ | |
80 dvd_input_t dev; | |
81 | |
82 /* Information required for a directory path drive. */ | |
83 char *path_root; | |
15874 | 84 |
85 /* Filesystem cache */ | |
86 int udfcache_level; /* 0 - turned off, 1 - on */ | |
87 void *udfcache; | |
7029 | 88 }; |
89 | |
90 struct dvd_file_s { | |
91 /* Basic information. */ | |
92 dvd_reader_t *dvd; | |
93 | |
94 /* Hack for selecting the right css title. */ | |
95 int css_title; | |
96 | |
97 /* Information required for an image file. */ | |
98 uint32_t lb_start; | |
99 uint32_t seek_pos; | |
100 | |
101 /* Information required for a directory path drive. */ | |
102 size_t title_sizes[ 9 ]; | |
103 dvd_input_t title_devs[ 9 ]; | |
104 | |
105 /* Calculated at open-time, size in blocks. */ | |
106 ssize_t filesize; | |
107 }; | |
108 | |
15874 | 109 /** |
110 * Set the level of caching on udf | |
111 * level = 0 (no caching) | |
112 * level = 1 (caching filesystem info) | |
113 */ | |
114 int DVDUDFCacheLevel(dvd_reader_t *device, int level) | |
115 { | |
116 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
117 | |
118 if(level > 0) { | |
119 level = 1; | |
120 } else if(level < 0) { | |
121 return dev->udfcache_level; | |
122 } | |
123 | |
124 dev->udfcache_level = level; | |
125 | |
126 return level; | |
127 } | |
128 | |
129 void *GetUDFCacheHandle(dvd_reader_t *device) | |
130 { | |
131 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
132 | |
133 return dev->udfcache; | |
134 } | |
135 | |
136 void SetUDFCacheHandle(dvd_reader_t *device, void *cache) | |
137 { | |
138 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
139 | |
140 dev->udfcache = cache; | |
141 } | |
142 | |
143 | |
144 | |
7029 | 145 /* Loop over all titles and call dvdcss_title to crack the keys. */ |
146 static int initAllCSSKeys( dvd_reader_t *dvd ) | |
147 { | |
148 struct timeval all_s, all_e; | |
149 struct timeval t_s, t_e; | |
150 char filename[ MAX_UDF_FILE_NAME_LEN ]; | |
151 uint32_t start, len; | |
152 int title; | |
153 | |
15874 | 154 char *nokeys_str = getenv("DVDREAD_NOKEYS"); |
155 if(nokeys_str != NULL) | |
156 return 0; | |
157 | |
7029 | 158 fprintf( stderr, "\n" ); |
159 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" ); | |
160 fprintf( stderr, "libdvdread: This can take a _long_ time, " | |
161 "please be patient\n\n" ); | |
162 | |
163 gettimeofday(&all_s, NULL); | |
164 | |
165 for( title = 0; title < 100; title++ ) { | |
166 gettimeofday( &t_s, NULL ); | |
167 if( title == 0 ) { | |
168 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" ); | |
169 } else { | |
170 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 ); | |
171 } | |
172 start = UDFFindFile( dvd, filename, &len ); | |
173 if( start != 0 && len != 0 ) { | |
174 /* Perform CSS key cracking for this title. */ | |
175 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", | |
176 filename, start ); | |
15874 | 177 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { |
7029 | 178 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start); |
179 } | |
180 gettimeofday( &t_e, NULL ); | |
181 fprintf( stderr, "libdvdread: Elapsed time %ld\n", | |
182 (long int) t_e.tv_sec - t_s.tv_sec ); | |
183 } | |
184 | |
185 if( title == 0 ) continue; | |
186 | |
187 gettimeofday( &t_s, NULL ); | |
188 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 ); | |
189 start = UDFFindFile( dvd, filename, &len ); | |
190 if( start == 0 || len == 0 ) break; | |
191 | |
192 /* Perform CSS key cracking for this title. */ | |
193 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", | |
194 filename, start ); | |
15874 | 195 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { |
7029 | 196 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start); |
197 } | |
198 gettimeofday( &t_e, NULL ); | |
199 fprintf( stderr, "libdvdread: Elapsed time %ld\n", | |
200 (long int) t_e.tv_sec - t_s.tv_sec ); | |
201 } | |
202 title--; | |
203 | |
204 fprintf( stderr, "libdvdread: Found %d VTS's\n", title ); | |
205 gettimeofday(&all_e, NULL); | |
206 fprintf( stderr, "libdvdread: Elapsed time %ld\n", | |
207 (long int) all_e.tv_sec - all_s.tv_sec ); | |
208 | |
209 return 0; | |
210 } | |
211 | |
212 | |
7033 | 213 #ifndef HAVE_MPLAYER |
214 #include "get_path.c" | |
215 #else | |
216 extern char * get_path( char * filename ); | |
217 #endif | |
218 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8881
diff
changeset
|
219 //extern char * dvdcss_cache_dir; |
7029 | 220 |
221 /** | |
222 * Open a DVD image or block device file. | |
223 */ | |
224 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) | |
225 { | |
226 dvd_reader_t *dvd; | |
227 dvd_input_t dev; | |
228 | |
15874 | 229 dev = dvdinput_open( location ); |
7029 | 230 if( !dev ) { |
231 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location ); | |
232 return 0; | |
233 } | |
234 | |
235 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); | |
236 if( !dvd ) return 0; | |
237 dvd->isImageFile = 1; | |
238 dvd->dev = dev; | |
239 dvd->path_root = 0; | |
240 | |
15874 | 241 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; |
242 dvd->udfcache = NULL; | |
243 | |
7029 | 244 if( have_css ) { |
245 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if | |
246 * DVDCSS_METHOD = key but region missmatch. Unfortunaly we | |
247 * don't have that information. */ | |
248 | |
249 dvd->css_state = 1; /* Need key init. */ | |
250 } | |
15874 | 251 dvd->css_title = 0; |
7029 | 252 |
253 return dvd; | |
254 } | |
255 | |
256 static dvd_reader_t *DVDOpenPath( const char *path_root ) | |
257 { | |
258 dvd_reader_t *dvd; | |
259 | |
260 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); | |
261 if( !dvd ) return 0; | |
262 dvd->isImageFile = 0; | |
263 dvd->dev = 0; | |
264 dvd->path_root = strdup( path_root ); | |
265 | |
15874 | 266 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; |
267 dvd->udfcache = NULL; | |
268 | |
269 dvd->css_state = 0; /* Only used in the UDF path */ | |
270 dvd->css_title = 0; /* Only matters in the UDF path */ | |
271 | |
7029 | 272 return dvd; |
273 } | |
274 | |
275 #if defined(__sun) | |
276 /* /dev/rdsk/c0t6d0s0 (link to /devices/...) | |
277 /vol/dev/rdsk/c0t6d0/?? | |
278 /vol/rdsk/<name> */ | |
279 static char *sun_block2char( const char *path ) | |
280 { | |
281 char *new_path; | |
282 | |
283 /* Must contain "/dsk/" */ | |
284 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path ); | |
285 | |
286 /* Replace "/dsk/" with "/rdsk/" */ | |
287 new_path = malloc( strlen(path) + 2 ); | |
288 strcpy( new_path, path ); | |
289 strcpy( strstr( new_path, "/dsk/" ), "" ); | |
290 strcat( new_path, "/rdsk/" ); | |
291 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) ); | |
292 | |
293 return new_path; | |
294 } | |
295 #endif | |
296 | |
297 #if defined(SYS_BSD) | |
298 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r | |
299 OpenBSD /dev/rcd0c, it needs to be the raw device | |
300 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others | |
301 Darwin /dev/rdisk0, it needs to be the raw device | |
302 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */ | |
303 static char *bsd_block2char( const char *path ) | |
304 { | |
305 char *new_path; | |
306 | |
307 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */ | |
10511 | 308 if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) ) |
7029 | 309 return (char *) strdup( path ); |
310 | |
311 /* Replace "/dev/" with "/dev/r" */ | |
312 new_path = malloc( strlen(path) + 2 ); | |
313 strcpy( new_path, "/dev/r" ); | |
314 strcat( new_path, path + strlen( "/dev/" ) ); | |
315 | |
316 return new_path; | |
317 } | |
318 #endif | |
319 | |
320 dvd_reader_t *DVDOpen( const char *path ) | |
321 { | |
322 struct stat fileinfo; | |
323 int ret, have_css; | |
324 char *dev_name = 0; | |
325 | |
15874 | 326 if( path == NULL ) |
327 return 0; | |
7029 | 328 |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
329 #ifdef WIN32 |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
330 /* Stat doesn't work on devices under mingwin/cygwin. */ |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
331 if( path[0] && path[1] == ':' && path[2] == '\0' ) |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
332 { |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
333 /* Don't try to stat the file */ |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
334 fileinfo.st_mode = S_IFBLK; |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
335 } |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
336 else |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
337 #endif |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
338 { |
7029 | 339 ret = stat( path, &fileinfo ); |
340 if( ret < 0 ) { | |
341 /* If we can't stat the file, give up */ | |
342 fprintf( stderr, "libdvdread: Can't stat %s\n", path ); | |
343 perror(""); | |
344 return 0; | |
345 } | |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
346 } |
7029 | 347 |
348 /* Try to open libdvdcss or fall back to standard functions */ | |
15874 | 349 have_css = dvdinput_setup(); |
7029 | 350 |
351 /* First check if this is a block/char device or a file*/ | |
352 if( S_ISBLK( fileinfo.st_mode ) || | |
353 S_ISCHR( fileinfo.st_mode ) || | |
354 S_ISREG( fileinfo.st_mode ) ) { | |
355 | |
356 /** | |
357 * Block devices and regular files are assumed to be DVD-Video images. | |
358 */ | |
359 #if defined(__sun) | |
360 return DVDOpenImageFile( sun_block2char( path ), have_css ); | |
361 #elif defined(SYS_BSD) | |
362 return DVDOpenImageFile( bsd_block2char( path ), have_css ); | |
363 #else | |
364 return DVDOpenImageFile( path, have_css ); | |
365 #endif | |
366 | |
367 } else if( S_ISDIR( fileinfo.st_mode ) ) { | |
368 dvd_reader_t *auth_drive = 0; | |
369 char *path_copy; | |
370 #if defined(SYS_BSD) | |
371 struct fstab* fe; | |
15534 | 372 #elif defined(__sun) || defined(__linux__) || defined(__CYGWIN__) |
7029 | 373 FILE *mntfile; |
374 #endif | |
375 | |
376 /* XXX: We should scream real loud here. */ | |
377 if( !(path_copy = strdup( path ) ) ) return 0; | |
378 | |
379 /* Resolve any symlinks and get the absolut dir name. */ | |
380 { | |
381 char *new_path; | |
382 int cdir = open( ".", O_RDONLY ); | |
383 | |
384 if( cdir >= 0 ) { | |
385 chdir( path_copy ); | |
386 new_path = getcwd( NULL, PATH_MAX ); | |
10443 | 387 #ifndef __MINGW32__ |
7029 | 388 fchdir( cdir ); |
10443 | 389 #endif |
7029 | 390 close( cdir ); |
391 if( new_path ) { | |
392 free( path_copy ); | |
393 path_copy = new_path; | |
394 } | |
395 } | |
396 } | |
397 | |
398 /** | |
399 * If we're being asked to open a directory, check if that directory | |
400 * is the mountpoint for a DVD-ROM which we can use instead. | |
401 */ | |
402 | |
403 if( strlen( path_copy ) > 1 ) { | |
404 if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) | |
405 path_copy[ strlen( path_copy ) - 1 ] = '\0'; | |
406 } | |
407 | |
408 if( strlen( path_copy ) > 9 ) { | |
409 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]), | |
410 "/video_ts" ) ) { | |
411 path_copy[ strlen( path_copy ) - 9 ] = '\0'; | |
412 } | |
413 } | |
414 | |
415 #if defined(SYS_BSD) | |
416 if( ( fe = getfsfile( path_copy ) ) ) { | |
417 dev_name = bsd_block2char( fe->fs_spec ); | |
418 fprintf( stderr, | |
419 "libdvdread: Attempting to use device %s" | |
420 " mounted on %s for CSS authentication\n", | |
421 dev_name, | |
422 fe->fs_file ); | |
423 auth_drive = DVDOpenImageFile( dev_name, have_css ); | |
424 } | |
425 #elif defined(__sun) | |
426 mntfile = fopen( MNTTAB, "r" ); | |
427 if( mntfile ) { | |
428 struct mnttab mp; | |
429 int res; | |
430 | |
431 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) { | |
432 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) { | |
433 dev_name = sun_block2char( mp.mnt_special ); | |
434 fprintf( stderr, | |
435 "libdvdread: Attempting to use device %s" | |
436 " mounted on %s for CSS authentication\n", | |
437 dev_name, | |
438 mp.mnt_mountp ); | |
439 auth_drive = DVDOpenImageFile( dev_name, have_css ); | |
440 break; | |
441 } | |
442 } | |
443 fclose( mntfile ); | |
444 } | |
15534 | 445 #elif defined(__linux__) || defined(__CYGWIN__) |
7029 | 446 mntfile = fopen( MOUNTED, "r" ); |
447 if( mntfile ) { | |
448 struct mntent *me; | |
449 | |
450 while( ( me = getmntent( mntfile ) ) ) { | |
451 if( !strcmp( me->mnt_dir, path_copy ) ) { | |
452 fprintf( stderr, | |
453 "libdvdread: Attempting to use device %s" | |
454 " mounted on %s for CSS authentication\n", | |
455 me->mnt_fsname, | |
456 me->mnt_dir ); | |
457 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css ); | |
458 dev_name = strdup(me->mnt_fsname); | |
459 break; | |
460 } | |
461 } | |
462 fclose( mntfile ); | |
463 } | |
15534 | 464 #elif defined(__MINGW32__) |
7033 | 465 dev_name = strdup(path); |
466 auth_drive = DVDOpenImageFile( path, have_css ); | |
7029 | 467 #endif |
468 if( !dev_name ) { | |
469 fprintf( stderr, "libdvdread: Couldn't find device name.\n" ); | |
470 } else if( !auth_drive ) { | |
471 fprintf( stderr, "libdvdread: Device %s inaccessible, " | |
472 "CSS authentication not available.\n", dev_name ); | |
473 } | |
474 | |
475 free( dev_name ); | |
476 free( path_copy ); | |
477 | |
478 /** | |
479 * If we've opened a drive, just use that. | |
480 */ | |
481 if( auth_drive ) return auth_drive; | |
482 | |
483 /** | |
484 * Otherwise, we now try to open the directory tree instead. | |
485 */ | |
486 return DVDOpenPath( path ); | |
487 } | |
488 | |
489 /* If it's none of the above, screw it. */ | |
490 fprintf( stderr, "libdvdread: Could not open %s\n", path ); | |
491 return 0; | |
492 } | |
493 | |
494 void DVDClose( dvd_reader_t *dvd ) | |
495 { | |
496 if( dvd ) { | |
15874 | 497 if( dvd->dev ) dvdinput_close( dvd->dev ); |
7029 | 498 if( dvd->path_root ) free( dvd->path_root ); |
15874 | 499 if( dvd->udfcache ) FreeUDFCache( dvd->udfcache ); |
7029 | 500 free( dvd ); |
501 } | |
502 } | |
503 | |
504 /** | |
505 * Open an unencrypted file on a DVD image file. | |
506 */ | |
507 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename ) | |
508 { | |
509 uint32_t start, len; | |
510 dvd_file_t *dvd_file; | |
511 | |
512 start = UDFFindFile( dvd, filename, &len ); | |
513 if( !start ) return 0; | |
514 | |
515 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); | |
516 if( !dvd_file ) return 0; | |
517 dvd_file->dvd = dvd; | |
518 dvd_file->lb_start = start; | |
519 dvd_file->seek_pos = 0; | |
520 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); | |
521 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); | |
522 dvd_file->filesize = len / DVD_VIDEO_LB_LEN; | |
523 | |
524 return dvd_file; | |
525 } | |
526 | |
527 /** | |
528 * Searches for <file> in directory <path>, ignoring case. | |
529 * Returns 0 and full filename in <filename>. | |
530 * or -1 on file not found. | |
531 * or -2 on path not found. | |
532 */ | |
533 static int findDirFile( const char *path, const char *file, char *filename ) | |
534 { | |
535 DIR *dir; | |
536 struct dirent *ent; | |
537 | |
538 dir = opendir( path ); | |
539 if( !dir ) return -2; | |
540 | |
541 while( ( ent = readdir( dir ) ) != NULL ) { | |
542 if( !strcasecmp( ent->d_name, file ) ) { | |
543 sprintf( filename, "%s%s%s", path, | |
544 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ), | |
545 ent->d_name ); | |
546 return 0; | |
547 } | |
548 } | |
549 | |
550 return -1; | |
551 } | |
552 | |
553 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename ) | |
554 { | |
555 char video_path[ PATH_MAX + 1 ]; | |
556 const char *nodirfile; | |
557 int ret; | |
558 | |
559 /* Strip off the directory for our search */ | |
560 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) { | |
561 nodirfile = &(file[ 10 ]); | |
562 } else { | |
563 nodirfile = file; | |
564 } | |
565 | |
566 ret = findDirFile( dvd->path_root, nodirfile, filename ); | |
567 if( ret < 0 ) { | |
568 /* Try also with adding the path, just in case. */ | |
569 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root ); | |
570 ret = findDirFile( video_path, nodirfile, filename ); | |
571 if( ret < 0 ) { | |
572 /* Try with the path, but in lower case. */ | |
573 sprintf( video_path, "%s/video_ts/", dvd->path_root ); | |
574 ret = findDirFile( video_path, nodirfile, filename ); | |
575 if( ret < 0 ) { | |
576 return 0; | |
577 } | |
578 } | |
579 } | |
580 | |
581 return 1; | |
582 } | |
583 | |
584 /** | |
585 * Open an unencrypted file from a DVD directory tree. | |
586 */ | |
587 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ) | |
588 { | |
589 char full_path[ PATH_MAX + 1 ]; | |
590 dvd_file_t *dvd_file; | |
591 struct stat fileinfo; | |
592 dvd_input_t dev; | |
593 | |
594 /* Get the full path of the file. */ | |
595 if( !findDVDFile( dvd, filename, full_path ) ) return 0; | |
596 | |
15874 | 597 dev = dvdinput_open( full_path ); |
7029 | 598 if( !dev ) return 0; |
599 | |
600 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); | |
601 if( !dvd_file ) return 0; | |
602 dvd_file->dvd = dvd; | |
603 dvd_file->lb_start = 0; | |
604 dvd_file->seek_pos = 0; | |
605 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); | |
606 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); | |
607 dvd_file->filesize = 0; | |
608 | |
609 if( stat( full_path, &fileinfo ) < 0 ) { | |
610 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); | |
611 free( dvd_file ); | |
612 return 0; | |
613 } | |
614 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; | |
615 dvd_file->title_devs[ 0 ] = dev; | |
616 dvd_file->filesize = dvd_file->title_sizes[ 0 ]; | |
617 | |
618 return dvd_file; | |
619 } | |
620 | |
621 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu ) | |
622 { | |
623 char filename[ MAX_UDF_FILE_NAME_LEN ]; | |
624 uint32_t start, len; | |
625 dvd_file_t *dvd_file; | |
626 | |
627 if( title == 0 ) { | |
628 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" ); | |
629 } else { | |
630 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 ); | |
631 } | |
632 start = UDFFindFile( dvd, filename, &len ); | |
633 if( start == 0 ) return 0; | |
634 | |
635 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); | |
636 if( !dvd_file ) return 0; | |
637 dvd_file->dvd = dvd; | |
638 /*Hack*/ dvd_file->css_title = title << 1 | menu; | |
639 dvd_file->lb_start = start; | |
640 dvd_file->seek_pos = 0; | |
641 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); | |
642 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); | |
643 dvd_file->filesize = len / DVD_VIDEO_LB_LEN; | |
644 | |
645 /* Calculate the complete file size for every file in the VOBS */ | |
646 if( !menu ) { | |
647 int cur; | |
648 | |
649 for( cur = 2; cur < 10; cur++ ) { | |
650 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur ); | |
651 if( !UDFFindFile( dvd, filename, &len ) ) break; | |
652 dvd_file->filesize += len / DVD_VIDEO_LB_LEN; | |
653 } | |
654 } | |
655 | |
656 if( dvd->css_state == 1 /* Need key init */ ) { | |
7033 | 657 // initAllCSSKeys( dvd ); |
658 // dvd->css_state = 2; | |
7029 | 659 } |
660 /* | |
15874 | 661 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) { |
7029 | 662 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n", |
663 filename ); | |
664 } | |
665 */ | |
666 | |
667 return dvd_file; | |
668 } | |
669 | |
670 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) | |
671 { | |
672 char filename[ MAX_UDF_FILE_NAME_LEN ]; | |
673 char full_path[ PATH_MAX + 1 ]; | |
674 struct stat fileinfo; | |
675 dvd_file_t *dvd_file; | |
676 int i; | |
677 | |
678 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); | |
679 if( !dvd_file ) return 0; | |
680 dvd_file->dvd = dvd; | |
681 /*Hack*/ dvd_file->css_title = title << 1 | menu; | |
682 dvd_file->lb_start = 0; | |
683 dvd_file->seek_pos = 0; | |
684 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); | |
685 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); | |
686 dvd_file->filesize = 0; | |
15874 | 687 |
7029 | 688 if( menu ) { |
689 dvd_input_t dev; | |
690 | |
691 if( title == 0 ) { | |
692 sprintf( filename, "VIDEO_TS.VOB" ); | |
693 } else { | |
694 sprintf( filename, "VTS_%02i_0.VOB", title ); | |
695 } | |
696 if( !findDVDFile( dvd, filename, full_path ) ) { | |
697 free( dvd_file ); | |
698 return 0; | |
699 } | |
700 | |
15874 | 701 dev = dvdinput_open( full_path ); |
7029 | 702 if( dev == NULL ) { |
703 free( dvd_file ); | |
704 return 0; | |
705 } | |
706 | |
707 if( stat( full_path, &fileinfo ) < 0 ) { | |
708 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); | |
709 free( dvd_file ); | |
710 return 0; | |
711 } | |
712 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; | |
713 dvd_file->title_devs[ 0 ] = dev; | |
15874 | 714 dvdinput_title( dvd_file->title_devs[0], 0); |
7029 | 715 dvd_file->filesize = dvd_file->title_sizes[ 0 ]; |
716 | |
717 } else { | |
718 for( i = 0; i < 9; ++i ) { | |
719 | |
720 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 ); | |
721 if( !findDVDFile( dvd, filename, full_path ) ) { | |
722 break; | |
723 } | |
724 | |
725 if( stat( full_path, &fileinfo ) < 0 ) { | |
726 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); | |
727 break; | |
728 } | |
729 | |
730 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; | |
15874 | 731 dvd_file->title_devs[ i ] = dvdinput_open( full_path ); |
732 dvdinput_title( dvd_file->title_devs[ i ], 0 ); | |
7029 | 733 dvd_file->filesize += dvd_file->title_sizes[ i ]; |
734 } | |
8881
1e40d4a2466f
Function DVDOpenVOBPath only decrypts first VOB file and since each VOB file has
arpi
parents:
7423
diff
changeset
|
735 if( !dvd_file->title_devs[ 0 ] ) { |
7029 | 736 free( dvd_file ); |
737 return 0; | |
738 } | |
739 } | |
740 | |
741 return dvd_file; | |
742 } | |
743 | |
744 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum, | |
745 dvd_read_domain_t domain ) | |
746 { | |
747 char filename[ MAX_UDF_FILE_NAME_LEN ]; | |
15874 | 748 |
749 /* Check arguments. */ | |
750 if( dvd == NULL || titlenum < 0 ) | |
751 return NULL; | |
7029 | 752 |
753 switch( domain ) { | |
754 case DVD_READ_INFO_FILE: | |
755 if( titlenum == 0 ) { | |
756 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" ); | |
757 } else { | |
758 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum ); | |
759 } | |
760 break; | |
761 case DVD_READ_INFO_BACKUP_FILE: | |
762 if( titlenum == 0 ) { | |
763 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" ); | |
764 } else { | |
765 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum ); | |
766 } | |
767 break; | |
768 case DVD_READ_MENU_VOBS: | |
769 if( dvd->isImageFile ) { | |
770 return DVDOpenVOBUDF( dvd, titlenum, 1 ); | |
771 } else { | |
772 return DVDOpenVOBPath( dvd, titlenum, 1 ); | |
773 } | |
774 break; | |
775 case DVD_READ_TITLE_VOBS: | |
776 if( titlenum == 0 ) return 0; | |
777 if( dvd->isImageFile ) { | |
778 return DVDOpenVOBUDF( dvd, titlenum, 0 ); | |
779 } else { | |
780 return DVDOpenVOBPath( dvd, titlenum, 0 ); | |
781 } | |
782 break; | |
783 default: | |
784 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" ); | |
15874 | 785 return NULL; |
7029 | 786 } |
787 | |
788 if( dvd->isImageFile ) { | |
789 return DVDOpenFileUDF( dvd, filename ); | |
790 } else { | |
791 return DVDOpenFilePath( dvd, filename ); | |
792 } | |
793 } | |
794 | |
795 void DVDCloseFile( dvd_file_t *dvd_file ) | |
796 { | |
797 int i; | |
798 | |
799 if( dvd_file ) { | |
800 if( dvd_file->dvd->isImageFile ) { | |
801 ; | |
802 } else { | |
803 for( i = 0; i < 9; ++i ) { | |
804 if( dvd_file->title_devs[ i ] ) { | |
15874 | 805 dvdinput_close( dvd_file->title_devs[i] ); |
7029 | 806 } |
807 } | |
808 } | |
809 | |
810 free( dvd_file ); | |
811 dvd_file = 0; | |
812 } | |
813 } | |
814 | |
815 /* Internal, but used from dvd_udf.c */ | |
15874 | 816 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number, |
7029 | 817 size_t block_count, unsigned char *data, |
818 int encrypted ) | |
819 { | |
820 int ret; | |
821 | |
822 if( !device->dev ) { | |
823 fprintf( stderr, "libdvdread: Fatal error in block read.\n" ); | |
824 return 0; | |
825 } | |
826 | |
15874 | 827 ret = dvdinput_seek( device->dev, (int) lb_number ); |
7029 | 828 if( ret != (int) lb_number ) { |
829 fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number ); | |
830 return 0; | |
831 } | |
832 | |
15874 | 833 return dvdinput_read( device->dev, (char *) data, |
7029 | 834 (int) block_count, encrypted ); |
835 } | |
836 | |
837 /* This is using a single input and starting from 'dvd_file->lb_start' offset. | |
838 * | |
839 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset' | |
840 * into the buffer located at 'data' and if 'encrypted' is set | |
841 * descramble the data if it's encrypted. Returning either an | |
842 * negative error or the number of blocks read. */ | |
843 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset, | |
844 size_t block_count, unsigned char *data, | |
845 int encrypted ) | |
846 { | |
15874 | 847 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset, |
848 block_count, data, encrypted ); | |
7029 | 849 } |
850 | |
851 /* This is using possibly several inputs and starting from an offset of '0'. | |
852 * | |
853 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset' | |
854 * into the buffer located at 'data' and if 'encrypted' is set | |
855 * descramble the data if it's encrypted. Returning either an | |
856 * negative error or the number of blocks read. */ | |
857 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset, | |
858 size_t block_count, unsigned char *data, | |
859 int encrypted ) | |
860 { | |
861 int i; | |
862 int ret, ret2, off; | |
863 | |
864 ret = 0; | |
865 ret2 = 0; | |
866 for( i = 0; i < 9; ++i ) { | |
867 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */ | |
868 | |
869 if( offset < dvd_file->title_sizes[ i ] ) { | |
870 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) { | |
15874 | 871 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); |
7029 | 872 if( off < 0 || off != (int)offset ) { |
873 fprintf( stderr, "libdvdread: Can't seek to block %d\n", | |
874 offset ); | |
875 return off < 0 ? off : 0; | |
876 } | |
15874 | 877 ret = dvdinput_read( dvd_file->title_devs[ i ], data, |
7029 | 878 (int)block_count, encrypted ); |
879 break; | |
880 } else { | |
881 size_t part1_size = dvd_file->title_sizes[ i ] - offset; | |
882 /* FIXME: Really needs to be a while loop. | |
883 * (This is only true if you try and read >1GB at a time) */ | |
884 | |
885 /* Read part 1 */ | |
15874 | 886 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); |
7029 | 887 if( off < 0 || off != (int)offset ) { |
888 fprintf( stderr, "libdvdread: Can't seek to block %d\n", | |
889 offset ); | |
890 return off < 0 ? off : 0; | |
891 } | |
15874 | 892 ret = dvdinput_read( dvd_file->title_devs[ i ], data, |
7029 | 893 (int)part1_size, encrypted ); |
894 if( ret < 0 ) return ret; | |
895 /* FIXME: This is wrong if i is the last file in the set. | |
896 * also error from this read will not show in ret. */ | |
15874 | 897 |
898 /* Does the next part exist? If not then return now. */ | |
899 if( !dvd_file->title_devs[ i + 1 ] ) return ret; | |
7358
bb40478265df
I experienced several segfaults when trying to play (unencrypted) DVDs
arpi
parents:
7033
diff
changeset
|
900 |
7029 | 901 /* Read part 2 */ |
15874 | 902 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 ); |
7029 | 903 if( off < 0 || off != 0 ) { |
904 fprintf( stderr, "libdvdread: Can't seek to block %d\n", | |
905 0 ); | |
906 return off < 0 ? off : 0; | |
907 } | |
15874 | 908 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ], |
7029 | 909 data + ( part1_size |
910 * (int64_t)DVD_VIDEO_LB_LEN ), | |
911 (int)(block_count - part1_size), | |
912 encrypted ); | |
913 if( ret2 < 0 ) return ret2; | |
914 break; | |
915 } | |
916 } else { | |
917 offset -= dvd_file->title_sizes[ i ]; | |
918 } | |
919 } | |
920 | |
921 return ret + ret2; | |
922 } | |
923 | |
924 /* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */ | |
925 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset, | |
926 size_t block_count, unsigned char *data ) | |
927 { | |
928 int ret; | |
929 | |
15874 | 930 /* Check arguments. */ |
931 if( dvd_file == NULL || offset < 0 || data == NULL ) | |
932 return -1; | |
933 | |
7029 | 934 /* Hack, and it will still fail for multiple opens in a threaded app ! */ |
935 if( dvd_file->dvd->css_title != dvd_file->css_title ) { | |
936 dvd_file->dvd->css_title = dvd_file->css_title; | |
937 if( dvd_file->dvd->isImageFile ) { | |
15874 | 938 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start ); |
939 } | |
940 /* Here each vobu has it's own dvdcss handle, so no need to update | |
941 else { | |
942 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start ); | |
943 }*/ | |
7029 | 944 } |
945 | |
946 if( dvd_file->dvd->isImageFile ) { | |
947 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset, | |
948 block_count, data, DVDINPUT_READ_DECRYPT ); | |
949 } else { | |
950 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset, | |
951 block_count, data, DVDINPUT_READ_DECRYPT ); | |
952 } | |
953 | |
954 return (ssize_t)ret; | |
955 } | |
956 | |
10017
535a53c058f8
There are conflicting definitions for DVDFileSeek in the .c and .h file.
diego
parents:
9333
diff
changeset
|
957 int DVDFileSeek( dvd_file_t *dvd_file, int offset ) |
7029 | 958 { |
15874 | 959 /* Check arguments. */ |
960 if( dvd_file == NULL || offset < 0 ) | |
7029 | 961 return -1; |
15874 | 962 |
963 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) { | |
964 return -1; | |
965 } | |
966 dvd_file->seek_pos = (uint32_t) offset; | |
967 return offset; | |
7029 | 968 } |
969 | |
970 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size ) | |
971 { | |
972 unsigned char *secbuf; | |
973 unsigned int numsec, seek_sector, seek_byte; | |
974 int ret; | |
975 | |
15874 | 976 /* Check arguments. */ |
977 if( dvd_file == NULL || data == NULL ) | |
978 return -1; | |
979 | |
7029 | 980 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN; |
981 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN; | |
982 | |
15874 | 983 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) + |
984 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 ); | |
985 | |
7029 | 986 secbuf = (unsigned char *) malloc( numsec * DVD_VIDEO_LB_LEN ); |
987 if( !secbuf ) { | |
988 fprintf( stderr, "libdvdread: Can't allocate memory " | |
989 "for file read!\n" ); | |
990 return 0; | |
991 } | |
992 | |
993 if( dvd_file->dvd->isImageFile ) { | |
994 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector, | |
995 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS ); | |
996 } else { | |
997 ret = DVDReadBlocksPath( dvd_file, seek_sector, | |
998 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS ); | |
999 } | |
1000 | |
1001 if( ret != (int) numsec ) { | |
1002 free( secbuf ); | |
1003 return ret < 0 ? ret : 0; | |
1004 } | |
1005 | |
1006 memcpy( data, &(secbuf[ seek_byte ]), byte_size ); | |
1007 free( secbuf ); | |
1008 | |
1009 dvd_file->seek_pos += byte_size; | |
1010 return byte_size; | |
1011 } | |
1012 | |
1013 ssize_t DVDFileSize( dvd_file_t *dvd_file ) | |
1014 { | |
15874 | 1015 /* Check arguments. */ |
1016 if( dvd_file == NULL ) | |
1017 return -1; | |
1018 | |
7029 | 1019 return dvd_file->filesize; |
1020 } | |
15874 | 1021 |
1022 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid ) | |
1023 { | |
1024 struct md5_ctx ctx; | |
1025 int title; | |
1026 | |
1027 /* Check arguments. */ | |
1028 if( dvd == NULL || discid == NULL ) | |
1029 return 0; | |
1030 | |
1031 /* Go through the first 10 IFO:s, in order, | |
1032 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */ | |
1033 md5_init_ctx( &ctx ); | |
1034 for( title = 0; title < 10; title++ ) { | |
1035 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE ); | |
1036 if( dvd_file != NULL ) { | |
1037 ssize_t bytes_read; | |
1038 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN; | |
1039 char *buffer = malloc( file_size ); | |
1040 | |
1041 if( buffer == NULL ) { | |
1042 fprintf( stderr, "libdvdread: DVDDiscId, failed to " | |
1043 "allocate memory for file read!\n" ); | |
1044 return -1; | |
1045 } | |
1046 bytes_read = DVDReadBytes( dvd_file, buffer, file_size ); | |
1047 if( bytes_read != file_size ) { | |
1048 fprintf( stderr, "libdvdread: DVDDiscId read returned %d bytes" | |
1049 ", wanted %d\n", bytes_read, file_size ); | |
1050 DVDCloseFile( dvd_file ); | |
1051 return -1; | |
1052 } | |
1053 | |
1054 md5_process_bytes( buffer, file_size, &ctx ); | |
1055 | |
1056 DVDCloseFile( dvd_file ); | |
1057 free( buffer ); | |
1058 } | |
1059 } | |
1060 md5_finish_ctx( &ctx, discid ); | |
1061 | |
1062 return 0; | |
1063 } | |
1064 | |
1065 | |
1066 int DVDISOVolumeInfo( dvd_reader_t *dvd, | |
1067 char *volid, unsigned int volid_size, | |
1068 unsigned char *volsetid, unsigned int volsetid_size ) | |
1069 { | |
1070 unsigned char *buffer; | |
1071 int ret; | |
1072 | |
1073 /* Check arguments. */ | |
1074 if( dvd == NULL ) | |
1075 return 0; | |
1076 | |
1077 if( dvd->dev == NULL ) { | |
1078 /* No block access, so no ISO... */ | |
1079 return -1; | |
1080 } | |
1081 | |
1082 buffer = malloc( DVD_VIDEO_LB_LEN ); | |
1083 if( buffer == NULL ) { | |
1084 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to " | |
1085 "allocate memory for file read!\n" ); | |
1086 return -1; | |
1087 } | |
1088 | |
1089 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 ); | |
1090 if( ret != 1 ) { | |
1091 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to " | |
1092 "read ISO9660 Primary Volume Descriptor!\n" ); | |
1093 return -1; | |
1094 } | |
1095 | |
1096 if( (volid != NULL) && (volid_size > 0) ) { | |
1097 unsigned int n; | |
1098 for(n = 0; n < 32; n++) { | |
1099 if(buffer[40+n] == 0x20) { | |
1100 break; | |
1101 } | |
1102 } | |
1103 | |
1104 if(volid_size > n+1) { | |
1105 volid_size = n+1; | |
1106 } | |
1107 | |
1108 memcpy(volid, &buffer[40], volid_size-1); | |
1109 volid[volid_size-1] = '\0'; | |
1110 } | |
1111 | |
1112 if( (volsetid != NULL) && (volsetid_size > 0) ) { | |
1113 if(volsetid_size > 128) { | |
1114 volsetid_size = 128; | |
1115 } | |
1116 memcpy(volsetid, &buffer[190], volsetid_size); | |
1117 } | |
1118 return 0; | |
1119 } | |
1120 | |
1121 | |
1122 int DVDUDFVolumeInfo( dvd_reader_t *dvd, | |
1123 char *volid, unsigned int volid_size, | |
1124 unsigned char *volsetid, unsigned int volsetid_size ) | |
1125 { | |
1126 int ret; | |
1127 /* Check arguments. */ | |
1128 if( dvd == NULL ) | |
1129 return -1; | |
1130 | |
1131 if( dvd->dev == NULL ) { | |
1132 /* No block access, so no UDF VolumeSet Identifier */ | |
1133 return -1; | |
1134 } | |
1135 | |
1136 if( (volid != NULL) && (volid_size > 0) ) { | |
1137 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size); | |
1138 if(!ret) { | |
1139 return -1; | |
1140 } | |
1141 } | |
1142 if( (volsetid != NULL) && (volsetid_size > 0) ) { | |
1143 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size); | |
1144 if(!ret) { | |
1145 return -1; | |
1146 } | |
1147 } | |
1148 | |
1149 return 0; | |
1150 } |