diff libmpdvdkit2/device.c @ 16630:954cdf2171f6

upgrade to libdvdcss 1.2.9
author diego
date Sat, 01 Oct 2005 17:19:33 +0000
parents 80494fefb7ea
children 0af14c5fee82
line wrap: on
line diff
--- a/libmpdvdkit2/device.c	Sat Oct 01 17:18:10 2005 +0000
+++ b/libmpdvdkit2/device.c	Sat Oct 01 17:19:33 2005 +0000
@@ -2,9 +2,6 @@
  * device.h: DVD device access
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- *
- * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
- * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
  * $Id$
  *
  * Authors: Stéphane Borel <stef@via.ecp.fr>
@@ -34,11 +31,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#   include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
+#   include <unistd.h>
+#   include <limits.h>
 
 #if defined( WIN32 ) && !defined( SYS_CYGWIN )
 #   include <io.h>                                                 /* read() */
@@ -129,12 +127,9 @@
 
 int _dvdcss_open ( dvdcss_t dvdcss )
 {
-    char psz_debug[200];
     char const *psz_device = dvdcss->psz_device;
 
-    snprintf( psz_debug, 199, "opening target `%s'", psz_device );
-    psz_debug[199] = '\0';
-    _dvdcss_debug( dvdcss, psz_debug );
+    print_debug( dvdcss, "opening target `%s'", psz_device );
 
 #if defined( WIN32 )
     dvdcss->b_file = 1;
@@ -149,7 +144,7 @@
 
     if( !dvdcss->b_file && WIN2K )
     {
-        _dvdcss_debug( dvdcss, "using Win2K API for access" );
+        print_debug( dvdcss, "using Win2K API for access" );
         dvdcss->pf_seek  = win2k_seek;
         dvdcss->pf_read  = win2k_read;
         dvdcss->pf_readv = win_readv;
@@ -157,7 +152,7 @@
     }
     else if( !dvdcss->b_file )
     {
-        _dvdcss_debug( dvdcss, "using ASPI for access" );
+        print_debug( dvdcss, "using ASPI for access" );
         dvdcss->pf_seek  = aspi_seek;
         dvdcss->pf_read  = aspi_read;
         dvdcss->pf_readv = win_readv;
@@ -166,7 +161,7 @@
     else
 #endif
     {
-        _dvdcss_debug( dvdcss, "using libc for access" );
+        print_debug( dvdcss, "using libc for access" );
         dvdcss->pf_seek  = libc_seek;
         dvdcss->pf_read  = libc_read;
         dvdcss->pf_readv = libc_readv;
@@ -181,7 +176,9 @@
 
     if( dvdcss->i_raw_fd == -1 )
     {
-        _dvdcss_error( dvdcss, "failed opening raw device, continuing" );
+        print_debug( dvdcss, "cannot open %s (%s)",
+                             psz_device, strerror(errno) );
+        print_error( dvdcss, "failed to open raw device, but continuing" );
         return -1;
     }
     else
@@ -250,7 +247,9 @@
 
     if( dvdcss->i_fd == -1 )
     {
-        _dvdcss_error( dvdcss, "failed opening device" );
+        print_debug( dvdcss, "cannot open %s (%s)",
+                             psz_device, strerror(errno) );
+        print_error( dvdcss, "failed to open device" );
         return -1;
     }
 
@@ -287,7 +286,7 @@
 
     if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
     {
-        _dvdcss_error( dvdcss, "failed opening device" );
+        print_error( dvdcss, "failed opening device" );
         return -1;
     }
 
@@ -310,7 +309,7 @@
     hASPI = LoadLibrary( "wnaspi32.dll" );
     if( hASPI == NULL )
     {
-        _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" );
+        print_error( dvdcss, "unable to load wnaspi32.dll" );
         return -1;
     }
 
@@ -319,7 +318,7 @@
 
     if(lpGetSupport == NULL || lpSendCommand == NULL )
     {
-        _dvdcss_error( dvdcss, "unable to get aspi function pointers" );
+        print_error( dvdcss, "unable to get aspi function pointers" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -328,14 +327,14 @@
 
     if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
     {
-        _dvdcss_error( dvdcss, "no ASPI adapters found" );
+        print_error( dvdcss, "no ASPI adapters found" );
         FreeLibrary( hASPI );
         return -1;
     }
 
     if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
     {
-        _dvdcss_error( dvdcss, "unable to initalize aspi layer" );
+        print_error( dvdcss, "unable to initalize aspi layer" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -343,7 +342,7 @@
     i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
     if( i_hostadapters == 0 )
     {
-        _dvdcss_error( dvdcss, "no ASPI adapters ready" );
+        print_error( dvdcss, "no ASPI adapters ready" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -351,7 +350,7 @@
     fd = malloc( sizeof( struct w32_aspidev ) );
     if( fd == NULL )
     {
-        _dvdcss_error( dvdcss, "not enough memory" );
+        print_error( dvdcss, "not enough memory" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -402,7 +401,7 @@
                 {
                     free( (void*) fd );
                     FreeLibrary( hASPI );
-                    _dvdcss_error( dvdcss,"this is not a cdrom drive" );
+                    print_error( dvdcss,"this is not a cdrom drive" );
                     return -1;
                 }
             }
@@ -411,7 +410,7 @@
 
     free( (void*) fd );
     FreeLibrary( hASPI );
-    _dvdcss_error( dvdcss, "unable to get haid and target (aspi)" );
+    print_error( dvdcss, "unable to get haid and target (aspi)" );
     return -1;
 }
 #endif
@@ -429,12 +428,12 @@
         return i_blocks;
     }
 
-    i_seek = lseek( dvdcss->i_read_fd,
-                    (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
+    i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
+    i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET );
 
     if( i_seek < 0 )
     {
-        _dvdcss_error( dvdcss, "seek error" );
+        print_error( dvdcss, "seek error" );
         dvdcss->i_pos = -1;
         return i_seek;
     }
@@ -511,20 +510,20 @@
  *****************************************************************************/
 static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
 {
-    off_t i_ret;
+    off_t i_size, i_ret;
 
-    i_ret = read( dvdcss->i_read_fd, p_buffer,
-                  (off_t)i_blocks * DVDCSS_BLOCK_SIZE );
+    i_size = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
+    i_ret = read( dvdcss->i_read_fd, p_buffer, i_size );
 
     if( i_ret < 0 )
     {
-        _dvdcss_error( dvdcss, "read error" );
+        print_error( dvdcss, "read error" );
         dvdcss->i_pos = -1;
         return i_ret;
     }
 
     /* Handle partial reads */
-    if( i_ret != (off_t)i_blocks * DVDCSS_BLOCK_SIZE )
+    if( i_ret != i_size )
     {
         int i_seek;
 
@@ -667,7 +666,7 @@
         dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
         if( !dvdcss->p_readv_buffer )
         {
-            _dvdcss_error( dvdcss, " failed (readv)" );
+            print_error( dvdcss, " failed (readv)" );
             dvdcss->i_pos = -1;
             return -1;
         }