mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 20:27:23 +00:00
applying css-key cache patch
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7033 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
134caf9023
commit
a695955bd2
@ -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 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
|
||||
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 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
|
||||
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 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
|
||||
/* 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 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
|
||||
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" );
|
||||
|
@ -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 @@ extern dvdcss_t dvdcss_open ( char *psz_target )
|
||||
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 @@ extern dvdcss_t dvdcss_open ( char *psz_target )
|
||||
}
|
||||
}
|
||||
|
||||
if(!dvdcss_cache_dir) dvdcss_cache_dir = getenv( "DVDCSS_CACHE" );
|
||||
|
||||
/*
|
||||
* Open device
|
||||
*/
|
||||
@ -261,6 +266,46 @@ extern dvdcss_t dvdcss_open ( char *psz_target )
|
||||
}
|
||||
#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=§or[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=§or[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;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ struct dvdcss_s
|
||||
int b_ioctls;
|
||||
int b_scrambled;
|
||||
dvd_title_t *p_titles;
|
||||
char * psz_cache;
|
||||
|
||||
/* Error management */
|
||||
char * psz_error;
|
||||
|
Loading…
Reference in New Issue
Block a user