Mercurial > mplayer.hg
comparison libmpdvdkit2/libdvdcss.c @ 10720:f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
get_path() instead). anyway it's mostly cosmetics only.
author | arpi |
---|---|
date | Sat, 30 Aug 2003 13:35:25 +0000 |
parents | 454d8a4bd4f9 |
children | e482b16c7145 |
comparison
equal
deleted
inserted
replaced
10719:caec33353477 | 10720:f23c35ce0d16 |
---|---|
149 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss | 149 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss |
150 * calls. If an error occured, NULL is returned. | 150 * calls. If an error occured, NULL is returned. |
151 */ | 151 */ |
152 extern dvdcss_t dvdcss_open ( char *psz_target ) | 152 extern dvdcss_t dvdcss_open ( char *psz_target ) |
153 { | 153 { |
154 char psz_buffer[PATH_MAX]; | |
154 int i_ret; | 155 int i_ret; |
155 | 156 |
156 char *psz_method = getenv( "DVDCSS_METHOD" ); | 157 char *psz_method = getenv( "DVDCSS_METHOD" ); |
157 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | 158 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); |
158 char *psz_cache = getenv( "DVDCSS_CACHE" ); | 159 char *psz_cache = getenv( "DVDCSS_CACHE" ); |
188 /* | 189 /* |
189 * Find verbosity from DVDCSS_VERBOSE environment variable | 190 * Find verbosity from DVDCSS_VERBOSE environment variable |
190 */ | 191 */ |
191 if( psz_verbose != NULL ) | 192 if( psz_verbose != NULL ) |
192 { | 193 { |
193 switch( atoi( psz_verbose ) ) | 194 int i = atoi( psz_verbose ); |
194 { | 195 |
195 case 2: | 196 if( i >= 2 ) dvdcss->b_debug = 1; |
196 dvdcss->b_debug = 1; | 197 if( i >= 1 ) dvdcss->b_errors = 1; |
197 case 1: | |
198 dvdcss->b_errors = 1; | |
199 case 0: | |
200 break; | |
201 } | |
202 } | 198 } |
203 | 199 |
204 /* | 200 /* |
205 * Find method from DVDCSS_METHOD environment variable | 201 * Find method from DVDCSS_METHOD environment variable |
206 */ | 202 */ |
290 free( dvdcss ); | 286 free( dvdcss ); |
291 return NULL; | 287 return NULL; |
292 } | 288 } |
293 } | 289 } |
294 | 290 |
295 #ifndef WIN32 | |
296 if( psz_raw_device != NULL ) | |
297 { | |
298 _dvdcss_raw_open( dvdcss, psz_raw_device ); | |
299 } | |
300 #endif | |
301 | |
302 /* If the cache is enabled, extract a unique disc ID */ | 291 /* If the cache is enabled, extract a unique disc ID */ |
303 if( psz_cache ) | 292 if( psz_cache ) |
304 { | 293 { |
305 uint8_t p_sector[DVDCSS_BLOCK_SIZE]; | 294 uint8_t p_sector[DVDCSS_BLOCK_SIZE]; |
306 unsigned char psz_debug[PATH_MAX+30]; | 295 unsigned char psz_debug[PATH_MAX+30]; |
307 unsigned char * psz_data; | 296 unsigned char * psz_title, * psz_serial; |
308 int i; | 297 int i; |
309 | 298 |
310 /* We read sector 0. If it starts with 0x000001ba (BE), we are | 299 /* We read sector 0. If it starts with 0x000001ba (BE), we are |
311 * reading a VOB file, and we should not cache anything. */ | 300 * reading a VOB file, and we should not cache anything. */ |
312 | 301 |
343 { | 332 { |
344 goto nocache; | 333 goto nocache; |
345 } | 334 } |
346 | 335 |
347 /* Get the disc title */ | 336 /* Get the disc title */ |
348 psz_data = p_sector + 40; | 337 psz_title = p_sector + 40; |
349 psz_data[32] = '\0'; | 338 psz_title[32] = '\0'; |
350 | 339 |
351 for( i = 0 ; i < 32 ; i++ ) | 340 for( i = 0 ; i < 32 ; i++ ) |
352 { | 341 { |
353 if( psz_data[i] <= ' ' ) | 342 if( psz_title[i] <= ' ' ) |
354 { | 343 { |
355 psz_data[i] = '\0'; | 344 psz_title[i] = '\0'; |
356 break; | 345 break; |
357 } | 346 } |
358 else if( psz_data[i] == '/' || psz_data[i] == '\\' ) | 347 else if( psz_title[i] == '/' || psz_title[i] == '\\' ) |
359 { | 348 { |
360 psz_data[i] = '-'; | 349 psz_title[i] = '-'; |
361 } | 350 } |
362 } | 351 } |
363 | 352 |
364 /* If it's not long enough, try the date + serial */ | 353 /* Get the date + serial */ |
365 if( strlen( psz_data ) < 6 ) | 354 psz_serial = p_sector + 813; |
366 { | 355 psz_serial[16] = '\0'; |
367 psz_data = p_sector + 813; | 356 |
368 psz_data[16] = '\0'; | 357 /* Check that all characters are digits, otherwise convert. */ |
369 | 358 for( i = 0 ; i < 16 ; i++ ) |
370 /* Check that all characters are digits, otherwise convert. */ | 359 { |
371 for( i = 0 ; i < 16 ; i++ ) | 360 if( psz_serial[i] < '0' || psz_serial[i] > '9' ) |
372 { | 361 { |
373 if( psz_data[i] < '0' || psz_data[i] > '9' ) | 362 sprintf( psz_serial, |
374 { | 363 "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", |
375 sprintf( psz_data, | 364 psz_serial[0], psz_serial[1], psz_serial[2], |
376 "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", | 365 psz_serial[3], psz_serial[4], psz_serial[5], |
377 psz_data[0], psz_data[1], psz_data[2], | 366 psz_serial[6], psz_serial[7] ); |
378 psz_data[3], psz_data[4], psz_data[5], | 367 break; |
379 psz_data[6], psz_data[7] ); | |
380 break; | |
381 } | |
382 } | 368 } |
383 } | 369 } |
384 | 370 |
385 /* We have a disc name or ID, we can create the cache dir */ | 371 /* We have a disc name or ID, we can create the cache dir */ |
386 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache ); | 372 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache ); |
393 { | 379 { |
394 _dvdcss_error( dvdcss, "failed creating cache directory" ); | 380 _dvdcss_error( dvdcss, "failed creating cache directory" ); |
395 dvdcss->psz_cachefile[0] = '\0'; | 381 dvdcss->psz_cachefile[0] = '\0'; |
396 goto nocache; | 382 goto nocache; |
397 } | 383 } |
398 | 384 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
399 i += sprintf( dvdcss->psz_cachefile + i, "/%s", psz_data ); | 385 |
386 // i += sprintf( dvdcss->psz_cachefile + i, "/%s", psz_data ); | |
387 i += sprintf( dvdcss->psz_cachefile + i, "/%s#%s", psz_title, psz_serial ); | |
400 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) | 388 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
401 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); | 389 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
402 #else | 390 #else |
403 i_ret = mkdir( dvdcss->psz_cachefile ); | 391 i_ret = mkdir( dvdcss->psz_cachefile ); |
404 #endif | 392 #endif |
416 sprintf( psz_debug, "using CSS key cache dir: %s", | 404 sprintf( psz_debug, "using CSS key cache dir: %s", |
417 dvdcss->psz_cachefile ); | 405 dvdcss->psz_cachefile ); |
418 _dvdcss_debug( dvdcss, psz_debug ); | 406 _dvdcss_debug( dvdcss, psz_debug ); |
419 } | 407 } |
420 nocache: | 408 nocache: |
409 | |
410 #ifndef WIN32 | |
411 if( psz_raw_device != NULL ) | |
412 { | |
413 _dvdcss_raw_open( dvdcss, psz_raw_device ); | |
414 } | |
415 #endif | |
421 | 416 |
422 /* Seek at the beginning, just for safety. */ | 417 /* Seek at the beginning, just for safety. */ |
423 dvdcss->pf_seek( dvdcss, 0 ); | 418 dvdcss->pf_seek( dvdcss, 0 ); |
424 | 419 |
425 return dvdcss; | 420 return dvdcss; |