diff options
author | aurel <aurel@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2005-06-30 22:48:26 +0000 |
---|---|---|
committer | aurel <aurel@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2005-06-30 22:48:26 +0000 |
commit | eb3c1b5cedfc1b7d35a2d261780979b00170946e (patch) | |
tree | ccc33eb81679684b7f2ca3d7c610d721375c4ea5 /libmpdvdkit2 | |
parent | c8fbf4405d7b433f0dc622bc9dcf81d0ceb5ef36 (diff) | |
download | mpv-eb3c1b5cedfc1b7d35a2d261780979b00170946e.tar.bz2 mpv-eb3c1b5cedfc1b7d35a2d261780979b00170946e.tar.xz |
update libdvdread to v0.9.4
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15875 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdvdkit2')
-rw-r--r-- | libmpdvdkit2/Makefile | 4 | ||||
-rw-r--r-- | libmpdvdkit2/README | 6 | ||||
-rw-r--r-- | libmpdvdkit2/bswap.h | 26 | ||||
-rw-r--r-- | libmpdvdkit2/config.h | 2 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_input.c | 257 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_input.h | 24 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_reader.c | 311 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_reader.h | 208 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_udf.c | 369 | ||||
-rw-r--r-- | libmpdvdkit2/dvd_udf.h | 8 | ||||
-rw-r--r-- | libmpdvdkit2/ifo_print.c | 245 | ||||
-rw-r--r-- | libmpdvdkit2/ifo_print.h | 1 | ||||
-rw-r--r-- | libmpdvdkit2/ifo_read.c | 498 | ||||
-rw-r--r-- | libmpdvdkit2/ifo_read.h | 16 | ||||
-rw-r--r-- | libmpdvdkit2/ifo_types.h | 313 | ||||
-rw-r--r-- | libmpdvdkit2/nav_print.c | 20 | ||||
-rw-r--r-- | libmpdvdkit2/nav_print.h | 12 | ||||
-rw-r--r-- | libmpdvdkit2/nav_read.c | 120 | ||||
-rw-r--r-- | libmpdvdkit2/nav_read.h | 16 | ||||
-rw-r--r-- | libmpdvdkit2/nav_types.h | 161 |
20 files changed, 1997 insertions, 620 deletions
diff --git a/libmpdvdkit2/Makefile b/libmpdvdkit2/Makefile index 7df8e6fa43..602309557d 100644 --- a/libmpdvdkit2/Makefile +++ b/libmpdvdkit2/Makefile @@ -15,6 +15,7 @@ SRCS = css.c \ libdvdcss.c \ nav_print.c \ nav_read.c \ + md5.c \ #bsdi_ioctl.c @@ -34,7 +35,8 @@ endif # -funroll-loops removed, triggered gcc 3.0.4 (3.x?) bug CFLAGS= -I. $(OPTFLAGS) $(EXTRA_INC)\ - -DSYS_LINUX -D__USE_UNIX98 -D_REENTRANT -D_GNU_SOURCE + -DSYS_LINUX -D__USE_UNIX98 -D_REENTRANT -D_GNU_SOURCE \ + -DHAVE_DVDCSS_DVDCSS_H -DSTDC_HEADERS .c.o: $(CC) $(CFLAGS) -c -o $@ $< diff --git a/libmpdvdkit2/README b/libmpdvdkit2/README index 3a84c1b195..b1b55bfa87 100644 --- a/libmpdvdkit2/README +++ b/libmpdvdkit2/README @@ -1,12 +1,12 @@ -MPlayer DVD-kit v2.2 :) +MPlayer DVD-kit v2.3 :) made by Pontscho & A'rpi for the MPlayer project What the hell is this? ====================== Nothing special, just a collection of sources and patches and fixes: -- dvdread 0.9.3 + static libdvdcss (removed dlopen code) -- libdvdcss 1.2.5 +- dvdread 0.9.4 + static libdvdcss +- libdvdcss 1.2.8 - optimizations enabled, asserts disabled everything packed together with _static_ linking to maximize performance. diff --git a/libmpdvdkit2/bswap.h b/libmpdvdkit2/bswap.h index 240f06e16f..7b5e7448f2 100644 --- a/libmpdvdkit2/bswap.h +++ b/libmpdvdkit2/bswap.h @@ -32,6 +32,11 @@ #else +/* For __FreeBSD_version */ +#if defined(HAVE_SYS_PARAM_H) +#include <sys/param.h> +#endif + #if defined(__linux__) #include <byteswap.h> #define B2N_16(x) x = bswap_16(x) @@ -50,6 +55,18 @@ #define B2N_32(x) x = swap32(x) #define B2N_64(x) x = swap64(x) +#elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 +#include <sys/endian.h> +#define B2N_16(x) x = be16toh(x) +#define B2N_32(x) x = be32toh(x) +#define B2N_64(x) x = be64toh(x) + +#elif defined(__DragonFly__) +#include <sys/endian.h> +#define B2N_16(x) x = be16toh(x) +#define B2N_32(x) x = be32toh(x) +#define B2N_64(x) x = be64toh(x) + #elif defined(ARCH_X86) inline static unsigned short bswap_16(unsigned short x) { @@ -88,17 +105,12 @@ inline static unsigned long long int bswap_64(unsigned long long int x) } #define B2N_64(x) x = bswap_64(x) -#elif defined(__DragonFly__) -#include <sys/endian.h> -#define B2N_16(x) x = be16toh(x) -#define B2N_32(x) x = be32toh(x) -#define B2N_64(x) x = be64toh(x) - /* This is a slow but portable implementation, it has multiple evaluation * problems so beware. - * FreeBSD and Solaris don't have <byteswap.h> or any other such + * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such * functionality! */ + #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) #define B2N_16(x) \ x = ((((x) & 0xff00) >> 8) | \ diff --git a/libmpdvdkit2/config.h b/libmpdvdkit2/config.h index 1520ef34e9..43e624c7c9 100644 --- a/libmpdvdkit2/config.h +++ b/libmpdvdkit2/config.h @@ -1,6 +1,6 @@ /* Version number of package */ -#define VERSION "1.2.2" +#define VERSION "1.2.3" #define HAVE_UNISTD_H 1 /* Define if your processor stores words with the most significant diff --git a/libmpdvdkit2/dvd_input.c b/libmpdvdkit2/dvd_input.c index a5c0e7f0d4..840d8e2086 100644 --- a/libmpdvdkit2/dvd_input.c +++ b/libmpdvdkit2/dvd_input.c @@ -21,6 +21,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <fcntl.h> @@ -29,21 +31,34 @@ #include "dvd_reader.h" #include "dvd_input.h" -#include "dvdcss.h" - -dvdcss_handle (*DVDcss_open) (const char *); -int (*DVDcss_close) (dvdcss_handle); -int (*DVDcss_seek) (dvdcss_handle, int, int); -int (*DVDcss_title) (dvdcss_handle, int); -int (*DVDcss_read) (dvdcss_handle, void *, int, int); -char * (*DVDcss_error) (dvdcss_handle); +/* The function pointers that is the exported interface of this file. */ +dvd_input_t (*dvdinput_open) (const char *); +int (*dvdinput_close) (dvd_input_t); +int (*dvdinput_seek) (dvd_input_t, int); +int (*dvdinput_title) (dvd_input_t, int); +int (*dvdinput_read) (dvd_input_t, void *, int, int); +char * (*dvdinput_error) (dvd_input_t); -dvd_input_t (*DVDinput_open) (const char *); -int (*DVDinput_close) (dvd_input_t); -int (*DVDinput_seek) (dvd_input_t, int, int); -int (*DVDinput_title) (dvd_input_t, int); -int (*DVDinput_read) (dvd_input_t, void *, int, int); -char * (*DVDinput_error) (dvd_input_t); +#ifdef HAVE_DVDCSS_DVDCSS_H +/* linking to libdvdcss */ +#include "dvdcss.h" +#define DVDcss_open(a) dvdcss_open((char*)(a)) +#define DVDcss_close dvdcss_close +#define DVDcss_seek dvdcss_seek +#define DVDcss_title dvdcss_title +#define DVDcss_read dvdcss_read +#define DVDcss_error dvdcss_error +#else +/* dlopening libdvdcss */ +#include <dlfcn.h> +typedef struct dvdcss_s *dvdcss_handle; +static dvdcss_handle (*DVDcss_open) (const char *); +static int (*DVDcss_close) (dvdcss_handle); +static int (*DVDcss_seek) (dvdcss_handle, int, int); +static int (*DVDcss_title) (dvdcss_handle, int); +static int (*DVDcss_read) (dvdcss_handle, void *, int, int); +static char * (*DVDcss_error) (dvdcss_handle); +#endif /* The DVDinput handle, add stuff here for new input methods. */ struct dvd_input_s { @@ -61,7 +76,7 @@ struct dvd_input_s { static dvd_input_t css_open(const char *target) { dvd_input_t dev; - + /* Allocate the handle structure */ dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s)); if(dev == NULL) { @@ -72,7 +87,7 @@ static dvd_input_t css_open(const char *target) /* Really open it with libdvdcss */ dev->dvdcss = DVDcss_open(target); if(dev->dvdcss == 0) { - fprintf(stderr, "libdvdread: Could not open device with libdvdcss.\n"); + fprintf(stderr, "libdvdread: Could not open %s with libdvdcss.\n", target); free(dev); return NULL; } @@ -91,9 +106,10 @@ static char *css_error(dvd_input_t dev) /** * seek into the device. */ -static int css_seek(dvd_input_t dev, int blocks, int flags) +static int css_seek(dvd_input_t dev, int blocks) { - return DVDcss_seek(dev->dvdcss, blocks, flags); + /* DVDINPUT_NOFLAGS should match the DVDCSS_NOFLAGS value. */ + return DVDcss_seek(dev->dvdcss, blocks, DVDINPUT_NOFLAGS); } /** @@ -131,34 +147,207 @@ static int css_close(dvd_input_t dev) + + + +/** + * initialize and open a DVD device or file. + */ +static dvd_input_t file_open(const char *target) +{ + dvd_input_t dev; + + /* Allocate the library structure */ + dev = (dvd_input_t) malloc(sizeof(dvd_input_t)); + if(dev == NULL) { + fprintf(stderr, "libdvdread: Could not allocate memory.\n"); + return NULL; + } + + /* Open the device */ + dev->fd = open(target, O_RDONLY); + if(dev->fd < 0) { + perror("libdvdread: Could not open input"); + free(dev); + return NULL; + } + + return dev; +} + +/** + * return the last error message + */ +static char *file_error(dvd_input_t dev) +{ + /* use strerror(errno)? */ + return (char *)"unknown error"; +} + +/** + * seek into the device. + */ +static int file_seek(dvd_input_t dev, int blocks) +{ + off_t pos; + + pos = lseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET); + if(pos < 0) { + return pos; + } + /* assert pos % DVD_VIDEO_LB_LEN == 0 */ + return (int) (pos / DVD_VIDEO_LB_LEN); +} + +/** + * set the block for the begining of a new title (key). + */ +static int file_title(dvd_input_t dev, int block) +{ + return -1; +} + +/** + * read data from the device. + */ +static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags) +{ + size_t len; + ssize_t ret; + + len = (size_t)blocks * DVD_VIDEO_LB_LEN; + + while(len > 0) { + + ret = read(dev->fd, buffer, len); + + if(ret < 0) { + /* One of the reads failed, too bad. We won't even bother + * returning the reads that went ok, and as in the posix spec + * the file postition is left unspecified after a failure. */ + return ret; + } + + if(ret == 0) { + /* Nothing more to read. Return the whole blocks, if any, that we got. + and adjust the file possition back to the previous block boundary. */ + size_t bytes = (size_t)blocks * DVD_VIDEO_LB_LEN - len; + off_t over_read = -(bytes % DVD_VIDEO_LB_LEN); + /*off_t pos =*/ lseek(dev->fd, over_read, SEEK_CUR); + /* should have pos % 2048 == 0 */ + return (int) (bytes / DVD_VIDEO_LB_LEN); + } + + len -= ret; + } + + return blocks; +} + +/** + * close the DVD device and clean up. + */ +static int file_close(dvd_input_t dev) +{ + int ret; + + ret = close(dev->fd); + + if(ret < 0) + return ret; + + free(dev); + + return 0; +} + + /** * Setup read functions with either libdvdcss or minimal DVD access. */ -int DVDInputSetup(void) +int dvdinput_setup(void) { - DVDcss_open = dvdcss_open; - DVDcss_close = dvdcss_close; - DVDcss_title = dvdcss_title; - DVDcss_seek = dvdcss_seek; - DVDcss_read = dvdcss_read; - DVDcss_error = dvdcss_error; + void *dvdcss_library = NULL; + char **dvdcss_version = NULL; + +#ifdef HAVE_DVDCSS_DVDCSS_H + /* linking to libdvdcss */ + dvdcss_library = &dvdcss_library; /* Give it some value != NULL */ + /* the DVDcss_* functions have been #defined at the top */ + dvdcss_version = &dvdcss_interface_2; + +#else + /* dlopening libdvdcss */ + dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY); + + if(dvdcss_library != NULL) { +#if defined(__OpenBSD__) && !defined(__ELF__) +#define U_S "_" +#else +#define U_S +#endif + DVDcss_open = (dvdcss_handle (*)(const char*)) + dlsym(dvdcss_library, U_S "dvdcss_open"); + DVDcss_close = (int (*)(dvdcss_handle)) + dlsym(dvdcss_library, U_S "dvdcss_close"); + DVDcss_title = (int (*)(dvdcss_handle, int)) + dlsym(dvdcss_library, U_S "dvdcss_title"); + DVDcss_seek = (int (*)(dvdcss_handle, int, int)) + dlsym(dvdcss_library, U_S "dvdcss_seek"); + DVDcss_read = (int (*)(dvdcss_handle, void*, int, int)) + dlsym(dvdcss_library, U_S "dvdcss_read"); + DVDcss_error = (char* (*)(dvdcss_handle)) + dlsym(dvdcss_library, U_S "dvdcss_error"); + dvdcss_version = (char **)dlsym(dvdcss_library, U_S "dvdcss_interface_2"); + + if(dlsym(dvdcss_library, U_S "dvdcss_crack")) { + fprintf(stderr, + "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n" + "libdvdread: You should get the latest version from " + "http://www.videolan.org/\n" ); + dlclose(dvdcss_library); + dvdcss_library = NULL; + } else if(!DVDcss_open || !DVDcss_close || !DVDcss_title || !DVDcss_seek + || !DVDcss_read || !DVDcss_error || !dvdcss_version) { + fprintf(stderr, "libdvdread: Missing symbols in libdvdcss.so.2, " + "this shouldn't happen !\n"); + dlclose(dvdcss_library); + } + } +#endif /* HAVE_DVDCSS_DVDCSS_H */ + + if(dvdcss_library != NULL) { /* char *psz_method = getenv( "DVDCSS_METHOD" ); char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method); fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose); */ -// fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n", -// *dvdcss_version); + /* + fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n", + *dvdcss_version); + */ - /* libdvdcss wraper functions */ - DVDinput_open = css_open; - DVDinput_close = css_close; - DVDinput_seek = css_seek; - DVDinput_title = css_title; - DVDinput_read = css_read; - DVDinput_error = css_error; + /* libdvdcss wrapper functions */ + dvdinput_open = css_open; + dvdinput_close = css_close; + dvdinput_seek = css_seek; + dvdinput_title = css_title; + dvdinput_read = css_read; + dvdinput_error = css_error; return 1; + } else { + fprintf(stderr, "libdvdread: Encrypted DVD support unavailable.\n"); + + /* libdvdcss replacement functions */ + dvdinput_open = file_open; + dvdinput_close = file_close; + dvdinput_seek = file_seek; + dvdinput_title = file_title; + dvdinput_read = file_read; + dvdinput_error = file_error; + return 0; + } } diff --git a/libmpdvdkit2/dvd_input.h b/libmpdvdkit2/dvd_input.h index ee28348995..e9e84917ea 100644 --- a/libmpdvdkit2/dvd_input.h +++ b/libmpdvdkit2/dvd_input.h @@ -5,10 +5,6 @@ * Copyright (C) 2001, 2002 Samuel Hocevar <sam@zoy.org>, * Håkan Hjort <d95hjort@dtek.chalmers.se> * - * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. - * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ - * $Id$ - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -31,25 +27,21 @@ #define DVDINPUT_READ_DECRYPT (1 << 0) -#define DVDINPUT_SEEK_MPEG (1 << 0) -#define DVDINPUT_SEEK_KEY (1 << 1) - - typedef struct dvd_input_s *dvd_input_t; /** - * Pointers which will be filled either the input meathods functions. + * Pointers which will be filled either the input methods functions. */ -extern dvd_input_t (*DVDinput_open) (const char *); -extern int (*DVDinput_close) (dvd_input_t); -extern int (*DVDinput_seek) (dvd_input_t, int, int); -extern int (*DVDinput_title) (dvd_input_t, int); -extern int (*DVDinput_read) (dvd_input_t, void *, int, int); -extern char * (*DVDinput_error) (dvd_input_t); +extern dvd_input_t (*dvdinput_open) (const char *); +extern int (*dvdinput_close) (dvd_input_t); +extern int (*dvdinput_seek) (dvd_input_t, int); +extern int (*dvdinput_title) (dvd_input_t, int); +extern int (*dvdinput_read) (dvd_input_t, void *, int, int); +extern char * (*dvdinput_error) (dvd_input_t); /** * Setup function accessed by dvd_reader.c. Returns 1 if there is CSS support. */ -int DVDInputSetup(void); +int dvdinput_setup(void); #endif /* DVD_INPUT_H_INCLUDED */ diff --git a/libmpdvdkit2/dvd_reader.c b/libmpdvdkit2/dvd_reader.c index f4da80a7de..4e5db5cc15 100644 --- a/libmpdvdkit2/dvd_reader.c +++ b/libmpdvdkit2/dvd_reader.c @@ -1,6 +1,7 @@ /* - * Copyright (C) 2001, 2002 Billy Biggs <vektor@dumbterm.net>, - * Håkan Hjort <d95hjort@dtek.chalmers.se> + * Copyright (C) 2001, 2002, 2003 Billy Biggs <vektor@dumbterm.net>, + * Håkan Hjort <d95hjort@dtek.chalmers.se>, + * Björn Englund <d4bjorn@dtek.chalmers.se> * * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ @@ -62,6 +63,9 @@ static void gettimeofday(struct timeval* t,void* timezone){ #include "dvd_udf.h" #include "dvd_input.h" #include "dvd_reader.h" +#include "md5.h" + +#define DEFAULT_UDF_CACHE_LEVEL 0 struct dvd_reader_s { /* Basic information. */ @@ -70,13 +74,17 @@ struct dvd_reader_s { /* Hack for keeping track of the css status. * 0: no css, 1: perhaps (need init of keys), 2: have done init */ int css_state; - int css_title; /* Last title that we have called DVDinpute_title for. */ + int css_title; /* Last title that we have called dvdinpute_title for. */ /* Information required for an image file. */ dvd_input_t dev; /* Information required for a directory path drive. */ char *path_root; + + /* Filesystem cache */ + int udfcache_level; /* 0 - turned off, 1 - on */ + void *udfcache; }; struct dvd_file_s { @@ -98,6 +106,42 @@ struct dvd_file_s { ssize_t filesize; }; +/** + * Set the level of caching on udf + * level = 0 (no caching) + * level = 1 (caching filesystem info) + */ +int DVDUDFCacheLevel(dvd_reader_t *device, int level) +{ + struct dvd_reader_s *dev = (struct dvd_reader_s *)device; + + if(level > 0) { + level = 1; + } else if(level < 0) { + return dev->udfcache_level; + } + + dev->udfcache_level = level; + + return level; +} + +void *GetUDFCacheHandle(dvd_reader_t *device) +{ + struct dvd_reader_s *dev = (struct dvd_reader_s *)device; + + return dev->udfcache; +} + +void SetUDFCacheHandle(dvd_reader_t *device, void *cache) +{ + struct dvd_reader_s *dev = (struct dvd_reader_s *)device; + + dev->udfcache = cache; +} + + + /* Loop over all titles and call dvdcss_title to crack the keys. */ static int initAllCSSKeys( dvd_reader_t *dvd ) { @@ -107,6 +151,10 @@ static int initAllCSSKeys( dvd_reader_t *dvd ) uint32_t start, len; int title; + char *nokeys_str = getenv("DVDREAD_NOKEYS"); + if(nokeys_str != NULL) + return 0; + fprintf( stderr, "\n" ); fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" ); fprintf( stderr, "libdvdread: This can take a _long_ time, " @@ -126,7 +174,7 @@ static int initAllCSSKeys( dvd_reader_t *dvd ) /* Perform CSS key cracking for this title. */ fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", filename, start ); - if( DVDinput_title( dvd->dev, (int)start ) < 0 ) { + if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start); } gettimeofday( &t_e, NULL ); @@ -144,7 +192,7 @@ static int initAllCSSKeys( dvd_reader_t *dvd ) /* Perform CSS key cracking for this title. */ fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", filename, start ); - if( DVDinput_title( dvd->dev, (int)start ) < 0 ) { + if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start); } gettimeofday( &t_e, NULL ); @@ -177,18 +225,8 @@ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) { dvd_reader_t *dvd; dvd_input_t dev; - - /* setup cache dir is no longer needed, it's now implemented in libdvdcss.c - if(!dvdcss_cache_dir){ - dvdcss_cache_dir=get_path( "" ); - if ( dvdcss_cache_dir ) { mkdir( dvdcss_cache_dir,493 ); free( dvdcss_cache_dir ); } - dvdcss_cache_dir=get_path( "DVDKeys" ); - if(dvdcss_cache_dir) mkdir( dvdcss_cache_dir,493 ); - } - */ - /* open it */ - dev = DVDinput_open( location ); + dev = dvdinput_open( location ); if( !dev ) { fprintf( stderr, "libdvdread: Can't open %s for reading\n", location ); return 0; @@ -200,6 +238,9 @@ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) dvd->dev = dev; dvd->path_root = 0; + dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; + dvd->udfcache = NULL; + if( have_css ) { /* Only if DVDCSS_METHOD = title, a bit if it's disc or if * DVDCSS_METHOD = key but region missmatch. Unfortunaly we @@ -207,6 +248,7 @@ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) dvd->css_state = 1; /* Need key init. */ } + dvd->css_title = 0; return dvd; } @@ -221,6 +263,12 @@ static dvd_reader_t *DVDOpenPath( const char *path_root ) dvd->dev = 0; dvd->path_root = strdup( path_root ); + dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; + dvd->udfcache = NULL; + + dvd->css_state = 0; /* Only used in the UDF path */ + dvd->css_title = 0; /* Only matters in the UDF path */ + return dvd; } @@ -275,7 +323,8 @@ dvd_reader_t *DVDOpen( const char *path ) int ret, have_css; char *dev_name = 0; - if( !path ) return 0; + if( path == NULL ) + return 0; #ifdef WIN32 /* Stat doesn't work on devices under mingwin/cygwin. */ @@ -297,7 +346,7 @@ dvd_reader_t *DVDOpen( const char *path ) } /* Try to open libdvdcss or fall back to standard functions */ - have_css = DVDInputSetup(); + have_css = dvdinput_setup(); /* First check if this is a block/char device or a file*/ if( S_ISBLK( fileinfo.st_mode ) || @@ -445,10 +494,10 @@ dvd_reader_t *DVDOpen( const char *path ) void DVDClose( dvd_reader_t *dvd ) { if( dvd ) { - if( dvd->dev ) DVDinput_close( dvd->dev ); + if( dvd->dev ) dvdinput_close( dvd->dev ); if( dvd->path_root ) free( dvd->path_root ); + if( dvd->udfcache ) FreeUDFCache( dvd->udfcache ); free( dvd ); - dvd = 0; } } @@ -545,7 +594,7 @@ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ) /* Get the full path of the file. */ if( !findDVDFile( dvd, filename, full_path ) ) return 0; - dev = DVDinput_open( full_path ); + dev = dvdinput_open( full_path ); if( !dev ) return 0; dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); @@ -609,8 +658,7 @@ static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu ) // dvd->css_state = 2; } /* - if( DVDinput_seek( dvd_file->dvd->dev, - (int)start, DVDINPUT_SEEK_KEY ) < 0 ) { + if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) { fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n", filename ); } @@ -636,7 +684,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); dvd_file->filesize = 0; - + if( menu ) { dvd_input_t dev; @@ -650,7 +698,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) return 0; } - dev = DVDinput_open( full_path ); + dev = dvdinput_open( full_path ); if( dev == NULL ) { free( dvd_file ); return 0; @@ -663,7 +711,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) } dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; dvd_file->title_devs[ 0 ] = dev; - DVDinput_seek( dvd_file->title_devs[0], 0, DVDINPUT_SEEK_KEY ); + dvdinput_title( dvd_file->title_devs[0], 0); dvd_file->filesize = dvd_file->title_sizes[ 0 ]; } else { @@ -680,9 +728,9 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) } dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; - dvd_file->title_devs[ i ] = DVDinput_open( full_path ); + dvd_file->title_devs[ i ] = dvdinput_open( full_path ); + dvdinput_title( dvd_file->title_devs[ i ], 0 ); dvd_file->filesize += dvd_file->title_sizes[ i ]; - DVDinput_seek( dvd_file->title_devs[ i ], 0, DVDINPUT_SEEK_KEY ); } if( !dvd_file->title_devs[ 0 ] ) { free( dvd_file ); @@ -697,6 +745,10 @@ dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum, dvd_read_domain_t domain ) { char filename[ MAX_UDF_FILE_NAME_LEN ]; + + /* Check arguments. */ + if( dvd == NULL || titlenum < 0 ) + return NULL; switch( domain ) { case DVD_READ_INFO_FILE: @@ -730,7 +782,7 @@ dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum, break; default: fprintf( stderr, "libdvdread: Invalid domain for file open.\n" ); - return 0; + return NULL; } if( dvd->isImageFile ) { @@ -750,7 +802,7 @@ void DVDCloseFile( dvd_file_t *dvd_file ) } else { for( i = 0; i < 9; ++i ) { if( dvd_file->title_devs[ i ] ) { - DVDinput_close( dvd_file->title_devs[i] ); + dvdinput_close( dvd_file->title_devs[i] ); } } } @@ -761,7 +813,7 @@ void DVDCloseFile( dvd_file_t *dvd_file ) } /* Internal, but used from dvd_udf.c */ -int DVDReadBlocksUDFRaw( dvd_reader_t *device, uint32_t lb_number, +int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number, size_t block_count, unsigned char *data, int encrypted ) { @@ -772,13 +824,13 @@ int DVDReadBlocksUDFRaw( dvd_reader_t *device, uint32_t lb_number, return 0; } - ret = DVDinput_seek( device->dev, (int) lb_number, DVDINPUT_NOFLAGS ); + ret = dvdinput_seek( device->dev, (int) lb_number ); if( ret != (int) lb_number ) { fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number ); return 0; } - return DVDinput_read( device->dev, (char *) data, + return dvdinput_read( device->dev, (char *) data, (int) block_count, encrypted ); } @@ -792,8 +844,8 @@ static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset, size_t block_count, unsigned char *data, int encrypted ) { - return DVDReadBlocksUDFRaw( dvd_file->dvd, dvd_file->lb_start + offset, - block_count, data, encrypted ); + return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset, + block_count, data, encrypted ); } /* This is using possibly several inputs and starting from an offset of '0'. @@ -816,14 +868,13 @@ static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset, if( offset < dvd_file->title_sizes[ i ] ) { if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) { - off = DVDinput_seek( dvd_file->title_devs[ i ], - (int)offset, DVDINPUT_NOFLAGS ); + off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); if( off < 0 || off != (int)offset ) { fprintf( stderr, "libdvdread: Can't seek to block %d\n", offset ); return off < 0 ? off : 0; } - ret = DVDinput_read( dvd_file->title_devs[ i ], data, + ret = dvdinput_read( dvd_file->title_devs[ i ], data, (int)block_count, encrypted ); break; } else { @@ -832,31 +883,29 @@ static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset, * (This is only true if you try and read >1GB at a time) */ /* Read part 1 */ - off = DVDinput_seek( dvd_file->title_devs[ i ], - (int)offset, DVDINPUT_NOFLAGS ); + off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); if( off < 0 || off != (int)offset ) { fprintf( stderr, "libdvdread: Can't seek to block %d\n", offset ); return off < 0 ? off : 0; } - ret = DVDinput_read( dvd_file->title_devs[ i ], data, + ret = dvdinput_read( dvd_file->title_devs[ i ], data, (int)part1_size, encrypted ); if( ret < 0 ) return ret; /* FIXME: This is wrong if i is the last file in the set. * also error from this read will not show in ret. */ - - /* Does the next part exist? If not then return now. */ - if( !dvd_file->title_devs[ i + 1 ] ) return ret; + + /* Does the next part exist? If not then return now. */ + if( !dvd_file->title_devs[ i + 1 ] ) return ret; /* Read part 2 */ - off = DVDinput_seek( dvd_file->title_devs[ i + 1 ], - 0, DVDINPUT_NOFLAGS ); + off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 ); if( off < 0 || off != 0 ) { fprintf( stderr, "libdvdread: Can't seek to block %d\n", 0 ); return off < 0 ? off : 0; } - ret2 = DVDinput_read( dvd_file->title_devs[ i + 1 ], + ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ], data + ( part1_size * (int64_t)DVD_VIDEO_LB_LEN ), (int)(block_count - part1_size), @@ -878,14 +927,20 @@ ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset, { int ret; |