X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdvdnav.c;h=dcf9310450ee22d19ba8614a5214b008395cc568;hb=b5c3569607e8e9088b40bb3c4ae74c95345ef84c;hp=857d734269cd79029548bfaf9bf109d4e18742f8;hpb=32b362986e094e10878bd1145d9d2df3dd7fd2a1;p=vlc diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index 857d734269..dcf9310450 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -52,6 +52,7 @@ #ifdef HAVE_FCNTL_H # include #endif +#include #include #include @@ -71,10 +72,6 @@ #define ANGLE_LONGTEXT N_( \ "Default DVD angle." ) -#define CACHING_TEXT N_("Caching value in ms") -#define CACHING_LONGTEXT N_( \ - "Caching value for DVDs. This "\ - "value should be set in milliseconds." ) #define MENU_TEXT N_("Start directly in menu") #define MENU_LONGTEXT N_( \ "Start the DVD directly in the main menu. This "\ @@ -92,8 +89,6 @@ vlc_module_begin () set_subcategory( SUBCAT_INPUT_ACCESS ) add_integer( "dvdnav-angle", 1, ANGLE_TEXT, ANGLE_LONGTEXT, false ) - add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, - CACHING_TEXT, CACHING_LONGTEXT, true ) add_bool( "dvdnav-menu", true, MENU_TEXT, MENU_LONGTEXT, false ) set_capability( "access_demux", 5 ) @@ -189,11 +184,16 @@ static int Open( vlc_object_t *p_this ) int i_angle; char *psz_file; char *psz_code; + bool forced = false; + + if( p_demux->psz_access != NULL + && !strncmp(p_demux->psz_access, "dvd", 3) ) + forced = true; if( !p_demux->psz_file || !*p_demux->psz_file ) { /* Only when selected */ - if( !p_demux->psz_access || !*p_demux->psz_access ) + if( !forced ) return VLC_EGENERIC; psz_file = var_InheritString( p_this, "dvd" ); @@ -216,7 +216,7 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; /* Try some simple probing to avoid going through dvdnav_open too often */ - if( ProbeDVD( psz_file ) != VLC_SUCCESS ) + if( !forced && ProbeDVD( psz_file ) != VLC_SUCCESS ) { free( psz_file ); return VLC_EGENERIC; @@ -349,9 +349,6 @@ static int Open( vlc_object_t *p_this ) i_angle = var_CreateGetInteger( p_demux, "dvdnav-angle" ); if( i_angle <= 0 ) i_angle = 1; - /* Update default_pts to a suitable value for dvdnav access */ - var_Create( p_demux, "dvdnav-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); - /* FIXME hack hack hack hack FIXME */ /* Get p_input and create variable */ p_sys->p_input = demux_GetParentInput( p_demux ); @@ -362,7 +359,6 @@ static int Open( vlc_object_t *p_this ) var_Create( p_sys->p_input, "color", VLC_VAR_ADDRESS ); var_Create( p_sys->p_input, "menu-palette", VLC_VAR_ADDRESS ); var_Create( p_sys->p_input, "highlight", VLC_VAR_BOOL ); - var_Create( p_sys->p_input, "highlight-mutex", VLC_VAR_MUTEX ); /* catch all key event */ var_AddCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux ); @@ -402,7 +398,6 @@ static void Close( vlc_object_t *p_this ) vlc_timer_destroy( p_sys->still.timer ); vlc_mutex_destroy( &p_sys->still.lock ); - var_Destroy( p_sys->p_input, "highlight-mutex" ); var_Destroy( p_sys->p_input, "highlight" ); var_Destroy( p_sys->p_input, "x-start" ); var_Destroy( p_sys->p_input, "x-end" ); @@ -559,8 +554,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) return VLC_SUCCESS; case DEMUX_GET_PTS_DELAY: - *va_arg( args, int64_t * ) - = (int64_t)var_GetInteger( p_demux, "dvdnav-caching" ) *1000; + *va_arg( args, int64_t * ) = + INT64_C(1000) * var_InheritInteger( p_demux, "disc-caching" ); return VLC_SUCCESS; case DEMUX_GET_META: @@ -1039,72 +1034,64 @@ static void DemuxTitles( demux_t *p_demux ) static void ButtonUpdate( demux_t *p_demux, bool b_mode ) { demux_sys_t *p_sys = p_demux->p_sys; - vlc_value_t val; int32_t i_title, i_part; dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part ); - if( var_Get( p_sys->p_input, "highlight-mutex", &val ) == VLC_SUCCESS ) - { - vlc_mutex_t *p_mutex = val.p_address; - dvdnav_highlight_area_t hl; - int32_t i_button; - bool b_button_ok; + dvdnav_highlight_area_t hl; + int32_t i_button; + bool b_button_ok; - if( dvdnav_get_current_highlight( p_sys->dvdnav, &i_button ) - != DVDNAV_STATUS_OK ) - { - msg_Err( p_demux, "dvdnav_get_current_highlight failed" ); - return; - } + if( dvdnav_get_current_highlight( p_sys->dvdnav, &i_button ) + != DVDNAV_STATUS_OK ) + { + msg_Err( p_demux, "dvdnav_get_current_highlight failed" ); + return; + } - b_button_ok = false; - if( i_button > 0 && i_title == 0 ) - { - pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav ); + b_button_ok = false; + if( i_button > 0 && i_title == 0 ) + { + pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav ); - b_button_ok = DVDNAV_STATUS_OK == - dvdnav_get_highlight_area( pci, i_button, b_mode, &hl ); - } + b_button_ok = DVDNAV_STATUS_OK == + dvdnav_get_highlight_area( pci, i_button, b_mode, &hl ); + } - if( b_button_ok ) + if( b_button_ok ) + { + for( unsigned i = 0; i < 4; i++ ) { - int i; - for( i = 0; i < 4; i++ ) - { - uint32_t i_yuv = p_sys->clut[(hl.palette>>(16+i*4))&0x0f]; - uint8_t i_alpha = ( (hl.palette>>(i*4))&0x0f ) * 0xff / 0xf; - - p_sys->palette[i][0] = (i_yuv >> 16) & 0xff; - p_sys->palette[i][1] = (i_yuv >> 0) & 0xff; - p_sys->palette[i][2] = (i_yuv >> 8) & 0xff; - p_sys->palette[i][3] = i_alpha; - } + uint32_t i_yuv = p_sys->clut[(hl.palette>>(16+i*4))&0x0f]; + uint8_t i_alpha = ( (hl.palette>>(i*4))&0x0f ) * 0xff / 0xf; - vlc_mutex_lock( p_mutex ); - var_SetInteger( p_sys->p_input, "x-start", hl.sx ); - var_SetInteger( p_sys->p_input, "x-end", hl.ex ); - var_SetInteger( p_sys->p_input, "y-start", hl.sy ); - var_SetInteger( p_sys->p_input, "y-end", hl.ey ); + p_sys->palette[i][0] = (i_yuv >> 16) & 0xff; + p_sys->palette[i][1] = (i_yuv >> 0) & 0xff; + p_sys->palette[i][2] = (i_yuv >> 8) & 0xff; + p_sys->palette[i][3] = i_alpha; + } - var_SetAddress( p_sys->p_input, "menu-palette", p_sys->palette ); + vlc_global_lock( VLC_HIGHLIGHT_MUTEX ); + var_SetInteger( p_sys->p_input, "x-start", hl.sx ); + var_SetInteger( p_sys->p_input, "x-end", hl.ex ); + var_SetInteger( p_sys->p_input, "y-start", hl.sy ); + var_SetInteger( p_sys->p_input, "y-end", hl.ey ); - var_SetBool( p_sys->p_input, "highlight", true ); - vlc_mutex_unlock( p_mutex ); + var_SetAddress( p_sys->p_input, "menu-palette", p_sys->palette ); + var_SetBool( p_sys->p_input, "highlight", true ); - msg_Dbg( p_demux, "buttonUpdate %d", i_button ); - } - else - { - msg_Dbg( p_demux, "buttonUpdate not done b=%d t=%d", - i_button, i_title ); + msg_Dbg( p_demux, "buttonUpdate %d", i_button ); + } + else + { + msg_Dbg( p_demux, "buttonUpdate not done b=%d t=%d", + i_button, i_title ); - /* Show all */ - vlc_mutex_lock( p_mutex ); - var_SetBool( p_sys->p_input, "highlight", false ); - vlc_mutex_unlock( p_mutex ); - } + /* Show all */ + vlc_global_lock( VLC_HIGHLIGHT_MUTEX ); + var_SetBool( p_sys->p_input, "highlight", false ); } + vlc_global_unlock( VLC_HIGHLIGHT_MUTEX ); } static void ESSubtitleUpdate( demux_t *p_demux ) @@ -1448,43 +1435,51 @@ static int EventIntf( vlc_object_t *p_input, char const *psz_var, *****************************************************************************/ static int ProbeDVD( const char *psz_name ) { -#ifdef HAVE_SYS_STAT_H - struct stat stat_info; - uint8_t pi_anchor[2]; - int i_fd, i_ret; - if( !*psz_name ) - { /* Triggers libdvdcss autodetection */ return VLC_SUCCESS; - } - if( (i_fd = vlc_open( psz_name, O_RDONLY |O_NONBLOCK )) == -1 ) - { - return VLC_SUCCESS; /* Let dvdnav_open() do the probing */ - } + int fd = vlc_open( psz_name, O_RDONLY | O_NONBLOCK ); + if( fd == -1 ) +#ifdef HAVE_FDOPENDIR + return VLC_EGENERIC; +#else + return (errno == ENOENT) ? VLC_EGENERIC : VLC_SUCCESS; +#endif - i_ret = VLC_EGENERIC; + int ret = VLC_EGENERIC; - if( fstat( i_fd, &stat_info ) || !S_ISREG( stat_info.st_mode ) ) +#ifdef HAVE_SYS_STAT_H + struct stat stat_info; + + if( fstat( fd, &stat_info ) == -1 ) + goto bailout; + + if( !S_ISREG( stat_info.st_mode ) ) { - if( !S_ISFIFO( stat_info.st_mode ) ) - i_ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */ + if( S_ISDIR( stat_info.st_mode ) || S_ISBLK( stat_info.st_mode ) ) + ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */ goto bailout; } +#endif + /* Match extension as the anchor exhibits too many false positives */ + const char *ext = strrchr( psz_name, '.' ); + if( ext == NULL ) + goto bailout; + ext++; + if( strcasecmp( ext, "iso" ) && strcasecmp( ext, "img" ) && + strcasecmp( ext, "mdf" ) && strcasecmp( ext, "dvd" ) ) + goto bailout; /* Try to find the anchor (2 bytes at LBA 256) */ - if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1 - && read( i_fd, pi_anchor, 2 ) == 2 - && GetWLE( pi_anchor ) == 2 ) - i_ret = VLC_SUCCESS; /* Found a potential anchor */ + uint16_t anchor; -bailout: - close( i_fd ); + if( lseek( fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1 + && read( fd, &anchor, 2 ) == 2 + && GetWLE( &anchor ) == 2 ) + ret = VLC_SUCCESS; /* Found a potential anchor */ - return i_ret; -#else - - return VLC_SUCCESS; -#endif +bailout: + close( fd ); + return ret; }