diff options
Diffstat (limited to 'lib/libdvd/patches/libdvdcss.diff')
-rw-r--r-- | lib/libdvd/patches/libdvdcss.diff | 354 |
1 files changed, 188 insertions, 166 deletions
diff --git a/lib/libdvd/patches/libdvdcss.diff b/lib/libdvd/patches/libdvdcss.diff index 3c33cda7bc..4e181091b9 100644 --- a/lib/libdvd/patches/libdvdcss.diff +++ b/lib/libdvd/patches/libdvdcss.diff @@ -1,172 +1,194 @@ -diff -uwr ../../libdvdcss-1.2.12/src/device.c lib/libdvd/libdvdcss/src/device.c ---- ../../libdvdcss-1.2.12/src/device.c Sun Mar 11 23:07:48 2012 -+++ lib/libdvd/libdvdcss/src/device.c Tue Jan 28 19:47:56 2014 -@@ -23,6 +23,10 @@ - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - *****************************************************************************/ - -+/* -+ Modifications for XBMC are all contained within WITH_CACHE -+*/ -+ - /***************************************************************************** - * Preamble - *****************************************************************************/ -@@ -521,17 +525,24 @@ - * won't send back the right result). - * (See Microsoft Q241374: Read and Write Access Required for SCSI - * Pass Through Requests) */ -+ -+#ifdef WITH_CACHE -+ DWORD flags = FILE_FLAG_NO_BUFFERING; /* we handle buffering ourself */ -+#else -+ DWORD flags = FILE_FLAG_RANDOM_ACCESS; -+#endif //!WITH_CACHE -+ - dvdcss->i_fd = (int) - CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, -- FILE_FLAG_RANDOM_ACCESS, NULL ); -+ flags, NULL ); - - if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE ) - dvdcss->i_fd = (int) - CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, -- FILE_FLAG_RANDOM_ACCESS, NULL ); -+ flags, NULL ); - - if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE ) - { -@@ -727,6 +738,9 @@ - static int win2k_seek( dvdcss_t dvdcss, int i_blocks ) - { - LARGE_INTEGER li_seek; -+#ifdef WITH_CACHE -+ int iBytesToSkip; -+#endif - - #ifndef INVALID_SET_FILE_POINTER - # define INVALID_SET_FILE_POINTER ((DWORD)-1) -@@ -738,6 +752,28 @@ - return i_blocks; - } - -+#ifdef WITH_CACHE -+ -+ // if our buffer contains the position which we want to seek too, we can -+ // just decrease dwCacheBufferSize -+ iBytesToSkip = (i_blocks - dvdcss->i_pos) * DVDCSS_BLOCK_SIZE; -+ if (iBytesToSkip > 0 && iBytesToSkip < dvdcss->buffer_size) -+ { -+ dvdcss->buffer_size -= iBytesToSkip; -+ dvdcss->i_pos = i_blocks; -+ return dvdcss->i_pos; -+ } -+ else if (iBytesToSkip < 0 && (DISC_CACHE_SIZE - dvdcss->buffer_size) >= -iBytesToSkip) -+ { -+ // we want to seek backwards, and we have enough old data in our buffer -+ dvdcss->buffer_size -= iBytesToSkip; // since iBytesToSkip is negative, dwCacheBufferSize will get bigger -+ dvdcss->i_pos = i_blocks; -+ return dvdcss->i_pos; -+ } -+ else dvdcss->buffer_size = 0; -+ -+#endif -+ - li_seek.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE; - - li_seek.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd, -@@ -827,6 +863,66 @@ - { - int i_bytes; - -+#ifdef WITH_CACHE -+ -+ if (dvdcss->buffer_size < i_blocks * DVDCSS_BLOCK_SIZE) -+ { -+ // we don't have enough data in our buffer -+ int iRemaining = i_blocks * DVDCSS_BLOCK_SIZE; -+ int iCopied = 0; -+ // copy data we already have and read again into the cache -+ if (dvdcss->buffer_size > 0) memcpy(p_buffer, dvdcss->buffer + (DISC_CACHE_SIZE - dvdcss->buffer_size), dvdcss->buffer_size); -+ iCopied = dvdcss->buffer_size; -+ iRemaining -= dvdcss->buffer_size; -+ (BYTE*)p_buffer += iCopied; -+ dvdcss->buffer_size = 0; -+ -+ // if remaining size is bigger >= DISC_CACHE_SIZE, don't cache it. Just read -+ if (iRemaining >= DISC_CACHE_SIZE) -+ { -+ if (!ReadFile((HANDLE)dvdcss->i_fd, p_buffer, iRemaining, (LPDWORD)&i_bytes, NULL)) -+ { -+ dvdcss->i_pos = -1; -+ return -1; -+ } -+ dvdcss->i_pos += (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE; -+ return (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE; -+ } -+ else -+ { -+ // read a chunk into the cache and copy the needed bytes into p_buffer -+ if (!ReadFile((HANDLE)dvdcss->i_fd, dvdcss->buffer, DISC_CACHE_SIZE, &dvdcss->buffer_size, NULL)) -+ { -+ // read error, maybe we tried to read to much. Try again but now without cache -+ if (!ReadFile((HANDLE)dvdcss->i_fd, p_buffer, iRemaining, (LPDWORD)&i_bytes, NULL)) -+ { -+ dvdcss->i_pos = -1; -+ return -1; -+ } -+ dvdcss->i_pos += (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE; -+ return (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE; -+ } -+ // copy bytes into the buffer -+ memcpy(p_buffer, dvdcss->buffer, iRemaining); -+ dvdcss->buffer_size -= iRemaining; -+ dvdcss->i_pos += (iRemaining + iCopied) / DVDCSS_BLOCK_SIZE; -+ return (iRemaining + iCopied) / DVDCSS_BLOCK_SIZE; -+ } -+ } -+ else -+ { -+ // we have enough data in our cache, just copy it -+ memcpy(p_buffer, dvdcss->buffer + (DISC_CACHE_SIZE - dvdcss->buffer_size), i_blocks * DVDCSS_BLOCK_SIZE); -+ dvdcss->buffer_size -= i_blocks * DVDCSS_BLOCK_SIZE; -+ dvdcss->i_pos += i_blocks; -+ return i_blocks; -+ } -+ -+ dvdcss->i_pos = -1; -+ return -1; -+ -+#else // WITH_CACHE -+ - if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer, - i_blocks * DVDCSS_BLOCK_SIZE, - (LPDWORD)&i_bytes, NULL ) ) -@@ -837,6 +933,7 @@ - - dvdcss->i_pos += i_bytes / DVDCSS_BLOCK_SIZE; - return i_bytes / DVDCSS_BLOCK_SIZE; -+#endif // WITH_CACHE - } - - static int aspi_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks ) -Only in lib/libdvd/libdvdcss/src/: device.lo -Only in lib/libdvd/libdvdcss/src/: device.o -Only in lib/libdvd/libdvdcss/src/dvdcss: Makefile -diff -uwr ../../libdvdcss-1.2.12/src/libdvdcss.c lib/libdvd/libdvdcss/src/libdvdcss.c ---- ../../libdvdcss-1.2.12/src/libdvdcss.c Sun Mar 11 23:07:48 2012 -+++ lib/libdvd/libdvdcss/src/libdvdcss.c Tue Jan 28 19:47:05 2014 +Only in lib/libdvd/libdvdcss/: .libs +diff -uwr ../libdvdcss-1.2.13/Makefile.am lib/libdvd/libdvdcss/Makefile.am +--- ../libdvdcss-1.2.13/Makefile.am Wed Feb 27 10:05:36 2013 ++++ lib/libdvd/libdvdcss/Makefile.am Sat Feb 1 22:41:19 2014 +@@ -4,13 +4,7 @@ +
+ dist_doc_DATA = AUTHORS COPYING NEWS README ChangeLog
+
+-DISTCLEANFILES = ChangeLog
+-
+-ChangeLog: $(wildcard $(srcdir)/.git/logs/HEAD)
+- -cd $(srcdir) && git log > $(abs_builddir)/$(@)-tmp
+- test -s $(@)-tmp && mv $(@)-tmp $(@)
+- -rm -f $(@)-tmp
+- test -e $(@) || touch $(@)
++DISTCLEANFILES =
+
+ lib_LTLIBRARIES = libdvdcss.la
+ EXTRA_PROGRAMS = csstest dvd_region
+diff -uwr ../libdvdcss-1.2.13/src/device.c lib/libdvd/libdvdcss/src/device.c +--- ../libdvdcss-1.2.13/src/device.c Wed Feb 27 10:05:36 2013 ++++ lib/libdvd/libdvdcss/src/device.c Sat Feb 1 19:41:54 2014 +@@ -22,6 +22,10 @@ + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *****************************************************************************/
+
++/*
++ Modifications for XBMC are all contained within WITH_CACHE
++*/
++
+ /*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+@@ -509,17 +513,24 @@ + * won't send back the right result).
+ * (See Microsoft Q241374: Read and Write Access Required for SCSI
+ * Pass Through Requests) */
++
++#ifdef WITH_CACHE
++ DWORD flags = FILE_FLAG_NO_BUFFERING; /* we handle buffering ourself */
++#else
++ DWORD flags = FILE_FLAG_RANDOM_ACCESS;
++#endif //!WITH_CACHE
++
+ dvdcss->i_fd = (int)
+ CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING,
+- FILE_FLAG_RANDOM_ACCESS, NULL );
++ flags, NULL );
+
+ if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
+ dvdcss->i_fd = (int)
+ CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING,
+- FILE_FLAG_RANDOM_ACCESS, NULL );
++ flags, NULL );
+
+ if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
+ {
+@@ -714,6 +725,9 @@ + static int win2k_seek( dvdcss_t dvdcss, int i_blocks )
+ {
+ LARGE_INTEGER li_seek;
++#ifdef WITH_CACHE
++ int iBytesToSkip;
++#endif
+
+ #ifndef INVALID_SET_FILE_POINTER
+ # define INVALID_SET_FILE_POINTER ((DWORD)-1)
+@@ -725,6 +739,28 @@ + return i_blocks;
+ }
+
++#ifdef WITH_CACHE
++
++ // if our buffer contains the position which we want to seek too, we can
++ // just decrease dwCacheBufferSize
++ iBytesToSkip = (i_blocks - dvdcss->i_pos) * DVDCSS_BLOCK_SIZE;
++ if (iBytesToSkip > 0 && iBytesToSkip < dvdcss->buffer_size)
++ {
++ dvdcss->buffer_size -= iBytesToSkip;
++ dvdcss->i_pos = i_blocks;
++ return dvdcss->i_pos;
++ }
++ else if (iBytesToSkip < 0 && (DISC_CACHE_SIZE - dvdcss->buffer_size) >= -iBytesToSkip)
++ {
++ // we want to seek backwards, and we have enough old data in our buffer
++ dvdcss->buffer_size -= iBytesToSkip; // since iBytesToSkip is negative, dwCacheBufferSize will get bigger
++ dvdcss->i_pos = i_blocks;
++ return dvdcss->i_pos;
++ }
++ else dvdcss->buffer_size = 0;
++
++#endif
++
+ li_seek.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE;
+
+ li_seek.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd,
+@@ -814,6 +850,66 @@ + {
+ int i_bytes;
+
++#ifdef WITH_CACHE
++
++ if (dvdcss->buffer_size < i_blocks * DVDCSS_BLOCK_SIZE)
++ {
++ // we don't have enough data in our buffer
++ int iRemaining = i_blocks * DVDCSS_BLOCK_SIZE;
++ int iCopied = 0;
++ // copy data we already have and read again into the cache
++ if (dvdcss->buffer_size > 0) memcpy(p_buffer, dvdcss->buffer + (DISC_CACHE_SIZE - dvdcss->buffer_size), dvdcss->buffer_size);
++ iCopied = dvdcss->buffer_size;
++ iRemaining -= dvdcss->buffer_size;
++ (BYTE*)p_buffer += iCopied;
++ dvdcss->buffer_size = 0;
++
++ // if remaining size is bigger >= DISC_CACHE_SIZE, don't cache it. Just read
++ if (iRemaining >= DISC_CACHE_SIZE)
++ {
++ if (!ReadFile((HANDLE)dvdcss->i_fd, p_buffer, iRemaining, (LPDWORD)&i_bytes, NULL))
++ {
++ dvdcss->i_pos = -1;
++ return -1;
++ }
++ dvdcss->i_pos += (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE;
++ return (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE;
++ }
++ else
++ {
++ // read a chunk into the cache and copy the needed bytes into p_buffer
++ if (!ReadFile((HANDLE)dvdcss->i_fd, dvdcss->buffer, DISC_CACHE_SIZE, &dvdcss->buffer_size, NULL))
++ {
++ // read error, maybe we tried to read to much. Try again but now without cache
++ if (!ReadFile((HANDLE)dvdcss->i_fd, p_buffer, iRemaining, (LPDWORD)&i_bytes, NULL))
++ {
++ dvdcss->i_pos = -1;
++ return -1;
++ }
++ dvdcss->i_pos += (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE;
++ return (i_bytes + iCopied) / DVDCSS_BLOCK_SIZE;
++ }
++ // copy bytes into the buffer
++ memcpy(p_buffer, dvdcss->buffer, iRemaining);
++ dvdcss->buffer_size -= iRemaining;
++ dvdcss->i_pos += (iRemaining + iCopied) / DVDCSS_BLOCK_SIZE;
++ return (iRemaining + iCopied) / DVDCSS_BLOCK_SIZE;
++ }
++ }
++ else
++ {
++ // we have enough data in our cache, just copy it
++ memcpy(p_buffer, dvdcss->buffer + (DISC_CACHE_SIZE - dvdcss->buffer_size), i_blocks * DVDCSS_BLOCK_SIZE);
++ dvdcss->buffer_size -= i_blocks * DVDCSS_BLOCK_SIZE;
++ dvdcss->i_pos += i_blocks;
++ return i_blocks;
++ }
++
++ dvdcss->i_pos = -1;
++ return -1;
++
++#else // WITH_CACHE
++
+ if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer,
+ i_blocks * DVDCSS_BLOCK_SIZE,
+ (LPDWORD)&i_bytes, NULL ) )
+@@ -824,6 +920,7 @@ +
+ dvdcss->i_pos += i_bytes / DVDCSS_BLOCK_SIZE;
+ return i_bytes / DVDCSS_BLOCK_SIZE;
++#endif // WITH_CACHE
+ }
+
+ static int aspi_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
+Only in lib/libdvd/libdvdcss/src: device.lo +Only in lib/libdvd/libdvdcss/src: device.o +Only in lib/libdvd/libdvdcss/src: error.lo +Only in lib/libdvd/libdvdcss/src: error.o +Only in lib/libdvd/libdvdcss/src: ioctl.lo +Only in lib/libdvd/libdvdcss/src: ioctl.o +diff -uwr ../libdvdcss-1.2.13/src/libdvdcss.c lib/libdvd/libdvdcss/src/libdvdcss.c +--- ../libdvdcss-1.2.13/src/libdvdcss.c Tue Feb 26 08:08:36 2013 ++++ lib/libdvd/libdvdcss/src/libdvdcss.c Sat Feb 1 18:37:25 2014 @@ -195,6 +195,10 @@ dvdcss->b_debug = 0; dvdcss->b_errors = 0; -+#ifdef WITH_CACHE -+ dvdcss->buffer_size = 0; -+#endif -+ ++#ifdef WITH_CACHE
++ dvdcss->buffer_size = 0;
++#endif
++
/* * Find verbosity from DVDCSS_VERBOSE environment variable */ @@ -175,7 +197,7 @@ diff -uwr ../../libdvdcss-1.2.12/src/libdvdcss.c lib/libdvd/libdvdcss/src/libdvd } } - -+ /* if wo don't have b_ioctls, we don't have a disk key, make sure area is nulled */ ++ /* if wo don't have b_ioctls, we don't have a disk key, make sure area is nulled */
memset( dvdcss->css.p_disc_key, 0, KEY_SIZE ); /* If disc is CSS protected and the ioctls work, authenticate the drive */ if( dvdcss->b_scrambled && dvdcss->b_ioctls ) |