[MPlayer-dev-eng] [PATCH] sync libdvdcss with upstream version

Diego Biurrun diego at biurrun.de
Wed Oct 18 01:05:09 CEST 2006


Hi!

This patch syncs our internal libdvdcss with their SVN HEAD (I've been
told by Sam Hocevar that a release is imminent).  Why?  Because all our
patches are merged and we would then carry a vanilla version.  The
changes are mostly cosmetics and warning fixes.  Testing very much
welcome.

Diego
-------------- next part --------------
Index: libmpdvdkit2/libdvdcss.c
===================================================================
--- libmpdvdkit2/libdvdcss.c	(revision 20289)
+++ libmpdvdkit2/libdvdcss.c	(working copy)
@@ -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;
 
 /**
@@ -159,9 +157,9 @@
  * and when possible, the disc key is retrieved.
  *
  * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss
- * calls. If an error occured, NULL is returned.
+ * 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 @@
     /*
      *  Open device
      */
+    _dvdcss_check( dvdcss );
     i_ret = _dvdcss_open( dvdcss );
     if( i_ret < 0 )
     {
@@ -387,7 +386,7 @@
             "# This file is a cache directory tag created by libdvdcss.\r\n"
             "# For information about cache directory tags, see:\r\n"
             "#   http://www.brynosaurus.com/cachedir/\r\n";
-        unsigned char psz_tagfile[PATH_MAX+1+12+1];
+        char psz_tagfile[PATH_MAX + 1 + 12 + 1];
         int i_fd;
 
         sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
@@ -403,9 +402,9 @@
     if( psz_cache )
     {
         uint8_t p_sector[DVDCSS_BLOCK_SIZE];
-        unsigned char   psz_debug[PATH_MAX+30];
-        unsigned char   psz_key[1 + KEY_SIZE * 2 + 1];
-        unsigned char * psz_title, * psz_serial;
+        char psz_debug[PATH_MAX + 30];
+        char psz_key[1 + KEY_SIZE * 2 + 1];
+        char *psz_title, *psz_serial;
         int i;
 
         /* We read sector 0. If it starts with 0x000001ba (BE), we are
@@ -446,7 +445,7 @@
         }
 
         /* Get the disc title */
-        psz_title = p_sector + 40;
+        psz_title = (char *)p_sector + 40;
         psz_title[32] = '\0';
 
         for( i = 0 ; i < 32 ; i++ )
@@ -463,7 +462,7 @@
         }
 
         /* Get the date + serial */
-        psz_serial = p_sector + 813;
+        psz_serial = (char *)p_sector + 813;
         psz_serial[16] = '\0';
 
         /* Check that all characters are digits, otherwise convert. */
@@ -471,7 +470,7 @@
         {
             if( psz_serial[i] < '0' || psz_serial[i] > '9' )
             {
-                unsigned char psz_tmp[16 + 1];
+                char psz_tmp[16 + 1];
                 sprintf( psz_tmp,
                          "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
                          psz_serial[0], psz_serial[1], psz_serial[2],
@@ -550,17 +549,17 @@
 }
 
 /**
- * \brief Return a string containing the latest error that occured in the
+ * \brief Return a string containing the latest error that occurred in the
  *        given \e libdvdcss instance.
  *
  * \param dvdcss a \e libdvdcss instance.
  * \return a null-terminated string containing the latest error message.
  *
  * This function returns a constant string containing the latest error that
- * occured in \e libdvdcss. It can be used to format error messages at your
+ * 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 @@
  * 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 @@
  * \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 @@
  *          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 @@
  * 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 @@
  *  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 );
 }
Index: libmpdvdkit2/ioctl.h
===================================================================
--- libmpdvdkit2/ioctl.h	(revision 20289)
+++ libmpdvdkit2/ioctl.h	(working copy)
@@ -318,8 +318,8 @@
  * win32 aspi specific
  *****************************************************************************/
 
-typedef WINAPI DWORD (*GETASPI32SUPPORTINFO)(VOID);
-typedef WINAPI DWORD (*SENDASPI32COMMAND)(LPVOID);
+typedef DWORD (CALLBACK *GETASPI32SUPPORTINFO)(VOID);
+typedef DWORD (CALLBACK *SENDASPI32COMMAND)(LPVOID);
 
 #define WIN2K               ( GetVersion() < 0x80000000 )
 #define ASPI_HAID           0
Index: libmpdvdkit2/libdvdcss.h
===================================================================
--- libmpdvdkit2/libdvdcss.h	(revision 20289)
+++ libmpdvdkit2/libdvdcss.h	(working copy)
@@ -78,6 +78,19 @@
  * Functions used across the library
  *****************************************************************************/
 #define print_error(dvdcss,msg) _print_error(dvdcss,msg)
+#if defined( _MSC_VER )
+#include <stdarg.h>
+__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 @@
         fprintf( stderr, msg, ##args ); \
         fprintf( stderr, "\n" ); \
     }
+#endif
 
 void _print_error ( dvdcss_t, char * );
 
Index: libmpdvdkit2/device.c
===================================================================
--- libmpdvdkit2/device.c	(revision 20289)
+++ libmpdvdkit2/device.c	(working copy)
@@ -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 <stef at via.ecp.fr>
- *          Samuel Hocevar <sam at zoy.org>
+ *          Sam Hocevar <sam at zoy.org>
  *          H?kan Hjort <d95hjort at dtek.chalmers.se>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -58,6 +55,16 @@
 #   include <sys/uio.h>                                      /* struct iovec */
 #endif
 
+#ifdef DARWIN_DVD_IOCTL
+#   include <paths.h>
+#   include <CoreFoundation/CoreFoundation.h>
+#   include <IOKit/IOKitLib.h>
+#   include <IOKit/IOBSD.h>
+#   include <IOKit/storage/IOMedia.h>
+#   include <IOKit/storage/IOCDMedia.h>
+#   include <IOKit/storage/IODVDMedia.h>
+#endif
+
 #include "dvdcss/dvdcss.h"
 
 #include "common.h"
@@ -139,6 +146,148 @@
 #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 @@
     }
 
     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 )
     {
Index: libmpdvdkit2/device.h
===================================================================
--- libmpdvdkit2/device.h	(revision 20289)
+++ libmpdvdkit2/device.h	(working copy)
@@ -44,9 +44,10 @@
 /*****************************************************************************
  * Device reading prototypes
  *****************************************************************************/
-int _dvdcss_use_ioctls ( dvdcss_t );
-int _dvdcss_open       ( dvdcss_t );
-int _dvdcss_close      ( dvdcss_t );
+int  _dvdcss_use_ioctls ( dvdcss_t );
+void _dvdcss_check      ( dvdcss_t );
+int  _dvdcss_open       ( dvdcss_t );
+int  _dvdcss_close      ( dvdcss_t );
 
 /*****************************************************************************
  * Device reading prototypes, raw-device specific
Index: libmpdvdkit2/dvdcss/dvdcss.h
===================================================================
--- libmpdvdkit2/dvdcss/dvdcss.h	(revision 20289)
+++ libmpdvdkit2/dvdcss/dvdcss.h	(working copy)
@@ -56,29 +56,37 @@
 #define DVDCSS_SEEK_KEY        (1 << 1)
 
 
+#if defined(LIBDVDCSS_EXPORTS)
+#define LIBDVDCSS_EXPORT __declspec(dllexport) extern
+#elif defined(LIBDVDCSS_IMPORTS)
+#define LIBDVDCSS_EXPORT __declspec(dllimport) extern
+#else
+#define LIBDVDCSS_EXPORT extern
+#endif
+
 /*
  * Our version number. The variable name contains the interface version.
  */
-extern char *        dvdcss_interface_2;
+LIBDVDCSS_EXPORT char *        dvdcss_interface_2;
 
 
 /*
  * Exported prototypes.
  */
-extern dvdcss_t dvdcss_open  ( char *psz_target );
-extern int      dvdcss_close ( dvdcss_t );
-extern int      dvdcss_seek  ( dvdcss_t,
+LIBDVDCSS_EXPORT dvdcss_t dvdcss_open  ( char *psz_target );
+LIBDVDCSS_EXPORT int      dvdcss_close ( dvdcss_t );
+LIBDVDCSS_EXPORT int      dvdcss_seek  ( dvdcss_t,
                                int i_blocks,
                                int i_flags );
-extern int      dvdcss_read  ( dvdcss_t,
+LIBDVDCSS_EXPORT int      dvdcss_read  ( dvdcss_t,
                                void *p_buffer,
                                int i_blocks,
                                int i_flags );
-extern int      dvdcss_readv ( dvdcss_t,
+LIBDVDCSS_EXPORT int      dvdcss_readv ( dvdcss_t,
                                void *p_iovec,
                                int i_blocks,
                                int i_flags );
-extern char *   dvdcss_error ( dvdcss_t );
+LIBDVDCSS_EXPORT char *   dvdcss_error ( dvdcss_t );
 
 
 /*
Index: libmpdvdkit2/css.c
===================================================================
--- libmpdvdkit2/css.c	(revision 20289)
+++ libmpdvdkit2/css.c	(working copy)
@@ -2,9 +2,6 @@
  * css.c: Functions for DVD authentication and descrambling
  *****************************************************************************
  * Copyright (C) 1999-2003 VideoLAN
- *
- * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
- * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
  * $Id$
  *
  * Authors: St?phane Borel <stef at via.ecp.fr>
@@ -173,7 +170,7 @@
 
         if( i_fd >= 0 )
         {
-            unsigned char psz_key[KEY_SIZE * 3];
+            char psz_key[KEY_SIZE * 3];
             unsigned int k0, k1, k2, k3, k4;
 
             psz_key[KEY_SIZE * 3 - 1] = '\0';
@@ -222,7 +219,7 @@
         i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT, 0644 );
         if( i_fd >= 0 )
         {
-            unsigned char psz_key[KEY_SIZE * 3 + 2];
+            char psz_key[KEY_SIZE * 3 + 2];
 
             sprintf( psz_key, "%02x:%02x:%02x:%02x:%02x\r\n",
                               p_title_key[0], p_title_key[1], p_title_key[2],
Index: libmpdvdkit2/common.h
===================================================================
--- libmpdvdkit2/common.h	(revision 20289)
+++ libmpdvdkit2/common.h	(working copy)
@@ -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 <sam at via.ecp.fr>
@@ -49,13 +46,13 @@
 
 #if defined( WIN32 )
 
-#ifndef PATH_MAX
-#   define PATH_MAX MAX_PATH
-#endif
+#   ifndef PATH_MAX
+#      define PATH_MAX MAX_PATH
+#   endif
 
 /* several type definitions */
 #   if defined( __MINGW32__ )
-#define lseek _lseeki64
+#       define lseek _lseeki64
 #       if !defined( _OFF_T_ )
 typedef long long _off_t;
 typedef _off_t off_t;
@@ -79,5 +76,9 @@
 #       define snprintf _snprintf  /* snprintf not defined in mingw32 (bug?) */
 #   endif
 
+#else
+
+#   define lseek64 lseek
+
 #endif
 


More information about the MPlayer-dev-eng mailing list