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