X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdvdnav.c;h=5a200cbf2da6330e616db171cafdae962eb64730;hb=c3cc1221caf65094bc4611e71f314f3eb050a797;hp=f9df8aa02e50126b081aca02a28ad932b52c8209;hpb=df61d33b06e2b3cbbe746b2f5a9bea5b370c24ff;p=vlc diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c index f9df8aa02e..5a200cbf2d 100644 --- a/modules/access/dvdnav.c +++ b/modules/access/dvdnav.c @@ -29,10 +29,12 @@ # include "config.h" #endif -#include +#include +#include #include #include #include +#include #include @@ -50,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" @@ -82,8 +84,8 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); vlc_module_begin(); - set_shortname( _("DVD with menus") ); - set_description( _("DVDnav Input") ); + 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, @@ -120,7 +122,7 @@ typedef struct } event_thread_t; -static int EventThread( vlc_object_t * ); +static void* EventThread( vlc_object_t * ); struct demux_sys_t { @@ -153,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 * ); @@ -164,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: *****************************************************************************/ @@ -189,7 +193,7 @@ static int Open( vlc_object_t *p_this ) } } else - psz_name = strdup( p_demux->psz_path ); + psz_name = ToLocaleDup( p_demux->psz_path ); #ifdef WIN32 if( psz_name[0] && psz_name[1] == ':' && @@ -252,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" ); @@ -271,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 ); @@ -284,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 ); @@ -564,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: *****************************************************************************/ @@ -586,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; @@ -605,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; @@ -730,11 +763,11 @@ static int Demux( demux_t *p_demux ) msg_Dbg( p_demux, "DVDNAV_CELL_CHANGE" ); msg_Dbg( p_demux, " - cellN=%d", event->cellN ); msg_Dbg( p_demux, " - pgN=%d", event->pgN ); - msg_Dbg( p_demux, " - cell_length="I64Fd, event->cell_length ); - msg_Dbg( p_demux, " - pg_length="I64Fd, event->pg_length ); - msg_Dbg( p_demux, " - pgc_length="I64Fd, event->pgc_length ); - msg_Dbg( p_demux, " - cell_start="I64Fd, event->cell_start ); - msg_Dbg( p_demux, " - pg_start="I64Fd, event->pg_start ); + msg_Dbg( p_demux, " - cell_length=%"PRId64, event->cell_length ); + msg_Dbg( p_demux, " - pg_length=%"PRId64, event->pg_length ); + msg_Dbg( p_demux, " - pgc_length=%"PRId64, event->pgc_length ); + msg_Dbg( p_demux, " - cell_start=%"PRId64, event->cell_start ); + msg_Dbg( p_demux, " - pg_start=%"PRId64, event->pg_start ); /* Store the lenght in time of the current PGC */ p_sys->i_pgc_length = event->pgc_length / 90 * 1000; @@ -826,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 ) || @@ -927,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 ) @@ -935,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; @@ -1023,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] ) { @@ -1129,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; @@ -1216,23 +1261,25 @@ 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; vlc_object_t *p_vout = NULL; - vlc_mutex_init( p_ev, &p_ev->lock ); + vlc_mutex_init( &p_ev->lock ); p_ev->b_moved = false; p_ev->b_clicked = false; 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; @@ -1241,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 ) { @@ -1261,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; @@ -1289,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 ); @@ -1341,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' ) @@ -1364,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; @@ -1377,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];