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