📄 dvd_reader.c
字号:
#ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */ /* Also WIN32 does not have symlinks, so we don't need this bit of code. */ /* Resolve any symlinks and get the absolut dir name. */ { char *new_path; int cdir = open( ".", O_RDONLY ); if( cdir >= 0 ) { chdir( path_copy ); new_path = getcwd( NULL, XINE_PATH_MAX ); fchdir( cdir ); close( cdir ); if( new_path ) { free( path_copy ); path_copy = new_path; } } }#endif /** * If we're being asked to open a directory, check if that directory * is the mountpoint for a DVD-ROM which we can use instead. */ if( strlen( path_copy ) > 1 ) { if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) path_copy[ strlen( path_copy ) - 1 ] = '\0'; } if( strlen( path_copy ) > 9 ) { if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]), "/video_ts" ) ) { path_copy[ strlen( path_copy ) - 9 ] = '\0'; } }#if defined(SYS_BSD) if( ( fe = getfsfile( path_copy ) ) ) { dev_name = bsd_block2char( fe->fs_spec ); fprintf( stderr, "libdvdread: Attempting to use device %s" " mounted on %s for CSS authentication\n", dev_name, fe->fs_file ); auth_drive = DVDOpenImageFile( dev_name, have_css ); }#elif defined(__sun) mntfile = fopen( MNTTAB, "r" ); if( mntfile ) { struct mnttab mp; int res; while( ( res = getmntent( mntfile, &mp ) ) != -1 ) { if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) { dev_name = sun_block2char( mp.mnt_special ); fprintf( stderr, "libdvdread: Attempting to use device %s" " mounted on %s for CSS authentication\n", dev_name, mp.mnt_mountp ); auth_drive = DVDOpenImageFile( dev_name, have_css ); break; } } fclose( mntfile ); }#elif defined(__linux__) mntfile = fopen( MOUNTED, "r" ); if( mntfile ) { struct mntent *me; while( ( me = getmntent( mntfile ) ) ) { if( !strcmp( me->mnt_dir, path_copy ) ) { fprintf( stderr, "libdvdread: Attempting to use device %s" " mounted on %s for CSS authentication\n", me->mnt_fsname, me->mnt_dir ); auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css ); /* If the device is not encrypted, don't access the device * directly as it would fail for non-UDF DVDs */ if ( auth_drive && dvdinput_is_encrypted( auth_drive->dev ) == 0) { DVDClose( auth_drive ); auth_drive = NULL; break; } dev_name = strdup(me->mnt_fsname); break; } } fclose( mntfile ); }#elif defined(_MSC_VER) auth_drive = DVDOpenImageFile( path, have_css );#endif#ifndef _MSC_VER if( !dev_name ) { fprintf( stderr, "libdvdread: Couldn't find device name.\n" ); } else if( !auth_drive ) { fprintf( stderr, "libdvdread: Device %s inaccessible, " "CSS authentication not available.\n", dev_name ); }#else if( !auth_drive ) { fprintf( stderr, "libdvdread: Device %s inaccessible, " "CSS authentication not available.\n", dev_name ); }#endif free( dev_name ); free( path_copy ); /** * If we've opened a drive, just use that. */ if( auth_drive ) { free(path); return auth_drive; } /** * Otherwise, we now try to open the directory tree instead. */ ret_val = DVDOpenPath( path ); free( path ); return ret_val; } /* If it's none of the above, screw it. */ fprintf( stderr, "libdvdread: Could not open %s\n", path ); free( path ); return 0;}void DVDClose( dvd_reader_t *dvd ){ if( dvd ) { if( dvd->dev ) dvdinput_close( dvd->dev ); if( dvd->path_root ) free( dvd->path_root ); if( dvd->udfcache ) FreeUDFCache( dvd->udfcache ); free( dvd ); }}/** * Open an unencrypted file on a DVD image file. */static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename ){ uint32_t start, len; dvd_file_t *dvd_file; start = UDFFindFile( dvd, filename, &len ); if( !start ) { fprintf( stderr, "libdvdnav:DVDOpenFileUDF:UDFFindFile %s failed\n", filename ); return 0; } dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); if( !dvd_file ) { fprintf( stderr, "libdvdnav:DVDOpenFileUDF:malloc failed\n" ); return 0; } dvd_file->dvd = dvd; dvd_file->lb_start = start; dvd_file->seek_pos = 0; memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); dvd_file->filesize = len / DVD_VIDEO_LB_LEN; return dvd_file;}/** * Searches for <file> in directory <path>, ignoring case. * Returns 0 and full filename in <filename>. * or -1 on file not found. * or -2 on path not found. */static int findDirFile( const char *path, const char *file, char *filename ) { DIR *dir; struct dirent *ent; dir = opendir( path ); if( !dir ) return -2; while( ( ent = readdir( dir ) ) != NULL ) { if( !strcasecmp( ent->d_name, file ) ) { sprintf( filename, "%s%s%s", path, ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ), ent->d_name ); closedir (dir); return 0; } } closedir (dir); return -1;}static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename ){ char video_path[ XINE_PATH_MAX + 1 ]; const char *nodirfile; int ret; /* Strip off the directory for our search */ if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) { nodirfile = &(file[ 10 ]); } else { nodirfile = file; } ret = findDirFile( dvd->path_root, nodirfile, filename ); if( ret < 0 ) { /* Try also with adding the path, just in case. */ sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root ); ret = findDirFile( video_path, nodirfile, filename ); if( ret < 0 ) { /* Try with the path, but in lower case. */ sprintf( video_path, "%s/video_ts/", dvd->path_root ); ret = findDirFile( video_path, nodirfile, filename ); if( ret < 0 ) { return 0; } } } return 1;}/** * Open an unencrypted file from a DVD directory tree. */static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ){ char full_path[ XINE_PATH_MAX + 1 ]; dvd_file_t *dvd_file; struct stat fileinfo; dvd_input_t dev; /* Get the full path of the file. */ if( !findDVDFile( dvd, filename, full_path ) ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:findDVDFile %s failed\n", filename ); return 0; } dev = dvdinput_open( full_path ); if( !dev ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvdinput_open %s failed\n", full_path ); return 0; } dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); if( !dvd_file ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvd_file malloc failed\n" ); return 0; } dvd_file->dvd = dvd; dvd_file->lb_start = 0; dvd_file->seek_pos = 0; memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); dvd_file->filesize = 0; if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); free( dvd_file ); return 0; } dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; dvd_file->title_devs[ 0 ] = dev; dvd_file->filesize = dvd_file->title_sizes[ 0 ]; return dvd_file;}static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu ){ char filename[ MAX_UDF_FILE_NAME_LEN ]; uint32_t start, len; dvd_file_t *dvd_file; if( title == 0 ) { sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" ); } else { sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 ); } start = UDFFindFile( dvd, filename, &len ); if( start == 0 ) return 0; dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); if( !dvd_file ) return 0; dvd_file->dvd = dvd; /*Hack*/ dvd_file->css_title = title << 1 | menu; dvd_file->lb_start = start; dvd_file->seek_pos = 0; memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); dvd_file->filesize = len / DVD_VIDEO_LB_LEN; /* Calculate the complete file size for every file in the VOBS */ if( !menu ) { int cur; for( cur = 2; cur < 10; cur++ ) { sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur ); if( !UDFFindFile( dvd, filename, &len ) ) break; dvd_file->filesize += len / DVD_VIDEO_LB_LEN; } } if( dvd->css_state == 1 /* Need key init */ ) { initAllCSSKeys( dvd ); dvd->css_state = 2; } /* if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) { fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n", filename ); } */ return dvd_file;}static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ){ char filename[ MAX_UDF_FILE_NAME_LEN ]; char full_path[ XINE_PATH_MAX + 1 ]; struct stat fileinfo; dvd_file_t *dvd_file; int i; dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); if( !dvd_file ) return 0; dvd_file->dvd = dvd; /*Hack*/ dvd_file->css_title = title << 1 | menu; dvd_file->lb_start = 0; dvd_file->seek_pos = 0; memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); dvd_file->filesize = 0; if( menu ) { dvd_input_t dev; if( title == 0 ) { sprintf( filename, "VIDEO_TS.VOB" ); } else { sprintf( filename, "VTS_%02i_0.VOB", title ); } if( !findDVDFile( dvd, filename, full_path ) ) { free( dvd_file ); return 0; } dev = dvdinput_open( full_path ); if( dev == NULL ) { free( dvd_file ); return 0; } if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); free( dvd_file ); return 0; } dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; dvd_file->title_devs[ 0 ] = dev; dvdinput_title( dvd_file->title_devs[0], 0); dvd_file->filesize = dvd_file->title_sizes[ 0 ]; } else { for( i = 0; i < 9; ++i ) { sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 ); if( !findDVDFile( dvd, filename, full_path ) ) { break; } if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); break; } dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; dvd_file->title_devs[ i ] = dvdinput_open( full_path ); dvdinput_title( dvd_file->title_devs[ i ], 0 ); dvd_file->filesize += dvd_file->title_sizes[ i ]; } if( !dvd_file->title_devs[ 0 ] ) { free( dvd_file ); return 0; } } return dvd_file;}dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum, dvd_read_domain_t domain ){ char filename[ MAX_UDF_FILE_NAME_LEN ]; /* Check arguments. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -