On the road to 1.1.0-RC
[vlc/solaris.git] / modules / access / dvdnav.c
blobb8d4eb6ed5af805577e6e494cddf98ae951c0be0
1 /*****************************************************************************
2 * dvdnav.c: DVD module using the dvdnav library.
3 *****************************************************************************
4 * Copyright (C) 2004-2009 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <assert.h>
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_input.h>
36 #include <vlc_access.h>
37 #include <vlc_demux.h>
38 #include <vlc_charset.h>
39 #include <vlc_fs.h>
41 #include <vlc_dialog.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 #include <sys/types.h>
47 #ifdef HAVE_SYS_STAT_H
48 # include <sys/stat.h>
49 #endif
50 #ifdef HAVE_FCNTL_H
51 # include <fcntl.h>
52 #endif
54 #include <vlc_keys.h>
55 #include <vlc_iso_lang.h>
57 /* FIXME we should find a better way than including that */
58 #include "../../src/text/iso-639_def.h"
61 #include <dvdnav/dvdnav.h>
63 #include "../demux/ps.h"
65 /*****************************************************************************
66 * Module descriptor
67 *****************************************************************************/
68 #define ANGLE_TEXT N_("DVD angle")
69 #define ANGLE_LONGTEXT N_( \
70 "Default DVD angle." )
72 #define CACHING_TEXT N_("Caching value in ms")
73 #define CACHING_LONGTEXT N_( \
74 "Caching value for DVDs. This "\
75 "value should be set in milliseconds." )
76 #define MENU_TEXT N_("Start directly in menu")
77 #define MENU_LONGTEXT N_( \
78 "Start the DVD directly in the main menu. This "\
79 "will try to skip all the useless warning introductions." )
81 #define LANGUAGE_DEFAULT ("en")
83 static int Open ( vlc_object_t * );
84 static void Close( vlc_object_t * );
86 vlc_module_begin ()
87 set_shortname( N_("DVD with menus") )
88 set_description( N_("DVDnav Input") )
89 set_category( CAT_INPUT )
90 set_subcategory( SUBCAT_INPUT_ACCESS )
91 add_integer( "dvdnav-angle", 1, NULL, ANGLE_TEXT,
92 ANGLE_LONGTEXT, false )
93 add_integer( "dvdnav-caching", DEFAULT_PTS_DELAY / 1000, NULL,
94 CACHING_TEXT, CACHING_LONGTEXT, true )
95 add_bool( "dvdnav-menu", true, NULL,
96 MENU_TEXT, MENU_LONGTEXT, false )
97 set_capability( "access_demux", 5 )
98 add_shortcut( "dvd" )
99 add_shortcut( "dvdnav" )
100 add_shortcut( "file" )
101 set_callbacks( Open, Close )
102 vlc_module_end ()
104 /* Shall we use libdvdnav's read ahead cache? */
105 #define DVD_READ_CACHE 1
107 /*****************************************************************************
108 * Local prototypes
109 *****************************************************************************/
110 struct demux_sys_t
112 dvdnav_t *dvdnav;
114 /* */
115 bool b_reset_pcr;
117 struct
119 bool b_created;
120 bool b_enabled;
121 vlc_mutex_t lock;
122 vlc_timer_t timer;
123 } still;
125 /* track */
126 ps_track_t tk[PS_TK_COUNT];
127 int i_mux_rate;
129 /* for spu variables */
130 input_thread_t *p_input;
132 /* event */
133 vlc_object_t *p_vout;
135 /* palette for menus */
136 uint32_t clut[16];
137 uint8_t palette[4][4];
138 bool b_spu_change;
140 /* */
141 int i_title;
142 input_title_t **title;
144 /* lenght of program group chain */
145 mtime_t i_pgc_length;
148 static int Control( demux_t *, int, va_list );
149 static int Demux( demux_t * );
150 static int DemuxBlock( demux_t *, const uint8_t *, int );
152 static void DemuxTitles( demux_t * );
153 static void ESSubtitleUpdate( demux_t * );
154 static void ButtonUpdate( demux_t *, bool );
156 static void ESNew( demux_t *, int );
157 static int ProbeDVD( demux_t *, char * );
159 static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var );
161 static int ControlInternal( demux_t *, int, ... );
163 static void StillTimer( void * );
165 static int EventKey( vlc_object_t *, char const *,
166 vlc_value_t, vlc_value_t, void * );
167 static int EventMouse( vlc_object_t *, char const *,
168 vlc_value_t, vlc_value_t, void * );
169 static int EventIntf( vlc_object_t *, char const *,
170 vlc_value_t, vlc_value_t, void * );
172 /*****************************************************************************
173 * DemuxOpen:
174 *****************************************************************************/
175 static int Open( vlc_object_t *p_this )
177 demux_t *p_demux = (demux_t*)p_this;
178 demux_sys_t *p_sys;
179 dvdnav_t *p_dvdnav;
180 int i_angle;
181 char *psz_name;
182 char *psz_code;
184 if( !p_demux->psz_path || !*p_demux->psz_path )
186 /* Only when selected */
187 if( !p_demux->psz_access || !*p_demux->psz_access )
188 return VLC_EGENERIC;
190 psz_name = var_CreateGetString( p_this, "dvd" );
191 if( !psz_name )
193 psz_name = strdup("");
196 else
197 psz_name = ToLocaleDup( p_demux->psz_path );
199 #ifdef WIN32
200 /* Remove trailing backslash, otherwise dvdnav_open will fail */
201 if( *psz_name && *(psz_name + strlen(psz_name) - 1) == '\\' )
203 *(psz_name + strlen(psz_name) - 1) = '\0';
205 #endif
207 /* Try some simple probing to avoid going through dvdnav_open too often */
208 if( ProbeDVD( p_demux, psz_name ) != VLC_SUCCESS )
210 free( psz_name );
211 return VLC_EGENERIC;
214 /* Open dvdnav */
215 if( dvdnav_open( &p_dvdnav, psz_name ) != DVDNAV_STATUS_OK )
217 msg_Warn( p_demux, "cannot open dvdnav" );
218 free( psz_name );
219 return VLC_EGENERIC;
221 free( psz_name );
223 /* Fill p_demux field */
224 DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
225 p_sys->dvdnav = p_dvdnav;
226 p_sys->b_reset_pcr = false;
228 ps_track_init( p_sys->tk );
229 p_sys->i_mux_rate = 0;
230 p_sys->i_pgc_length = 0;
231 p_sys->b_spu_change = false;
233 if( 1 )
235 // Hack for libdvdnav CVS.
236 // Without it dvdnav_get_number_of_titles() fails.
237 // Remove when fixed in libdvdnav CVS.
238 uint8_t buffer[DVD_VIDEO_LB_LEN];
239 int i_event, i_len;
241 if( dvdnav_get_next_block( p_sys->dvdnav, buffer, &i_event, &i_len )
242 == DVDNAV_STATUS_ERR )
244 msg_Warn( p_demux, "dvdnav_get_next_block failed" );
247 dvdnav_sector_search( p_sys->dvdnav, 0, SEEK_SET );
250 /* Configure dvdnav */
251 if( dvdnav_set_readahead_flag( p_sys->dvdnav, DVD_READ_CACHE ) !=
252 DVDNAV_STATUS_OK )
254 msg_Warn( p_demux, "cannot set read-a-head flag" );
257 if( dvdnav_set_PGC_positioning_flag( p_sys->dvdnav, 1 ) !=
258 DVDNAV_STATUS_OK )
260 msg_Warn( p_demux, "cannot set PGC positioning flag" );
263 /* Set menu language
264 * XXX A menu-language may be better than sub-language */
265 psz_code = DemuxGetLanguageCode( p_demux, "sub-language" );
266 if( dvdnav_menu_language_select( p_sys->dvdnav, psz_code ) !=
267 DVDNAV_STATUS_OK )
269 msg_Warn( p_demux, "can't set menu language to '%s' (%s)",
270 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
271 /* We try to fall back to 'en' */
272 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
273 dvdnav_menu_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
275 free( psz_code );
277 /* Set audio language */
278 psz_code = DemuxGetLanguageCode( p_demux, "audio-language" );
279 if( dvdnav_audio_language_select( p_sys->dvdnav, psz_code ) !=
280 DVDNAV_STATUS_OK )
282 msg_Warn( p_demux, "can't set audio language to '%s' (%s)",
283 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
284 /* We try to fall back to 'en' */
285 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
286 dvdnav_audio_language_select( p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
288 free( psz_code );
290 /* Set spu language */
291 psz_code = DemuxGetLanguageCode( p_demux, "sub-language" );
292 if( dvdnav_spu_language_select( p_sys->dvdnav, psz_code ) !=
293 DVDNAV_STATUS_OK )
295 msg_Warn( p_demux, "can't set spu language to '%s' (%s)",
296 psz_code, dvdnav_err_to_string( p_sys->dvdnav ) );
297 /* We try to fall back to 'en' */
298 if( strcmp( psz_code, LANGUAGE_DEFAULT ) )
299 dvdnav_spu_language_select(p_sys->dvdnav, (char*)LANGUAGE_DEFAULT );
301 free( psz_code );
303 DemuxTitles( p_demux );
305 if( var_CreateGetBool( p_demux, "dvdnav-menu" ) )
307 msg_Dbg( p_demux, "trying to go to dvd menu" );
309 if( dvdnav_title_play( p_sys->dvdnav, 1 ) != DVDNAV_STATUS_OK )
311 msg_Err( p_demux, "cannot set title (can't decrypt DVD?)" );
312 dialog_Fatal( p_demux, _("Playback failure"), "%s",
313 _("VLC cannot set the DVD's title. It possibly "
314 "cannot decrypt the entire disc.") );
315 dvdnav_close( p_sys->dvdnav );
316 free( p_sys );
317 return VLC_EGENERIC;
320 if( dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Title ) !=
321 DVDNAV_STATUS_OK )
323 /* Try going to menu root */
324 if( dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root ) !=
325 DVDNAV_STATUS_OK )
326 msg_Warn( p_demux, "cannot go to dvd menu" );
330 i_angle = var_CreateGetInteger( p_demux, "dvdnav-angle" );
331 if( i_angle <= 0 ) i_angle = 1;
333 /* Update default_pts to a suitable value for dvdnav access */
334 var_Create( p_demux, "dvdnav-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
336 /* FIXME hack hack hack hack FIXME */
337 /* Get p_input and create variable */
338 p_sys->p_input = demux_GetParentInput( p_demux );
339 var_Create( p_sys->p_input, "x-start", VLC_VAR_INTEGER );
340 var_Create( p_sys->p_input, "y-start", VLC_VAR_INTEGER );
341 var_Create( p_sys->p_input, "x-end", VLC_VAR_INTEGER );
342 var_Create( p_sys->p_input, "y-end", VLC_VAR_INTEGER );
343 var_Create( p_sys->p_input, "color", VLC_VAR_ADDRESS );
344 var_Create( p_sys->p_input, "menu-palette", VLC_VAR_ADDRESS );
345 var_Create( p_sys->p_input, "highlight", VLC_VAR_BOOL );
346 var_Create( p_sys->p_input, "highlight-mutex", VLC_VAR_MUTEX );
348 /* catch all key event */
349 var_AddCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
350 /* catch vout creation event */
351 var_AddCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
353 p_sys->still.b_enabled = false;
354 vlc_mutex_init( &p_sys->still.lock );
355 if( !vlc_timer_create( &p_sys->still.timer, StillTimer, p_sys ) )
356 p_sys->still.b_created = true;
358 return VLC_SUCCESS;
361 /*****************************************************************************
362 * Close:
363 *****************************************************************************/
364 static void Close( vlc_object_t *p_this )
366 demux_t *p_demux = (demux_t*)p_this;
367 demux_sys_t *p_sys = p_demux->p_sys;
368 int i;
370 /* Stop vout event handler */
371 var_DelCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
372 if( p_sys->p_vout != NULL )
373 { /* Should not happen, but better be safe than sorry. */
374 msg_Warn( p_sys->p_vout, "removing dangling mouse DVD callbacks" );
375 var_DelCallback( p_sys->p_vout, "mouse-moved", EventMouse, p_demux );
376 var_DelCallback( p_sys->p_vout, "mouse-clicked", EventMouse, p_demux );
379 /* Stop key event handler (FIXME: should really be per-vout too) */
380 var_DelCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
382 /* Stop still image handler */
383 if( p_sys->still.b_created )
384 vlc_timer_destroy( p_sys->still.timer );
385 vlc_mutex_destroy( &p_sys->still.lock );
387 var_Destroy( p_sys->p_input, "highlight-mutex" );
388 var_Destroy( p_sys->p_input, "highlight" );
389 var_Destroy( p_sys->p_input, "x-start" );
390 var_Destroy( p_sys->p_input, "x-end" );
391 var_Destroy( p_sys->p_input, "y-start" );
392 var_Destroy( p_sys->p_input, "y-end" );
393 var_Destroy( p_sys->p_input, "color" );
394 var_Destroy( p_sys->p_input, "menu-palette" );
396 vlc_object_release( p_sys->p_input );
398 for( i = 0; i < PS_TK_COUNT; i++ )
400 ps_track_t *tk = &p_sys->tk[i];
401 if( tk->b_seen )
403 es_format_Clean( &tk->fmt );
404 if( tk->es ) es_out_Del( p_demux->out, tk->es );
408 dvdnav_close( p_sys->dvdnav );
409 free( p_sys );
412 /*****************************************************************************
413 * Control:
414 *****************************************************************************/
415 static int Control( demux_t *p_demux, int i_query, va_list args )
417 demux_sys_t *p_sys = p_demux->p_sys;
418 input_title_t ***ppp_title;
419 int i;
421 switch( i_query )
423 case DEMUX_SET_POSITION:
424 case DEMUX_GET_POSITION:
425 case DEMUX_GET_TIME:
426 case DEMUX_GET_LENGTH:
428 uint32_t pos, len;
429 if( dvdnav_get_position( p_sys->dvdnav, &pos, &len ) !=
430 DVDNAV_STATUS_OK || len == 0 )
432 return VLC_EGENERIC;
435 switch( i_query )
437 case DEMUX_GET_POSITION:
438 *va_arg( args, double* ) = (double)pos / (double)len;
439 return VLC_SUCCESS;
441 case DEMUX_SET_POSITION:
442 pos = va_arg( args, double ) * len;
443 if( dvdnav_sector_search( p_sys->dvdnav, pos, SEEK_SET ) ==
444 DVDNAV_STATUS_OK )
446 return VLC_SUCCESS;
448 break;
450 case DEMUX_GET_TIME:
451 if( p_sys->i_pgc_length > 0 )
453 *va_arg( args, int64_t * ) = p_sys->i_pgc_length*pos/len;
454 return VLC_SUCCESS;
456 break;
458 case DEMUX_GET_LENGTH:
459 if( p_sys->i_pgc_length > 0 )
461 *va_arg( args, int64_t * ) = (int64_t)p_sys->i_pgc_length;
462 return VLC_SUCCESS;
464 break;
466 return VLC_EGENERIC;
469 /* Special for access_demux */
470 case DEMUX_CAN_PAUSE:
471 case DEMUX_CAN_SEEK:
472 case DEMUX_CAN_CONTROL_PACE:
473 /* TODO */
474 *va_arg( args, bool * ) = true;
475 return VLC_SUCCESS;
477 case DEMUX_SET_PAUSE_STATE:
478 return VLC_SUCCESS;
480 case DEMUX_GET_TITLE_INFO:
481 ppp_title = va_arg( args, input_title_t*** );
482 *va_arg( args, int* ) = p_sys->i_title;
483 *va_arg( args, int* ) = 0; /* Title offset */
484 *va_arg( args, int* ) = 1; /* Chapter offset */
486 /* Duplicate title infos */
487 *ppp_title = malloc( sizeof( input_title_t ** ) * p_sys->i_title );
488 for( i = 0; i < p_sys->i_title; i++ )
490 (*ppp_title)[i] = vlc_input_title_Duplicate( p_sys->title[i] );
492 return VLC_SUCCESS;
494 case DEMUX_SET_TITLE:
495 i = (int)va_arg( args, int );
496 if( ( i == 0 && dvdnav_menu_call( p_sys->dvdnav, DVD_MENU_Root )
497 != DVDNAV_STATUS_OK ) ||
498 ( i != 0 && dvdnav_title_play( p_sys->dvdnav, i )
499 != DVDNAV_STATUS_OK ) )
501 msg_Warn( p_demux, "cannot set title/chapter" );
502 return VLC_EGENERIC;
504 p_demux->info.i_update |=
505 INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
506 p_demux->info.i_title = i;
507 p_demux->info.i_seekpoint = 0;
508 return VLC_SUCCESS;
510 case DEMUX_SET_SEEKPOINT:
511 i = va_arg( args, int );
512 if( p_demux->info.i_title == 0 )
514 static const int argtab[] = {
515 DVD_MENU_Escape,
516 DVD_MENU_Root,
517 DVD_MENU_Title,
518 DVD_MENU_Part,
519 DVD_MENU_Subpicture,
520 DVD_MENU_Audio,
521 DVD_MENU_Angle
523 enum { numargs = sizeof(argtab)/sizeof(int) };
524 if( (unsigned)i >= numargs || DVDNAV_STATUS_OK !=
525 dvdnav_menu_call(p_sys->dvdnav,argtab[i]) )
526 return VLC_EGENERIC;
528 else if( dvdnav_part_play( p_sys->dvdnav, p_demux->info.i_title,
529 i + 1 ) != DVDNAV_STATUS_OK )
531 msg_Warn( p_demux, "cannot set title/chapter" );
532 return VLC_EGENERIC;
534 p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
535 p_demux->info.i_seekpoint = i;
536 return VLC_SUCCESS;
538 case DEMUX_GET_PTS_DELAY:
539 *va_arg( args, int64_t * )
540 = (int64_t)var_GetInteger( p_demux, "dvdnav-caching" ) *1000;
541 return VLC_SUCCESS;
543 case DEMUX_GET_META:
545 const char *title_name = NULL;
547 dvdnav_get_title_string(p_sys->dvdnav, &title_name);
548 if( (NULL != title_name) && ('\0' != title_name[0]) )
550 vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
551 vlc_meta_Set( p_meta, vlc_meta_Title, title_name );
552 return VLC_SUCCESS;
554 return VLC_EGENERIC;
557 /* TODO implement others */
558 default:
559 return VLC_EGENERIC;
563 static int ControlInternal( demux_t *p_demux, int i_query, ... )
565 va_list args;
566 int i_result;
568 va_start( args, i_query );
569 i_result = Control( p_demux, i_query, args );
570 va_end( args );
572 return i_result;
574 /*****************************************************************************
575 * Demux:
576 *****************************************************************************/
577 static int Demux( demux_t *p_demux )
579 demux_sys_t *p_sys = p_demux->p_sys;
581 uint8_t buffer[DVD_VIDEO_LB_LEN];
582 uint8_t *packet = buffer;
583 int i_event;
584 int i_len;
586 #if DVD_READ_CACHE
587 if( dvdnav_get_next_cache_block( p_sys->dvdnav, &packet, &i_event, &i_len )
588 == DVDNAV_STATUS_ERR )
589 #else
590 if( dvdnav_get_next_block( p_sys->dvdnav, packet, &i_event, &i_len )
591 == DVDNAV_STATUS_ERR )
592 #endif
594 msg_Warn( p_demux, "cannot get next block (%s)",
595 dvdnav_err_to_string( p_sys->dvdnav ) );
596 if( p_demux->info.i_title == 0 )
598 msg_Dbg( p_demux, "jumping to first title" );
599 return ControlInternal( p_demux, DEMUX_SET_TITLE, 1 ) == VLC_SUCCESS ? 1 : -1;
601 return -1;
604 switch( i_event )
606 case DVDNAV_BLOCK_OK: /* mpeg block */
607 vlc_mutex_lock( &p_sys->still.lock );
608 vlc_timer_schedule( p_sys->still.timer, false, 0, 0 );
609 p_sys->still.b_enabled = false;
610 vlc_mutex_unlock( &p_sys->still.lock );
611 if( p_sys->b_reset_pcr )
613 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
614 p_sys->b_reset_pcr = false;
616 DemuxBlock( p_demux, packet, i_len );
617 break;
619 case DVDNAV_NOP: /* Nothing */
620 msg_Dbg( p_demux, "DVDNAV_NOP" );
621 break;
623 case DVDNAV_STILL_FRAME:
625 dvdnav_still_event_t *event = (dvdnav_still_event_t*)packet;
626 bool b_still_init = false;
628 vlc_mutex_lock( &p_sys->still.lock );
629 if( !p_sys->still.b_enabled )
631 msg_Dbg( p_demux, "DVDNAV_STILL_FRAME" );
632 msg_Dbg( p_demux, " - length=0x%x", event->length );
633 p_sys->still.b_enabled = true;
635 if( event->length != 0xff && p_sys->still.b_created )
637 mtime_t delay = event->length * CLOCK_FREQ;
638 vlc_timer_schedule( p_sys->still.timer, false, delay, 0 );
641 b_still_init = true;
643 vlc_mutex_unlock( &p_sys->still.lock );
645 if( b_still_init )
647 /* We send a dummy mpeg2 end of sequence to force still frame display */
648 static const uint8_t buffer[] = {
649 0x00, 0x00, 0x01, 0xe0, 0x00, 0x07,
650 0x80, 0x00, 0x00,
651 0x00, 0x00, 0x01, 0xB7,
653 DemuxBlock( p_demux, buffer, sizeof(buffer) );
655 bool b_empty;
656 es_out_Control( p_demux->out, ES_OUT_GET_EMPTY, &b_empty );
657 p_sys->b_reset_pcr = true;
659 msleep( 40000 );
660 break;
663 case DVDNAV_SPU_CLUT_CHANGE:
665 int i;
667 msg_Dbg( p_demux, "DVDNAV_SPU_CLUT_CHANGE" );
668 /* Update color lookup table (16 *uint32_t in packet) */
669 memcpy( p_sys->clut, packet, 16 * sizeof( uint32_t ) );
671 /* HACK to get the SPU tracks registered in the right order */
672 for( i = 0; i < 0x1f; i++ )
674 if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
675 ESNew( p_demux, 0xbd20 + i );
677 /* END HACK */
678 break;
681 case DVDNAV_SPU_STREAM_CHANGE:
683 dvdnav_spu_stream_change_event_t *event =
684 (dvdnav_spu_stream_change_event_t*)packet;
685 int i;
687 msg_Dbg( p_demux, "DVDNAV_SPU_STREAM_CHANGE" );
688 msg_Dbg( p_demux, " - physical_wide=%d",
689 event->physical_wide );
690 msg_Dbg( p_demux, " - physical_letterbox=%d",
691 event->physical_letterbox);
692 msg_Dbg( p_demux, " - physical_pan_scan=%d",
693 event->physical_pan_scan );
695 ESSubtitleUpdate( p_demux );
696 p_sys->b_spu_change = true;
698 /* HACK to get the SPU tracks registered in the right order */
699 for( i = 0; i < 0x1f; i++ )
701 if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
702 ESNew( p_demux, 0xbd20 + i );
704 /* END HACK */
705 break;
708 case DVDNAV_AUDIO_STREAM_CHANGE:
710 dvdnav_audio_stream_change_event_t *event =
711 (dvdnav_audio_stream_change_event_t*)packet;
712 msg_Dbg( p_demux, "DVDNAV_AUDIO_STREAM_CHANGE" );
713 msg_Dbg( p_demux, " - physical=%d", event->physical );
714 /* TODO */
715 break;
718 case DVDNAV_VTS_CHANGE:
720 int32_t i_title = 0;
721 int32_t i_part = 0;
722 int i;
724 dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t*)packet;
725 msg_Dbg( p_demux, "DVDNAV_VTS_CHANGE" );
726 msg_Dbg( p_demux, " - vtsN=%d", event->new_vtsN );
727 msg_Dbg( p_demux, " - domain=%d", event->new_domain );
729 /* reset PCR */
730 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
732 for( i = 0; i < PS_TK_COUNT; i++ )
734 ps_track_t *tk = &p_sys->tk[i];
735 if( tk->b_seen )
737 es_format_Clean( &tk->fmt );
738 if( tk->es ) es_out_Del( p_demux->out, tk->es );
740 tk->b_seen = false;
743 if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
744 &i_part ) == DVDNAV_STATUS_OK )
746 if( i_title >= 0 && i_title < p_sys->i_title &&
747 p_demux->info.i_title != i_title )
749 p_demux->info.i_update |= INPUT_UPDATE_TITLE;
750 p_demux->info.i_title = i_title;
753 break;
756 case DVDNAV_CELL_CHANGE:
758 int32_t i_title = 0;
759 int32_t i_part = 0;
761 dvdnav_cell_change_event_t *event =
762 (dvdnav_cell_change_event_t*)packet;
763 msg_Dbg( p_demux, "DVDNAV_CELL_CHANGE" );
764 msg_Dbg( p_demux, " - cellN=%d", event->cellN );
765 msg_Dbg( p_demux, " - pgN=%d", event->pgN );
766 msg_Dbg( p_demux, " - cell_length=%"PRId64, event->cell_length );
767 msg_Dbg( p_demux, " - pg_length=%"PRId64, event->pg_length );
768 msg_Dbg( p_demux, " - pgc_length=%"PRId64, event->pgc_length );
769 msg_Dbg( p_demux, " - cell_start=%"PRId64, event->cell_start );
770 msg_Dbg( p_demux, " - pg_start=%"PRId64, event->pg_start );
772 /* Store the lenght in time of the current PGC */
773 p_sys->i_pgc_length = event->pgc_length / 90 * 1000;
775 /* FIXME is it correct or there is better way to know chapter change */
776 if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
777 &i_part ) == DVDNAV_STATUS_OK )
779 if( i_title >= 0 && i_title < p_sys->i_title &&
780 i_part >= 1 && i_part <= p_sys->title[i_title]->i_seekpoint &&
781 p_demux->info.i_seekpoint != i_part - 1 )
783 p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
784 p_demux->info.i_seekpoint = i_part - 1;
787 break;
790 case DVDNAV_NAV_PACKET:
792 #ifdef DVDNAV_DEBUG
793 msg_Dbg( p_demux, "DVDNAV_NAV_PACKET" );
794 #endif
795 /* A lot of thing to do here :
796 * - handle packet
797 * - fetch pts (for time display)
798 * - ...
800 DemuxBlock( p_demux, packet, i_len );
801 if( p_sys->b_spu_change )
803 ButtonUpdate( p_demux, false );
804 p_sys->b_spu_change = false;
806 break;
809 case DVDNAV_STOP: /* EOF */
810 msg_Dbg( p_demux, "DVDNAV_STOP" );
812 #if DVD_READ_CACHE
813 dvdnav_free_cache_block( p_sys->dvdnav, packet );
814 #endif
815 return 0;
817 case DVDNAV_HIGHLIGHT:
819 dvdnav_highlight_event_t *event = (dvdnav_highlight_event_t*)packet;
820 msg_Dbg( p_demux, "DVDNAV_HIGHLIGHT" );
821 msg_Dbg( p_demux, " - display=%d", event->display );
822 msg_Dbg( p_demux, " - buttonN=%d", event->buttonN );
823 ButtonUpdate( p_demux, false );
824 break;
827 case DVDNAV_HOP_CHANNEL:
828 msg_Dbg( p_demux, "DVDNAV_HOP_CHANNEL" );
829 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
830 break;
832 case DVDNAV_WAIT:
833 msg_Dbg( p_demux, "DVDNAV_WAIT" );
835 bool b_empty;
836 es_out_Control( p_demux->out, ES_OUT_GET_EMPTY, &b_empty );
837 if( !b_empty )
839 msleep( 40*1000 );
841 else
843 dvdnav_wait_skip( p_sys->dvdnav );
844 p_sys->b_reset_pcr = true;
846 break;
848 default:
849 msg_Warn( p_demux, "Unknown event (0x%x)", i_event );
850 break;
853 #if DVD_READ_CACHE
854 dvdnav_free_cache_block( p_sys->dvdnav, packet );
855 #endif
857 return 1;
860 /* Get a 2 char code
861 * FIXME: partiallyy duplicated from src/input/es_out.c
863 static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var )
865 const iso639_lang_t *pl;
866 char *psz_lang;
867 char *p;
869 psz_lang = var_CreateGetString( p_demux, psz_var );
870 if( !psz_lang )
871 return strdup(LANGUAGE_DEFAULT);
873 /* XXX: we will use only the first value
874 * (and ignore other ones in case of a list) */
875 if( ( p = strchr( psz_lang, ',' ) ) )
876 *p = '\0';
878 for( pl = p_languages; pl->psz_eng_name != NULL; pl++ )
880 if( *psz_lang == '\0' )
881 continue;
882 if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
883 !strcasecmp( pl->psz_native_name, psz_lang ) ||
884 !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
885 !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
886 !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
887 break;
890 free( psz_lang );
892 if( pl->psz_eng_name != NULL )
893 return strdup( pl->psz_iso639_1 );
895 return strdup(LANGUAGE_DEFAULT);
898 static void DemuxTitles( demux_t *p_demux )
900 demux_sys_t *p_sys = p_demux->p_sys;
901 input_title_t *t;
902 seekpoint_t *s;
903 int32_t i_titles;
904 int i;
906 /* Menu */
907 t = vlc_input_title_New();
908 t->b_menu = true;
909 t->psz_name = strdup( "DVD Menu" );
911 s = vlc_seekpoint_New();
912 s->psz_name = strdup( "Resume" );
913 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
915 s = vlc_seekpoint_New();
916 s->psz_name = strdup( "Root" );
917 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
919 s = vlc_seekpoint_New();
920 s->psz_name = strdup( "Title" );
921 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
923 s = vlc_seekpoint_New();
924 s->psz_name = strdup( "Chapter" );
925 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
927 s = vlc_seekpoint_New();
928 s->psz_name = strdup( "Subtitle" );
929 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
931 s = vlc_seekpoint_New();
932 s->psz_name = strdup( "Audio" );
933 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
935 s = vlc_seekpoint_New();
936 s->psz_name = strdup( "Angle" );
937 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
939 TAB_APPEND( p_sys->i_title, p_sys->title, t );
941 /* Find out number of titles/chapters */
942 dvdnav_get_number_of_titles( p_sys->dvdnav, &i_titles );
943 for( i = 1; i <= i_titles; i++ )
945 int32_t i_chapters = 0;
946 int j;
948 dvdnav_get_number_of_parts( p_sys->dvdnav, i, &i_chapters );
950 t = vlc_input_title_New();
951 for( j = 0; j < __MAX( i_chapters, 1 ); j++ )
953 s = vlc_seekpoint_New();
954 TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
957 TAB_APPEND( p_sys->i_title, p_sys->title, t );
961 /*****************************************************************************
962 * Update functions:
963 *****************************************************************************/
964 static void ButtonUpdate( demux_t *p_demux, bool b_mode )
966 demux_sys_t *p_sys = p_demux->p_sys;
967 vlc_value_t val;
968 int32_t i_title, i_part;
970 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
972 if( var_Get( p_sys->p_input, "highlight-mutex", &val ) == VLC_SUCCESS )
974 vlc_mutex_t *p_mutex = val.p_address;
975 dvdnav_highlight_area_t hl;
976 int32_t i_button;
977 bool b_button_ok;
979 if( dvdnav_get_current_highlight( p_sys->dvdnav, &i_button )
980 != DVDNAV_STATUS_OK )
982 msg_Err( p_demux, "dvdnav_get_current_highlight failed" );
983 return;
986 b_button_ok = false;
987 if( i_button > 0 && i_title == 0 )
989 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
991 b_button_ok = DVDNAV_STATUS_OK ==
992 dvdnav_get_highlight_area( pci, i_button, b_mode, &hl );
995 if( b_button_ok )
997 int i;
998 for( i = 0; i < 4; i++ )
1000 uint32_t i_yuv = p_sys->clut[(hl.palette>>(16+i*4))&0x0f];
1001 uint8_t i_alpha = ( (hl.palette>>(i*4))&0x0f ) * 0xff / 0xf;
1003 p_sys->palette[i][0] = (i_yuv >> 16) & 0xff;
1004 p_sys->palette[i][1] = (i_yuv >> 0) & 0xff;
1005 p_sys->palette[i][2] = (i_yuv >> 8) & 0xff;
1006 p_sys->palette[i][3] = i_alpha;
1009 vlc_mutex_lock( p_mutex );
1010 var_SetInteger( p_sys->p_input, "x-start", hl.sx );
1011 var_SetInteger( p_sys->p_input, "x-end", hl.ex );
1012 var_SetInteger( p_sys->p_input, "y-start", hl.sy );
1013 var_SetInteger( p_sys->p_input, "y-end", hl.ey );
1015 var_SetAddress( p_sys->p_input, "menu-palette", p_sys->palette );
1017 var_SetBool( p_sys->p_input, "highlight", true );
1018 vlc_mutex_unlock( p_mutex );
1020 msg_Dbg( p_demux, "buttonUpdate %d", i_button );
1022 else
1024 msg_Dbg( p_demux, "buttonUpdate not done b=%d t=%d",
1025 i_button, i_title );
1027 /* Show all */
1028 vlc_mutex_lock( p_mutex );
1029 var_SetBool( p_sys->p_input, "highlight", false );
1030 vlc_mutex_unlock( p_mutex );
1035 static void ESSubtitleUpdate( demux_t *p_demux )
1037 demux_sys_t *p_sys = p_demux->p_sys;
1038 int i_spu = dvdnav_get_active_spu_stream( p_sys->dvdnav );
1039 int32_t i_title, i_part;
1041 ButtonUpdate( p_demux, false );
1043 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1044 if( i_title > 0 ) return;
1046 if( i_spu >= 0 && i_spu <= 0x1f )
1048 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
1050 ESNew( p_demux, 0xbd20 + i_spu );
1052 /* be sure to unselect it (reset) */
1053 es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
1054 (bool)false );
1056 /* now select it */
1057 es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
1059 else
1061 for( i_spu = 0; i_spu <= 0x1F; i_spu++ )
1063 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(0xbd20 + i_spu)];
1064 if( tk->b_seen )
1066 es_out_Control( p_demux->out, ES_OUT_SET_ES_STATE, tk->es,
1067 (bool)false );
1073 /*****************************************************************************
1074 * DemuxBlock: demux a given block
1075 *****************************************************************************/
1076 static int DemuxBlock( demux_t *p_demux, const uint8_t *pkt, int i_pkt )
1078 demux_sys_t *p_sys = p_demux->p_sys;
1079 const uint8_t *p = pkt;
1081 while( p < &pkt[i_pkt] )
1083 int i_size = ps_pkt_size( p, &pkt[i_pkt] - p );
1084 block_t *p_pkt;
1085 if( i_size <= 0 )
1087 break;
1090 /* Create a block */
1091 p_pkt = block_New( p_demux, i_size );
1092 memcpy( p_pkt->p_buffer, p, i_size);
1094 /* Parse it and send it */
1095 switch( 0x100 | p[3] )
1097 case 0x1b9:
1098 case 0x1bb:
1099 case 0x1bc:
1100 #ifdef DVDNAV_DEBUG
1101 if( p[3] == 0xbc )
1103 msg_Warn( p_demux, "received a PSM packet" );
1105 else if( p[3] == 0xbb )
1107 msg_Warn( p_demux, "received a SYSTEM packet" );
1109 #endif
1110 block_Release( p_pkt );
1111 break;
1113 case 0x1ba:
1115 int64_t i_scr;
1116 int i_mux_rate;
1117 if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
1119 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr + 1 );
1120 if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
1122 block_Release( p_pkt );
1123 break;
1125 default:
1127 int i_id = ps_pkt_id( p_pkt );
1128 if( i_id >= 0xc0 )
1130 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1132 if( !tk->b_seen )
1134 ESNew( p_demux, i_id );
1136 if( tk->b_seen && tk->es &&
1137 !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
1139 es_out_Send( p_demux->out, tk->es, p_pkt );
1141 else
1143 block_Release( p_pkt );
1146 else
1148 block_Release( p_pkt );
1150 break;
1154 p += i_size;
1157 return VLC_SUCCESS;
1160 /*****************************************************************************
1161 * ESNew: register a new elementary stream
1162 *****************************************************************************/
1163 static void ESNew( demux_t *p_demux, int i_id )
1165 demux_sys_t *p_sys = p_demux->p_sys;
1166 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
1167 bool b_select = false;
1169 if( tk->b_seen ) return;
1171 if( ps_track_fill( tk, 0, i_id ) )
1173 msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
1174 return;
1177 /* Add a new ES */
1178 if( tk->fmt.i_cat == VIDEO_ES )
1180 b_select = true;
1182 else if( tk->fmt.i_cat == AUDIO_ES )
1184 int i_audio = -1;
1185 /* find the audio number PLEASE find another way */
1186 if( (i_id&0xbdf8) == 0xbd88 ) /* dts */
1188 i_audio = i_id&0x07;
1190 else if( (i_id&0xbdf0) == 0xbd80 ) /* a52 */
1192 i_audio = i_id&0xf;
1194 else if( (i_id&0xbdf0) == 0xbda0 ) /* lpcm */
1196 i_audio = i_id&0x1f;
1198 else if( ( i_id&0xe0 ) == 0xc0 ) /* mpga */
1200 i_audio = i_id&0x1f;
1202 if( i_audio >= 0 )
1204 int i_lang = dvdnav_audio_stream_to_lang( p_sys->dvdnav, i_audio );
1205 if( i_lang != 0xffff )
1207 tk->fmt.psz_language = malloc( 3 );
1208 tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1209 tk->fmt.psz_language[1] = (i_lang )&0xff;
1210 tk->fmt.psz_language[2] = 0;
1212 if( dvdnav_get_active_audio_stream( p_sys->dvdnav ) == i_audio )
1214 b_select = true;
1218 else if( tk->fmt.i_cat == SPU_ES )
1220 int32_t i_title, i_part;
1221 int i_lang = dvdnav_spu_stream_to_lang( p_sys->dvdnav, i_id&0x1f );
1222 if( i_lang != 0xffff )
1224 tk->fmt.psz_language = malloc( 3 );
1225 tk->fmt.psz_language[0] = (i_lang >> 8)&0xff;
1226 tk->fmt.psz_language[1] = (i_lang )&0xff;
1227 tk->fmt.psz_language[2] = 0;
1230 /* Palette */
1231 tk->fmt.subs.spu.palette[0] = 0xBeef;
1232 memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
1233 16 * sizeof( uint32_t ) );
1235 /* We select only when we are not in the menu */
1236 dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part );
1237 if( i_title > 0 &&
1238 dvdnav_get_active_spu_stream( p_sys->dvdnav ) == (i_id&0x1f) )
1240 b_select = true;
1244 tk->es = es_out_Add( p_demux->out, &tk->fmt );
1245 if( b_select )
1247 es_out_Control( p_demux->out, ES_OUT_SET_ES, tk->es );
1249 tk->b_seen = true;
1251 if( tk->fmt.i_cat == VIDEO_ES ) ButtonUpdate( p_demux, false );
1254 /*****************************************************************************
1255 * Still image end
1256 *****************************************************************************/
1257 static void StillTimer( void *p_data )
1259 demux_sys_t *p_sys = p_data;
1261 vlc_mutex_lock( &p_sys->still.lock );
1262 if( likely(p_sys->still.b_enabled) )
1264 p_sys->still.b_enabled = false;
1265 dvdnav_still_skip( p_sys->dvdnav );
1267 vlc_mutex_unlock( &p_sys->still.lock );
1270 static int EventMouse( vlc_object_t *p_vout, char const *psz_var,
1271 vlc_value_t oldval, vlc_value_t val, void *p_data )
1273 demux_t *p_demux = p_data;
1274 demux_sys_t *p_sys = p_demux->p_sys;
1276 /* FIXME? PCI usage thread safe? */
1277 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1278 int x = val.coords.x;
1279 int y = val.coords.y;
1281 if( psz_var[6] == 'm' ) /* mouse-moved */
1282 dvdnav_mouse_select( p_sys->dvdnav, pci, x, y );
1283 else
1285 assert( psz_var[6] == 'c' ); /* mouse-clicked */
1287 ButtonUpdate( p_demux, true );
1288 dvdnav_mouse_activate( p_sys->dvdnav, pci, x, y );
1290 (void)p_vout;
1291 (void)oldval;
1292 return VLC_SUCCESS;
1295 static int EventKey( vlc_object_t *p_this, char const *psz_var,
1296 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1298 demux_t *p_demux = p_data;
1299 demux_sys_t *p_sys = p_demux->p_sys;
1301 /* FIXME: thread-safe ? */
1302 pci_t *pci = dvdnav_get_current_nav_pci( p_sys->dvdnav );
1304 switch( newval.i_int )
1306 case ACTIONID_NAV_LEFT:
1307 dvdnav_left_button_select( p_sys->dvdnav, pci );
1308 break;
1309 case ACTIONID_NAV_RIGHT:
1310 dvdnav_right_button_select( p_sys->dvdnav, pci );
1311 break;
1312 case ACTIONID_NAV_UP:
1313 dvdnav_upper_button_select( p_sys->dvdnav, pci );
1314 break;
1315 case ACTIONID_NAV_DOWN:
1316 dvdnav_lower_button_select( p_sys->dvdnav, pci );
1317 break;
1318 case ACTIONID_NAV_ACTIVATE:
1319 ButtonUpdate( p_demux, true );
1320 dvdnav_button_activate( p_sys->dvdnav, pci );
1321 break;
1324 (void)p_this; (void)psz_var; (void)oldval;
1325 return VLC_SUCCESS;
1328 static int EventIntf( vlc_object_t *p_input, char const *psz_var,
1329 vlc_value_t oldval, vlc_value_t val, void *p_data )
1331 demux_t *p_demux = p_data;
1332 demux_sys_t *p_sys = p_demux->p_sys;
1334 if (val.i_int == INPUT_EVENT_VOUT)
1336 vlc_object_t *p_vout;
1338 p_vout = p_sys->p_vout;
1339 if( p_vout != NULL )
1341 var_DelCallback( p_vout, "mouse-moved", EventMouse, p_demux );
1342 var_DelCallback( p_vout, "mouse-clicked", EventMouse, p_demux );
1343 vlc_object_release( p_vout );
1346 p_vout = (vlc_object_t *)input_GetVout( (input_thread_t *)p_input );
1347 p_sys->p_vout = p_vout;
1348 if( p_vout != NULL )
1350 var_AddCallback( p_vout, "mouse-moved", EventMouse, p_demux );
1351 var_AddCallback( p_vout, "mouse-clicked", EventMouse, p_demux );
1354 (void) psz_var; (void) oldval;
1355 return VLC_SUCCESS;
1358 /*****************************************************************************
1359 * ProbeDVD: very weak probing that avoids going too often into a dvdnav_open()
1360 *****************************************************************************/
1361 static int ProbeDVD( demux_t *p_demux, char *psz_name )
1363 (void)p_demux;
1364 #ifdef HAVE_SYS_STAT_H
1365 struct stat stat_info;
1366 uint8_t pi_anchor[2];
1367 int i_fd, i_ret;
1369 if( !*psz_name )
1371 /* Triggers libdvdcss autodetection */
1372 return VLC_SUCCESS;
1375 if( (i_fd = vlc_open( psz_name, O_RDONLY |O_NONBLOCK )) == -1 )
1377 return VLC_SUCCESS; /* Let dvdnav_open() do the probing */
1380 i_ret = VLC_EGENERIC;
1382 if( fstat( i_fd, &stat_info ) || !S_ISREG( stat_info.st_mode ) )
1384 if( !S_ISFIFO( stat_info.st_mode ) )
1385 i_ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */
1386 goto bailout;
1389 /* Try to find the anchor (2 bytes at LBA 256) */
1390 if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1
1391 && read( i_fd, pi_anchor, 2 ) == 2
1392 && GetWLE( pi_anchor ) == 2 )
1393 i_ret = VLC_SUCCESS; /* Found a potential anchor */
1395 bailout:
1396 close( i_fd );
1398 return i_ret;
1399 #else
1401 return VLC_SUCCESS;
1402 #endif