]> git.sesse.net Git - vlc/blob - modules/access/dvdnav.c
* modules/access/dvd*.c: implemented DEMUX_GET_TIME/DEMUX_GET_LENGTH based on the...
[vlc] / modules / access / dvdnav.c
1 /*****************************************************************************
2  * dvdnav.c: DVD module using the dvdnav library.
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/input.h>
31
32 #include "vlc_keys.h"
33 #include "iso_lang.h"
34
35 #include <dvdnav/dvdnav.h>
36
37 #include "../demux/ps.h"
38
39 /*****************************************************************************
40  * Module descriptor
41  *****************************************************************************/
42 #define CACHING_TEXT N_("Caching value in ms")
43 #define CACHING_LONGTEXT N_( \
44     "Allows you to modify the default caching value for DVDnav streams. This "\
45     "value should be set in millisecond units." )
46
47 static int  Open ( vlc_object_t * );
48 static void Close( vlc_object_t * );
49
50 vlc_module_begin();
51     set_description( _("DVDnav Input") );
52     add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, NULL,
53         CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
54     set_capability( "access_demux", 0 );
55     add_shortcut( "dvd" );
56     add_shortcut( "dvdnav" );
57     add_shortcut( "dvdnavsimple" );
58     set_callbacks( Open, Close );
59 vlc_module_end();
60
61 /* Shall we use libdvdnav's read ahead cache? */
62 #define DVD_READ_CACHE 1
63
64 /*****************************************************************************
65  * Local prototypes
66  *****************************************************************************/
67 static char *ParseCL( vlc_object_t *, char *, vlc_bool_t, int *, int *, int *);
68
69 typedef struct
70 {
71     VLC_COMMON_MEMBERS
72
73     demux_t        *p_demux;
74     vlc_mutex_t     lock;
75
76     vlc_bool_t      b_moved;
77     vlc_bool_t      b_clicked;
78     vlc_bool_t      b_key;
79
80     vlc_bool_t      b_still;
81     int64_t         i_still_end;
82
83 } event_thread_t;
84
85 static int EventThread( vlc_object_t * );
86
87 struct demux_sys_t
88 {
89     dvdnav_t    *dvdnav;
90
91     /* track */
92     ps_track_t  tk[PS_TK_COUNT];
93     int         i_mux_rate;
94
95     /* for spu variables */
96     input_thread_t *p_input;
97
98     /* event */
99     event_thread_t *p_ev;
100
101     /* FIXME */
102     uint8_t     alpha[4];
103     uint32_t    clut[16];
104
105     /* */
106     int i_aspect;
107
108     /* */
109     vlc_bool_t  b_es_out_ok;
110     vlc_bool_t  b_simple;
111
112     int           i_title;
113     input_title_t **title;
114 };
115
116 static int Control( demux_t *, int, va_list );
117 static int Demux  ( demux_t * );
118 static int DemuxBlock  ( demux_t *, uint8_t *pkt, int i_pkt );
119
120 static void DemuxTitles( demux_t *p_demux );
121 static void ESSubtitleUpdate( demux_t * );
122 static void ButtonUpdate( demux_t * );
123
124 /*****************************************************************************
125  * DemuxOpen:
126  *****************************************************************************/
127 static int Open( vlc_object_t *p_this )
128 {
129     demux_t     *p_demux = (demux_t*)p_this;
130     demux_sys_t *p_sys;
131     dvdnav_t    *p_dvdnav;
132     int         i_title, i_chapter, i_angle;
133     char        *psz_name;
134
135     psz_name = ParseCL( VLC_OBJECT(p_demux), p_demux->psz_path, VLC_TRUE,
136                         &i_title, &i_chapter, &i_angle );
137     if( !psz_name )
138     {
139         return VLC_EGENERIC;
140     }
141
142     /* Open dvdnav */
143     if( dvdnav_open( &p_dvdnav, psz_name ) != DVDNAV_STATUS_OK )
144     {
145         msg_Warn( p_demux, "cannot open dvdnav" );
146         free( psz_name );
147         return VLC_EGENERIC;
148     }
149     free( psz_name );
150
151     /* Fill p_demux field */
152     p_demux->pf_demux = Demux;
153     p_demux->pf_control = Control;
154     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
155     memset( p_sys, 0, sizeof( demux_sys_t ) );
156     p_sys->dvdnav = p_dvdnav;
157
158     p_sys->b_simple =
159         strcmp( p_demux->psz_access, "dvdnavsimple" ) ? VLC_FALSE : VLC_TRUE;
160     if( p_sys->b_simple && i_title < 1 )
161     {
162         /* Skip menu part */
163         i_title = 1;
164     }
165
166     ps_track_init( p_sys->tk );
167     p_sys->i_aspect = -1;
168     p_sys->b_es_out_ok = VLC_FALSE;
169     p_sys->i_mux_rate = 0;
170
171     if( 1 )
172     {
173         // Hack for libdvdnav CVS.
174         // Without it dvdnav_get_number_of_titles() fails.
175         // Remove when fixed in libdvdnav CVS.
176         uint8_t buffer[DVD_VIDEO_LB_LEN];
177         int i_event, i_len;
178
179         if( dvdnav_get_next_block( p_sys->dvdnav, buffer, &i_event, &i_len )
180               == DVDNAV_STATUS_ERR )
181         {
182             msg_Warn( p_demux, "dvdnav_get_next_block failed" );
183         }
184
185         dvdnav_sector_search( p_sys->dvdnav, 0, SEEK_SET );
186     }
187
188     /* Configure dvdnav */
189     if( dvdnav_set_readahead_flag( p_sys->dvdnav, DVD_READ_CACHE ) !=
190           DVDNAV_STATUS_OK )
191     {
192         msg_Warn( p_demux, "cannot set read-a-head flag" );
193     }
194
195     if( dvdnav_set_PGC_positioning_flag( p_sys->dvdnav, 1 ) !=
196           DVDNAV_STATUS_OK )
197     {
198         msg_Warn( p_demux, "cannot set PGC positioning flag" );
199     }
200
201     if( dvdnav_menu_language_select (p_sys->dvdnav,"en") != DVDNAV_STATUS_OK ||
202         dvdnav_audio_language_select(p_sys->dvdnav,"en") != DVDNAV_STATUS_OK ||
203         dvdnav_spu_language_select  (p_sys->dvdnav,"en") != DVDNAV_STATUS_OK )
204     {
205         msg_Warn( p_demux, "something failed while setting en language (%s)",
206                   dvdnav_err_to_string( p_sys->dvdnav ) );
207     }
208
209     DemuxTitles( p_demux );
210
211     /* Set forced title/chapter */
212     if( i_title != 0 )
213     {
214         if( dvdnav_title_play( p_sys->dvdnav, i_title ) != DVDNAV_STATUS_OK )
215         {
216             msg_Warn( p_demux, "cannot set title" );
217             i_title = 0;
218         }
219         else
220         {
221             p_demux->info.i_update |= INPUT_UPDATE_TITLE;
222             p_demux->info.i_title = i_title;
223         }
224     }
225
226     if( i_chapter != 1 && i_title != 0 )
227     {
228         if( dvdnav_part_play( p_sys->dvdnav, i_title, i_chapter ) !=
229             DVDNAV_STATUS_OK )
230         {
231             msg_Warn( p_demux, "cannot set chapter" );
232             i_chapter = 1;
233         }
234         else
235         {
236             p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
237             p_demux->info.i_seekpoint = i_chapter;
238         }
239     }
240
241     /* Update default_pts to a suitable value for dvdnav access */
242     var_Create( p_demux, "dvdnav-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
243
244     /* For simple mode (no menus), we're done */
245     if( p_sys->b_simple ) return VLC_SUCCESS;
246
247     /* FIXME hack hack hack hack FIXME */
248     /* Get p_input and create variable */
249     p_sys->p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
250     var_Create( p_sys->p_input, "x-start", VLC_VAR_INTEGER );
251     var_Create( p_sys->p_input, "y-start", VLC_VAR_INTEGER );
252     var_Create( p_sys->p_input, "x-end", VLC_VAR_INTEGER );
253     var_Create( p_sys->p_input, "y-end", VLC_VAR_INTEGER );
254     var_Create( p_sys->p_input, "color", VLC_VAR_ADDRESS );
255     var_Create( p_sys->p_input, "contrast", VLC_VAR_ADDRESS );
256     var_Create( p_sys->p_input, "highlight", VLC_VAR_BOOL );
257     var_Create( p_sys->p_input, "highlight-mutex", VLC_VAR_MUTEX );
258
259     /* Now create our event thread catcher */
260     p_sys->p_ev = vlc_object_create( p_demux, sizeof( event_thread_t ) );
261     p_sys->p_ev->p_demux = p_demux;
262     vlc_thread_create( p_sys->p_ev, "dvdnav event thread handler", EventThread,
263                        VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
264
265     return VLC_SUCCESS;
266 }
267
268 /*****************************************************************************
269  * Close:
270  *****************************************************************************/
271 static void Close( vlc_object_t *p_this )
272 {
273     demux_t     *p_demux = (demux_t*)p_this;
274     demux_sys_t *p_sys = p_demux->p_sys;
275     int i;
276
277     if( !p_sys->b_simple )
278     {
279         /* stop the event handler */
280         p_sys->p_ev->b_die = VLC_TRUE;
281         vlc_thread_join( p_sys->p_ev );
282         vlc_object_destroy( p_sys->p_ev );
283
284         var_Destroy( p_sys->p_input, "highlight-mutex" );
285         var_Destroy( p_sys->p_input, "highlight" );
286         var_Destroy( p_sys->p_input, "x-start" );
287         var_Destroy( p_sys->p_input, "x-end" );
288         var_Destroy( p_sys->p_input, "y-start" );
289         var_Destroy( p_sys->p_input, "y-end" );
290         var_Destroy( p_sys->p_input, "color" );
291         var_Destroy( p_sys->p_input, "contrast" );
292
293         vlc_object_release( p_sys->p_input );
294     }
295
296     for( i = 0; i < PS_TK_COUNT; i++ )
297     {
298         ps_track_t *tk = &p_sys->tk[i];
299         if( tk->b_seen )
300         {
301             es_format_Clean( &tk->fmt );
302             if( tk->es ) es_out_Del( p_demux->out, tk->es );
303         }
304     }
305
306     dvdnav_close( p_sys->dvdnav );
307     free( p_sys );
308 }
309
310 /*****************************************************************************
311  * Control:
312  *****************************************************************************/
313 static int Control( demux_t *p_demux, int i_query, va_list args )
314 {
315     demux_sys_t *p_sys = p_demux->p_sys;
316     double f, *pf;
317     vlc_bool_t *pb;
318     int64_t *pi64;
319     input_title_t ***ppp_title;
320     int          *pi_int;
321     int i;
322
323     switch( i_query )
324     {
325         case DEMUX_SET_POSITION:
326         case DEMUX_GET_POSITION:
327         case DEMUX_GET_TIME:
328         case DEMUX_GET_LENGTH:
329         {
330             uint32_t pos, len;
331             if( dvdnav_get_position( p_sys->dvdnav, &pos, &len ) !=
332                   DVDNAV_STATUS_OK || len == 0 )
333             {
334                 return VLC_EGENERIC;
335             }
336
337             if( i_query == DEMUX_GET_POSITION )
338             {
339                 pf = (double*)va_arg( args, double* );
340                 *pf = (double)pos / (double)len;
341                 return VLC_SUCCESS;
342             }
343             else if( i_query == DEMUX_SET_POSITION )
344             {
345                 f = (double)va_arg( args, double );
346                 pos = f * len;
347                 if( dvdnav_sector_search( p_sys->dvdnav, pos, SEEK_SET ) ==
348                       DVDNAV_STATUS_OK )
349                 {
350                     return VLC_SUCCESS;
351                 }
352             }
353             else if( i_query == DEMUX_GET_TIME )
354             {
355                 pi64 = (int64_t*)va_arg( args, int64_t * );
356                 if( p_sys->i_mux_rate > 0 )
357                 {
358                     *pi64 = (int64_t)1000000 * 2048 * pos / 50 /
359                         p_sys->i_mux_rate;
360                     return VLC_SUCCESS;
361                 }
362             }
363             else if( i_query == DEMUX_GET_LENGTH )
364             {
365                 pi64 = (int64_t*)va_arg( args, int64_t * );
366                 if( p_sys->i_mux_rate > 0 )
367                 {
368                     *pi64 = (int64_t)1000000 * len * 2048 / 50 /
369                         p_sys->i_mux_rate;
370                     return VLC_SUCCESS;
371                 }
372             }
373
374             return VLC_EGENERIC;
375         }
376
377         /* Special for access_demux */
378         case DEMUX_CAN_PAUSE:
379         case DEMUX_CAN_CONTROL_PACE:
380             /* TODO */
381             pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
382             *pb = VLC_TRUE;
383             return VLC_SUCCESS;
384
385         case DEMUX_SET_PAUSE_STATE:
386             return VLC_SUCCESS;
387
388         case DEMUX_GET_TITLE_INFO:
389             ppp_title = (input_title_t***)va_arg( args, input_title_t*** );
390             pi_int    = (int*)va_arg( args, int* );
391
392             /* Duplicate title infos */
393             *pi_int = p_sys->i_title;
394             *ppp_title = malloc( sizeof( input_title_t ** ) * p_sys->i_title );
395             for( i = 0; i < p_sys->i_title; i++ )
396             {
397                 (*ppp_title)[i] = vlc_input_title_Duplicate( p_sys->title[i] );
398             }
399             return VLC_SUCCESS;
400
401         case DEMUX_SET_TITLE:
402             i = (int)va_arg( args, int );
403             if( ( i == 0 && dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root )
404                   != DVDNAV_STATUS_OK ) ||
405                 ( i != 0 && dvdnav_title_play( p_sys->dvdnav, i )
406                   != DVDNAV_STATUS_OK ) )
407             {
408                 msg_Warn( p_demux, "cannot set title/chapter" );
409                 return VLC_EGENERIC;
410             }
411             p_demux->info.i_update |=
412                 INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
413             p_demux->info.i_title = i;
414             p_demux->info.i_seekpoint = 0;
415             return VLC_SUCCESS;
416
417         case DEMUX_SET_SEEKPOINT:
418             i = (int)va_arg( args, int );
419             if( p_demux->info.i_title == 0 )
420             {
421                 int i_ret;
422                 /* Special case */
423                 switch( i )
424                 {
425                 case 0:
426                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Escape );
427                     break;
428                 case 1:
429                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root );
430                     break;
431                 case 2:
432                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Title );
433                     break;
434                 case 3:
435                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Part );
436                     break;
437                 case 4:
438                     i_ret = dvdnav_menu_call( p_sys->dvdnav,
439                                               DVD_MENU_Subpicture );
440                     break;
441                 case 5:
442                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Audio );
443                     break;
444                 case 6:
445                     i_ret = dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Angle );
446                     break;
447                 default:
448                     return VLC_EGENERIC;
449                 }
450
451                 if( i_ret != DVDNAV_STATUS_OK )
452                     return VLC_EGENERIC;
453             }
454             else if( dvdnav_part_play( p_sys->dvdnav, p_demux->info.i_title,
455                                        i + 1 ) != DVDNAV_STATUS_OK )
456             {
457                 msg_Warn( p_demux, "cannot set title/chapter" );
458                 return VLC_EGENERIC;
459             }
460             p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
461             p_demux->info.i_seekpoint = i;
462             return VLC_SUCCESS;
463
464         case DEMUX_GET_PTS_DELAY:
465             pi64 = (int64_t*)va_arg( args, int64_t * );
466             *pi64 = (int64_t)var_GetInteger( p_demux, "dvdnav-caching" ) *1000;
467             return VLC_SUCCESS;
468
469         /* TODO implement others */
470         default:
471             return VLC_EGENERIC;
472     }
473 }
474
475 /*****************************************************************************
476  * Demux:
477  *****************************************************************************/
478 static int Demux( demux_t *p_demux )
479 {
480     demux_sys_t *p_sys = p_demux->p_sys;
481
482     uint8_t buffer[DVD_VIDEO_LB_LEN];
483     uint8_t *packet = buffer;
484     int i_event;
485     int i_len;
486
487     if( !p_sys->b_es_out_ok )
488     {
489         if( !p_sys->b_simple )
490         {
491             /* We do ourself the selection/unselection
492              * Problem: bypass --audio-channel and --spu-channel
493              * Solution: call ourself dvdnav_??set_channel -> TODO
494              */
495             es_out_Control( p_demux->out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
496         }
497
498         p_sys->b_es_out_ok = VLC_TRUE;
499     }
500
501 #if DVD_READ_CACHE
502     if( dvdnav_get_next_cache_block( p_sys->dvdnav, &packet, &i_event, &i_len )
503         == DVDNAV_STATUS_ERR )
504 #else
505     if( dvdnav_get_next_block( p_sys->dvdnav, packet, &i_event, &i_len )
506         == DVDNAV_STATUS_ERR )
507 #endif
508     {
509         msg_Warn( p_demux, "cannot get next block (%s)",
510                   dvdnav_err_to_string( p_sys->dvdnav ) );
511         return -1;
512     }
513
514     switch( i_event )
515     {
516     case DVDNAV_BLOCK_OK:   /* mpeg block */
517         DemuxBlock( p_demux, packet, i_len );
518         break;
519
520     case DVDNAV_NOP:    /* Nothing */
521         msg_Dbg( p_demux, "DVDNAV_NOP" );
522         break;
523
524     case DVDNAV_STILL_FRAME:
525     {
526         dvdnav_still_event_t *event = (dvdnav_still_event_t*)packet;
527         if( !p_sys->b_simple )
528         {
529             vlc_mutex_lock( &p_sys->p_ev->lock );
530             if( !p_sys->p_ev->b_still )
531             {
532                 msg_Dbg( p_demux, "DVDNAV_STILL_FRAME" );
533                 msg_Dbg( p_demux, "     - length=0x%x", event->length );
534                 p_sys->p_ev->b_still = VLC_TRUE;
535                 if( event->length == 0xff )
536                 {
537                     p_sys->p_ev->i_still_end = 0;
538                 }
539                 else
540                 {
541                     p_sys->p_ev->i_still_end = (int64_t)event->length *
542                         1000000 + mdate() + p_sys->p_input->i_pts_delay;
543                 }
544             }
545             vlc_mutex_unlock( &p_sys->p_ev->lock );
546             msleep( 40000 );
547         }
548         else
549         {
550             dvdnav_still_skip( p_sys->dvdnav );
551         }
552         break;
553     }
554     case DVDNAV_SPU_STREAM_CHANGE:
555     {
556         dvdnav_spu_stream_change_event_t *event =
557             (dvdnav_spu_stream_change_event_t*)packet;
558         msg_Dbg( p_demux, "DVDNAV_SPU_STREAM_CHANGE" );
559         msg_Dbg( p_demux, "     - physical_wide=%d",
560                  event->physical_wide );
561         msg_Dbg( p_demux, "     - physical_letterbox=%d",
562                  event->physical_letterbox);
563         msg_Dbg( p_demux, "     - physical_pan_scan=%d",
564                  event->physical_pan_scan );
565
566         if( !p_sys->b_simple )
567         {
568             ESSubtitleUpdate( p_demux );
569         }
570         break;
571     }
572     case DVDNAV_AUDIO_STREAM_CHANGE:
573     {
574         dvdnav_audio_stream_change_event_t *event =
575             (dvdnav_audio_stream_change_event_t*)packet;
576         msg_Dbg( p_demux, "DVDNAV_AUDIO_STREAM_CHANGE" );
577         msg_Dbg( p_demux, "     - physical=%d", event->physical );
578         /* TODO */
579         break;
580     }
581     case DVDNAV_VTS_CHANGE:
582     {
583         int32_t i_title = 0;
584         int32_t i_part  = 0;
585         int i;
586
587         dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t*)packet;
588         msg_Dbg( p_demux, "DVDNAV_VTS_CHANGE" );
589         msg_Dbg( p_demux, "     - vtsN=%d", event->new_vtsN );
590         msg_Dbg( p_demux, "     - domain=%d", event->new_domain );
591
592         /* dvdnav_get_video_aspect / dvdnav_get_video_scale_permission */
593         /* TODO check if we always have VTS and CELL */
594         p_sys->i_aspect = dvdnav_get_video_aspect( p_sys->dvdnav );
595
596         /* reset PCR */
597         es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
598
599         for( i = 0; i < PS_TK_COUNT; i++ )
600         {
601             ps_track_t *tk = &p_sys->tk[i];
602             if( tk->b_seen )
603             {
604                 es_format_Clean( &tk->fmt );
605                 if( tk->es ) es_out_Del( p_demux->out, tk->es );
606             }
607             tk->b_seen = VLC_FALSE;
608         }
609
610         if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
611                                        &i_part ) == DVDNAV_STATUS_OK )
612         {
613             if( p_sys->b_simple && i_title == 0 )
614             {
615                 /* we have returned in menu, stop dvd */
616                 /* FIXME is it the right way ? */
617                 return 0;
618             }
619             if( i_title >= 0 && i_title < p_sys->i_title &&
620                 p_demux->info.i_title != i_title )
621             {
622                 p_demux->info.i_update |= INPUT_UPDATE_TITLE;
623                 p_demux->info.i_title = i_title;
624             }
625         }
626         break;
627     }
628     case DVDNAV_CELL_CHANGE:
629     {
630         int32_t i_title = 0;
631         int32_t i_part  = 0;
632
633         dvdnav_cell_change_event_t *event =
634             (dvdnav_cell_change_event_t*)packet;
635         msg_Dbg( p_demux, "DVDNAV_CELL_CHANGE" );
636         msg_Dbg( p_demux, "     - cellN=%d", event->cellN );
637         msg_Dbg( p_demux, "     - pgN=%d", event->pgN );
638         msg_Dbg( p_demux, "     - cell_length=%lld", event->cell_length );
639         msg_Dbg( p_demux, "     - pg_length=%lld", event->pg_length );
640         msg_Dbg( p_demux, "     - pgc_length=%lld", event->pgc_length );
641         msg_Dbg( p_demux, "     - cell_start=%lld", event->cell_start );
642         msg_Dbg( p_demux, "     - pg_start=%lld", event->pg_start );
643
644         /* FIXME is it correct or there is better way to know chapter change */
645         if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
646                                        &i_part ) == DVDNAV_STATUS_OK )
647         {
648             if( i_title >= 0 && i_title < p_sys->i_title &&
649                 i_part >= 1 && i_part <= p_sys->title[i_title]->i_seekpoint &&
650                 p_demux->info.i_seekpoint != i_part - 1 )
651             {
652                 p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
653                 p_demux->info.i_seekpoint = i_part - 1;
654             }
655         }
656         break;
657     }
658
659     case DVDNAV_NAV_PACKET:
660     {
661 #ifdef DVDNAV_DEBUG
662         msg_Dbg( p_demux, "DVDNAV_NAV_PACKET" );
663 #endif
664         /* A lot of thing to do here :
665          *  - handle packet
666          *  - fetch pts (for time display)
667          *  - ...
668          */
669         DemuxBlock( p_demux, packet, i_len );
670         break;
671     }
672     case DVDNAV_STOP:   /* EOF */
673         msg_Dbg( p_demux, "DVDNAV_STOP" );
674         return 0;
675
676     case DVDNAV_HIGHLIGHT:
677     {
678         dvdnav_highlight_event_t *event = (dvdnav_highlight_event_t*)packet;
679         msg_Dbg( p_demux, "DVDNAV_HIGHLIGHT" );
680         msg_Dbg( p_demux, "     - display=%d", event->display );
681         msg_Dbg( p_demux, "     - buttonN=%d", event->buttonN );
682         if( !p_sys->b_simple )
683         {
684             ButtonUpdate( p_demux );
685         }
686         break;
687     }
688
689     case DVDNAV_SPU_CLUT_CHANGE:
690         msg_Dbg( p_demux, "DVDNAV_SPU_CLUT_CHANGE" );
691         /* Update color lookup table (16 *uint32_t in packet) */
692         memcpy( p_sys->clut, packet, 16 * sizeof( uint32_t ) );
693         break;
694
695     case DVDNAV_HOP_CHANNEL:
696         msg_Dbg( p_demux, "DVDNAV_HOP_CHANNEL" );
697         /* We should try to flush all our internal buffer */
698         break;
699
700     case DVDNAV_WAIT:
701         msg_Dbg( p_demux, "DVDNAV_WAIT" );
702
703         dvdnav_wait_skip( p_sys->dvdnav );
704         break;
705
706     default:
707         msg_Warn( p_demux, "Unknown event (0x%x)", i_event );
708         break;
709     }
710
711 #if DVD_READ_CACHE
712     dvdnav_free_cache_block( p_sys->dvdnav, packet );
713 #endif
714
715     return 1;
716 }
717
718 /*****************************************************************************
719  * ParseCL: parse command line.
720  * Titles start from 0 (menu), chapters and angles start from 1.
721  *****************************************************************************/
722 static char *ParseCL( vlc_object_t *p_this, char *psz_name, vlc_bool_t b_force,
723                       int *i_title, int *i_chapter, int *i_angle )
724 {
725     char *psz_parser, *psz_source, *psz_next;
726
727     psz_source = strdup( psz_name );
728     if( psz_source == NULL ) return NULL;
729
730     *i_title = 0;
731     *i_chapter = 1;
732     *i_angle = 1;
733
734     /* Start with the end, because you could have :
735      * dvdnav:/Volumes/my@toto/VIDEO_TS@1,1
736      * (yes, this is kludgy). */
737     for( psz_parser = psz_source + strlen(psz_source) - 1;
738          psz_parser >= psz_source && *psz_parser != '@';
739          psz_parser-- );
740
741     if( psz_parser >= psz_source && *psz_parser == '@' )
742     {
743         /* Found options */
744         *psz_parser = '\0';
745         ++psz_parser;
746
747         *i_title = (int)strtol( psz_parser, &psz_next, 10 );
748         if( *psz_next )
749         {
750             psz_parser = psz_next + 1;
751             *i_chapter = (int)strtol( psz_parser, &psz_next, 10 );
752             if( *psz_next )
753             {
754                 *i_angle = (int)strtol( psz_next + 1, NULL, 10 );
755             }
756         }
757     }
758
759     *i_title   = *i_title >= 0 ? *i_title : 0;
760     *i_chapter = *i_chapter > 0 ? *i_chapter : 1;
761     *i_angle   = *i_angle > 0 ? *i_angle : 1;
762
763     if( !*psz_source )
764     {
765         free( psz_source );
766         if( !b_force )
767         {
768             return NULL;
769         }
770         psz_source = config_GetPsz( p_this, "dvd" );
771         if( !psz_source ) return NULL;
772     }
773
774 #ifdef WIN32
775     if( psz_source[0] && psz_source[1] == ':' &&
776         psz_source[2] == '\\' && psz_source[3] == '\0' )
777     {
778         psz_source[2] = '\0';
779     }
780 #endif
781
782     msg_Dbg( p_this, "dvdroot=%s title=%d chapter=%d angle=%d",
783              psz_source, *i_title, *i_chapter, *i_angle );
784
785     return psz_source;
786 }
787
788 static void DemuxTitles( demux_t *p_demux )
789 {
790     demux_sys_t *p_sys = p_demux->p_sys;
791     input_title_t *t;
792     seekpoint_t *s;
793     int32_t i_titles;
794     int i;
795
796     /* Menu */
797     t = vlc_input_title_New();
798     t->b_menu = VLC_TRUE;
799     t->psz_name = strdup( "DVD Menu" );
800
801     s = vlc_seekpoint_New();
802     s->psz_name = strdup( "Resume" );
803     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
804
805     s = vlc_seekpoint_New();
806     s->psz_name = strdup( "Root" );
807     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
808
809     s = vlc_seekpoint_New();
810     s->psz_name = strdup( "Title" );
811     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
812
813     s = vlc_seekpoint_New();
814     s->psz_name = strdup( "Chapter" );
815     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
816
817     s = vlc_seekpoint_New();
818     s->psz_name = strdup( "Subtitle" );
819     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
820
821     s = vlc_seekpoint_New();
822     s->psz_name = strdup( "Audio" );
823     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
824
825     s = vlc_seekpoint_New();
826     s->psz_name = strdup( "Angle" );
827     TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
828
829     TAB_APPEND( p_sys->i_title, p_sys->title, t );
830
831     /* Find out number of titles/chapters */
832     dvdnav_get_number_of_titles( p_sys->dvdnav, &i_titles );
833     for( i = 1; i <= i_titles; i++ )
834     {
835         int32_t i_chapters = 0;
836         int j;
837
838         dvdnav_get_number_of_parts( p_sys->dvdnav, i, &i_chapters );
839
840         t = vlc_input_title_New();
841         for( j = 0; j < __MAX( i_chapters, 1 ); j++ )
842         {
843             s = vlc_seekpoint_New();
844             s->psz_name = malloc( strlen( _("Chapter %i") ) + 20 );
845             sprintf( s->psz_name, _("Chapter %i"), j + 1 );
846             TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
847         }
848
849         TAB_APPEND( p_sys->i_title, p_sys->title, t );
850     }
851 }
852
853 /*****************************************************************************
854  * Update functions:
855  *****************************************************************************/
856 static void ButtonUpdate( demux_t *p_demux )
857 {
858     demux_sys_t *p_sys = p_demux->p_sys;
859     vlc_value_t val;
860     int32_t i_title, i_part;
861
862     dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
863
864     if( var_Get( p_sys->p_input, "highlight-mutex", &val ) == VLC_SUCCESS )
865     {
866         vlc_mutex_t *p_mutex = val.p_address;
867         dvdnav_highlight_area_t hl;
868         int32_t i_button;
869
870         if( dvdnav_get_current_highlight( p_sys->dvdnav, &i_button )
871             != DVDNAV_STATUS_OK )
872         {
873             msg_Err( p_demux, "dvdnav_get_current_highlight failed" );
874             return;
875         }
876
877         if( i_button > 0 && i_title ==  0 )
878         {
879             pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
880
881             dvdnav_get_highlight_area( pci, i_button, 1, &hl );
882
883             /* I fear it is plain wrong */
884             //val.p_address = (void *)&hl.palette;
885             p_sys->alpha[0] = hl.palette&0x0f;
886             p_sys->alpha[1] = (hl.palette>>4)&0x0f;
887             p_sys->alpha[2] = (hl.palette>>8)&0x0f;
888             p_sys->alpha[3] = (hl.palette>>12)&0x0f;
889
890             vlc_mutex_lock( p_mutex );
891             val.i_int = hl.sx; var_Set( p_sys->p_input, "x-start", val );
892             val.i_int = hl.ex; var_Set( p_sys->p_input, "x-end", val );
893             val.i_int = hl.sy; var_Set( p_sys->p_input, "y-start", val );
894             val.i_int = hl.ey; var_Set( p_sys->p_input, "y-end", val );
895
896             val.p_address = (void *)p_sys->alpha;
897             var_Set( p_sys->p_input, "contrast", val );
898
899             val.b_bool = VLC_TRUE; var_Set( p_sys->p_input, "highlight", val );
900             vlc_mutex_unlock( p_mutex );
901
902             msg_Dbg( p_demux, "buttonUpdate %d", i_button );
903         }
904         else
905         {
906             msg_Dbg( p_demux, "buttonUpdate not done b=%d t=%d",
907                      i_button, i_title );
908
909             /* Show all */
910             vlc_mutex_lock( p_mutex );
911             val.b_bool = VLC_FALSE;
912             var_Set( p_sys->p_input, "highlight", val );
913             vlc_mutex_unlock( p_mutex );
914         }
915     }
916 }
917
918 static void ESNew( demux_t *p_demux, int i_id );
919
920 static void ESSubtitleUpdate( demux_t *p_demux )
921 {
922     demux_sys_t *p_sys = p_demux->p_sys;
923     int         i_spu = dvdnav_get_active_spu_stream( p_sys->dvdnav );
924     int32_t i_title, i_part;
925
926     ButtonUpdate( p_demux );
927
928     dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
929     if( i_title > 0 )
930     {
931         return;
932     }
933
934     if( i_spu >= 0 && i_spu <= 0x1f )
935     {
936         ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
937
938         if( !tk->b_seen )
939         {
940             ESNew( p_demux, 0xbd20 + i_spu);
941         }
942         /* be sure to unselect it (reset) */
943         es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
944                         (vlc_bool_t)VLC_FALSE );
945
946         /* now select it */
947         es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
948     }
949     else
950     {
951         for( i_spu = 0; i_spu <= 0x1F; i_spu++ )
952         {
953             ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
954             if( tk->b_seen )
955             {
956                 es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
957                                 (vlc_bool_t)VLC_FALSE );
958             }
959         }
960     }
961 }
962
963 /*****************************************************************************
964  * DemuxBlock: demux a given block
965  *****************************************************************************/
966 static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt )
967 {
968     demux_sys_t *p_sys = p_demux->p_sys;
969     uint8_t     *p = pkt;
970
971     while( p < &pkt[i_pkt] )
972     {
973         int i_size = ps_pkt_size( p, &pkt[i_pkt] - p );
974         block_t *p_pkt;
975         if( i_size <= 0 )
976         {
977             break;
978         }
979
980         /* Create a block */
981         p_pkt = block_New( p_demux, i_size );
982         memcpy( p_pkt->p_buffer, p, i_size);
983
984         /* Parse it and send it */
985         switch( 0x100 | p[3] )
986         {
987         case 0x1b9:
988         case 0x1bb:
989         case 0x1bc:
990 #ifdef DVDNAV_DEBUG
991             if( p[3] == 0xbc )
992             {
993                 msg_Warn( p_demux, "received a PSM packet" );
994             }
995             else if( p[3] == 0xbb )
996             {
997                 msg_Warn( p_demux, "received a SYSTEM packet" );
998             }
999 #endif
1000             block_Release( p_pkt );
1001             break;
1002
1003         case 0x1ba:
1004         {
1005             int64_t i_scr;
1006             int i_mux_rate;
1007             if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
1008             {
1009                 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr );
1010                 if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
1011             }
1012             block_Release( p_pkt );
1013             break;
1014         }
1015         default:
1016         {
1017             int i_id = ps_pkt_id( p_pkt );
1018             if( i_id >= 0xc0 )
1019             {
1020                 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1021
1022                 if( !tk->b_seen )
1023                 {
1024                     ESNew( p_demux, i_id );
1025                 }
1026                 if( tk->b_seen && tk->es &&
1027                     !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
1028                 {
1029                     es_out_Send( p_demux->out, tk->es, p_pkt );
1030                 }
1031                 else
1032                 {
1033                     block_Release( p_pkt );
1034                 }
1035             }
1036             else
1037             {
1038                 block_Release( p_pkt );
1039             }
1040             break;
1041         }
1042         }
1043
1044         p += i_size;
1045     }
1046
1047     return VLC_SUCCESS;
1048 }
1049
1050 /*****************************************************************************
1051  * ESNew: register a new elementary stream
1052  *****************************************************************************/
1053 static void ESNew( demux_t *p_demux, int i_id )
1054 {
1055     demux_sys_t *p_sys = p_demux->p_sys;
1056     ps_track_t  *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1057     vlc_bool_t  b_select = VLC_FALSE;
1058
1059     if( tk->b_seen )
1060     {
1061         return;
1062     }
1063
1064     if( ps_track_fill( tk, i_id ) )
1065     {
1066         msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
1067         return;
1068     }
1069
1070     /* Add a new ES */
1071     if( tk->fmt.i_cat == VIDEO_ES )
1072     {
1073         if( p_sys->i_aspect >= 0 )
1074         {
1075             tk->fmt.video.i_aspect = p_sys->i_aspect;
1076         }
1077         b_select = VLC_TRUE;
1078     }
1079     else if( tk->fmt.i_cat == AUDIO_ES )
1080     {
1081         int i_audio = -1;
1082         /* find the audio number PLEASE find another way */
1083         if( (i_id&0xbdf8) == 0xbd88 )       /* dts */
1084         {
1085             i_audio = i_id&0x07;
1086         }
1087         else if( (i_id&0xbdf0) == 0xbd80 )  /* a52 */
1088         {
1089             i_audio = i_id&0xf;
1090         }
1091         else if( (i_id&0xbdf0) == 0xbda0 )  /* lpcm */
1092         {
1093             i_audio = i_id&0x1f;
1094         }
1095         else if( ( i_id&0xe0 ) == 0xc0 )    /* mpga */
1096         {
1097             i_audio = i_id&0x1f;
1098         }
1099         if( i_audio >= 0 )
1100         {
1101             int i_lang = dvdnav_audio_stream_to_lang( p_sys->dvdnav, i_audio );
1102             if( i_lang != 0xffff )
1103             {
1104                 tk->fmt.psz_language = malloc( 3 );
1105                 tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1106                 tk->fmt.psz_language[1] = (i_lang     )&0xff;
1107                 tk->fmt.psz_language[2] = 0;
1108             }
1109             if( dvdnav_get_active_audio_stream( p_sys->dvdnav ) == i_audio )
1110             {
1111                 b_select = VLC_TRUE;
1112             }
1113         }
1114     }
1115     else if( tk->fmt.i_cat == SPU_ES )
1116     {
1117         int32_t i_title, i_part;
1118         int i_lang = dvdnav_spu_stream_to_lang( p_sys->dvdnav, i_id&0x1f );
1119         if( i_lang != 0xffff )
1120         {
1121             tk->fmt.psz_language = malloc( 3 );
1122             tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1123             tk->fmt.psz_language[1] = (i_lang     )&0xff;
1124             tk->fmt.psz_language[2] = 0;
1125         }
1126
1127         /* Palette */
1128         tk->fmt.subs.spu.palette[0] = 0xBeef;
1129         memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
1130                 16 * sizeof( uint32_t ) );
1131
1132         /* We select only when we are not in the menu */
1133         dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1134         if( i_title > 0 &&
1135             dvdnav_get_active_spu_stream( p_sys->dvdnav ) == (i_id&0x1f) )
1136         {
1137             b_select = VLC_TRUE;
1138         }
1139     }
1140
1141     tk->es = es_out_Add( p_demux->out, &tk->fmt );
1142     if( b_select )
1143     {
1144         es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
1145     }
1146     tk->b_seen = VLC_TRUE;
1147 }
1148
1149 /*****************************************************************************
1150  * Event handler code
1151  *****************************************************************************/
1152 static int  EventMouse( vlc_object_t *, char const *,
1153                         vlc_value_t, vlc_value_t, void * );
1154 static int  EventKey  ( vlc_object_t *, char const *,
1155                         vlc_value_t, vlc_value_t, void * );
1156
1157 static int EventThread( vlc_object_t *p_this )
1158 {
1159     event_thread_t *p_ev = (event_thread_t*)p_this;
1160     demux_sys_t    *p_sys = p_ev->p_demux->p_sys;
1161     vlc_object_t   *p_vout = NULL;
1162
1163     vlc_mutex_init( p_ev, &p_ev->lock );
1164     p_ev->b_moved   = VLC_FALSE;
1165     p_ev->b_clicked = VLC_FALSE;
1166     p_ev->b_key     = VLC_FALSE;
1167     p_ev->b_still   = VLC_FALSE;
1168
1169     /* catch all key event */
1170     var_AddCallback( p_ev->p_vlc, "key-pressed", EventKey, p_ev );
1171
1172     /* main loop */
1173     while( !p_ev->b_die )
1174     {
1175         vlc_bool_t b_activated = VLC_FALSE;
1176
1177         /* KEY part */
1178         if( p_ev->b_key )
1179         {
1180             pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1181
1182             vlc_value_t valk;
1183             struct hotkey *p_hotkeys = p_ev->p_vlc->p_hotkeys;
1184             int i, i_action = -1;
1185
1186             vlc_mutex_lock( &p_ev->lock );
1187             var_Get( p_ev->p_vlc, "key-pressed", &valk );
1188             for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1189             {
1190                 if( p_hotkeys[i].i_key == valk.i_int )
1191                 {
1192                     i_action = p_hotkeys[i].i_action;
1193                 }
1194             }
1195
1196             switch( i_action )
1197             {
1198             case ACTIONID_NAV_LEFT:
1199                 dvdnav_left_button_select( p_sys->dvdnav, pci );
1200                 break;
1201             case ACTIONID_NAV_RIGHT:
1202                 dvdnav_right_button_select( p_sys->dvdnav, pci );
1203                 break;
1204             case ACTIONID_NAV_UP:
1205                 dvdnav_upper_button_select( p_sys->dvdnav, pci );
1206                 break;
1207             case ACTIONID_NAV_DOWN:
1208                 dvdnav_lower_button_select( p_sys->dvdnav, pci );
1209                 break;
1210             case ACTIONID_NAV_ACTIVATE:
1211                 b_activated = VLC_TRUE;
1212                 dvdnav_button_activate( p_sys->dvdnav, pci );
1213                 break;
1214             default:
1215                 break;
1216             }
1217             p_ev->b_key = VLC_FALSE;
1218             vlc_mutex_unlock( &p_ev->lock );
1219         }
1220
1221         /* VOUT part */
1222         if( p_vout && ( p_ev->b_moved || p_ev->b_clicked ) )
1223         {
1224             pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1225             vlc_value_t valx, valy;
1226
1227             vlc_mutex_lock( &p_ev->lock );
1228             var_Get( p_vout, "mouse-x", &valx );
1229             var_Get( p_vout, "mouse-y", &valy );
1230
1231             if( p_ev->b_moved )
1232             {
1233                 dvdnav_mouse_select( p_sys->dvdnav, pci, valx.i_int,
1234                                      valy.i_int );
1235             }
1236             if( p_ev->b_clicked )
1237             {
1238                 b_activated = VLC_TRUE;
1239                 dvdnav_mouse_activate( p_sys->dvdnav, pci, valx.i_int,
1240                                        valy.i_int );
1241             }
1242
1243             p_ev->b_moved = VLC_FALSE;
1244             p_ev->b_clicked = VLC_FALSE;
1245             vlc_mutex_unlock( &p_ev->lock );
1246         }
1247         if( p_vout && p_vout->b_die )
1248         {
1249             var_DelCallback( p_vout, "mouse-moved", EventMouse, p_ev );
1250             var_DelCallback( p_vout, "mouse-clicked", EventMouse, p_ev );
1251             vlc_object_release( p_vout );
1252             p_vout = NULL;
1253         }
1254         if( p_vout == NULL )
1255         {
1256             p_vout = vlc_object_find( p_sys->p_input, VLC_OBJECT_VOUT,
1257                                       FIND_CHILD );
1258             if( p_vout)
1259             {
1260                 var_AddCallback( p_vout, "mouse-moved", EventMouse, p_ev );
1261                 var_AddCallback( p_vout, "mouse-clicked", EventMouse, p_ev );
1262             }
1263         }
1264
1265         /* Still part */
1266         vlc_mutex_lock( &p_ev->lock );
1267         if( p_ev->b_still )
1268         {
1269             if( /* b_activated || // This breaks menus */
1270                 ( p_ev->i_still_end > 0 && p_ev->i_still_end < mdate() ))
1271             {
1272                 p_ev->b_still = VLC_FALSE;
1273                 dvdnav_still_skip( p_sys->dvdnav );
1274             }
1275         }
1276         vlc_mutex_unlock( &p_ev->lock );
1277
1278         /* Wait a bit */
1279         msleep( 10000 );
1280     }
1281
1282     /* Release callback */
1283     if( p_vout )
1284     {
1285         var_DelCallback( p_vout, "mouse-moved", EventMouse, p_ev );
1286         var_DelCallback( p_vout, "mouse-clicked", EventMouse, p_ev );
1287         vlc_object_release( p_vout );
1288     }
1289     var_DelCallback( p_ev->p_vlc, "key-pressed", EventKey, p_ev );
1290
1291     vlc_mutex_destroy( &p_ev->lock );
1292
1293     return VLC_SUCCESS;
1294 }
1295
1296 static int EventMouse( vlc_object_t *p_this, char const *psz_var,
1297                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1298 {
1299     event_thread_t *p_ev = p_data;
1300     vlc_mutex_lock( &p_ev->lock );
1301     if( psz_var[6] == 'c' )
1302         p_ev->b_clicked = VLC_TRUE;
1303     else if( psz_var[6] == 'm' )
1304         p_ev->b_moved = VLC_TRUE;
1305     vlc_mutex_unlock( &p_ev->lock );
1306
1307     return VLC_SUCCESS;
1308 }
1309
1310 static int EventKey( vlc_object_t *p_this, char const *psz_var,
1311                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
1312 {
1313     event_thread_t *p_ev = p_data;
1314     vlc_mutex_lock( &p_ev->lock );
1315     p_ev->b_key = VLC_TRUE;
1316     vlc_mutex_unlock( &p_ev->lock );
1317
1318     return VLC_SUCCESS;
1319 }