Mercurial > mplayer.hg
annotate libmpdvdkit2/libdvdcss.c @ 10823:df1433f614f6
disable sse support for mingw because of missing memalign
author | faust3 |
---|---|
date | Sat, 06 Sep 2003 12:06:59 +0000 |
parents | e482b16c7145 |
children | c7afdb04c8c8 |
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 | |
9882 | 116 #ifndef HAVE_MPLAYER |
117 #include "get_path.c" | |
118 #else | |
119 extern char * get_path( char * filename ); | |
120 #endif | |
121 | |
7027 | 122 /** |
123 * \brief Symbol for version checks. | |
124 * | |
125 * The name of this symbol contains the library major number, which makes it | |
126 * easy to check which \e libdvdcss development headers are installed on the | |
127 * system with tools such as autoconf. | |
128 * | |
129 * The variable itself contains the exact version number of the library, | |
130 * which can be useful for specific feature needs. | |
131 */ | |
132 char * dvdcss_interface_2 = VERSION; | |
133 | |
134 /** | |
135 * \brief Open a DVD device or directory and return a dvdcss instance. | |
136 * | |
137 * \param psz_target a string containing the target name, for instance | |
138 * "/dev/hdc" or "E:". | |
139 * \return a handle to a dvdcss instance or NULL on error. | |
140 * | |
141 * Initialize the \e libdvdcss library and open the requested DVD device or | |
142 * directory. \e libdvdcss checks whether ioctls can be performed on the disc, | |
143 * and when possible, the disc key is retrieved. | |
144 * | |
145 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss | |
146 * calls. If an error occured, NULL is returned. | |
147 */ | |
148 extern dvdcss_t dvdcss_open ( char *psz_target ) | |
149 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
150 char psz_buffer[PATH_MAX]; |
7027 | 151 int i_ret; |
152 | |
153 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
154 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
|
155 char *psz_cache = getenv( "DVDCSS_CACHE" ); |
7027 | 156 #ifndef WIN32 |
157 char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" ); | |
158 #endif | |
159 | |
160 dvdcss_t dvdcss; | |
161 | |
162 /* | |
163 * Allocate the library structure | |
164 */ | |
165 dvdcss = malloc( sizeof( struct dvdcss_s ) ); | |
166 if( dvdcss == NULL ) | |
167 { | |
168 return NULL; | |
169 } | |
170 | |
171 /* | |
172 * Initialize structure with default values | |
173 */ | |
174 #ifndef WIN32 | |
175 dvdcss->i_raw_fd = -1; | |
176 #endif | |
177 dvdcss->p_titles = NULL; | |
178 dvdcss->psz_device = (char *)strdup( psz_target ); | |
179 dvdcss->psz_error = "no error"; | |
180 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
|
181 dvdcss->psz_cachefile[0] = '\0'; |
7027 | 182 dvdcss->b_debug = 0; |
183 dvdcss->b_errors = 0; | |
184 | |
185 /* | |
186 * Find verbosity from DVDCSS_VERBOSE environment variable | |
187 */ | |
188 if( psz_verbose != NULL ) | |
189 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
190 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
|
191 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
192 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
|
193 if( i >= 1 ) dvdcss->b_errors = 1; |
7027 | 194 } |
195 | |
196 /* | |
197 * Find method from DVDCSS_METHOD environment variable | |
198 */ | |
199 if( psz_method != NULL ) | |
200 { | |
201 if( !strncmp( psz_method, "key", 4 ) ) | |
202 { | |
203 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
204 } | |
205 else if( !strncmp( psz_method, "disc", 5 ) ) | |
206 { | |
207 dvdcss->i_method = DVDCSS_METHOD_DISC; | |
208 } | |
209 else if( !strncmp( psz_method, "title", 5 ) ) | |
210 { | |
211 dvdcss->i_method = DVDCSS_METHOD_TITLE; | |
212 } | |
213 else | |
214 { | |
215 _dvdcss_error( dvdcss, "unknown decrypt method, please choose " | |
216 "from 'title', 'key' or 'disc'" ); | |
217 free( dvdcss->psz_device ); | |
218 free( dvdcss ); | |
219 return NULL; | |
220 } | |
221 } | |
222 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
223 /* |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
224 * 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
|
225 */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
226 if( psz_cache != NULL ) |
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[0] == '\0' ) |
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 psz_cache = NULL; |
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 /* 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
|
233 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
|
234 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
235 _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
|
236 psz_cache = NULL; |
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 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
239 else psz_cache = get_path( "DVDKeys" ); |
7032 | 240 |
7027 | 241 /* |
242 * Open device | |
243 */ | |
244 i_ret = _dvdcss_open( dvdcss ); | |
245 if( i_ret < 0 ) | |
246 { | |
247 free( dvdcss->psz_device ); | |
248 free( dvdcss ); | |
249 return NULL; | |
250 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
251 |
7027 | 252 dvdcss->b_scrambled = 1; /* Assume the worst */ |
253 dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss ); | |
254 | |
255 if( dvdcss->b_ioctls ) | |
256 { | |
257 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
|
258 if( i_ret < 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
259 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
260 /* Disable the CSS ioctls and hope that it works? */ |
7027 | 261 _dvdcss_debug( dvdcss, |
262 "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
|
263 dvdcss->b_ioctls = 0; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
264 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
265 else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
266 { |
7027 | 267 _dvdcss_debug( dvdcss, i_ret ? "disc is scrambled" |
268 : "disc is unscrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
269 dvdcss->b_scrambled = i_ret; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
270 } |
7027 | 271 } |
272 | |
273 /* If disc is CSS protected and the ioctls work, authenticate the drive */ | |
274 if( dvdcss->b_scrambled && dvdcss->b_ioctls ) | |
275 { | |
276 i_ret = _dvdcss_disckey( dvdcss ); | |
277 | |
278 if( i_ret < 0 ) | |
279 { | |
280 _dvdcss_close( dvdcss ); | |
281 free( dvdcss->psz_device ); | |
282 free( dvdcss ); | |
283 return NULL; | |
284 } | |
285 } | |
286 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
287 /* 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
|
288 if( psz_cache ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
289 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
290 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
|
291 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
|
292 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
|
293 int i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
294 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
295 /* 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
|
296 * 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
|
297 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
298 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
|
299 if( i_ret != 0 ) |
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 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
302 } |
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 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
|
305 if( i_ret != 1 ) |
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 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
308 } |
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 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
|
311 && 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
|
312 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
313 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
314 } |
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 /* 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
|
317 * - 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
|
318 * - 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
|
319 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
320 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
|
321 if( i_ret != 16 ) |
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 goto nocache; |
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 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
326 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
|
327 if( i_ret != 1 ) |
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 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
330 } |
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 /* 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
|
333 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
|
334 psz_title[32] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
335 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
336 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
|
337 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
338 if( psz_title[i] <= ' ' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
339 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
340 psz_title[i] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
341 break; |
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 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
|
344 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
345 psz_title[i] = '-'; |
9333
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 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
348 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
349 /* Get the date + serial */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
350 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
|
351 psz_serial[16] = '\0'; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
352 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
353 /* 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
|
354 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
|
355 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
356 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
|
357 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
358 sprintf( psz_serial, |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
359 "%.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
|
360 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
|
361 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
|
362 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
|
363 break; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
364 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
365 } |
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 /* 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
|
368 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
|
369 #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
|
370 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
|
371 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
372 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
|
373 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
374 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
|
375 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
376 _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
|
377 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
378 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
379 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
380 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
|
381 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
382 // 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
|
383 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
|
384 #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
|
385 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
|
386 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
387 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
|
388 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
389 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
|
390 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
391 _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
|
392 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
393 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
394 } |
9882 | 395 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
|
396 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
397 /* 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
|
398 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
|
399 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
400 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
|
401 dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
402 _dvdcss_debug( dvdcss, psz_debug ); |
7032 | 403 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
404 nocache: |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
405 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
406 #ifndef WIN32 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
407 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
|
408 { |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
409 _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
|
410 } |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
411 #endif |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
412 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
413 /* 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
|
414 dvdcss->pf_seek( dvdcss, 0 ); |
7032 | 415 |
7027 | 416 return dvdcss; |
417 } | |
418 | |
419 /** | |
420 * \brief Return a string containing the latest error that occured in the | |
421 * given \e libdvdcss instance. | |
422 * | |
423 * \param dvdcss a \e libdvdcss instance. | |
424 * \return a null-terminated string containing the latest error message. | |
425 * | |
426 * This function returns a constant string containing the latest error that | |
427 * occured in \e libdvdcss. It can be used to format error messages at your | |
428 * convenience in your application. | |
429 */ | |
430 extern char * dvdcss_error ( dvdcss_t dvdcss ) | |
431 { | |
432 return dvdcss->psz_error; | |
433 } | |
434 | |
435 /** | |
436 * \brief Seek in the disc and change the current key if requested. | |
437 * | |
438 * \param dvdcss a \e libdvdcss instance. | |
439 * \param i_blocks an absolute block offset to seek to. | |
440 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with one of #DVDCSS_SEEK_KEY | |
441 * or #DVDCSS_SEEK_MPEG. | |
442 * \return the new position in blocks, or a negative value in case an error | |
443 * happened. | |
444 * | |
445 * This function seeks to the requested position, in logical blocks. | |
446 * | |
447 * You typically set \p i_flags to #DVDCSS_NOFLAGS when seeking in a .IFO. | |
448 * | |
449 * If #DVDCSS_SEEK_MPEG is specified in \p i_flags and if \e libdvdcss finds it | |
450 * reasonable to do so (ie, if the dvdcss method is not "title"), the current | |
451 * title key will be checked and a new one will be calculated if necessary. | |
452 * This flag is typically used when reading data from a VOB. | |
453 * | |
454 * If #DVDCSS_SEEK_KEY is specified, the title key will be always checked, | |
455 * even with the "title" method. This is equivalent to using the now | |
456 * deprecated dvdcss_title() call. This flag is typically used when seeking | |
457 * in a new title. | |
458 */ | |
459 extern int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) | |
460 { | |
461 /* title cracking method is too slow to be used at each seek */ | |
462 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
|
463 && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) |
7027 | 464 || ( i_flags & DVDCSS_SEEK_KEY ) ) |
465 { | |
466 /* check the title key */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
467 if( _dvdcss_title( dvdcss, i_blocks ) ) |
7027 | 468 { |
469 return -1; | |
470 } | |
471 } | |
472 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
473 return dvdcss->pf_seek( dvdcss, i_blocks ); |
7027 | 474 } |
475 | |
476 /** | |
477 * \brief Read from the disc and decrypt data if requested. | |
478 * | |
479 * \param dvdcss a \e libdvdcss instance. | |
480 * \param p_buffer a buffer that will contain the data read from the disc. | |
481 * \param i_blocks the amount of blocks to read. | |
482 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
483 * \return the amount of blocks read, or a negative value in case an | |
484 * error happened. | |
485 * | |
486 * This function reads \p i_blocks logical blocks from the DVD. | |
487 * | |
488 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
489 * .IFO file on the DVD. | |
490 * | |
491 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_read() will | |
492 * automatically decrypt scrambled sectors. This flag is typically used when | |
493 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
494 * discs or unscrambled sectors, and can be safely used on those. | |
495 * | |
496 * \warning dvdcss_read() expects to be able to write \p i_blocks * | |
497 * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer. | |
498 */ | |
499 extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, | |
500 int i_blocks, | |
501 int i_flags ) | |
502 { | |
503 int i_ret, i_index; | |
504 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
505 i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks ); |
7027 | 506 |
507 if( i_ret <= 0 | |
508 || !dvdcss->b_scrambled | |
509 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
510 { | |
511 return i_ret; | |
512 } | |
513 | |
514 if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) ) | |
515 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
516 /* 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
|
517 * check that there are no encrypted blocks */ |
7027 | 518 for( i_index = i_ret; i_index; i_index-- ) |
519 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
520 if( ((uint8_t*)p_buffer)[0x14] & 0x30 ) |
7027 | 521 { |
522 _dvdcss_error( dvdcss, "no key but found encrypted block" ); | |
523 /* Only return the initial range of unscrambled blocks? */ | |
524 /* 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
|
525 break; |
7027 | 526 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
527 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
7027 | 528 } |
529 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
530 else |
7027 | 531 { |
532 /* Decrypt the blocks we managed to read */ | |
533 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
|
534 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
535 _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
|
536 ((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
|
537 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
|
538 } |
7027 | 539 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
540 |
7027 | 541 return i_ret; |
542 } | |
543 | |
544 /** | |
545 * \brief Read from the disc into multiple buffers and decrypt data if | |
546 * requested. | |
547 * | |
548 * \param dvdcss a \e libdvdcss instance. | |
549 * \param p_iovec a pointer to an array of iovec structures that will contain | |
550 * the data read from the disc. | |
551 * \param i_blocks the amount of blocks to read. | |
552 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
553 * \return the amount of blocks read, or a negative value in case an | |
554 * error happened. | |
555 * | |
556 * This function reads \p i_blocks logical blocks from the DVD and writes them | |
557 * to an array of iovec structures. | |
558 * | |
559 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
560 * .IFO file on the DVD. | |
561 * | |
562 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_readv() will | |
563 * automatically decrypt scrambled sectors. This flag is typically used when | |
564 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
565 * discs or unscrambled sectors, and can be safely used on those. | |
566 * | |
567 * \warning dvdcss_readv() expects to be able to write \p i_blocks * | |
568 * #DVDCSS_BLOCK_SIZE bytes in the buffers pointed by \p p_iovec. | |
569 * Moreover, all iov_len members of the iovec structures should be | |
570 * multiples of #DVDCSS_BLOCK_SIZE. | |
571 */ | |
572 extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, | |
573 int i_blocks, | |
574 int i_flags ) | |
575 { | |
576 struct iovec *_p_iovec = (struct iovec *)p_iovec; | |
577 int i_ret, i_index; | |
578 void *iov_base; | |
579 size_t iov_len; | |
580 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
581 i_ret = dvdcss->pf_readv( dvdcss, _p_iovec, i_blocks ); |
7027 | 582 |
583 if( i_ret <= 0 | |
584 || !dvdcss->b_scrambled | |
585 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
586 { | |
587 return i_ret; | |
588 } | |
589 | |
590 /* Initialize loop for decryption */ | |
591 iov_base = _p_iovec->iov_base; | |
592 iov_len = _p_iovec->iov_len; | |
593 | |
594 /* Decrypt the blocks we managed to read */ | |
595 for( i_index = i_ret; i_index; i_index-- ) | |
596 { | |
597 /* Check that iov_len is a multiple of 2048 */ | |
598 if( iov_len & 0x7ff ) | |
599 { | |
600 return -1; | |
601 } | |
602 | |
603 while( iov_len == 0 ) | |
604 { | |
605 _p_iovec++; | |
606 iov_base = _p_iovec->iov_base; | |
607 iov_len = _p_iovec->iov_len; | |
608 } | |
609 | |
610 _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
|
611 ((uint8_t*)iov_base)[0x14] &= 0x8f; |
7027 | 612 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
613 iov_base = (void *) ((uint8_t*)iov_base + DVDCSS_BLOCK_SIZE); |
7027 | 614 iov_len -= DVDCSS_BLOCK_SIZE; |
615 } | |
616 | |
617 return i_ret; | |
618 } | |
619 | |
620 /** | |
621 * \brief Close the DVD and clean up the library. | |
622 * | |
623 * \param dvdcss a \e libdvdcss instance. | |
624 * \return zero in case of success, a negative value otherwise. | |
625 * | |
626 * This function closes the DVD device and frees all the memory allocated | |
627 * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be | |
628 * used again. | |
629 */ | |
630 extern int dvdcss_close ( dvdcss_t dvdcss ) | |
631 { | |
632 dvd_title_t *p_title; | |
633 int i_ret; | |
634 | |
635 /* Free our list of keys */ | |
636 p_title = dvdcss->p_titles; | |
637 while( p_title ) | |
638 { | |
639 dvd_title_t *p_tmptitle = p_title->p_next; | |
640 free( p_title ); | |
641 p_title = p_tmptitle; | |
642 } | |
643 | |
644 i_ret = _dvdcss_close( dvdcss ); | |
645 | |
646 if( i_ret < 0 ) | |
647 { | |
648 return i_ret; | |
649 } | |
650 | |
651 free( dvdcss->psz_device ); | |
652 free( dvdcss ); | |
653 | |
654 return 0; | |
655 } | |
656 | |
657 /* | |
658 * Deprecated. See dvdcss_seek(). | |
659 */ | |
660 #undef dvdcss_title | |
661 extern int dvdcss_title ( dvdcss_t dvdcss, int i_block ) | |
662 { | |
663 return _dvdcss_title( dvdcss, i_block ); | |
664 } | |
665 |