From a0618fd3103e27253602f2c98b10e82e01267094 Mon Sep 17 00:00:00 2001 From: diego Date: Wed, 25 Oct 2006 11:55:06 +0000 Subject: [PATCH] Sync with upstream r201. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@20441 b3059339-0415-0410-9bf9-f77b7e298cf2 --- Copyright | 2 +- libmpdvdkit2/common.h | 7 +- libmpdvdkit2/device.c | 161 ++++++++++++++++++++++++++-- libmpdvdkit2/device.h | 1 + libmpdvdkit2/libdvdcss.c | 19 ++-- libmpdvdkit2/libdvdcss.h | 14 +++ libmpdvdkit2/libdvdcss_changes.diff | 43 -------- 7 files changed, 184 insertions(+), 63 deletions(-) delete mode 100644 libmpdvdkit2/libdvdcss_changes.diff diff --git a/Copyright b/Copyright index c8fac98a69..36c49e9dc7 100644 --- a/Copyright +++ b/Copyright @@ -39,7 +39,7 @@ Directory: liba52 License: GNU General Public License Name: libdvdcss -Version: 1.2.9 + patches +Version: Subversion r201 (post 1.2.9 release) Homepage: http://developers.videolan.org/libdvdcss/ Directory: libmpdvdkit2 License: GNU General Public License diff --git a/libmpdvdkit2/common.h b/libmpdvdkit2/common.h index d1a1fc38e9..58b0dad3a4 100644 --- a/libmpdvdkit2/common.h +++ b/libmpdvdkit2/common.h @@ -3,9 +3,6 @@ * Collection of useful common types and macros definitions ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN - * - * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. - * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ * $Id$ * * Authors: Samuel Hocevar @@ -79,5 +76,9 @@ typedef __int64 off_t; # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */ # endif +#else + +# define lseek64 lseek + #endif diff --git a/libmpdvdkit2/device.c b/libmpdvdkit2/device.c index 53d05bf3cb..580ce3c0fe 100644 --- a/libmpdvdkit2/device.c +++ b/libmpdvdkit2/device.c @@ -1,14 +1,11 @@ /***************************************************************************** * device.h: DVD device access ***************************************************************************** - * Copyright (C) 1998-2002 VideoLAN - * - * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff. - * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ + * Copyright (C) 1998-2006 VideoLAN * $Id$ * * Authors: Stéphane Borel - * Samuel Hocevar + * Sam Hocevar * Håkan Hjort * * This program is free software; you can redistribute it and/or modify @@ -58,6 +55,16 @@ # include /* struct iovec */ #endif +#ifdef DARWIN_DVD_IOCTL +# include +# include +# include +# include +# include +# include +# include +#endif + #include "dvdcss/dvdcss.h" #include "common.h" @@ -139,6 +146,148 @@ int _dvdcss_use_ioctls( dvdcss_t dvdcss ) #endif } +void _dvdcss_check ( dvdcss_t dvdcss ) +{ +#if defined( WIN32 ) + DWORD drives; + int i; +#elif defined( DARWIN_DVD_IOCTL ) + io_object_t next_media; + mach_port_t master_port; + kern_return_t kern_result; + io_iterator_t media_iterator; + CFMutableDictionaryRef classes_to_match; +#else + char *ppsz_devices[] = { "/dev/dvd", "/dev/cdrom", "/dev/hdc", NULL }; + int i, i_fd; +#endif + + /* If the device name is non-null, return */ + if( dvdcss->psz_device[0] ) + { + return; + } + +#if defined( WIN32 ) + drives = GetLogicalDrives(); + + for( i = 0; drives; i++ ) + { + char psz_device[5]; + DWORD cur = 1 << i; + UINT i_ret; + + if( (drives & cur) == 0 ) + { + continue; + } + drives &= ~cur; + + sprintf( psz_device, "%c:\\", 'A' + i ); + i_ret = GetDriveType( psz_device ); + if( i_ret != DRIVE_CDROM ) + { + continue; + } + + /* Remove trailing backslash */ + psz_device[2] = '\0'; + + /* FIXME: we want to differenciate between CD and DVD drives + * using DeviceIoControl() */ + print_debug( dvdcss, "defaulting to drive `%s'", psz_device ); + free( dvdcss->psz_device ); + dvdcss->psz_device = strdup( psz_device ); + return; + } +#elif defined( DARWIN_DVD_IOCTL ) + + kern_result = IOMasterPort( MACH_PORT_NULL, &master_port ); + if( kern_result != KERN_SUCCESS ) + { + return; + } + + classes_to_match = IOServiceMatching( kIODVDMediaClass ); + if( classes_to_match == NULL ) + { + return; + } + + CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ), + kCFBooleanTrue ); + + kern_result = IOServiceGetMatchingServices( master_port, classes_to_match, + &media_iterator ); + if( kern_result != KERN_SUCCESS ) + { + return; + } + + next_media = IOIteratorNext( media_iterator ); + for( ; ; ) + { + char psz_buf[0x32]; + size_t i_pathlen; + CFTypeRef psz_path; + + next_media = IOIteratorNext( media_iterator ); + if( next_media == 0 ) + { + break; + } + + psz_path = IORegistryEntryCreateCFProperty( next_media, + CFSTR( kIOBSDNameKey ), + kCFAllocatorDefault, + 0 ); + if( psz_path == NULL ) + { + IOObjectRelease( next_media ); + continue; + } + + snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' ); + i_pathlen = strlen( psz_buf ); + + if( CFStringGetCString( psz_path, + (char*)&psz_buf + i_pathlen, + sizeof(psz_buf) - i_pathlen, + kCFStringEncodingASCII ) ) + { + print_debug( dvdcss, "defaulting to drive `%s'", psz_buf ); + CFRelease( psz_path ); + IOObjectRelease( next_media ); + IOObjectRelease( media_iterator ); + free( dvdcss->psz_device ); + dvdcss->psz_device = strdup( psz_buf ); + return; + } + + CFRelease( psz_path ); + + IOObjectRelease( next_media ); + } + + IOObjectRelease( media_iterator ); +#else + for( i = 0; ppsz_devices[i]; i++ ) + { + i_fd = open( ppsz_devices[i], 0 ); + if( i_fd != -1 ) + { + print_debug( dvdcss, "defaulting to drive `%s'", ppsz_devices[i] ); + close( i_fd ); + free( dvdcss->psz_device ); + dvdcss->psz_device = strdup( ppsz_devices[i] ); + return; + } + } +#endif + + print_error( dvdcss, "could not find a suitable default drive" ); +} + int _dvdcss_open ( dvdcss_t dvdcss ) { char const *psz_device = dvdcss->psz_device; @@ -443,7 +592,7 @@ static int libc_seek( dvdcss_t dvdcss, int i_blocks ) } i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE; - i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET ); + i_seek = lseek64( dvdcss->i_read_fd, i_seek, SEEK_SET ); if( i_seek < 0 ) { diff --git a/libmpdvdkit2/device.h b/libmpdvdkit2/device.h index 75a2967902..867703172b 100644 --- a/libmpdvdkit2/device.h +++ b/libmpdvdkit2/device.h @@ -45,6 +45,7 @@ struct iovec * Device reading prototypes *****************************************************************************/ int _dvdcss_use_ioctls ( dvdcss_t ); +void _dvdcss_check ( dvdcss_t ); int _dvdcss_open ( dvdcss_t ); int _dvdcss_close ( dvdcss_t ); diff --git a/libmpdvdkit2/libdvdcss.c b/libmpdvdkit2/libdvdcss.c index 2c3e425ee6..c07c1b61b5 100644 --- a/libmpdvdkit2/libdvdcss.c +++ b/libmpdvdkit2/libdvdcss.c @@ -5,9 +5,6 @@ * Håkan Hjort * * Copyright (C) 1998-2002 VideoLAN - * - * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff. - * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ * $Id$ * * This program is free software; you can redistribute it and/or modify @@ -145,6 +142,7 @@ * The variable itself contains the exact version number of the library, * which can be useful for specific feature needs. */ +LIBDVDCSS_EXPORT char * dvdcss_interface_2; char * dvdcss_interface_2 = VERSION; /** @@ -161,7 +159,7 @@ char * dvdcss_interface_2 = VERSION; * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss * calls. If an error occurred, NULL is returned. */ -extern dvdcss_t dvdcss_open ( char *psz_target ) +LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( char *psz_target ) { char psz_buffer[PATH_MAX]; int i_ret; @@ -337,6 +335,7 @@ extern dvdcss_t dvdcss_open ( char *psz_target ) /* * Open device */ + _dvdcss_check( dvdcss ); i_ret = _dvdcss_open( dvdcss ); if( i_ret < 0 ) { @@ -560,7 +559,7 @@ extern dvdcss_t dvdcss_open ( char *psz_target ) * occurred in \e libdvdcss. It can be used to format error messages at your * convenience in your application. */ -extern char * dvdcss_error ( dvdcss_t dvdcss ) +LIBDVDCSS_EXPORT char * dvdcss_error ( dvdcss_t dvdcss ) { return dvdcss->psz_error; } @@ -589,7 +588,7 @@ extern char * dvdcss_error ( dvdcss_t dvdcss ) * deprecated dvdcss_title() call. This flag is typically used when seeking * in a new title. */ -extern int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) +LIBDVDCSS_EXPORT int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) { /* title cracking method is too slow to be used at each seek */ if( ( ( i_flags & DVDCSS_SEEK_MPEG ) @@ -629,7 +628,7 @@ extern int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) * \warning dvdcss_read() expects to be able to write \p i_blocks * * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer. */ -extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, +LIBDVDCSS_EXPORT int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks, int i_flags ) { @@ -702,7 +701,7 @@ extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, * Moreover, all iov_len members of the iovec structures should be * multiples of #DVDCSS_BLOCK_SIZE. */ -extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, +LIBDVDCSS_EXPORT int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, int i_blocks, int i_flags ) { @@ -760,7 +759,7 @@ extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be * used again. */ -extern int dvdcss_close ( dvdcss_t dvdcss ) +LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss ) { dvd_title_t *p_title; int i_ret; @@ -791,7 +790,7 @@ extern int dvdcss_close ( dvdcss_t dvdcss ) * Deprecated. See dvdcss_seek(). */ #undef dvdcss_title -extern int dvdcss_title ( dvdcss_t dvdcss, int i_block ) +LIBDVDCSS_EXPORT int dvdcss_title ( dvdcss_t dvdcss, int i_block ) { return _dvdcss_title( dvdcss, i_block ); } diff --git a/libmpdvdkit2/libdvdcss.h b/libmpdvdkit2/libdvdcss.h index a594f883ce..9fad5d84ce 100644 --- a/libmpdvdkit2/libdvdcss.h +++ b/libmpdvdkit2/libdvdcss.h @@ -78,6 +78,19 @@ struct dvdcss_s * Functions used across the library *****************************************************************************/ #define print_error(dvdcss,msg) _print_error(dvdcss,msg) +#if defined( _MSC_VER ) +#include +__forceinline void print_debug(dvdcss_t dvdcss, const char *msg,...) +{ + va_list args; + + fprintf( stderr, "libdvdcss debug: " ); + va_start( args, msg ); + vfprintf( stderr, msg, args ); + va_end( args ); + fprintf( stderr, "\n" ); +} +#else #define print_debug(dvdcss,msg,args...) \ if( dvdcss->b_debug ) \ { \ @@ -85,6 +98,7 @@ struct dvdcss_s fprintf( stderr, msg, ##args ); \ fprintf( stderr, "\n" ); \ } +#endif void _print_error ( dvdcss_t, char * ); diff --git a/libmpdvdkit2/libdvdcss_changes.diff b/libmpdvdkit2/libdvdcss_changes.diff deleted file mode 100644 index 4bd4f41cce..0000000000 --- a/libmpdvdkit2/libdvdcss_changes.diff +++ /dev/null @@ -1,43 +0,0 @@ ---- common.h 2005-10-11 10:55:45.000000000 +0200 -+++ common.h 2005-10-11 14:07:42.000000000 +0200 -@@ -50,10 +53,9 @@ - # define PATH_MAX MAX_PATH - #endif - --#define lseek _lseeki64 -- - /* several type definitions */ - # if defined( __MINGW32__ ) -+#define lseek _lseeki64 - # if !defined( _OFF_T_ ) - typedef long long _off_t; - typedef _off_t off_t; ---- device.c 2005-07-11 13:33:34.000000000 +0200 -+++ device.c 2005-10-01 19:08:07.000000000 +0200 -@@ -143,8 +132,11 @@ - print_debug( dvdcss, "opening target `%s'", psz_device ); - - #if defined( WIN32 ) -- /* If device is not "X:", we are actually opening a file. */ -- dvdcss->b_file = !psz_device[0] || psz_device[1] != ':' || psz_device[2]; -+ dvdcss->b_file = 1; -+ /* If device is "X:" or "X:\", we are not actually opening a file. */ -+ if (psz_device[0] && psz_device[1] == ':' && -+ (!psz_device[2] || (psz_device[2] == '\\' && !psz_device[3]))) -+ dvdcss->b_file = 0; - - /* Initialize readv temporary buffer */ - dvdcss->p_readv_buffer = NULL; ---- libdvdcss.c 2004-08-13 15:40:18.000000000 +0200 -+++ libdvdcss.c 2005-10-01 19:11:27.000000000 +0200 -@@ -301,6 +301,10 @@ - { - psz_home = getenv( "HOME" ); - } -+ if( psz_home == NULL ) -+ { -+ psz_home = getenv( "USERPROFILE" ); -+ } - - /* Cache our keys in ${HOME}/.dvdcss/ */ - if( psz_home )