/** * Open a DVD image or block device file or use stream_cb functions. */ static dvd_reader_t *DVDOpenImageFile( const char *location, void *stream, dvd_reader_stream_cb *stream_cb, int have_css ) { dvd_reader_t *dvd; dvd_input_t dev; dev = dvdinput_open( location, stream, stream_cb ); if( !dev ) { fprintf( stderr, "libdvdread: Can't open %s for reading\n", location ); return NULL; } dvd = calloc( 1, sizeof( dvd_reader_t ) ); if( !dvd ) { dvdinput_close(dev); return NULL; } dvd->isImageFile = 1; dvd->dev = dev; dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; if( have_css ) { /* Only if DVDCSS_METHOD = title, a bit if it's disc or if * DVDCSS_METHOD = key but region mismatch. Unfortunately we * don't have that information. */ dvd->css_state = 1; /* Need key init. */ } return dvd; }
/** * Open an unencrypted file from a DVD directory tree. */ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ) { char full_path[ 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 ) ) return 0; dev = dvdinput_open( full_path ); if( !dev ) return 0; dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); if( !dvd_file ) 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 ) { if(dvd->verbose >= 1) { 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; }
/** * Open a DVD image or block device file. */ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) { dvd_reader_t *dvd; dvd_input_t dev; dev = dvdinput_open( location ); if( !dev ) { fprintf( stderr, "libdvdread: Can't open %s for reading\n", location ); return 0; } dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); if( !dvd ) return 0; dvd->isImageFile = 1; dvd->dev = dev; dvd->path_root = 0; dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; dvd->udfcache = NULL; if( have_css ) { /* Only if DVDCSS_METHOD = title, a bit if it's disc or if * DVDCSS_METHOD = key but region missmatch. Unfortunaly we * don't have that information. */ dvd->css_state = 1; /* Need key init. */ } dvd->css_title = 0; return dvd; }
/** * Open a DVD image or block device file. * Checks if the root directory in the udf image file can be found. * If not it assumes this isn't a valid udf image and returns NULL */ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) { dvd_reader_t *dvd; dvd_input_t dev; int verbose; verbose = get_verbose(); dev = dvdinput_open( location ); if( !dev ) { if(verbose >= 1) { fprintf( stderr, "libdvdread: Can't open '%s' for reading: %s\n", location, strerror(errno)); } return NULL; } dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); if( !dvd ) { int tmp_errno = errno; dvdinput_close(dev); errno = tmp_errno; return NULL; } dvd->verbose = verbose; dvd->isImageFile = 1; dvd->dev = dev; dvd->path_root = NULL; dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; dvd->udfcache = NULL; dvd->align = NULL; if( have_css ) { /* Only if DVDCSS_METHOD = title, a bit if it's disc or if * DVDCSS_METHOD = key but region missmatch. Unfortunaly we * don't have that information. */ dvd->css_state = 1; /* Need key init. */ } dvd->css_title = 0; /* sanity check, is it a valid UDF image, can we find the root dir */ if(!UDFFindFile(dvd, "/", NULL)) { dvdinput_close(dvd->dev); if(dvd->udfcache) { FreeUDFCache(dvd, dvd->udfcache); } if(dvd->align) { if(dvd->verbose >= 0) { fprintf(stderr, "libdvdread: DVDOpenImageFile(): Memory leak in align functions 1\n"); } } free(dvd); return NULL; } return dvd; }
/** * Open a DVD image or block device file. */ static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) { dvd_reader_t *dvd; dvd_input_t dev; static int volid_size = 32, volsetid_size = 128; char volid[volid_size]; unsigned char volsetid[volsetid_size]; dev = dvdinput_open( location ); if( !dev ) { fprintf( stderr, "libdvdread: Can't open %s for reading\n", location ); return NULL; } dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); if( !dvd ) { dvdinput_close(dev); return NULL; } dvd->dev = dev; dvd->path_root = NULL; dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; dvd->udfcache = NULL; if( have_css ) { /* Only if DVDCSS_METHOD = title, a bit if it's disc or if * DVDCSS_METHOD = key but region mismatch. Unfortunately we * don't have that information. */ dvd->css_state = 1; /* Need key init. */ } else { dvd->css_state = 0; } dvd->css_title = 0; // check is iso9660/udf format if (DVDUDFVolumeInfo(dvd, volid, volid_size, volsetid, volsetid_size) == 0) { dvd->isImageFile = 1; } else if (DVDISOVolumeInfo(dvd, volid, volid_size, volsetid, volsetid_size) == 0) { dvd->isImageFile = 2; } else{ dvdinput_close(dev); free(dvd); dvd = NULL; } return dvd; }
/** * Open an unencrypted file from a DVD directory tree. */ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, const char *filename ) { char full_path[ 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, "libdvdread:DVDOpenFilePath:findDVDFile %s failed\n", filename ); return NULL; } dev = dvdinput_open( full_path, NULL, NULL ); if( !dev ) { fprintf( stderr, "libdvdread:DVDOpenFilePath:dvdinput_open %s failed\n", full_path ); return NULL; } dvd_file = calloc( 1, sizeof( dvd_file_t ) ); if( !dvd_file ) { fprintf( stderr, "libdvdread:DVDOpenFilePath:dvd_file malloc failed\n" ); dvdinput_close(dev); return NULL; } dvd_file->dvd = dvd; if( mythfile_stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); free( dvd_file ); dvdinput_close( dev ); return NULL; } 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 *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) { char filename[ MAX_UDF_FILE_NAME_LEN ]; char full_path[ PATH_MAX + 1 ]; struct stat fileinfo; dvd_file_t *dvd_file; dvd_file = calloc( 1, sizeof( dvd_file_t ) ); if( !dvd_file ) return NULL; dvd_file->dvd = dvd; /*Hack*/ dvd_file->css_title = title << 1 | menu; if( menu ) { dvd_input_t dev; if( title == 0 ) { strcpy( filename, "VIDEO_TS.VOB" ); } else { sprintf( filename, "VTS_%02i_0.VOB", title ); } if( !findDVDFile( dvd, filename, full_path ) ) { free( dvd_file ); return NULL; } dev = dvdinput_open( full_path, NULL, NULL ); if( dev == NULL ) { free( dvd_file ); return NULL; } if( mythfile_stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); dvdinput_close(dev); free( dvd_file ); return NULL; } 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 { int i; for( i = 0; i < TITLES_MAX; ++i ) { sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 ); if( !findDVDFile( dvd, filename, full_path ) ) { break; } if( mythfile_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, NULL, NULL ); 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 NULL; } } 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[ 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 ) { if(dvd->verbose >= 1) { 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 ) { if(dvd->verbose >= 1) { 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; }