[Mplayer-cvslog] CVS: main/libmpdvdkit2 css.c,1.1,1.2 libdvdcss.c,1.1,1.2 libdvdcss.h,1.1,1.2

Arpi of Ize arpi at mplayerhq.hu
Sat Aug 17 00:46:04 CEST 2002


Update of /cvsroot/mplayer/main/libmpdvdkit2
In directory mail:/var/tmp.root/cvs-serv20047

Modified Files:
	css.c libdvdcss.c libdvdcss.h 
Log Message:
applying css-key cache patch


Index: css.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdvdkit2/css.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- css.c	16 Aug 2002 22:35:45 -0000	1.1
+++ css.c	16 Aug 2002 22:46:01 -0000	1.2
@@ -38,6 +38,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "dvdcss/dvdcss.h"
 
@@ -269,7 +272,8 @@
     dvd_title_t *p_title;
     dvd_title_t *p_newtitle;
     dvd_key_t    p_title_key;
-    int          i_ret;
+    int          i_ret=-1;
+    char* key_file=NULL;
 
     if( ! dvdcss->b_scrambled )
     {
@@ -293,8 +297,24 @@
         return 0;
     }
 
+    /* check teh CSS Key cache, if available: */
+    if(dvdcss->psz_cache){
+	int fd;
+	key_file=malloc(strlen(dvdcss->psz_cache)+12+4);
+	sprintf(key_file,"%s/%0.10x",dvdcss->psz_cache,i_block);
+	if ( (fd=open( key_file,O_RDONLY ) ) > 0 ){
+	    if(read(fd, p_title_key, 5)==5){
+		// success!
+		free(key_file); key_file=NULL;
+		i_ret=1;
+		_dvdcss_debug( dvdcss, "key found in cache" );
+	    }
+	    close(fd);
+	}
+    }
+
     /* Crack or decrypt CSS title key for current VTS */
-    i_ret = _dvdcss_titlekey( dvdcss, i_block, p_title_key );
+    if(i_ret<0) i_ret = _dvdcss_titlekey( dvdcss, i_block, p_title_key );
 
     if( i_ret < 0 )
     {
@@ -307,6 +327,16 @@
         /* Still store this in the cache, so we don't need to check again. */
     }
 
+    /* store in key-cache */
+    if(key_file){
+	int fd;
+	if ( (fd=open( key_file,O_RDWR|O_CREAT|O_EXCL,0644 ) ) > 0 ){
+	    write(fd, p_title_key, 5);
+	    close(fd);
+	}
+	free(key_file);
+    }
+
     /* Find our spot in the list */
     p_newtitle = NULL;
     p_title = dvdcss->p_titles;
@@ -1437,7 +1467,7 @@
         return 1;
     }
 
-    if( i_encrypted == 0 )
+    if( i_encrypted == 0 && i_reads>0 )
     {
         memset( p_titlekey, 0, KEY_SIZE );
         _dvdcss_debug( dvdcss, "file was unscrambled" );

Index: libdvdcss.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdvdkit2/libdvdcss.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- libdvdcss.c	16 Aug 2002 22:35:45 -0000	1.1
+++ libdvdcss.c	16 Aug 2002 22:46:01 -0000	1.2
@@ -117,6 +117,8 @@
  */
 char * dvdcss_interface_2 = VERSION;
 
+char * dvdcss_cache_dir = NULL;
+
 /**
  * \brief Open a DVD device or directory and return a dvdcss instance.
  *
@@ -164,6 +166,7 @@
     dvdcss->i_method = DVDCSS_METHOD_KEY;
     dvdcss->b_debug = 0;
     dvdcss->b_errors = 0;
+    dvdcss->psz_cache = NULL;
 
     /*
      *  Find verbosity from DVDCSS_VERBOSE environment variable
@@ -208,6 +211,8 @@
         }
     }
 
+    if(!dvdcss_cache_dir) dvdcss_cache_dir = getenv( "DVDCSS_CACHE" );
+
     /*
      *  Open device
      */
@@ -260,6 +265,46 @@
         _dvdcss_raw_open( dvdcss, psz_raw_device );
     }
 #endif
+
+    /* if the CACHE is enabled, extract some unique disc ID */
+    if(dvdcss_cache_dir){
+	char* disc_id=NULL;
+	char title_name[64];
+	char sector[DVDCSS_BLOCK_SIZE];
+	// 32768+40  -> disc title (32 uppercase chars)
+	// 32768+813 -> disc manufacturing date + serial no (16 digit number)
+	_dvdcss_seek( dvdcss, 32768/DVDCSS_BLOCK_SIZE);
+	if(_dvdcss_read( dvdcss, sector, 1) == 1){
+	    // check disc title first:
+	    char* title_name=&sector[40];
+	    int i=31;
+	    while(i>=0 && title_name[i]<=32) i--;
+	    title_name[i+1]=0;
+	    if(strlen(title_name)>5){
+		disc_id=strdup(title_name);
+	    } else {
+		// use disc date+serial:
+		title_name=&sector[813];
+		title_name[16]=0;
+	        for ( i=0;i<16;i++ )
+		    if ( ( title_name[i] < '0' )||( title_name[i] > '9' ) ){
+		        disc_id=malloc(16+4);
+	                sprintf( disc_id,"%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X",title_name[0],title_name[1],title_name[2],title_name[3],title_name[4],title_name[5],title_name[6],title_name[7] );
+			break;
+		    }
+		if(!disc_id) disc_id=strdup(title_name);
+	    }
+	    if(disc_id){
+		// yeah, we have a disc name/id, let's set up cache path:
+		char* dir;
+		dvdcss->psz_cache = malloc(strlen(dvdcss_cache_dir)+strlen(disc_id)+4);
+		sprintf(dvdcss->psz_cache,"%s/%s",dvdcss_cache_dir,disc_id);
+		mkdir( dvdcss->psz_cache,493 );
+		free(disc_id);
+		fprintf(stderr,"Using CSS Key-cache dir: %s\n",dvdcss->psz_cache);
+	    }
+	}
+    }
 
     return dvdcss;
 }

Index: libdvdcss.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdvdkit2/libdvdcss.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- libdvdcss.h	16 Aug 2002 22:35:45 -0000	1.1
+++ libdvdcss.h	16 Aug 2002 22:46:01 -0000	1.2
@@ -38,6 +38,7 @@
     int          b_ioctls;
     int          b_scrambled;
     dvd_title_t *p_titles;
+    char *	 psz_cache;
 
     /* Error management */
     char * psz_error;




More information about the MPlayer-cvslog mailing list