From 1559e11e0001f39c791289c2c7f3734277934bdc Mon Sep 17 00:00:00 2001 From: Gildas Bazin Date: Wed, 4 Aug 2004 10:40:43 +0000 Subject: [PATCH] * modules/access/dvdnav.c: very basic probing that avoids doing a dvdnav_open() on files when they are not DVD images. * src/input/input.c: auto-probe access_demux as well. * modules/access/vcd/vcd.c: raised priority above the file access one. --- modules/access/dvdnav.c | 76 +++++++++++++++++++++++++++++++++++++--- modules/access/vcd/vcd.c | 2 +- src/input/input.c | 2 +- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index 310576d32d..b4436c9c6c 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -29,6 +29,16 @@ #include #include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif + #include "vlc_keys.h" #include "iso_lang.h" @@ -51,7 +61,7 @@ vlc_module_begin(); set_description( _("DVDnav Input") ); add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE ); - set_capability( "access_demux", 0 ); + set_capability( "access_demux", 5 ); add_shortcut( "dvd" ); add_shortcut( "dvdnav" ); add_shortcut( "dvdnavsimple" ); @@ -121,6 +131,8 @@ static void DemuxTitles( demux_t *p_demux ); static void ESSubtitleUpdate( demux_t * ); static void ButtonUpdate( demux_t * ); +static int ProbeDVD( demux_t *, char * ); + /***************************************************************************** * DemuxOpen: *****************************************************************************/ @@ -139,6 +151,16 @@ 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( p_demux, psz_name ) != VLC_SUCCESS ) + { + free( psz_name ); + return VLC_EGENERIC; + } + + msg_Dbg( p_this, "dvdroot=%s title=%d chapter=%d angle=%d", + psz_name, i_title, i_chapter, i_angle ); + /* Open dvdnav */ if( dvdnav_open( &p_dvdnav, psz_name ) != DVDNAV_STATUS_OK ) { @@ -779,9 +801,6 @@ static char *ParseCL( vlc_object_t *p_this, char *psz_name, vlc_bool_t b_force, } #endif - msg_Dbg( p_this, "dvdroot=%s title=%d chapter=%d angle=%d", - psz_source, *i_title, *i_chapter, *i_angle ); - return psz_source; } @@ -1317,3 +1336,52 @@ static int EventKey( vlc_object_t *p_this, char const *psz_var, return VLC_SUCCESS; } + +/***************************************************************************** + * ProbeDVD: very weak probing that avoids going too often into a dvdnav_open() + *****************************************************************************/ +static int ProbeDVD( demux_t *p_demux, char *psz_name ) +{ +#ifdef HAVE_SYS_STAT_H + struct stat stat_info; + uint8_t pi_anchor[2]; + uint16_t i_tag_id = 0; + int i_fd, i_ret; + + if( stat( psz_name, &stat_info ) || !S_ISREG( stat_info.st_mode ) ) + { + /* Let dvdnav_open() do the probing */ + return VLC_SUCCESS; + } + + if( (i_fd = open( psz_name, O_RDONLY )) == -1 ) + { + /* Let dvdnav_open() do the probing */ + return VLC_SUCCESS; + } + + /* Try to find the anchor (2 bytes at LBA 256) */ + i_ret = VLC_SUCCESS; + if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) == -1 ) + { + i_ret = VLC_EGENERIC; + } + + if( read( i_fd, pi_anchor, 2 ) == 2 ) + { + i_tag_id = GetWLE(pi_anchor); + if( i_tag_id != 2 ) i_ret = VLC_EGENERIC; /* Not an anchor */ + } + else + { + i_ret = VLC_EGENERIC; + } + + close( i_fd ); + + return i_ret; +#else + + return VLC_SUCCESS; +#endif +} diff --git a/modules/access/vcd/vcd.c b/modules/access/vcd/vcd.c index 76822e43f1..68e997de5d 100644 --- a/modules/access/vcd/vcd.c +++ b/modules/access/vcd/vcd.c @@ -44,7 +44,7 @@ static void Close( vlc_object_t * ); vlc_module_begin(); set_description( _("VCD input") ); - set_capability( "access2", 10 ); + set_capability( "access2", 60 ); set_callbacks( Open, Close ); add_usage_hint( N_("[vcd:][device][@[title][,[chapter]]]") ); diff --git a/src/input/input.c b/src/input/input.c index 176c686f61..39b92d6fa7 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -1455,7 +1455,7 @@ static int InputSourceInit( input_thread_t *p_input, psz_demux = psz_forced_demux; /* Try access_demux if no demux given */ - if( *psz_access && *psz_demux == '\0' ) + if( *psz_demux == '\0' ) { in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path, NULL, p_input->p_es_out ); -- 2.39.2