David Dielsky
2014-10-20 17:10:20 UTC
libdvdcss | branch: master | David Dielsky <***@gmail.com> | Tue Apr 8 23:29:53 2014 +0200| [d14eee3198f9733ea8e68a136ca278d4c7bb598b] | committer: Jean-Baptiste Kempf
Read in advance 50 sectors during CSS key computation, in order to reduce number of read access
src/css.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/css.c b/src/css.c
index 5aeae86..4e1e756 100644
--- a/src/css.c
+++ b/src/css.c
@@ -62,6 +62,7 @@
#include "device.h"
#define PSZ_KEY_SIZE (KEY_SIZE * 3)
+#define BLOCK_BUFFER_SIZE 50
/*****************************************************************************
* Local prototypes
@@ -1498,6 +1499,10 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
i_tries = 0;
i_success = 0;
+ /* Read in advance 50 sectors in a buffer, to reduce the number of read access */
+ int nb_sectors = BLOCK_BUFFER_SIZE;
+ void* p_read_buffer = malloc( nb_sectors * DVDCSS_BLOCK_SIZE );
+
do
{
i_ret = dvdcss->pf_seek( dvdcss, i_pos );
@@ -1507,6 +1512,13 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
print_error( dvdcss, "seek failed" );
}
+ /* every BLOCK_BUFFER_SIZE sectors, read BLOCK_BUFFER_SIZE sectors more */
+ if ( ( i_reads % nb_sectors == 0 ) && p_read_buffer )
+ {
+ dvdcss_read(dvdcss, p_read_buffer, nb_sectors, DVDCSS_NOFLAGS);
+ dvdcss->pf_seek( dvdcss, i_pos );
+ }
+
i_ret = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
/* Either we are at the end of the physical device or the auth
@@ -1585,6 +1597,8 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
print_debug( dvdcss, "end of title reached" );
}
+ free( p_read_buffer );
+
/* Print some statistics. */
print_debug( dvdcss, "successful attempts %d/%d, scrambled blocks %d/%d",
i_success, i_tries, i_encrypted, i_reads );
Read in advance 50 sectors during CSS key computation, in order to reduce number of read access
http://git.videolan.org/gitweb.cgi/libdvdcss.git/?a=commit;h=d14eee3198f9733ea8e68a136ca278d4c7bb598b
---src/css.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/css.c b/src/css.c
index 5aeae86..4e1e756 100644
--- a/src/css.c
+++ b/src/css.c
@@ -62,6 +62,7 @@
#include "device.h"
#define PSZ_KEY_SIZE (KEY_SIZE * 3)
+#define BLOCK_BUFFER_SIZE 50
/*****************************************************************************
* Local prototypes
@@ -1498,6 +1499,10 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
i_tries = 0;
i_success = 0;
+ /* Read in advance 50 sectors in a buffer, to reduce the number of read access */
+ int nb_sectors = BLOCK_BUFFER_SIZE;
+ void* p_read_buffer = malloc( nb_sectors * DVDCSS_BLOCK_SIZE );
+
do
{
i_ret = dvdcss->pf_seek( dvdcss, i_pos );
@@ -1507,6 +1512,13 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
print_error( dvdcss, "seek failed" );
}
+ /* every BLOCK_BUFFER_SIZE sectors, read BLOCK_BUFFER_SIZE sectors more */
+ if ( ( i_reads % nb_sectors == 0 ) && p_read_buffer )
+ {
+ dvdcss_read(dvdcss, p_read_buffer, nb_sectors, DVDCSS_NOFLAGS);
+ dvdcss->pf_seek( dvdcss, i_pos );
+ }
+
i_ret = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
/* Either we are at the end of the physical device or the auth
@@ -1585,6 +1597,8 @@ static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
print_debug( dvdcss, "end of title reached" );
}
+ free( p_read_buffer );
+
/* Print some statistics. */
print_debug( dvdcss, "successful attempts %d/%d, scrambled blocks %d/%d",
i_success, i_tries, i_encrypted, i_reads );