MacOS: fixes memory management issue. closes #3807
[vlc/solaris.git] / modules / access / dvdnav.c
blob90d915509335638dbcbb6cf261e5a1c7ec5ed156
1 /*****************************************************************************
2 * dvdnav.c: DVD module using the dvdnav library.
3 *****************************************************************************
4 * Copyright (C) 2004-2009 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <assert.h>
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_input.h>
36 #include <vlc_access.h>
37 #include <vlc_demux.h>
38 #include <vlc_charset.h>
39 #include <vlc_fs.h>
41 #include <vlc_dialog.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 #include <sys/types.h>
47 #ifdef HAVE_SYS_STAT_H
48 # include <sys/stat.h>
49 #endif
50 #ifdef HAVE_FCNTL_H
51 # include <fcntl.h>
52 #endif
54 #include <vlc_keys.h>
55 #include <vlc_iso_lang.h>
57 /* FIXME we should find a better way than including that */
58 #include "../../src/text/iso-639_def.h"
61 #include <dvdnav/dvdnav.h>
63 #include "../demux/ps.h"
65 /*****************************************************************************
66 * Module descriptor
67 *****************************************************************************/
68 #define ANGLE_TEXT N_("DVD angle")
69 #define ANGLE_LONGTEXT N_( \
70 "Default DVD angle." )
72 #define CACHING_TEXT N_("Caching value in ms")
73 #define CACHING_LONGTEXT N_( \
74 "Caching value for DVDs. This "\
75 "value should be set in milliseconds." )
76 #define MENU_TEXT N_("Start directly in menu")
77 #define MENU_LONGTEXT N_( \
78 "Start the DVD directly in the main menu. This "\
79 "will try to skip all the useless warning introductions." )
81 #define LANGUAGE_DEFAULT ("en")
83 static int Open ( vlc_object_t * );
84 static void Close( vlc_object_t * );
86 vlc_module_begin ()
87 set_shortname( N_("DVD with menus") )
88 set_description( N_("DVDnav Input") )
89 set_category( CAT_INPUT )
90 set_subcategory( SUBCAT_INPUT_ACCESS )
91 add_integer( "dvdnav-angle", 1, NULL, ANGLE_TEXT,
92 ANGLE_LONGTEXT, false )
93 add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, NULL,
94 CACHING_TEXT, CACHING_LONGTEXT, true )
95 add_bool( "dvdnav-menu", true, NULL,
96 MENU_TEXT, MENU_LONGTEXT, false )
97 set_capability( "access_demux", 5 )
98 add_shortcut( "dvd" )
99 add_shortcut( "dvdnav" )
100 add_shortcut( "file" )
101 set_callbacks( Open, Close )
102 vlc_module_end ()
104 /* Shall we use libdvdnav's read ahead cache? */
105 #define DVD_READ_CACHE 1
107 /*****************************************************************************
108 * Local prototypes
109 *****************************************************************************/
110 struct demux_sys_t
112 dvdnav_t *dvdnav;
114 /* */
115 bool b_reset_pcr;
117 struct
119 bool b_created;
120 bool b_enabled;
121 vlc_mutex_t lock;
122 vlc_timer_t timer;
123 } still;
125 /* track */
126 ps_track_t tk[PS_TK_COUNT];
127 int i_mux_rate;
129 /* for spu variables */
130 input_thread_t *p_input;
132 /* event */
133 vlc_object_t *p_vout;
135 /* palette for menus */
136 uint32_t clut[16];
137 uint8_t palette[4][4];
138 bool b_spu_change;
140 /* Aspect ration */
141 struct {
142 unsigned i_num;
143 unsigned i_den;
144 } sar;
146 /* */
147 int i_title;
148 input_title_t **title;
150 /* lenght of program group chain */
151 mtime_t i_pgc_length;
152 int i_vobu_index;
153 int i_vobu_flush;
156 static int Control( demux_t *, int, va_list );
157 static int Demux( demux_t * );
158 static int DemuxBlock( demux_t *, const uint8_t *, int );
159 static void DemuxForceStill( demux_t * );
161 static void DemuxTitles( demux_t * );
162 static void ESSubtitleUpdate( demux_t * );
163 static void ButtonUpdate( demux_t *, bool );
165 static void ESNew( demux_t *, int );
166 static int ProbeDVD( demux_t *, char * );
168 static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var );
170 static int ControlInternal( demux_t *, int, ... );
172 static void StillTimer( void * );
174 static int EventKey( vlc_object_t *, char const *,
175 vlc_value_t, vlc_value_t, void * );
176 static int EventMouse( vlc_object_t *, char const *,
177 vlc_value_t, vlc_value_t, void * );
178 static int EventIntf( vlc_object_t *, char const *,
179 vlc_value_t, vlc_value_t, void * );
181 /*****************************************************************************
182 * DemuxOpen:
183 *****************************************************************************/
184 static int Open( vlc_object_t *p_this )
186 demux_t *p_demux = (demux_t*)p_this;
187 demux_sys_t *p_sys;
188 dvdnav_t *p_dvdnav;
189 int i_angle;
190 char *psz_name;
191 char *psz_code;
193 if( !p_demux->psz_path || !*p_demux->psz_path )
195 /* Only when selected */
196 if( !p_demux->psz_access || !*p_demux->psz_access )
197 return VLC_EGENERIC;
199 psz_name = var_CreateGetString( p_this, "dvd" );
200 if( !psz_name )
202 psz_name = strdup("");
205 else
206 psz_name = ToLocaleDup( p_demux->psz_path );
208 #ifdef WIN32
209 /* Remove trailing backslash, otherwise dvdnav_open will fail */
210 if( *psz_name && *(psz_name + strlen(psz_name) - 1) == '\\' )
212 *(psz_name + strlen(psz_name) - 1) = '\0';
214 #endif
216 /* Try some simple probing to avoid going through dvdnav_open too often */
217 if( ProbeDVD( p_demux, psz_name ) != VLC_SUCCESS )
219 free( psz_name );
220 return VLC_EGENERIC;
223 /* Open dvdnav */
224 if( dvdnav_open( &p_dvdnav, psz_name ) != DVDNAV_STATUS_OK )
226 msg_Warn( p_demux, "cannot open dvdnav" );
227 free( psz_name );
228 return VLC_EGENERIC;
230 free( psz_name );
232 /* Fill p_demux field */
233 DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
234 p_sys->dvdnav = p_dvdnav;
235 p_sys->b_reset_pcr = false;
237 ps_track_init( p_sys->tk );
238 p_sys->sar.i_num = 0;
239 p_sys->sar.i_den = 0;
240 p_sys->i_mux_rate = 0;
241 p_sys->i_pgc_length = 0;
242 p_sys->b_spu_change = false;
243 p_sys->i_vobu_index = 0;
244 p_sys->i_vobu_flush = 0;
246 if( 1 )
248 // Hack for libdvdnav CVS.
249 // Without it dvdnav_get_number_of_titles() fails.
250 // Remove when fixed in libdvdnav CVS.
251 uint8_t buffer[DVD_VIDEO_LB_LEN];
252 int i_event, i_len;
254 if( dvdnav_get_next_block( p_sys->dvdnav, buffer, &i_event, &i_len )
255 == DVDNAV_STATUS_ERR )
257 msg_Warn( p_demux, "dvdnav_get_next_block failed" );
260 dvdnav_sector_search( p_sys->dvdnav, 0, SEEK_SET );
263 /* Configure dvdnav */
264 if( dvdnav_set_readahead_flag( p_sys->dvdnav, DVD_READ_CACHE ) !=
265 DVDNAV_STATUS_OK )
267 msg_Warn( p_demux, "cannot set read-a-head flag" );
270 if( dvdnav_set_PGC_positioning_flag( p_sys->dvdnav, 1 ) !=
271 DVDNAV_STATUS_OK )
273 msg_Warn( p_demux, "cannot set PGC positioning flag" );
276 /* Set menu language
277 * XXX A menu-language may be better than sub-language */
278 psz_code = DemuxGetLanguageCode( p_demux, "sub-language" );
279 if( dvdnav_menu_language_select( p_sys->dvdnav, psz_code ) !=
280 DVDNAV_STATUS_OK )
282 msg_Warn( p_demux, "can't set menu language to '%s' (%s)",
283 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
284 /* We try to fall back to 'en' */
285 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
286 dvdnav_menu_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
288 free( psz_code );
290 /* Set audio language */
291 psz_code = DemuxGetLanguageCode( p_demux, "audio-language" );
292 if( dvdnav_audio_language_select( p_sys->dvdnav, psz_code ) !=
293 DVDNAV_STATUS_OK )
295 msg_Warn( p_demux, "can't set audio language to '%s' (%s)",
296 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
297 /* We try to fall back to 'en' */
298 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
299 dvdnav_audio_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
301 free( psz_code );
303 /* Set spu language */
304 psz_code = DemuxGetLanguageCode( p_demux, "sub-language" );
305 if( dvdnav_spu_language_select( p_sys->dvdnav, psz_code ) !=
306 DVDNAV_STATUS_OK )
308 msg_Warn( p_demux, "can't set spu language to '%s' (%s)",
309 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
310 /* We try to fall back to 'en' */
311 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
312 dvdnav_spu_language_select(p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
314 free( psz_code );
316 DemuxTitles( p_demux );
318 if( var_CreateGetBool( p_demux, "dvdnav-menu" ) )
320 msg_Dbg( p_demux, "trying to go to dvd menu" );
322 if( dvdnav_title_play( p_sys->dvdnav, 1 ) != DVDNAV_STATUS_OK )
324 msg_Err( p_demux, "cannot set title (can't decrypt DVD?)" );
325 dialog_Fatal( p_demux, _("Playback failure"), "%s",
326 _("VLC cannot set the DVD's title. It possibly "
327 "cannot decrypt the entire disc.") );
328 dvdnav_close( p_sys->dvdnav );
329 free( p_sys );
330 return VLC_EGENERIC;
333 if( dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Title ) !=
334 DVDNAV_STATUS_OK )
336 /* Try going to menu root */
337 if( dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root ) !=
338 DVDNAV_STATUS_OK )
339 msg_Warn( p_demux, "cannot go to dvd menu" );
343 i_angle = var_CreateGetInteger( p_demux, "dvdnav-angle" );
344 if( i_angle <= 0 ) i_angle = 1;
346 /* Update default_pts to a suitable value for dvdnav access */
347 var_Create( p_demux, "dvdnav-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
349 /* FIXME hack hack hack hack FIXME */
350 /* Get p_input and create variable */
351 p_sys->p_input = demux_GetParentInput( p_demux );
352 var_Create( p_sys->p_input, "x-start", VLC_VAR_INTEGER );
353 var_Create( p_sys->p_input, "y-start", VLC_VAR_INTEGER );
354 var_Create( p_sys->p_input, "x-end", VLC_VAR_INTEGER );
355 var_Create( p_sys->p_input, "y-end", VLC_VAR_INTEGER );
356 var_Create( p_sys->p_input, "color", VLC_VAR_ADDRESS );
357 var_Create( p_sys->p_input, "menu-palette", VLC_VAR_ADDRESS );
358 var_Create( p_sys->p_input, "highlight", VLC_VAR_BOOL );
359 var_Create( p_sys->p_input, "highlight-mutex", VLC_VAR_MUTEX );
361 /* catch all key event */
362 var_AddCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
363 /* catch vout creation event */
364 var_AddCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
366 p_sys->still.b_enabled = false;
367 vlc_mutex_init( &p_sys->still.lock );
368 if( !vlc_timer_create( &p_sys->still.timer, StillTimer, p_sys ) )
369 p_sys->still.b_created = true;
371 return VLC_SUCCESS;
374 /*****************************************************************************
375 * Close:
376 *****************************************************************************/
377 static void Close( vlc_object_t *p_this )
379 demux_t *p_demux = (demux_t*)p_this;
380 demux_sys_t *p_sys = p_demux->p_sys;
381 int i;
383 /* Stop vout event handler */
384 var_DelCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
385 if( p_sys->p_vout != NULL )
386 { /* Should not happen, but better be safe than sorry. */
387 msg_Warn( p_sys->p_vout, "removing dangling mouse DVD callbacks" );
388 var_DelCallback( p_sys->p_vout, "mouse-moved", EventMouse, p_demux );
389 var_DelCallback( p_sys->p_vout, "mouse-clicked", EventMouse, p_demux );
392 /* Stop key event handler (FIXME: should really be per-vout too) */
393 var_DelCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
395 /* Stop still image handler */
396 if( p_sys->still.b_created )
397 vlc_timer_destroy( p_sys->still.timer );
398 vlc_mutex_destroy( &p_sys->still.lock );
400 var_Destroy( p_sys->p_input, "highlight-mutex" );
401 var_Destroy( p_sys->p_input, "highlight" );
402 var_Destroy( p_sys->p_input, "x-start" );
403 var_Destroy( p_sys->p_input, "x-end" );
404 var_Destroy( p_sys->p_input, "y-start" );
405 var_Destroy( p_sys->p_input, "y-end" );
406 var_Destroy( p_sys->p_input, "color" );
407 var_Destroy( p_sys->p_input, "menu-palette" );
409 vlc_object_release( p_sys->p_input );
411 for( i = 0; i < PS_TK_COUNT; i++ )
413 ps_track_t *tk = &p_sys->tk[i];
414 if( tk->b_seen )
416 es_format_Clean( &tk->fmt );
417 if( tk->es ) es_out_Del( p_demux->out, tk->es );
421 dvdnav_close( p_sys->dvdnav );
422 free( p_sys );
425 /*****************************************************************************
426 * Control:
427 *****************************************************************************/
428 static int Control( demux_t *p_demux, int i_query, va_list args )
430 demux_sys_t *p_sys = p_demux->p_sys;
431 input_title_t ***ppp_title;
432 int i;
434 switch( i_query )
436 case DEMUX_SET_POSITION:
437 case DEMUX_GET_POSITION:
438 case DEMUX_GET_TIME:
439 case DEMUX_GET_LENGTH:
441 uint32_t pos, len;
442 if( dvdnav_get_position( p_sys->dvdnav, &pos, &len ) !=
443 DVDNAV_STATUS_OK || len == 0 )
445 return VLC_EGENERIC;
448 switch( i_query )
450 case DEMUX_GET_POSITION:
451 *va_arg( args, double* ) = (double)pos / (double)len;
452 return VLC_SUCCESS;
454 case DEMUX_SET_POSITION:
455 pos = va_arg( args, double ) * len;
456 if( dvdnav_sector_search( p_sys->dvdnav, pos, SEEK_SET ) ==
457 DVDNAV_STATUS_OK )
459 return VLC_SUCCESS;
461 break;
463 case DEMUX_GET_TIME:
464 if( p_sys->i_pgc_length > 0 )
466 *va_arg( args, int64_t * ) = p_sys->i_pgc_length*pos/len;
467 return VLC_SUCCESS;
469 break;
471 case DEMUX_GET_LENGTH:
472 if( p_sys->i_pgc_length > 0 )
474 *va_arg( args, int64_t * ) = (int64_t)p_sys->i_pgc_length;
475 return VLC_SUCCESS;
477 break;
479 return VLC_EGENERIC;
482 /* Special for access_demux */
483 case DEMUX_CAN_PAUSE:
484 case DEMUX_CAN_SEEK:
485 case DEMUX_CAN_CONTROL_PACE:
486 /* TODO */
487 *va_arg( args, bool * ) = true;
488 return VLC_SUCCESS;
490 case DEMUX_SET_PAUSE_STATE:
491 return VLC_SUCCESS;
493 case DEMUX_GET_TITLE_INFO:
494 ppp_title = va_arg( args, input_title_t*** );
495 *va_arg( args, int* ) = p_sys->i_title;
496 *va_arg( args, int* ) = 0; /* Title offset */
497 *va_arg( args, int* ) = 1; /* Chapter offset */
499 /* Duplicate title infos */
500 *ppp_title = malloc( sizeof( input_title_t ** ) * p_sys->i_title );
501 for( i = 0; i < p_sys->i_title; i++ )
503 (*ppp_title)[i] = vlc_input_title_Duplicate( p_sys->title[i] );
505 return VLC_SUCCESS;
507 case DEMUX_SET_TITLE:
508 i = (int)va_arg( args, int );
509 if( ( i == 0 && dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root )
510 != DVDNAV_STATUS_OK ) ||
511 ( i != 0 && dvdnav_title_play( p_sys->dvdnav, i )
512 != DVDNAV_STATUS_OK ) )
514 msg_Warn( p_demux, "cannot set title/chapter" );
515 return VLC_EGENERIC;
517 p_demux->info.i_update |=
518 INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
519 p_demux->info.i_title = i;
520 p_demux->info.i_seekpoint = 0;
521 return VLC_SUCCESS;
523 case DEMUX_SET_SEEKPOINT:
524 i = va_arg( args, int );
525 if( p_demux->info.i_title == 0 )
527 static const int argtab[] = {
528 DVD_MENU_Escape,
529 DVD_MENU_Root,
530 DVD_MENU_Title,
531 DVD_MENU_Part,
532 DVD_MENU_Subpicture,
533 DVD_MENU_Audio,
534 DVD_MENU_Angle
536 enum { numargs = sizeof(argtab)/sizeof(int) };
537 if( (unsigned)i >= numargs || DVDNAV_STATUS_OK !=
538 dvdnav_menu_call(p_sys->dvdnav,argtab[i]) )
539 return VLC_EGENERIC;
541 else if( dvdnav_part_play( p_sys->dvdnav, p_demux->info.i_title,
542 i + 1 ) != DVDNAV_STATUS_OK )
544 msg_Warn( p_demux, "cannot set title/chapter" );
545 return VLC_EGENERIC;
547 p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
548 p_demux->info.i_seekpoint = i;
549 return VLC_SUCCESS;
551 case DEMUX_GET_PTS_DELAY:
552 *va_arg( args, int64_t * )
553 = (int64_t)var_GetInteger( p_demux, "dvdnav-caching" ) *1000;
554 return VLC_SUCCESS;
556 case DEMUX_GET_META:
558 const char *title_name = NULL;
560 dvdnav_get_title_string(p_sys->dvdnav, &title_name);
561 if( (NULL != title_name) && ('\0' != title_name[0]) )
563 vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
564 vlc_meta_Set( p_meta, vlc_meta_Title, title_name );
565 return VLC_SUCCESS;
567 return VLC_EGENERIC;
570 /* TODO implement others */
571 default:
572 return VLC_EGENERIC;
576 static int ControlInternal( demux_t *p_demux, int i_query, ... )
578 va_list args;
579 int i_result;
581 va_start( args, i_query );
582 i_result = Control( p_demux, i_query, args );
583 va_end( args );
585 return i_result;
587 /*****************************************************************************
588 * Demux:
589 *****************************************************************************/
590 static int Demux( demux_t *p_demux )
592 demux_sys_t *p_sys = p_demux->p_sys;
594 uint8_t buffer[DVD_VIDEO_LB_LEN];
595 uint8_t *packet = buffer;
596 int i_event;
597 int i_len;
599 #if DVD_READ_CACHE
600 if( dvdnav_get_next_cache_block( p_sys->dvdnav, &packet, &i_event, &i_len )
601 == DVDNAV_STATUS_ERR )
602 #else
603 if( dvdnav_get_next_block( p_sys->dvdnav, packet, &i_event, &i_len )
604 == DVDNAV_STATUS_ERR )
605 #endif
607 msg_Warn( p_demux, "cannot get next block (%s)",
608 dvdnav_err_to_string( p_sys->dvdnav ) );
609 if( p_demux->info.i_title == 0 )
611 msg_Dbg( p_demux, "jumping to first title" );
612 return ControlInternal( p_demux, DEMUX_SET_TITLE, 1 ) == VLC_SUCCESS ? 1 : -1;
614 return -1;
617 switch( i_event )
619 case DVDNAV_BLOCK_OK: /* mpeg block */
620 vlc_mutex_lock( &p_sys->still.lock );
621 vlc_timer_schedule( p_sys->still.timer, false, 0, 0 );
622 p_sys->still.b_enabled = false;
623 vlc_mutex_unlock( &p_sys->still.lock );
624 if( p_sys->b_reset_pcr )
626 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
627 p_sys->b_reset_pcr = false;
629 DemuxBlock( p_demux, packet, i_len );
630 if( p_sys->i_vobu_index > 0 )
632 if( p_sys->i_vobu_flush == p_sys->i_vobu_index )
633 DemuxForceStill( p_demux );
634 p_sys->i_vobu_index++;
636 break;
638 case DVDNAV_NOP: /* Nothing */
639 msg_Dbg( p_demux, "DVDNAV_NOP" );
640 break;
642 case DVDNAV_STILL_FRAME:
644 dvdnav_still_event_t *event = (dvdnav_still_event_t*)packet;
645 bool b_still_init = false;
647 vlc_mutex_lock( &p_sys->still.lock );
648 if( !p_sys->still.b_enabled )
650 msg_Dbg( p_demux, "DVDNAV_STILL_FRAME" );
651 msg_Dbg( p_demux, " - length=0x%x", event->length );
652 p_sys->still.b_enabled = true;
654 if( event->length != 0xff && p_sys->still.b_created )
656 mtime_t delay = event->length * CLOCK_FREQ;
657 vlc_timer_schedule( p_sys->still.timer, false, delay, 0 );
660 b_still_init = true;
662 vlc_mutex_unlock( &p_sys->still.lock );
664 if( b_still_init )
666 DemuxForceStill( p_demux );
667 p_sys->b_reset_pcr = true;
669 msleep( 40000 );
670 break;
673 case DVDNAV_SPU_CLUT_CHANGE:
675 int i;
677 msg_Dbg( p_demux, "DVDNAV_SPU_CLUT_CHANGE" );
678 /* Update color lookup table (16 *uint32_t in packet) */
679 memcpy( p_sys->clut, packet, 16 * sizeof( uint32_t ) );
681 /* HACK to get the SPU tracks registered in the right order */
682 for( i = 0; i < 0x1f; i++ )
684 if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
685 ESNew( p_demux, 0xbd20 + i );
687 /* END HACK */
688 break;
691 case DVDNAV_SPU_STREAM_CHANGE:
693 dvdnav_spu_stream_change_event_t *event =
694 (dvdnav_spu_stream_change_event_t*)packet;
695 int i;
697 msg_Dbg( p_demux, "DVDNAV_SPU_STREAM_CHANGE" );
698 msg_Dbg( p_demux, " - physical_wide=%d",
699 event->physical_wide );
700 msg_Dbg( p_demux, " - physical_letterbox=%d",
701 event->physical_letterbox);
702 msg_Dbg( p_demux, " - physical_pan_scan=%d",
703 event->physical_pan_scan );
705 ESSubtitleUpdate( p_demux );
706 p_sys->b_spu_change = true;
708 /* HACK to get the SPU tracks registered in the right order */
709 for( i = 0; i < 0x1f; i++ )
711 if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
712 ESNew( p_demux, 0xbd20 + i );
714 /* END HACK */
715 break;
718 case DVDNAV_AUDIO_STREAM_CHANGE:
720 dvdnav_audio_stream_change_event_t *event =
721 (dvdnav_audio_stream_change_event_t*)packet;
722 msg_Dbg( p_demux, "DVDNAV_AUDIO_STREAM_CHANGE" );
723 msg_Dbg( p_demux, " - physical=%d", event->physical );
724 /* TODO */
725 break;
728 case DVDNAV_VTS_CHANGE:
730 int32_t i_title = 0;
731 int32_t i_part = 0;
732 int i;
734 dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t*)packet;
735 msg_Dbg( p_demux, "DVDNAV_VTS_CHANGE" );
736 msg_Dbg( p_demux, " - vtsN=%d", event->new_vtsN );
737 msg_Dbg( p_demux, " - domain=%d", event->new_domain );
739 /* reset PCR */
740 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
742 for( i = 0; i < PS_TK_COUNT; i++ )
744 ps_track_t *tk = &p_sys->tk[i];
745 if( tk->b_seen )
747 es_format_Clean( &tk->fmt );
748 if( tk->es ) es_out_Del( p_demux->out, tk->es );
750 tk->b_seen = false;
753 #if defined(HAVE_DVDNAV_GET_VIDEO_RESOLUTION)
754 uint32_t i_width, i_height;
755 if( dvdnav_get_video_resolution( p_sys->dvdnav,
756 &i_width, &i_height ) )
757 i_width = i_height = 0;
758 switch( dvdnav_get_video_aspect( p_sys->dvdnav ) )
760 case 0:
761 p_sys->sar.i_num = 4 * i_height;
762 p_sys->sar.i_den = 3 * i_width;
763 break;
764 case 3:
765 p_sys->sar.i_num = 16 * i_height;
766 p_sys->sar.i_den = 9 * i_width;
767 break;
768 default:
769 p_sys->sar.i_num = 0;
770 p_sys->sar.i_den = 0;
771 break;
773 #endif
775 if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
776 &i_part ) == DVDNAV_STATUS_OK )
778 if( i_title >= 0 && i_title < p_sys->i_title &&
779 p_demux->info.i_title != i_title )
781 p_demux->info.i_update |= INPUT_UPDATE_TITLE;
782 p_demux->info.i_title = i_title;
785 break;
788 case DVDNAV_CELL_CHANGE:
790 int32_t i_title = 0;
791 int32_t i_part = 0;
793 dvdnav_cell_change_event_t *event =
794 (dvdnav_cell_change_event_t*)packet;
795 msg_Dbg( p_demux, "DVDNAV_CELL_CHANGE" );
796 msg_Dbg( p_demux, " - cellN=%d", event->cellN );
797 msg_Dbg( p_demux, " - pgN=%d", event->pgN );
798 msg_Dbg( p_demux, " - cell_length=%"PRId64, event->cell_length );
799 msg_Dbg( p_demux, " - pg_length=%"PRId64, event->pg_length );
800 msg_Dbg( p_demux, " - pgc_length=%"PRId64, event->pgc_length );
801 msg_Dbg( p_demux, " - cell_start=%"PRId64, event->cell_start );
802 msg_Dbg( p_demux, " - pg_start=%"PRId64, event->pg_start );
804 /* Store the lenght in time of the current PGC */
805 p_sys->i_pgc_length = event->pgc_length / 90 * 1000;
806 p_sys->i_vobu_index = 0;
807 p_sys->i_vobu_flush = 0;
809 /* FIXME is it correct or there is better way to know chapter change */
810 if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
811 &i_part ) == DVDNAV_STATUS_OK )
813 if( i_title >= 0 && i_title < p_sys->i_title &&
814 i_part >= 1 && i_part <= p_sys->title[i_title]->i_seekpoint &&
815 p_demux->info.i_seekpoint != i_part - 1 )
817 p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
818 p_demux->info.i_seekpoint = i_part - 1;
821 break;
824 case DVDNAV_NAV_PACKET:
826 p_sys->i_vobu_index = 1;
827 p_sys->i_vobu_flush = 0;
829 /* Look if we have need to force a flush (and when) */
830 const pci_gi_t *p_pci_gi = &dvdnav_get_current_nav_pci( p_sys->dvdnav )->pci_gi;
831 if( p_pci_gi->vobu_se_e_ptm != 0 && p_pci_gi->vobu_se_e_ptm < p_pci_gi->vobu_e_ptm )
833 const dsi_gi_t *p_dsi_gi = &dvdnav_get_current_nav_dsi( p_sys->dvdnav )->dsi_gi;
834 if( p_dsi_gi->vobu_3rdref_ea != 0 )
835 p_sys->i_vobu_flush = p_dsi_gi->vobu_3rdref_ea;
836 else if( p_dsi_gi->vobu_2ndref_ea != 0 )
837 p_sys->i_vobu_flush = p_dsi_gi->vobu_2ndref_ea;
838 else if( p_dsi_gi->vobu_1stref_ea != 0 )
839 p_sys->i_vobu_flush = p_dsi_gi->vobu_1stref_ea;
842 #ifdef DVDNAV_DEBUG
843 msg_Dbg( p_demux, "DVDNAV_NAV_PACKET" );
844 #endif
845 /* A lot of thing to do here :
846 * - handle packet
847 * - fetch pts (for time display)
848 * - ...
850 DemuxBlock( p_demux, packet, i_len );
851 if( p_sys->b_spu_change )
853 ButtonUpdate( p_demux, false );
854 p_sys->b_spu_change = false;
856 break;
859 case DVDNAV_STOP: /* EOF */
860 msg_Dbg( p_demux, "DVDNAV_STOP" );
862 #if DVD_READ_CACHE
863 dvdnav_free_cache_block( p_sys->dvdnav, packet );
864 #endif
865 return 0;
867 case DVDNAV_HIGHLIGHT:
869 dvdnav_highlight_event_t *event = (dvdnav_highlight_event_t*)packet;
870 msg_Dbg( p_demux, "DVDNAV_HIGHLIGHT" );
871 msg_Dbg( p_demux, " - display=%d", event->display );
872 msg_Dbg( p_demux, " - buttonN=%d", event->buttonN );
873 ButtonUpdate( p_demux, false );
874 break;
877 case DVDNAV_HOP_CHANNEL:
878 msg_Dbg( p_demux, "DVDNAV_HOP_CHANNEL" );
879 p_sys->i_vobu_index = 0;
880 p_sys->i_vobu_flush = 0;
881 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
882 break;
884 case DVDNAV_WAIT:
885 msg_Dbg( p_demux, "DVDNAV_WAIT" );
887 bool b_empty;
888 es_out_Control( p_demux->out, ES_OUT_GET_EMPTY, &b_empty );
889 if( !b_empty )
891 msleep( 40*1000 );
893 else
895 dvdnav_wait_skip( p_sys->dvdnav );
896 p_sys->b_reset_pcr = true;
898 break;
900 default:
901 msg_Warn( p_demux, "Unknown event (0x%x)", i_event );
902 break;
905 #if DVD_READ_CACHE
906 dvdnav_free_cache_block( p_sys->dvdnav, packet );
907 #endif
909 return 1;
912 /* Get a 2 char code
913 * FIXME: partiallyy duplicated from src/input/es_out.c
915 static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var )
917 const iso639_lang_t *pl;
918 char *psz_lang;
919 char *p;
921 psz_lang = var_CreateGetString( p_demux, psz_var );
922 if( !psz_lang )
923 return strdup(LANGUAGE_DEFAULT);
925 /* XXX: we will use only the first value
926 * (and ignore other ones in case of a list) */
927 if( ( p = strchr( psz_lang, ',' ) ) )
928 *p = '\0';
930 for( pl = p_languages; pl->psz_eng_name != NULL; pl++ )
932 if( *psz_lang == '\0' )
933 continue;
934 if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
935 !strcasecmp( pl->psz_native_name, psz_lang ) ||
936 !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
937 !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
938 !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
939 break;
942 free( psz_lang );
944 if( pl->psz_eng_name != NULL )
945 return strdup( pl->psz_iso639_1 );
947 return strdup(LANGUAGE_DEFAULT);
950 static void DemuxTitles( demux_t *p_demux )
952 demux_sys_t *p_sys = p_demux->p_sys;
953 input_title_t *t;
954 seekpoint_t *s;
955 int32_t i_titles;
956 int i;
958 /* Menu */
959 t = vlc_input_title_New();
960 t->b_menu = true;
961 t->psz_name = strdup( "DVD Menu" );
963 s = vlc_seekpoint_New();
964 s->psz_name = strdup( "Resume" );
965 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
967 s = vlc_seekpoint_New();
968 s->psz_name = strdup( "Root" );
969 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
971 s = vlc_seekpoint_New();
972 s->psz_name = strdup( "Title" );
973 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
975 s = vlc_seekpoint_New();
976 s->psz_name = strdup( "Chapter" );
977 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
979 s = vlc_seekpoint_New();
980 s->psz_name = strdup( "Subtitle" );
981 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
983 s = vlc_seekpoint_New();
984 s->psz_name = strdup( "Audio" );
985 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
987 s = vlc_seekpoint_New();
988 s->psz_name = strdup( "Angle" );
989 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
991 TAB_APPEND( p_sys->i_title, p_sys->title, t );
993 /* Find out number of titles/chapters */
994 dvdnav_get_number_of_titles( p_sys->dvdnav, &i_titles );
995 for( i = 1; i <= i_titles; i++ )
997 int32_t i_chapters = 0;
998 int j;
1000 dvdnav_get_number_of_parts( p_sys->dvdnav, i, &i_chapters );
1002 t = vlc_input_title_New();
1003 for( j = 0; j < __MAX( i_chapters, 1 ); j++ )
1005 s = vlc_seekpoint_New();
1006 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
1009 TAB_APPEND( p_sys->i_title, p_sys->title, t );
1013 /*****************************************************************************
1014 * Update functions:
1015 *****************************************************************************/
1016 static void ButtonUpdate( demux_t *p_demux, bool b_mode )
1018 demux_sys_t *p_sys = p_demux->p_sys;
1019 vlc_value_t val;
1020 int32_t i_title, i_part;
1022 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1024 if( var_Get( p_sys->p_input, "highlight-mutex", &val ) == VLC_SUCCESS )
1026 vlc_mutex_t *p_mutex = val.p_address;
1027 dvdnav_highlight_area_t hl;
1028 int32_t i_button;
1029 bool b_button_ok;
1031 if( dvdnav_get_current_highlight( p_sys->dvdnav, &i_button )
1032 != DVDNAV_STATUS_OK )
1034 msg_Err( p_demux, "dvdnav_get_current_highlight failed" );
1035 return;
1038 b_button_ok = false;
1039 if( i_button > 0 && i_title == 0 )
1041 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1043 b_button_ok = DVDNAV_STATUS_OK ==
1044 dvdnav_get_highlight_area( pci, i_button, b_mode, &hl );
1047 if( b_button_ok )
1049 int i;
1050 for( i = 0; i < 4; i++ )
1052 uint32_t i_yuv = p_sys->clut[(hl.palette>>(16+i*4))&0x0f];
1053 uint8_t i_alpha = ( (hl.palette>>(i*4))&0x0f ) * 0xff / 0xf;
1055 p_sys->palette[i][0] = (i_yuv >> 16) & 0xff;
1056 p_sys->palette[i][1] = (i_yuv >> 0) & 0xff;
1057 p_sys->palette[i][2] = (i_yuv >> 8) & 0xff;
1058 p_sys->palette[i][3] = i_alpha;
1061 vlc_mutex_lock( p_mutex );
1062 var_SetInteger( p_sys->p_input, "x-start", hl.sx );
1063 var_SetInteger( p_sys->p_input, "x-end", hl.ex );
1064 var_SetInteger( p_sys->p_input, "y-start", hl.sy );
1065 var_SetInteger( p_sys->p_input, "y-end", hl.ey );
1067 var_SetAddress( p_sys->p_input, "menu-palette", p_sys->palette );
1069 var_SetBool( p_sys->p_input, "highlight", true );
1070 vlc_mutex_unlock( p_mutex );
1072 msg_Dbg( p_demux, "buttonUpdate %d", i_button );
1074 else
1076 msg_Dbg( p_demux, "buttonUpdate not done b=%d t=%d",
1077 i_button, i_title );
1079 /* Show all */
1080 vlc_mutex_lock( p_mutex );
1081 var_SetBool( p_sys->p_input, "highlight", false );
1082 vlc_mutex_unlock( p_mutex );
1087 static void ESSubtitleUpdate( demux_t *p_demux )
1089 demux_sys_t *p_sys = p_demux->p_sys;
1090 int i_spu = dvdnav_get_active_spu_stream( p_sys->dvdnav );
1091 int32_t i_title, i_part;
1093 ButtonUpdate( p_demux, false );
1095 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1096 if( i_title > 0 ) return;
1098 if( i_spu >= 0 && i_spu <= 0x1f )
1100 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
1102 ESNew( p_demux, 0xbd20 + i_spu );
1104 /* be sure to unselect it (reset) */
1105 es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
1106 (bool)false );
1108 /* now select it */
1109 es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
1111 else
1113 for( i_spu = 0; i_spu <= 0x1F; i_spu++ )
1115 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
1116 if( tk->b_seen )
1118 es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
1119 (bool)false );
1125 /*****************************************************************************
1126 * DemuxBlock: demux a given block
1127 *****************************************************************************/
1128 static int DemuxBlock( demux_t *p_demux, const uint8_t *pkt, int i_pkt )
1130 demux_sys_t *p_sys = p_demux->p_sys;
1131 const uint8_t *p = pkt;
1133 while( p < &pkt[i_pkt] )
1135 int i_size = ps_pkt_size( p, &pkt[i_pkt] - p );
1136 block_t *p_pkt;
1137 if( i_size <= 0 )
1139 break;
1142 /* Create a block */
1143 p_pkt = block_New( p_demux, i_size );
1144 memcpy( p_pkt->p_buffer, p, i_size);
1146 /* Parse it and send it */
1147 switch( 0x100 | p[3] )
1149 case 0x1b9:
1150 case 0x1bb:
1151 case 0x1bc:
1152 #ifdef DVDNAV_DEBUG
1153 if( p[3] == 0xbc )
1155 msg_Warn( p_demux, "received a PSM packet" );
1157 else if( p[3] == 0xbb )
1159 msg_Warn( p_demux, "received a SYSTEM packet" );
1161 #endif
1162 block_Release( p_pkt );
1163 break;
1165 case 0x1ba:
1167 int64_t i_scr;
1168 int i_mux_rate;
1169 if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
1171 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr + 1 );
1172 if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
1174 block_Release( p_pkt );
1175 break;
1177 default:
1179 int i_id = ps_pkt_id( p_pkt );
1180 if( i_id >= 0xc0 )
1182 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1184 if( !tk->b_seen )
1186 ESNew( p_demux, i_id );
1188 if( tk->b_seen && tk->es &&
1189 !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
1191 es_out_Send( p_demux->out, tk->es, p_pkt );
1193 else
1195 block_Release( p_pkt );
1198 else
1200 block_Release( p_pkt );
1202 break;
1206 p += i_size;
1209 return VLC_SUCCESS;
1212 /*****************************************************************************
1213 * Force still images to be displayed by sending EOS and stopping buffering.
1214 *****************************************************************************/
1215 static void DemuxForceStill( demux_t *p_demux )
1217 static const uint8_t buffer[] = {
1218 0x00, 0x00, 0x01, 0xe0, 0x00, 0x07,
1219 0x80, 0x00, 0x00,
1220 0x00, 0x00, 0x01, 0xB7,
1222 DemuxBlock( p_demux, buffer, sizeof(buffer) );
1224 bool b_empty;
1225 es_out_Control( p_demux->out, ES_OUT_GET_EMPTY, &b_empty );
1228 /*****************************************************************************
1229 * ESNew: register a new elementary stream
1230 *****************************************************************************/
1231 static void ESNew( demux_t *p_demux, int i_id )
1233 demux_sys_t *p_sys = p_demux->p_sys;
1234 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1235 bool b_select = false;
1237 if( tk->b_seen ) return;
1239 if( ps_track_fill( tk, 0, i_id ) )
1241 msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
1242 return;
1245 /* Add a new ES */
1246 if( tk->fmt.i_cat == VIDEO_ES )
1248 tk->fmt.video.i_sar_num = p_sys->sar.i_num;
1249 tk->fmt.video.i_sar_den = p_sys->sar.i_den;
1250 b_select = true;
1252 else if( tk->fmt.i_cat == AUDIO_ES )
1254 int i_audio = -1;
1255 /* find the audio number PLEASE find another way */
1256 if( (i_id&0xbdf8) == 0xbd88 ) /* dts */
1258 i_audio = i_id&0x07;
1260 else if( (i_id&0xbdf0) == 0xbd80 ) /* a52 */
1262 i_audio = i_id&0xf;
1264 else if( (i_id&0xbdf0) == 0xbda0 ) /* lpcm */
1266 i_audio = i_id&0x1f;
1268 else if( ( i_id&0xe0 ) == 0xc0 ) /* mpga */
1270 i_audio = i_id&0x1f;
1272 if( i_audio >= 0 )
1274 int i_lang = dvdnav_audio_stream_to_lang( p_sys->dvdnav, i_audio );
1275 if( i_lang != 0xffff )
1277 tk->fmt.psz_language = malloc( 3 );
1278 tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1279 tk->fmt.psz_language[1] = (i_lang )&0xff;
1280 tk->fmt.psz_language[2] = 0;
1282 if( dvdnav_get_active_audio_stream( p_sys->dvdnav ) == i_audio )
1284 b_select = true;
1288 else if( tk->fmt.i_cat == SPU_ES )
1290 int32_t i_title, i_part;
1291 int i_lang = dvdnav_spu_stream_to_lang( p_sys->dvdnav, i_id&0x1f );
1292 if( i_lang != 0xffff )
1294 tk->fmt.psz_language = malloc( 3 );
1295 tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1296 tk->fmt.psz_language[1] = (i_lang )&0xff;
1297 tk->fmt.psz_language[2] = 0;
1300 /* Palette */
1301 tk->fmt.subs.spu.palette[0] = 0xBeef;
1302 memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
1303 16 * sizeof( uint32_t ) );
1305 /* We select only when we are not in the menu */
1306 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1307 if( i_title > 0 &&
1308 dvdnav_get_active_spu_stream( p_sys->dvdnav ) == (i_id&0x1f) )
1310 b_select = true;
1314 tk->es = es_out_Add( p_demux->out, &tk->fmt );
1315 if( b_select )
1317 es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
1319 tk->b_seen = true;
1321 if( tk->fmt.i_cat == VIDEO_ES ) ButtonUpdate( p_demux, false );
1324 /*****************************************************************************
1325 * Still image end
1326 *****************************************************************************/
1327 static void StillTimer( void *p_data )
1329 demux_sys_t *p_sys = p_data;
1331 vlc_mutex_lock( &p_sys->still.lock );
1332 if( likely(p_sys->still.b_enabled) )
1334 p_sys->still.b_enabled = false;
1335 dvdnav_still_skip( p_sys->dvdnav );
1337 vlc_mutex_unlock( &p_sys->still.lock );
1340 static int EventMouse( vlc_object_t *p_vout, char const *psz_var,
1341 vlc_value_t oldval, vlc_value_t val, void *p_data )
1343 demux_t *p_demux = p_data;
1344 demux_sys_t *p_sys = p_demux->p_sys;
1346 /* FIXME? PCI usage thread safe? */
1347 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1348 int x = val.coords.x;
1349 int y = val.coords.y;
1351 if( psz_var[6] == 'm' ) /* mouse-moved */
1352 dvdnav_mouse_select( p_sys->dvdnav, pci, x, y );
1353 else
1355 assert( psz_var[6] == 'c' ); /* mouse-clicked */
1357 ButtonUpdate( p_demux, true );
1358 dvdnav_mouse_activate( p_sys->dvdnav, pci, x, y );
1360 (void)p_vout;
1361 (void)oldval;
1362 return VLC_SUCCESS;
1365 static int EventKey( vlc_object_t *p_this, char const *psz_var,
1366 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1368 demux_t *p_demux = p_data;
1369 demux_sys_t *p_sys = p_demux->p_sys;
1371 /* FIXME: thread-safe ? */
1372 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1374 switch( newval.i_int )
1376 case ACTIONID_NAV_LEFT:
1377 dvdnav_left_button_select( p_sys->dvdnav, pci );
1378 break;
1379 case ACTIONID_NAV_RIGHT:
1380 dvdnav_right_button_select( p_sys->dvdnav, pci );
1381 break;
1382 case ACTIONID_NAV_UP:
1383 dvdnav_upper_button_select( p_sys->dvdnav, pci );
1384 break;
1385 case ACTIONID_NAV_DOWN:
1386 dvdnav_lower_button_select( p_sys->dvdnav, pci );
1387 break;
1388 case ACTIONID_NAV_ACTIVATE:
1389 ButtonUpdate( p_demux, true );
1390 dvdnav_button_activate( p_sys->dvdnav, pci );
1391 break;
1394 (void)p_this; (void)psz_var; (void)oldval;
1395 return VLC_SUCCESS;
1398 static int EventIntf( vlc_object_t *p_input, char const *psz_var,
1399 vlc_value_t oldval, vlc_value_t val, void *p_data )
1401 demux_t *p_demux = p_data;
1402 demux_sys_t *p_sys = p_demux->p_sys;
1404 if (val.i_int == INPUT_EVENT_VOUT)
1406 vlc_object_t *p_vout;
1408 p_vout = p_sys->p_vout;
1409 if( p_vout != NULL )
1411 var_DelCallback( p_vout, "mouse-moved", EventMouse, p_demux );
1412 var_DelCallback( p_vout, "mouse-clicked", EventMouse, p_demux );
1413 vlc_object_release( p_vout );
1416 p_vout = (vlc_object_t *)input_GetVout( (input_thread_t *)p_input );
1417 p_sys->p_vout = p_vout;
1418 if( p_vout != NULL )
1420 var_AddCallback( p_vout, "mouse-moved", EventMouse, p_demux );
1421 var_AddCallback( p_vout, "mouse-clicked", EventMouse, p_demux );
1424 (void) psz_var; (void) oldval;
1425 return VLC_SUCCESS;
1428 /*****************************************************************************
1429 * ProbeDVD: very weak probing that avoids going too often into a dvdnav_open()
1430 *****************************************************************************/
1431 static int ProbeDVD( demux_t *p_demux, char *psz_name )
1433 (void)p_demux;
1434 #ifdef HAVE_SYS_STAT_H
1435 struct stat stat_info;
1436 uint8_t pi_anchor[2];
1437 int i_fd, i_ret;
1439 if( !*psz_name )
1441 /* Triggers libdvdcss autodetection */
1442 return VLC_SUCCESS;
1445 if( (i_fd = vlc_open( psz_name, O_RDONLY |O_NONBLOCK )) == -1 )
1447 return VLC_SUCCESS; /* Let dvdnav_open() do the probing */
1450 i_ret = VLC_EGENERIC;
1452 if( fstat( i_fd, &stat_info ) || !S_ISREG( stat_info.st_mode ) )
1454 if( !S_ISFIFO( stat_info.st_mode ) )
1455 i_ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */
1456 goto bailout;
1459 /* Try to find the anchor (2 bytes at LBA 256) */
1460 if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1
1461 && read( i_fd, pi_anchor, 2 ) == 2
1462 && GetWLE( pi_anchor ) == 2 )
1463 i_ret = VLC_SUCCESS; /* Found a potential anchor */
1465 bailout:
1466 close( i_fd );
1468 return i_ret;
1469 #else
1471 return VLC_SUCCESS;
1472 #endif