diff options
author | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-08-16 22:46:01 +0000 |
---|---|---|
committer | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-08-16 22:46:01 +0000 |
commit | a695955bd29a2691bf5e918d2e4716d58299b0cb (patch) | |
tree | c7df6cff274ed1025ca8f37775ae0afcc8335d34 /libmpdvdkit2/css.c | |
parent | 134caf90233ebfb7de946fa323ac2dba1ed5db4d (diff) | |
download | mpv-a695955bd29a2691bf5e918d2e4716d58299b0cb.tar.bz2 mpv-a695955bd29a2691bf5e918d2e4716d58299b0cb.tar.xz |
applying css-key cache patch
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7033 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdvdkit2/css.c')
-rw-r--r-- | libmpdvdkit2/css.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/libmpdvdkit2/css.c b/libmpdvdkit2/css.c index 580719b190..156eab0c98 100644 --- a/libmpdvdkit2/css.c +++ b/libmpdvdkit2/css.c @@ -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" ); |