]> git.sesse.net Git - vlc/blobdiff - extras/libdvdcss/libdvdcss.c
*With DVDCSS_METHOD=disc or key, the keys are no longer buffered on start.
[vlc] / extras / libdvdcss / libdvdcss.c
index 947c1e945559a2b036053cd051ea2b379c24f5dc..638fb8c0b4ddc975c9f9c3c5701f7a0dea087d80 100644 (file)
@@ -2,7 +2,7 @@
  * libdvdcss.c: DVD reading library.
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.c,v 1.24 2001/11/27 10:18:33 massiot Exp $
+ * $Id: libdvdcss.c,v 1.27 2002/01/14 22:06:57 stef Exp $
  *
  * Authors: Stéphane Borel <stef@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -26,8 +26,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -35,6 +33,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#include <videolan/vlc.h>
+
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
@@ -45,9 +45,6 @@
 #   include <sys/uio.h>                                      /* struct iovec */
 #endif
 
-#include "config.h"
-#include "common.h"
-
 #if defined( WIN32 )
 #   include "input_iovec.h"
 #endif
@@ -187,6 +184,8 @@ extern dvdcss_handle dvdcss_open ( char *psz_target )
         }
     }
 
+    memset( dvdcss->css.p_unenc_key, 0, KEY_SIZE );
+
 #ifndef WIN32
     if( psz_raw_device != NULL )
     {
@@ -212,8 +211,25 @@ extern int dvdcss_seek ( dvdcss_handle 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 )
-             && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) 
-       || ( i_flags & DVDCSS_SEEK_KEY ) )
+             && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) )
+    {
+        int     i_ret;
+
+        /* Crack or decrypt CSS title key for current VTS */
+        i_ret = CSSGetTitleKey( dvdcss, i_blocks );
+
+        if( i_ret < 0 )
+        {
+            _dvdcss_error( dvdcss, "fatal error in vts css key" );
+            return i_ret;
+        }
+        else if( i_ret > 0 )
+        {
+            _dvdcss_error( dvdcss, "decryption unavailable" );
+            return -1;
+        }
+    }
+    else if( i_flags & DVDCSS_SEEK_KEY )
     {
         /* check the title key */
         if( dvdcss_title( dvdcss, i_blocks ) )