diff options
author | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-08-16 22:50:22 +0000 |
---|---|---|
committer | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-08-16 22:50:22 +0000 |
commit | b1187223a37f7e79c386c6ec86b3cd082bf9021f (patch) | |
tree | 084ec952478e36b67d3de3ad1a335227e47289bb /libmpdvdkit2/dvd_input.c | |
parent | a695955bd29a2691bf5e918d2e4716d58299b0cb (diff) | |
download | mpv-b1187223a37f7e79c386c6ec86b3cd082bf9021f.tar.bz2 mpv-b1187223a37f7e79c386c6ec86b3cd082bf9021f.tar.xz |
apply mplayer-specific patches
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7034 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdvdkit2/dvd_input.c')
-rw-r--r-- | libmpdvdkit2/dvd_input.c | 182 |
1 files changed, 9 insertions, 173 deletions
diff --git a/libmpdvdkit2/dvd_input.c b/libmpdvdkit2/dvd_input.c index c2d788fdb2..80a1de5beb 100644 --- a/libmpdvdkit2/dvd_input.c +++ b/libmpdvdkit2/dvd_input.c @@ -21,13 +21,11 @@ #include <stdlib.h> #include <fcntl.h> #include <unistd.h> -#include <dlfcn.h> #include "dvd_reader.h" #include "dvd_input.h" -/* For libdvdcss */ -typedef struct dvdcss_s *dvdcss_handle; +#include "dvdcss.h" dvdcss_handle (*DVDcss_open) (const char *); int (*DVDcss_close) (dvdcss_handle); @@ -123,176 +121,26 @@ 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 "unknown error"; -} - -/** - * seek into the device. - */ -static int file_seek(dvd_input_t dev, int blocks, int flags) -{ - 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) { - void *dvdcss_library = NULL; - char **dvdcss_version = NULL; - - 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_open = dvdcss_open; + DVDcss_close = dvdcss_close; + DVDcss_title = dvdcss_title; + DVDcss_seek = dvdcss_seek; + DVDcss_read = dvdcss_read; + DVDcss_error = 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); - } - } - - 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; @@ -303,16 +151,4 @@ int DVDInputSetup(void) 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; - } } |