]> git.sesse.net Git - vlc/blobdiff - extras/libdvdcss/libdvdcss.c
* Fixed a Win32 bug in libdvdcss. This bug was appearing on title change.
[vlc] / extras / libdvdcss / libdvdcss.c
index afb68ec0aca9f59939d4fd81f1c701f03d5a7222..30b037f43ae8b41fb2bb9428a7eedde76b0f36bf 100644 (file)
@@ -2,7 +2,7 @@
  * libdvdcss.c: DVD reading library.
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.c,v 1.9 2001/07/25 08:41:21 gbazin Exp $
+ * $Id: libdvdcss.c,v 1.13 2001/07/30 18:56:35 gbazin Exp $
  *
  * Authors: Stéphane Borel <stef@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -38,8 +38,7 @@
 #endif
 
 #if defined( WIN32 )
-#   include <io.h>
-#   include "input_iovec.h"
+#   include <io.h>                                                 /* read() */
 #else
 #   include <sys/uio.h>                                      /* struct iovec */
 #endif
 #include "config.h"
 #include "common.h"
 
+#if defined( WIN32 )
+#   include "input_iovec.h"
+#endif
+
 #include "videolan/dvdcss.h"
 #include "libdvdcss.h"
 #include "ioctl.h"
@@ -150,9 +153,9 @@ extern int dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
 }
 
 /*****************************************************************************
- * dvdcss_crack: crack the current title key
+ * dvdcss_title: crack the current title key if needed
  *****************************************************************************/
-extern int dvdcss_crack ( dvdcss_handle dvdcss, int i_block )
+extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
 {
     dvd_title_t *p_title;
     dvd_key_t p_key;
@@ -163,6 +166,8 @@ extern int dvdcss_crack ( dvdcss_handle dvdcss, int i_block )
         return 0;
     }
 
+    //fprintf( stderr, "looking for a key for offset %i\n", i_block );
+
     /* Check if we've already cracked this key */
     p_title = dvdcss->p_titles;
     while( p_title != NULL
@@ -193,6 +198,9 @@ extern int dvdcss_crack ( dvdcss_handle dvdcss, int i_block )
         return -1;
     }
 
+    //fprintf( stderr, "cracked key is %.2x %.2x %.2x %.2x %.2x\n",
+    //         p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );
+
     /* Add key to keytable if it isn't empty */
     if( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] )
     {
@@ -255,7 +263,7 @@ extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
     p_title = dvdcss->p_titles;
     while( p_title != NULL
             && p_title->p_next
-            && p_title->p_next->i_startlb < dvdcss->i_seekpos )
+            && p_title->p_next->i_startlb <= dvdcss->i_seekpos )
     {
         p_title = p_title->p_next;
     }
@@ -303,7 +311,7 @@ extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
     p_title = dvdcss->p_titles;
     while( p_title != NULL
             && p_title->p_next != NULL
-            && p_title->p_next->i_startlb < dvdcss->i_seekpos )
+            && p_title->p_next->i_startlb <= dvdcss->i_seekpos )
     {
         p_title = p_title->p_next;
     }
@@ -452,6 +460,8 @@ static int _dvdcss_close ( dvdcss_handle dvdcss )
 static int _dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
 {
 #if defined( WIN32 )
+    dvdcss->i_seekpos = i_blocks;
+
     if( WIN2K )
     {
         LARGE_INTEGER li_read;
@@ -802,7 +812,7 @@ static int _win32_dvdcss_aread( int i_fd, void *p_data, int i_blocks )
 
         /* transfer the next 64kb (_win32_dvdcss_aread is called recursively)
          * We need to check the status of the read on return */
-        if( _win32_dvdcss_aread( i_fd, p_data + 32 * DVDCSS_BLOCK_SIZE,
+        if( _win32_dvdcss_aread( i_fd, (u8*) p_data + 32 * DVDCSS_BLOCK_SIZE,
                                  i_blocks - 32) < 0 )
         {
             return -1;