Mercurial > mplayer.hg
comparison libmpdvdkit2/libdvdcss.c @ 7032:fd2d4be9ed6f
applying css-key cache patch
author | arpi |
---|---|
date | Fri, 16 Aug 2002 22:46:01 +0000 |
parents | c9a4dfaa9868 |
children | 596919e4f601 |
comparison
equal
deleted
inserted
replaced
7031:a1ff955aa49b | 7032:fd2d4be9ed6f |
---|---|
115 * The variable itself contains the exact version number of the library, | 115 * The variable itself contains the exact version number of the library, |
116 * which can be useful for specific feature needs. | 116 * which can be useful for specific feature needs. |
117 */ | 117 */ |
118 char * dvdcss_interface_2 = VERSION; | 118 char * dvdcss_interface_2 = VERSION; |
119 | 119 |
120 char * dvdcss_cache_dir = NULL; | |
121 | |
120 /** | 122 /** |
121 * \brief Open a DVD device or directory and return a dvdcss instance. | 123 * \brief Open a DVD device or directory and return a dvdcss instance. |
122 * | 124 * |
123 * \param psz_target a string containing the target name, for instance | 125 * \param psz_target a string containing the target name, for instance |
124 * "/dev/hdc" or "E:". | 126 * "/dev/hdc" or "E:". |
162 dvdcss->psz_device = (char *)strdup( psz_target ); | 164 dvdcss->psz_device = (char *)strdup( psz_target ); |
163 dvdcss->psz_error = "no error"; | 165 dvdcss->psz_error = "no error"; |
164 dvdcss->i_method = DVDCSS_METHOD_KEY; | 166 dvdcss->i_method = DVDCSS_METHOD_KEY; |
165 dvdcss->b_debug = 0; | 167 dvdcss->b_debug = 0; |
166 dvdcss->b_errors = 0; | 168 dvdcss->b_errors = 0; |
169 dvdcss->psz_cache = NULL; | |
167 | 170 |
168 /* | 171 /* |
169 * Find verbosity from DVDCSS_VERBOSE environment variable | 172 * Find verbosity from DVDCSS_VERBOSE environment variable |
170 */ | 173 */ |
171 if( psz_verbose != NULL ) | 174 if( psz_verbose != NULL ) |
205 free( dvdcss->psz_device ); | 208 free( dvdcss->psz_device ); |
206 free( dvdcss ); | 209 free( dvdcss ); |
207 return NULL; | 210 return NULL; |
208 } | 211 } |
209 } | 212 } |
213 | |
214 if(!dvdcss_cache_dir) dvdcss_cache_dir = getenv( "DVDCSS_CACHE" ); | |
210 | 215 |
211 /* | 216 /* |
212 * Open device | 217 * Open device |
213 */ | 218 */ |
214 i_ret = _dvdcss_open( dvdcss ); | 219 i_ret = _dvdcss_open( dvdcss ); |
259 { | 264 { |
260 _dvdcss_raw_open( dvdcss, psz_raw_device ); | 265 _dvdcss_raw_open( dvdcss, psz_raw_device ); |
261 } | 266 } |
262 #endif | 267 #endif |
263 | 268 |
269 /* if the CACHE is enabled, extract some unique disc ID */ | |
270 if(dvdcss_cache_dir){ | |
271 char* disc_id=NULL; | |
272 char title_name[64]; | |
273 char sector[DVDCSS_BLOCK_SIZE]; | |
274 // 32768+40 -> disc title (32 uppercase chars) | |
275 // 32768+813 -> disc manufacturing date + serial no (16 digit number) | |
276 _dvdcss_seek( dvdcss, 32768/DVDCSS_BLOCK_SIZE); | |
277 if(_dvdcss_read( dvdcss, sector, 1) == 1){ | |
278 // check disc title first: | |
279 char* title_name=§or[40]; | |
280 int i=31; | |
281 while(i>=0 && title_name[i]<=32) i--; | |
282 title_name[i+1]=0; | |
283 if(strlen(title_name)>5){ | |
284 disc_id=strdup(title_name); | |
285 } else { | |
286 // use disc date+serial: | |
287 title_name=§or[813]; | |
288 title_name[16]=0; | |
289 for ( i=0;i<16;i++ ) | |
290 if ( ( title_name[i] < '0' )||( title_name[i] > '9' ) ){ | |
291 disc_id=malloc(16+4); | |
292 sprintf( disc_id,"%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X",title_name[0],title_name[1],title_name[2],title_name[3],title_name[4],title_name[5],title_name[6],title_name[7] ); | |
293 break; | |
294 } | |
295 if(!disc_id) disc_id=strdup(title_name); | |
296 } | |
297 if(disc_id){ | |
298 // yeah, we have a disc name/id, let's set up cache path: | |
299 char* dir; | |
300 dvdcss->psz_cache = malloc(strlen(dvdcss_cache_dir)+strlen(disc_id)+4); | |
301 sprintf(dvdcss->psz_cache,"%s/%s",dvdcss_cache_dir,disc_id); | |
302 mkdir( dvdcss->psz_cache,493 ); | |
303 free(disc_id); | |
304 fprintf(stderr,"Using CSS Key-cache dir: %s\n",dvdcss->psz_cache); | |
305 } | |
306 } | |
307 } | |
308 | |
264 return dvdcss; | 309 return dvdcss; |
265 } | 310 } |
266 | 311 |
267 /** | 312 /** |
268 * \brief Return a string containing the latest error that occured in the | 313 * \brief Return a string containing the latest error that occured in the |