Mercurial > mplayer.hg
annotate libmpdvdkit2/libdvdcss.c @ 15592:aadde9ec9058
Add a variable for the codec directory and set it to /usr/lib/codecs instead
of the old /usr/lib/win32.
author | diego |
---|---|
date | Sun, 29 May 2005 23:33:13 +0000 |
parents | c2ddedd0619e |
children | 954cdf2171f6 |
rev | line source |
---|---|
7027 | 1 /* libdvdcss.c: DVD reading library. |
2 * | |
3 * Authors: Stéphane Borel <stef@via.ecp.fr> | |
4 * Samuel Hocevar <sam@zoy.org> | |
5 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
6 * | |
7 * Copyright (C) 1998-2002 VideoLAN | |
14860
c2ddedd0619e
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
13097
diff
changeset
|
8 * |
c2ddedd0619e
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
13097
diff
changeset
|
9 * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff. |
c2ddedd0619e
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
13097
diff
changeset
|
10 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
7027 | 11 * $Id$ |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
17 * |
7027 | 18 * This program is distributed in the hope that it will be useful, |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
26 */ | |
27 | |
13097 | 28 /* |
7027 | 29 * \mainpage libdvdcss developer documentation |
30 * | |
31 * \section intro Introduction | |
32 * | |
33 * \e libdvdcss is a simple library designed for accessing DVDs like a block | |
34 * device without having to bother about the decryption. The important features | |
35 * are: | |
36 * \li portability: currently supported platforms are GNU/Linux, FreeBSD, | |
37 * NetBSD, OpenBSD, BSD/OS, BeOS, Windows 95/98, Windows NT/2000, MacOS X, | |
38 * Solaris, HP-UX and OS/2. | |
39 * \li adaptability: unlike most similar projects, libdvdcss doesn't require | |
40 * the region of your drive to be set and will try its best to read from | |
41 * the disc even in the case of a region mismatch. | |
42 * \li simplicity: a DVD player can be built around the \e libdvdcss API using | |
43 * no more than 4 or 5 library calls. | |
44 * | |
45 * \e libdvdcss is free software, released under the General Public License. | |
46 * This ensures that \e libdvdcss remains free and used only with free | |
47 * software. | |
48 * | |
49 * \section api The libdvdcss API | |
50 * | |
51 * The complete \e libdvdcss programming interface is documented in the | |
52 * dvdcss.h file. | |
53 * | |
54 * \section env Environment variables | |
55 * | |
56 * Some environment variables can be used to change the behaviour of | |
57 * \e libdvdcss without having to modify the program which uses it. These | |
58 * variables are: | |
59 * | |
60 * \li \b DVDCSS_VERBOSE: sets the verbosity level. | |
61 * - \c 0 outputs no messages at all. | |
62 * - \c 1 outputs error messages to stderr. | |
63 * - \c 2 outputs error messages and debug messages to stderr. | |
64 * | |
65 * \li \b DVDCSS_METHOD: sets the authentication and decryption method | |
66 * that \e libdvdcss will use to read scrambled discs. Can be one | |
67 * of \c title, \c key or \c disc. | |
68 * - \c key is the default method. \e libdvdcss will use a set of | |
69 * calculated player keys to try and get the disc key. This can fail | |
70 * if the drive does not recognize any of the player keys. | |
71 * - \c disc is a fallback method when \c key has failed. Instead of | |
72 * using player keys, \e libdvdcss will crack the disc key using | |
73 * a brute force algorithm. This process is CPU intensive and requires | |
74 * 64 MB of memory to store temporary data. | |
75 * - \c title is the fallback when all other methods have failed. It does | |
76 * not rely on a key exchange with the DVD drive, but rather uses a | |
77 * crypto attack to guess the title key. On rare cases this may fail | |
78 * because there is not enough encrypted data on the disc to perform | |
79 * a statistical attack, but in the other hand it is the only way to | |
80 * decrypt a DVD stored on a hard disc, or a DVD with the wrong region | |
81 * on an RPC2 drive. | |
82 * | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
83 * \li \b DVDCSS_RAW_DEVICE: specify the raw device to use. Exact usage will |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
84 * depend on your operating system, the Linux utility to set up raw devices |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
85 * is \c raw(8) for instance. Please note that on most operating systems, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
86 * using a raw device requires highly aligned buffers: Linux requires a |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
87 * 2048 bytes alignment (which is the size of a DVD sector). |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
88 * |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
89 * \li \b DVDCSS_CACHE: specify a directory in which to store title key |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
90 * values. This will speed up descrambling of DVDs which are in the |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
91 * cache. The DVDCSS_CACHE directory is created if it does not exist, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
92 * and a subdirectory is created named after the DVD's title or |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
93 * manufacturing date. |
7027 | 94 */ |
95 | |
96 /* | |
97 * Preamble | |
98 */ | |
99 #include "config.h" | |
100 | |
101 #include <stdio.h> | |
102 #include <stdlib.h> | |
103 #include <string.h> | |
104 #include <sys/types.h> | |
105 #include <sys/stat.h> | |
106 #include <fcntl.h> | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
107 #include <errno.h> |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
108 #include <unistd.h> |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
109 #include <limits.h> |
7027 | 110 |
7033 | 111 #include "dvdcss.h" |
7027 | 112 |
113 #include "common.h" | |
114 #include "css.h" | |
115 #include "libdvdcss.h" | |
116 #include "ioctl.h" | |
117 #include "device.h" | |
118 | |
9882 | 119 #ifndef HAVE_MPLAYER |
120 #include "get_path.c" | |
121 #else | |
122 extern char * get_path( char * filename ); | |
123 #endif | |
124 | |
7027 | 125 /** |
126 * \brief Symbol for version checks. | |
127 * | |
128 * The name of this symbol contains the library major number, which makes it | |
129 * easy to check which \e libdvdcss development headers are installed on the | |
130 * system with tools such as autoconf. | |
131 * | |
132 * The variable itself contains the exact version number of the library, | |
133 * which can be useful for specific feature needs. | |
134 */ | |
135 char * dvdcss_interface_2 = VERSION; | |
136 | |
137 /** | |
138 * \brief Open a DVD device or directory and return a dvdcss instance. | |
139 * | |
140 * \param psz_target a string containing the target name, for instance | |
141 * "/dev/hdc" or "E:". | |
142 * \return a handle to a dvdcss instance or NULL on error. | |
143 * | |
144 * Initialize the \e libdvdcss library and open the requested DVD device or | |
145 * directory. \e libdvdcss checks whether ioctls can be performed on the disc, | |
146 * and when possible, the disc key is retrieved. | |
147 * | |
148 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss | |
149 * calls. If an error occured, NULL is returned. | |
150 */ | |
151 extern dvdcss_t dvdcss_open ( char *psz_target ) | |
152 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
153 char psz_buffer[PATH_MAX]; |
7027 | 154 int i_ret; |
155 | |
156 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
157 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
158 char *psz_cache = getenv( "DVDCSS_CACHE" ); |
7027 | 159 #ifndef WIN32 |
160 char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" ); | |
161 #endif | |
162 | |
163 dvdcss_t dvdcss; | |
164 | |
165 /* | |
166 * Allocate the library structure | |
167 */ | |
168 dvdcss = malloc( sizeof( struct dvdcss_s ) ); | |
169 if( dvdcss == NULL ) | |
170 { | |
171 return NULL; | |
172 } | |
173 | |
174 /* | |
175 * Initialize structure with default values | |
176 */ | |
177 #ifndef WIN32 | |
178 dvdcss->i_raw_fd = -1; | |
179 #endif | |
180 dvdcss->p_titles = NULL; | |
181 dvdcss->psz_device = (char *)strdup( psz_target ); | |
182 dvdcss->psz_error = "no error"; | |
183 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
184 dvdcss->psz_cachefile[0] = '\0'; |
7027 | 185 dvdcss->b_debug = 0; |
186 dvdcss->b_errors = 0; | |
187 | |
188 /* | |
189 * Find verbosity from DVDCSS_VERBOSE environment variable | |
190 */ | |
191 if( psz_verbose != NULL ) | |
192 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
193 int i = atoi( psz_verbose ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
194 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
195 if( i >= 2 ) dvdcss->b_debug = 1; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
196 if( i >= 1 ) dvdcss->b_errors = 1; |
7027 | 197 } |
198 | |
199 /* | |
200 * Find method from DVDCSS_METHOD environment variable | |
201 */ | |
202 if( psz_method != NULL ) | |
203 { | |
204 if( !strncmp( psz_method, "key", 4 ) ) | |
205 { | |
206 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
207 } | |
208 else if( !strncmp( psz_method, "disc", 5 ) ) | |
209 { | |
210 dvdcss->i_method = DVDCSS_METHOD_DISC; | |
211 } | |
212 else if( !strncmp( psz_method, "title", 5 ) ) | |
213 { | |
214 dvdcss->i_method = DVDCSS_METHOD_TITLE; | |
215 } | |
216 else | |
217 { | |
218 _dvdcss_error( dvdcss, "unknown decrypt method, please choose " | |
219 "from 'title', 'key' or 'disc'" ); | |
220 free( dvdcss->psz_device ); | |
221 free( dvdcss ); | |
222 return NULL; | |
223 } | |
224 } | |
225 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
226 /* |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
227 * Find cache dir from the DVDCSS_CACHE environment variable |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
228 */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
229 if( psz_cache != NULL ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
230 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
231 if( psz_cache[0] == '\0' ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
232 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
233 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
234 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
235 /* Check that we can add the ID directory and the block filename */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
236 else if( strlen( psz_cache ) + 1 + 32 + 1 + 10 + 1 > PATH_MAX ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
237 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
238 _dvdcss_error( dvdcss, "cache directory name is too long" ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
239 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
240 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
241 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
242 else psz_cache = get_path( "DVDKeys" ); |
7032 | 243 |
7027 | 244 /* |
245 * Open device | |
246 */ | |
247 i_ret = _dvdcss_open( dvdcss ); | |
248 if( i_ret < 0 ) | |
249 { | |
250 free( dvdcss->psz_device ); | |
251 free( dvdcss ); | |
252 return NULL; | |
253 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
254 |
7027 | 255 dvdcss->b_scrambled = 1; /* Assume the worst */ |
256 dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss ); | |
257 | |
258 if( dvdcss->b_ioctls ) | |
259 { | |
260 i_ret = _dvdcss_test( dvdcss ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
261 if( i_ret < 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
262 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
263 /* Disable the CSS ioctls and hope that it works? */ |
7027 | 264 _dvdcss_debug( dvdcss, |
265 "could not check whether the disc was scrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
266 dvdcss->b_ioctls = 0; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
267 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
268 else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
269 { |
7027 | 270 _dvdcss_debug( dvdcss, i_ret ? "disc is scrambled" |
271 : "disc is unscrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
272 dvdcss->b_scrambled = i_ret; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
273 } |
7027 | 274 } |
275 | |
276 /* If disc is CSS protected and the ioctls work, authenticate the drive */ | |
277 if( dvdcss->b_scrambled && dvdcss->b_ioctls ) | |
278 { | |
279 i_ret = _dvdcss_disckey( dvdcss ); | |
280 | |
281 if( i_ret < 0 ) | |
282 { | |
283 _dvdcss_close( dvdcss ); | |
284 free( dvdcss->psz_device ); | |
285 free( dvdcss ); | |
286 return NULL; | |
287 } | |
288 } | |
289 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
290 /* If the cache is enabled, extract a unique disc ID */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
291 if( psz_cache ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
292 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
293 uint8_t p_sector[DVDCSS_BLOCK_SIZE]; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
294 unsigned char psz_debug[PATH_MAX+30]; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
295 unsigned char * psz_title, * psz_serial; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
296 int i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
297 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
298 /* We read sector 0. If it starts with 0x000001ba (BE), we are |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
299 * reading a VOB file, and we should not cache anything. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
300 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
301 i_ret = dvdcss->pf_seek( dvdcss, 0 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
302 if( i_ret != 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
303 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
304 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
305 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
306 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
307 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
308 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
309 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
310 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
311 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
312 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
313 if( p_sector[0] == 0x00 && p_sector[1] == 0x00 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
314 && p_sector[2] == 0x01 && p_sector[3] == 0xba ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
315 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
316 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
317 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
318 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
319 /* The data we are looking for is at sector 16 (32768 bytes): |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
320 * - offset 40: disc title (32 uppercase chars) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
321 * - offset 813: manufacturing date + serial no (16 digits) */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
322 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
323 i_ret = dvdcss->pf_seek( dvdcss, 16 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
324 if( i_ret != 16 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
325 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
326 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
327 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
328 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
329 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
330 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
331 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
332 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
333 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
334 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
335 /* Get the disc title */ |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
336 psz_title = p_sector + 40; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
337 psz_title[32] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
338 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
339 for( i = 0 ; i < 32 ; i++ ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
340 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
341 if( psz_title[i] <= ' ' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
342 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
343 psz_title[i] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
344 break; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
345 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
346 else if( psz_title[i] == '/' || psz_title[i] == '\\' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
347 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
348 psz_title[i] = '-'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
349 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
350 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
351 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
352 /* Get the date + serial */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
353 psz_serial = p_sector + 813; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
354 psz_serial[16] = '\0'; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
355 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
356 /* Check that all characters are digits, otherwise convert. */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
357 for( i = 0 ; i < 16 ; i++ ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
358 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
359 if( psz_serial[i] < '0' || psz_serial[i] > '9' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
360 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
361 sprintf( psz_serial, |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
362 "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
363 psz_serial[0], psz_serial[1], psz_serial[2], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
364 psz_serial[3], psz_serial[4], psz_serial[5], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
365 psz_serial[6], psz_serial[7] ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
366 break; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
367 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
368 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
369 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
370 /* We have a disc name or ID, we can create the cache dir */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
371 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
372 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
373 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
374 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
375 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
376 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
377 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
378 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
379 _dvdcss_error( dvdcss, "failed creating cache directory" ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
380 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
381 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
382 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
383 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
384 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
385 // i += sprintf( dvdcss->psz_cachefile + i, "/%s", psz_data ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
386 i += sprintf( dvdcss->psz_cachefile + i, "/%s#%s", psz_title, psz_serial ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
387 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
388 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
389 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
390 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
391 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
392 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
393 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
394 _dvdcss_error( dvdcss, "failed creating cache subdirectory" ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
395 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
396 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
397 } |
9882 | 398 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
399 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
400 /* Pointer to the filename we will use. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
401 dvdcss->psz_block = dvdcss->psz_cachefile + i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
402 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
403 sprintf( psz_debug, "using CSS key cache dir: %s", |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
404 dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
405 _dvdcss_debug( dvdcss, psz_debug ); |
7032 | 406 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
407 nocache: |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
408 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
409 #ifndef WIN32 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
410 if( psz_raw_device != NULL ) |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
411 { |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
412 _dvdcss_raw_open( dvdcss, psz_raw_device ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
413 } |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
414 #endif |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
415 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
416 /* Seek at the beginning, just for safety. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
417 dvdcss->pf_seek( dvdcss, 0 ); |
7032 | 418 |
7027 | 419 return dvdcss; |
420 } | |
421 | |
422 /** | |
423 * \brief Return a string containing the latest error that occured in the | |
424 * given \e libdvdcss instance. | |
425 * | |
426 * \param dvdcss a \e libdvdcss instance. | |
427 * \return a null-terminated string containing the latest error message. | |
428 * | |
429 * This function returns a constant string containing the latest error that | |
430 * occured in \e libdvdcss. It can be used to format error messages at your | |
431 * convenience in your application. | |
432 */ | |
433 extern char * dvdcss_error ( dvdcss_t dvdcss ) | |
434 { | |
435 return dvdcss->psz_error; | |
436 } | |
437 | |
438 /** | |
439 * \brief Seek in the disc and change the current key if requested. | |
440 * | |
441 * \param dvdcss a \e libdvdcss instance. | |
442 * \param i_blocks an absolute block offset to seek to. | |
443 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with one of #DVDCSS_SEEK_KEY | |
444 * or #DVDCSS_SEEK_MPEG. | |
445 * \return the new position in blocks, or a negative value in case an error | |
446 * happened. | |
447 * | |
448 * This function seeks to the requested position, in logical blocks. | |
449 * | |
450 * You typically set \p i_flags to #DVDCSS_NOFLAGS when seeking in a .IFO. | |
451 * | |
452 * If #DVDCSS_SEEK_MPEG is specified in \p i_flags and if \e libdvdcss finds it | |
453 * reasonable to do so (ie, if the dvdcss method is not "title"), the current | |
454 * title key will be checked and a new one will be calculated if necessary. | |
455 * This flag is typically used when reading data from a VOB. | |
456 * | |
457 * If #DVDCSS_SEEK_KEY is specified, the title key will be always checked, | |
458 * even with the "title" method. This is equivalent to using the now | |
459 * deprecated dvdcss_title() call. This flag is typically used when seeking | |
460 * in a new title. | |
461 */ | |
462 extern int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) | |
463 { | |
464 /* title cracking method is too slow to be used at each seek */ | |
465 if( ( ( i_flags & DVDCSS_SEEK_MPEG ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
466 && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) |
7027 | 467 || ( i_flags & DVDCSS_SEEK_KEY ) ) |
468 { | |
469 /* check the title key */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
470 if( _dvdcss_title( dvdcss, i_blocks ) ) |
7027 | 471 { |
472 return -1; | |
473 } | |
474 } | |
475 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
476 return dvdcss->pf_seek( dvdcss, i_blocks ); |
7027 | 477 } |
478 | |
479 /** | |
480 * \brief Read from the disc and decrypt data if requested. | |
481 * | |
482 * \param dvdcss a \e libdvdcss instance. | |
483 * \param p_buffer a buffer that will contain the data read from the disc. | |
484 * \param i_blocks the amount of blocks to read. | |
485 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
486 * \return the amount of blocks read, or a negative value in case an | |
487 * error happened. | |
488 * | |
489 * This function reads \p i_blocks logical blocks from the DVD. | |
490 * | |
491 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
492 * .IFO file on the DVD. | |
493 * | |
494 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_read() will | |
495 * automatically decrypt scrambled sectors. This flag is typically used when | |
496 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
497 * discs or unscrambled sectors, and can be safely used on those. | |
498 * | |
499 * \warning dvdcss_read() expects to be able to write \p i_blocks * | |
500 * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer. | |
501 */ | |
502 extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, | |
503 int i_blocks, | |
504 int i_flags ) | |
505 { | |
506 int i_ret, i_index; | |
507 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
508 i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks ); |
7027 | 509 |
510 if( i_ret <= 0 | |
511 || !dvdcss->b_scrambled | |
512 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
513 { | |
514 return i_ret; | |
515 } | |
516 | |
517 if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) ) | |
518 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
519 /* For what we believe is an unencrypted title, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
520 * check that there are no encrypted blocks */ |
7027 | 521 for( i_index = i_ret; i_index; i_index-- ) |
522 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
523 if( ((uint8_t*)p_buffer)[0x14] & 0x30 ) |
7027 | 524 { |
525 _dvdcss_error( dvdcss, "no key but found encrypted block" ); | |
526 /* Only return the initial range of unscrambled blocks? */ | |
527 /* or fail completely? return 0; */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
528 break; |
7027 | 529 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
530 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
7027 | 531 } |
532 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
533 else |
7027 | 534 { |
535 /* Decrypt the blocks we managed to read */ | |
536 for( i_index = i_ret; i_index; i_index-- ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
537 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
538 _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
539 ((uint8_t*)p_buffer)[0x14] &= 0x8f; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
540 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
541 } |
7027 | 542 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
543 |
7027 | 544 return i_ret; |
545 } | |
546 | |
547 /** | |
548 * \brief Read from the disc into multiple buffers and decrypt data if | |
549 * requested. | |
550 * | |
551 * \param dvdcss a \e libdvdcss instance. | |
552 * \param p_iovec a pointer to an array of iovec structures that will contain | |
553 * the data read from the disc. | |
554 * \param i_blocks the amount of blocks to read. | |
555 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
556 * \return the amount of blocks read, or a negative value in case an | |
557 * error happened. | |
558 * | |
559 * This function reads \p i_blocks logical blocks from the DVD and writes them | |
560 * to an array of iovec structures. | |
561 * | |
562 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
563 * .IFO file on the DVD. | |
564 * | |
565 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_readv() will | |
566 * automatically decrypt scrambled sectors. This flag is typically used when | |
567 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
568 * discs or unscrambled sectors, and can be safely used on those. | |
569 * | |
570 * \warning dvdcss_readv() expects to be able to write \p i_blocks * | |
571 * #DVDCSS_BLOCK_SIZE bytes in the buffers pointed by \p p_iovec. | |
572 * Moreover, all iov_len members of the iovec structures should be | |
573 * multiples of #DVDCSS_BLOCK_SIZE. | |
574 */ | |
575 extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, | |
576 int i_blocks, | |
577 int i_flags ) | |
578 { | |
579 struct iovec *_p_iovec = (struct iovec *)p_iovec; | |
580 int i_ret, i_index; | |
581 void *iov_base; | |
582 size_t iov_len; | |
583 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
584 i_ret = dvdcss->pf_readv( dvdcss, _p_iovec, i_blocks ); |
7027 | 585 |
586 if( i_ret <= 0 | |
587 || !dvdcss->b_scrambled | |
588 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
589 { | |
590 return i_ret; | |
591 } | |
592 | |
593 /* Initialize loop for decryption */ | |
594 iov_base = _p_iovec->iov_base; | |
595 iov_len = _p_iovec->iov_len; | |
596 | |
597 /* Decrypt the blocks we managed to read */ | |
598 for( i_index = i_ret; i_index; i_index-- ) | |
599 { | |
600 /* Check that iov_len is a multiple of 2048 */ | |
601 if( iov_len & 0x7ff ) | |
602 { | |
603 return -1; | |
604 } | |
605 | |
606 while( iov_len == 0 ) | |
607 { | |
608 _p_iovec++; | |
609 iov_base = _p_iovec->iov_base; | |
610 iov_len = _p_iovec->iov_len; | |
611 } | |
612 | |
613 _dvdcss_unscramble( dvdcss->css.p_title_key, iov_base ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
614 ((uint8_t*)iov_base)[0x14] &= 0x8f; |
7027 | 615 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
616 iov_base = (void *) ((uint8_t*)iov_base + DVDCSS_BLOCK_SIZE); |
7027 | 617 iov_len -= DVDCSS_BLOCK_SIZE; |
618 } | |
619 | |
620 return i_ret; | |
621 } | |
622 | |
623 /** | |
624 * \brief Close the DVD and clean up the library. | |
625 * | |
626 * \param dvdcss a \e libdvdcss instance. | |
627 * \return zero in case of success, a negative value otherwise. | |
628 * | |
629 * This function closes the DVD device and frees all the memory allocated | |
630 * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be | |
631 * used again. | |
632 */ | |
633 extern int dvdcss_close ( dvdcss_t dvdcss ) | |
634 { | |
635 dvd_title_t *p_title; | |
636 int i_ret; | |
637 | |
638 /* Free our list of keys */ | |
639 p_title = dvdcss->p_titles; | |
640 while( p_title ) | |
641 { | |
642 dvd_title_t *p_tmptitle = p_title->p_next; | |
643 free( p_title ); | |
644 p_title = p_tmptitle; | |
645 } | |
646 | |
647 i_ret = _dvdcss_close( dvdcss ); | |
648 | |
649 if( i_ret < 0 ) | |
650 { | |
651 return i_ret; | |
652 } | |
653 | |
654 free( dvdcss->psz_device ); | |
655 free( dvdcss ); | |
656 | |
657 return 0; | |
658 } | |
659 | |
660 /* | |
661 * Deprecated. See dvdcss_seek(). | |
662 */ | |
663 #undef dvdcss_title | |
664 extern int dvdcss_title ( dvdcss_t dvdcss, int i_block ) | |
665 { | |
666 return _dvdcss_title( dvdcss, i_block ); | |
667 } | |
668 |