X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdvdnav.c;h=f1349bc6536333ced9ebd7a06e9f47897468035c;hb=9da6dd53dab766aec020176861fcd63c606619b6;hp=763ceea60c397ee03212d9e67e652f6655d1af9f;hpb=13ae40b0efc4f1b1ce205d9a057537047fcab3f4;p=vlc diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index 763ceea60c..f1349bc653 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -29,7 +29,7 @@ # include "config.h" #endif -#include +#include #include #include #include @@ -52,7 +52,7 @@ #endif #include "vlc_keys.h" -#include "iso_lang.h" +#include "vlc_iso_lang.h" /* FIXME we should find a better way than including that */ #include "../../src/text/iso-639_def.h" @@ -83,22 +83,22 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -vlc_module_begin(); - set_shortname( N_("DVD with menus") ); - set_description( N_("DVDnav Input") ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_ACCESS ); +vlc_module_begin () + set_shortname( N_("DVD with menus") ) + set_description( N_("DVDnav Input") ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_ACCESS ) add_integer( "dvdnav-angle", 1, NULL, ANGLE_TEXT, ANGLE_LONGTEXT, false ); add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, true ); add_bool( "dvdnav-menu", true, NULL, MENU_TEXT, MENU_LONGTEXT, false ); - set_capability( "access_demux", 5 ); - add_shortcut( "dvd" ); - add_shortcut( "dvdnav" ); - set_callbacks( Open, Close ); -vlc_module_end(); + set_capability( "access_demux", 5 ) + add_shortcut( "dvd" ) + add_shortcut( "dvdnav" ) + set_callbacks( Open, Close ) +vlc_module_end () /* Shall we use libdvdnav's read ahead cache? */ #define DVD_READ_CACHE 1 @@ -122,7 +122,7 @@ typedef struct } event_thread_t; -static int EventThread( vlc_object_t * ); +static void* EventThread( vlc_object_t * ); struct demux_sys_t { @@ -155,7 +155,7 @@ struct demux_sys_t static int Control( demux_t *, int, va_list ); static int Demux( demux_t * ); -static int DemuxBlock( demux_t *, uint8_t *, int ); +static int DemuxBlock( demux_t *, const uint8_t *, int ); static void DemuxTitles( demux_t * ); static void ESSubtitleUpdate( demux_t * ); @@ -166,6 +166,8 @@ static int ProbeDVD( demux_t *, char * ); static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var ); +static int ControlInternal( demux_t *, int, ... ); + /***************************************************************************** * DemuxOpen: *****************************************************************************/ @@ -254,15 +256,19 @@ static int Open( vlc_object_t *p_this ) msg_Warn( p_demux, "cannot set PGC positioning flag" ); } - /* Set menu language ("en") - * XXX: maybe it would be better to set it like audio/spu - * or to create a --menu-language option */ - if( dvdnav_menu_language_select( p_sys->dvdnav, LANGUAGE_DEFAULT ) != + /* Set menu language + * XXX A menu-language may be better than sub-language */ + psz_code = DemuxGetLanguageCode( p_demux, "sub-language" ); + if( dvdnav_menu_language_select( p_sys->dvdnav, psz_code ) != DVDNAV_STATUS_OK ) { msg_Warn( p_demux, "can't set menu language to '%s' (%s)", - LANGUAGE_DEFAULT, dvdnav_err_to_string( p_sys->dvdnav ) ); + psz_code, dvdnav_err_to_string( p_sys->dvdnav ) ); + /* We try to fall back to 'en' */ + if( strcmp( psz_code, LANGUAGE_DEFAULT ) ) + dvdnav_menu_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT ); } + free( psz_code ); /* Set audio language */ psz_code = DemuxGetLanguageCode( p_demux, "audio-language" ); @@ -273,7 +279,7 @@ static int Open( vlc_object_t *p_this ) psz_code, dvdnav_err_to_string( p_sys->dvdnav ) ); /* We try to fall back to 'en' */ if( strcmp( psz_code, LANGUAGE_DEFAULT ) ) - dvdnav_audio_language_select( p_sys->dvdnav, LANGUAGE_DEFAULT ); + dvdnav_audio_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT ); } free( psz_code ); @@ -286,7 +292,7 @@ static int Open( vlc_object_t *p_this ) psz_code, dvdnav_err_to_string( p_sys->dvdnav ) ); /* We try to fall back to 'en' */ if( strcmp( psz_code, LANGUAGE_DEFAULT ) ) - dvdnav_spu_language_select(p_sys->dvdnav, LANGUAGE_DEFAULT ); + dvdnav_spu_language_select(p_sys->dvdnav, (char*)LANGUAGE_DEFAULT ); } free( psz_code ); @@ -566,6 +572,17 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) } } +static int ControlInternal( demux_t *p_demux, int i_query, ... ) +{ + va_list args; + int i_result; + + va_start( args, i_query ); + i_result = Control( p_demux, i_query, args ); + va_end( args ); + + return i_result; +} /***************************************************************************** * Demux: *****************************************************************************/ @@ -588,12 +605,18 @@ static int Demux( demux_t *p_demux ) { msg_Warn( p_demux, "cannot get next block (%s)", dvdnav_err_to_string( p_sys->dvdnav ) ); + if( p_demux->info.i_title == 0 ) + { + msg_Dbg( p_demux, "jumping to first title" ); + return ControlInternal( p_demux, DEMUX_SET_TITLE, 1 ) == VLC_SUCCESS ? 1 : -1; + } return -1; } switch( i_event ) { case DVDNAV_BLOCK_OK: /* mpeg block */ + p_sys->p_ev->b_still = false; DemuxBlock( p_demux, packet, i_len ); break; @@ -607,6 +630,14 @@ static int Demux( demux_t *p_demux ) vlc_mutex_lock( &p_sys->p_ev->lock ); if( !p_sys->p_ev->b_still ) { + /* We send a dummy mpeg2 end of sequence to force still frame display */ + static const uint8_t buffer[] = { + 0x00, 0x00, 0x01, 0xe0, 0x00, 0x07, + 0x80, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xB7, + }; + DemuxBlock( p_demux, buffer, sizeof(buffer) ); + msg_Dbg( p_demux, "DVDNAV_STILL_FRAME" ); msg_Dbg( p_demux, " - length=0x%x", event->length ); p_sys->p_ev->b_still = true; @@ -828,12 +859,18 @@ static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var ) char *p; psz_lang = var_CreateGetString( p_demux, psz_var ); + if( !psz_lang ) + return strdup(LANGUAGE_DEFAULT); + /* XXX: we will use only the first value * (and ignore other ones in case of a list) */ - if( ( p = strchr( psz_lang, ',' ) ) ) *p = '\0'; + if( ( p = strchr( psz_lang, ',' ) ) ) + *p = '\0'; for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ ) { + if( *psz_lang == '\0' ) + continue; if( !strcasecmp( pl->psz_eng_name, psz_lang ) || !strcasecmp( pl->psz_native_name, psz_lang ) || !strcasecmp( pl->psz_iso639_1, psz_lang ) || @@ -929,6 +966,7 @@ static void ButtonUpdate( demux_t *p_demux, bool b_mode ) vlc_mutex_t *p_mutex = val.p_address; 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 ) @@ -937,18 +975,20 @@ static void ButtonUpdate( demux_t *p_demux, bool b_mode ) return; } + b_button_ok = false; if( i_button > 0 && i_title == 0 ) { - int i; pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav ); - dvdnav_get_highlight_area( pci, i_button, b_mode, &hl ); - + b_button_ok = dvdnav_get_highlight_area( pci, i_button, b_mode, &hl ) == DVDNAV_STATUS_OK; + } + if( b_button_ok ) + { + 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; - i_alpha = i_alpha == 0xf ? 0xff : i_alpha << 4; + 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; @@ -1025,10 +1065,10 @@ static void ESSubtitleUpdate( demux_t *p_demux ) /***************************************************************************** * DemuxBlock: demux a given block *****************************************************************************/ -static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt ) +static int DemuxBlock( demux_t *p_demux, const uint8_t *pkt, int i_pkt ) { demux_sys_t *p_sys = p_demux->p_sys; - uint8_t *p = pkt; + const uint8_t *p = pkt; while( p < &pkt[i_pkt] ) { @@ -1131,7 +1171,10 @@ static void ESNew( demux_t *p_demux, int i_id ) { switch( p_sys->i_aspect ) { - /* TODO Any docs somewhere ? */ + case 1: tk->fmt.video.i_aspect = VOUT_ASPECT_FACTOR; break; + case 2: tk->fmt.video.i_aspect = VOUT_ASPECT_FACTOR * 4 / 3; break; + case 3: tk->fmt.video.i_aspect = VOUT_ASPECT_FACTOR * 16 / 9; break; + case 4: tk->fmt.video.i_aspect = VOUT_ASPECT_FACTOR * 221 / 10; break; default: tk->fmt.video.i_aspect = 0; break; @@ -1218,7 +1261,7 @@ static int EventMouse( vlc_object_t *, char const *, static int EventKey ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); -static int EventThread( vlc_object_t *p_this ) +static void* EventThread( vlc_object_t *p_this ) { event_thread_t *p_ev = (event_thread_t*)p_this; demux_sys_t *p_sys = p_ev->p_demux->p_sys; @@ -1230,11 +1273,13 @@ static int EventThread( vlc_object_t *p_this ) p_ev->i_key_action = 0; p_ev->b_still = false; + int canc = vlc_savecancel (); + /* catch all key event */ var_AddCallback( p_ev->p_libvlc, "key-action", EventKey, p_ev ); /* main loop */ - while( !p_ev->b_die ) + while( vlc_object_alive (p_ev) ) { bool b_activated = false; @@ -1243,9 +1288,6 @@ static int EventThread( vlc_object_t *p_this ) { pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav ); - vlc_value_t valk; - int i; - vlc_mutex_lock( &p_ev->lock ); switch( p_ev->i_key_action ) { @@ -1263,8 +1305,8 @@ static int EventThread( vlc_object_t *p_this ) break; case ACTIONID_NAV_ACTIVATE: b_activated = true; - dvdnav_button_activate( p_sys->dvdnav, pci ); ButtonUpdate( p_ev->p_demux, true ); + dvdnav_button_activate( p_sys->dvdnav, pci ); break; default: break; @@ -1291,16 +1333,16 @@ static int EventThread( vlc_object_t *p_this ) if( p_ev->b_clicked ) { b_activated = true; + ButtonUpdate( p_ev->p_demux, true ); dvdnav_mouse_activate( p_sys->dvdnav, pci, valx.i_int, valy.i_int ); - ButtonUpdate( p_ev->p_demux, true ); } p_ev->b_moved = false; p_ev->b_clicked = false; vlc_mutex_unlock( &p_ev->lock ); } - if( p_vout && p_vout->b_die ) + if( p_vout && !vlc_object_alive (p_vout) ) { var_DelCallback( p_vout, "mouse-moved", EventMouse, p_ev ); var_DelCallback( p_vout, "mouse-clicked", EventMouse, p_ev ); @@ -1343,15 +1385,16 @@ static int EventThread( vlc_object_t *p_this ) vlc_object_release( p_vout ); } var_DelCallback( p_ev->p_libvlc, "key-action", EventKey, p_ev ); - + vlc_restorecancel (canc); vlc_mutex_destroy( &p_ev->lock ); - return VLC_SUCCESS; + return NULL; } static int EventMouse( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + (void)p_this; (void)oldval; (void)newval; (void)p_data; event_thread_t *p_ev = p_data; vlc_mutex_lock( &p_ev->lock ); if( psz_var[6] == 'c' ) @@ -1366,6 +1409,7 @@ static int EventMouse( vlc_object_t *p_this, char const *psz_var, static int EventKey( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + (void)p_this; (void)psz_var; (void)oldval; event_thread_t *p_ev = p_data; vlc_mutex_lock( &p_ev->lock ); p_ev->i_key_action = newval.i_int; @@ -1379,6 +1423,7 @@ static int EventKey( vlc_object_t *p_this, char const *psz_var, *****************************************************************************/ static int ProbeDVD( demux_t *p_demux, char *psz_name ) { + (void)p_demux; #ifdef HAVE_SYS_STAT_H struct stat stat_info; uint8_t pi_anchor[2];