1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
diff -uwr libdvdread-4.2.1/Makefile xbmc/lib/libdvd/libdvdread/Makefile
--- libdvdread-4.2.1/Makefile Wed Dec 31 08:43:04 2008
+++ xbmc/lib/libdvd/libdvdread/Makefile Wed Jan 29 20:43:09 2014
@@ -121,7 +121,7 @@
# Clean targets
clean:
- rm -rf *~ $(.OBJDIR)/* version.h
+ rm -rf *~ $(.OBJDIR)/*
distclean: clean
Only in xbmc/lib/libdvd/libdvdread/: config.h
Only in xbmc/lib/libdvd/libdvdread/: config.mak
Only in xbmc/lib/libdvd/libdvdread/: obj
diff -uwr libdvdread-4.2.1/src/dvd_input.h xbmc/lib/libdvd/libdvdread/src/dvd_input.h
--- libdvdread-4.2.1/src/dvd_input.h Tue Jun 1 18:07:14 2010
+++ xbmc/lib/libdvd/libdvdread/src/dvd_input.h Sun Jan 26 18:36:38 2014
@@ -34,6 +34,13 @@
#if defined( __MINGW32__ )
# undef lseek
# define lseek _lseeki64
+# undef fseeko
+# define fseeko fseeko64
+# undef ftello
+# define ftello ftello64
+# define flockfile(...)
+# define funlockfile(...)
+# define getc_unlocked getc
# undef off_t
# define off_t off64_t
# undef stat
diff -uwr libdvdread-4.2.1/src/dvd_reader.c xbmc/lib/libdvd/libdvdread/src/dvd_reader.c
--- libdvdread-4.2.1/src/dvd_reader.c Sun Mar 17 14:08:06 2013
+++ xbmc/lib/libdvd/libdvdread/src/dvd_reader.c Wed Jan 29 20:48:38 2014
@@ -33,6 +33,11 @@
#include <unistd.h>
#include <limits.h>
#include <dirent.h>
+#ifndef WIN32
+#include <paths.h>
+#endif
+
+#define WITH_CACHE
/* misc win32 helpers */
#ifdef WIN32
@@ -106,6 +111,10 @@
uint32_t lb_start;
uint32_t seek_pos;
+#ifdef WITH_CACHE
+ char cache[DVD_VIDEO_LB_LEN];
+ uint32_t lb_cache;
+#endif
/* Information required for a directory path drive. */
size_t title_sizes[ TITLES_MAX ];
dvd_input_t title_devs[ TITLES_MAX ];
@@ -417,8 +426,9 @@
if( !(path_copy = strdup( path ) ) )
goto DVDOpen_error;
-#ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */
+#if !defined(WIN32) && !defined(_XBMC) /* don't have fchdir, and getcwd( NULL, ... ) is strange */
/* Also WIN32 does not have symlinks, so we don't need this bit of code. */
+ /* XBMC also doesn't need symlink resolution */
/* Resolve any symlinks and get the absolute dir name. */
{
@@ -618,6 +628,10 @@
memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
+#ifdef WITH_CACHE
+ dvd_file->lb_cache = -1;
+#endif
+
return dvd_file;
}
@@ -629,6 +643,18 @@
*/
static int findDirFile( const char *path, const char *file, char *filename )
{
+#if defined(_XBMC)
+ struct stat fileinfo;
+
+ // no emulated opendir function in xbmc, so we'll
+ // check if the file exists by stat'ing it ...
+ sprintf(filename, "%s%s%s", path,
+ ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
+ file );
+
+ if (stat(filename, &fileinfo) == 0) return 0;
+
+#else
DIR *dir;
struct dirent *ent;
@@ -645,6 +671,7 @@
}
}
closedir(dir);
+#endif // _XBMC
return -1;
}
@@ -723,6 +750,9 @@
dvd_file->title_devs[ 0 ] = dev;
dvd_file->filesize = dvd_file->title_sizes[ 0 ];
+#ifdef WITH_CACHE
+ dvd_file->lb_cache = -1;
+#endif
return dvd_file;
}
@@ -750,6 +780,9 @@
memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
+#ifdef WITH_CACHE
+ dvd_file->lb_cache = -1;
+#endif
/* Calculate the complete file size for every file in the VOBS */
if( !menu ) {
int cur;
@@ -793,6 +826,10 @@
memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
dvd_file->filesize = 0;
+#ifdef WITH_CACHE
+ dvd_file->lb_cache = -1;
+#endif
+
if( menu ) {
dvd_input_t dev;
@@ -1204,6 +1241,100 @@
return ret + ret2;
}
+#ifdef WITH_CACHE
+
+/* returns true aslong as the sector isn't all zeros */
+int DVDCheckSector(unsigned char *data, int offset)
+{
+ int i = 0;
+ int32_t *p = (int32_t*)data + (DVD_VIDEO_LB_LEN>>2)*offset;
+ for(;i<(DVD_VIDEO_LB_LEN<<2);i++) {
+ if(*(p+i) != 0)
+ break;
+ }
+ return (i!=(DVD_VIDEO_LB_LEN>>2));
+}
+
+int DVDReadBlocksCached( dvd_file_t *dvd_file, int offset,
+ size_t block_count, unsigned char *data, int encrypted )
+{
+ int ret=0;
+ /* Check arguments. */
+ if( dvd_file == NULL || offset < 0 || data == NULL )
+ return -1;
+
+ if(encrypted & DVDINPUT_READ_DECRYPT) {
+ /* Hack, and it will still fail for multiple opens in a threaded app ! */
+ if( dvd_file->dvd->css_title != dvd_file->css_title ) {
+ dvd_file->dvd->css_title = dvd_file->css_title;
+ if( dvd_file->dvd->isImageFile ) {
+ dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
+ }
+ /* Here each vobu has it's own dvdcss handle, so no need to update
+ else {
+ dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
+ }*/
+ }
+ }
+
+ /* check if first sector is in cache */
+ int cachehit = 0;
+ if( offset == dvd_file->lb_cache ) {
+ memcpy( data, dvd_file->cache, DVD_VIDEO_LB_LEN );
+ block_count--;
+ offset++;
+ data+=DVD_VIDEO_LB_LEN;
+ cachehit = 1;
+ }
+
+
+ if( block_count > 0 )
+ {
+ if( dvd_file->dvd->isImageFile )
+ ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
+ block_count, data, encrypted );
+ else
+ ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
+ block_count, data, encrypted );
+
+ if(ret<0)
+ return ret;
+
+ /* here is a hack for drive wich don't handle layerchange properly */
+ /* they start returning zero data while laser is shifting position */
+ /* normally just doing a reread will get the correct data */
+ if( dvd_file->dvd->isImageFile )
+ {
+ /* check sectors from the back */
+ int count = ret; /* previous call could have returned fewer than requested */
+ int i = count-1;
+ for(;i>=0;i--)
+ if(!DVDCheckSector(data, i)) break;
+
+ if(i>=0) {
+ fprintf( stderr, "libdvdread: potential layer change. %d zero sectors detected starting at %d!\n", i+1, offset);
+
+ /* reread the invalid sectors */
+ count = DVDReadBlocksUDF( dvd_file, (uint32_t)offset+i,
+ count-i, data+DVD_VIDEO_LB_LEN*i, encrypted );
+
+ if(count<0)
+ return count;
+ }
+ }
+
+ }
+
+ if(ret>0)
+ { /* store last sector read into cache */
+ dvd_file->lb_cache = offset+ret-1;
+ memcpy( dvd_file->cache, data+(DVD_VIDEO_LB_LEN*(ret-1)), DVD_VIDEO_LB_LEN );
+ }
+
+ return (ssize_t)(ret+cachehit);
+}
+#endif
+
/* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */
ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
size_t block_count, unsigned char *data )
@@ -1214,6 +1345,10 @@
if( dvd_file == NULL || offset < 0 || data == NULL )
return -1;
+#ifdef WITH_CACHE
+ return (ssize_t)DVDReadBlocksCached( dvd_file, offset, block_count, data, DVDINPUT_READ_DECRYPT );
+#endif
+
/* Hack, and it will still fail for multiple opens in a threaded app ! */
if( dvd_file->dvd->css_title != dvd_file->css_title ) {
dvd_file->dvd->css_title = dvd_file->css_title;
@@ -1296,6 +1431,10 @@
return 0;
}
+#ifdef WITH_CACHE
+ ret = DVDReadBlocksCached( dvd_file, (uint32_t) seek_sector,
+ (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
+#else
if( dvd_file->dvd->isImageFile ) {
ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
(size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
@@ -1303,6 +1442,7 @@
ret = DVDReadBlocksPath( dvd_file, seek_sector,
(size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
}
+#endif
if( ret != (int) numsec ) {
free( secbuf_base );
Only in xbmc/lib/libdvd/libdvdread/: version.h
diff -uwr libdvdread-4.2.1/version.sh xbmc/lib/libdvd/libdvdread/version.sh
--- libdvdread-4.2.1/version.sh Thu May 1 10:27:16 2008
+++ xbmc/lib/libdvd/libdvdread/version.sh Sun Jan 26 19:00:58 2014
@@ -1,18 +1,18 @@
-#!/bin/sh
-
-svn_revision=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2`
-test $svn_revision || svn_revision=`cd "$1" && grep revision .svn/entries 2>/dev/null | \
- cut -d '"' -f2 2> /dev/null`
-test $svn_revision || svn_revision=UNKNOWN
-
-if test "$svn_revision" = UNKNOWN && test -n "$2"; then
- NEW_REVISION="#define VERSION \"$2\""
-else
- NEW_REVISION="#define VERSION \"SVN-r$svn_revision\""
-fi
-OLD_REVISION=`cat version.h 2> /dev/null`
-
-# Update version.h only on revision changes to avoid spurious rebuilds
-if test "$NEW_REVISION" != "$OLD_REVISION"; then
- echo "$NEW_REVISION" > version.h
-fi
+##!/bin/sh
+#
+#svn_revision=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2`
+#test $svn_revision || svn_revision=`cd "$1" && grep revision .svn/entries 2>/dev/null | \
+# cut -d '"' -f2 2> /dev/null`
+#test $svn_revision || svn_revision=UNKNOWN
+#
+#if test "$svn_revision" = UNKNOWN && test -n "$2"; then
+# NEW_REVISION="#define VERSION \"$2\""
+#else
+# NEW_REVISION="#define VERSION \"SVN-r$svn_revision\""
+#fi
+#OLD_REVISION=`cat version.h 2> /dev/null`
+#
+## Update version.h only on revision changes to avoid spurious rebuilds
+#if test "$NEW_REVISION" != "$OLD_REVISION"; then
+# echo "$NEW_REVISION" > version.h
+#fi
|