]> git.sesse.net Git - vlc/blob - modules/access/dvdread.c
43a5511116e102a15de8bef5910ea47b4966abee
[vlc] / modules / access / dvdread.c
1 /*****************************************************************************
2  * dvdread.c : DvdRead input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Stéphane Borel <stef@via.ecp.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdio.h>
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <string.h>                                              /* strdup() */
31
32 #include <vlc/vlc.h>
33 #include <vlc/input.h>
34
35 #include "iso_lang.h"
36
37 #include "../demux/ps.h"
38
39 #ifdef HAVE_UNISTD_H
40 #   include <unistd.h>
41 #endif
42
43 #include <fcntl.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <string.h>
47
48 #include <dvdread/dvd_reader.h>
49 #include <dvdread/ifo_types.h>
50 #include <dvdread/ifo_read.h>
51 #include <dvdread/nav_read.h>
52 #include <dvdread/nav_print.h>
53
54 /*****************************************************************************
55  * Module descriptor
56  *****************************************************************************/
57 #define CACHING_TEXT N_("Caching value in ms")
58 #define CACHING_LONGTEXT N_( \
59     "Allows you to modify the default caching value for DVDread streams. " \
60     "This value should be set in millisecond units." )
61
62 #define CSSMETHOD_TEXT N_("Method used by libdvdcss for decryption")
63 #define CSSMETHOD_LONGTEXT N_( \
64     "Set the method used by libdvdcss for key decryption.\n" \
65     "title: decrypted title key is guessed from the encrypted sectors of " \
66            "the stream. Thus it should work with a file as well as the " \
67            "DVD device. But it sometimes takes much time to decrypt a title " \
68            "key and may even fail. With this method, the key is only checked "\
69            "at the beginning of each title, so it won't work if the key " \
70            "changes in the middle of a title.\n" \
71     "disc: the disc key is first cracked, then all title keys can be " \
72            "decrypted instantly, which allows us to check them often.\n" \
73     "key: the same as \"disc\" if you don't have a file with player keys " \
74            "at compilation time. If you do, the decryption of the disc key " \
75            "will be faster with this method. It is the one that was used by " \
76            "libcss.\n" \
77     "The default method is: key.")
78
79 static char *psz_css_list[] = { "title", "disc", "key" };
80 static char *psz_css_list_text[] = { N_("title"), N_("Disc"), N_("Key") };
81
82 static int  Open ( vlc_object_t * );
83 static void Close( vlc_object_t * );
84
85 vlc_module_begin();
86     set_description( _("DVDRead Input") );
87     add_integer( "dvdread-caching", DEFAULT_PTS_DELAY / 1000, NULL,
88         CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
89     add_string( "dvdread-css-method", NULL, NULL, CSSMETHOD_TEXT,
90                 CSSMETHOD_LONGTEXT, VLC_TRUE );
91         change_string_list( psz_css_list, psz_css_list_text, 0 );
92     set_capability( "access_demux", 0 );
93     //add_shortcut( "dvd" );
94     add_shortcut( "dvdread" );
95     add_shortcut( "dvdsimple" );
96     set_callbacks( Open, Close );
97 vlc_module_end();
98
99 /* how many blocks DVDRead will read in each loop */
100 #define DVD_BLOCK_READ_ONCE 4
101
102 /*****************************************************************************
103  * Local prototypes
104  *****************************************************************************/
105
106 struct demux_sys_t
107 {
108     /* DVDRead state */
109     dvd_reader_t *p_dvdread;
110     dvd_file_t   *p_title;
111
112     ifo_handle_t *p_vmg_file;
113     ifo_handle_t *p_vts_file;
114
115     int i_title;
116     int i_chapter, i_chapters;
117     int i_angle, i_angles;
118
119     tt_srpt_t    *p_tt_srpt;
120     pgc_t        *p_cur_pgc;
121     dsi_t        dsi_pack;
122     int          i_ttn;
123
124     int i_pack_len;
125     int i_cur_block;
126     int i_next_vobu;
127
128     /* Current title start/end blocks */
129     int i_title_start_block;
130     int i_title_end_block;
131     int i_title_blocks;
132     int i_title_offset;
133
134     int i_title_start_cell;
135     int i_title_end_cell;
136     int i_cur_cell;
137     int i_next_cell;
138
139     /* Track */
140     ps_track_t    tk[PS_TK_COUNT];
141     int           i_mux_rate;
142
143     int           i_titles;
144     input_title_t **titles;
145
146     /* Video */
147     int i_aspect;
148
149     /* SPU */
150     uint32_t clut[16];
151 };
152
153 static char *ParseCL( vlc_object_t *, char *, vlc_bool_t, int *, int *, int *);
154
155 static int Control   ( demux_t *, int, va_list );
156 static int Demux     ( demux_t * );
157 static int DemuxBlock( demux_t *, uint8_t *, int );
158
159 static void DemuxTitles( demux_t *, int *, int *, int * );
160 static void ESNew( demux_t *, int, int );
161
162 static int  DvdReadSetArea  ( demux_t *, int, int, int );
163 static void DvdReadSeek     ( demux_t *, int );
164 static void DvdReadHandleDSI( demux_t *, uint8_t * );
165 static void DvdReadFindCell ( demux_t * );
166
167 /*****************************************************************************
168  * Open:
169  *****************************************************************************/
170 static int Open( vlc_object_t *p_this )
171 {
172     demux_t      *p_demux = (demux_t*)p_this;
173     demux_sys_t  *p_sys;
174     int          i_title, i_chapter, i_angle;
175     char         *psz_name;
176     char         *psz_dvdcss_env;
177     dvd_reader_t *p_dvdread;
178     ifo_handle_t *p_vmg_file;
179
180     psz_name = ParseCL( VLC_OBJECT(p_demux), p_demux->psz_path, VLC_TRUE,
181                         &i_title, &i_chapter, &i_angle );
182     if( !psz_name )
183     {
184         return VLC_EGENERIC;
185     }
186
187     /* Override environment variable DVDCSS_METHOD with config option
188      * (FIXME: this creates a small memory leak) */
189     psz_dvdcss_env = config_GetPsz( p_demux, "dvdread-css-method" );
190     if( psz_dvdcss_env && *psz_dvdcss_env )
191     {
192         char *psz_env;
193
194         psz_env = malloc( strlen("DVDCSS_METHOD=") +
195                           strlen( psz_dvdcss_env ) + 1 );
196
197         if( !psz_env )
198         {
199             free( psz_dvdcss_env );
200             return VLC_ENOMEM;
201         }
202
203         sprintf( psz_env, "%s%s", "DVDCSS_METHOD=", psz_dvdcss_env );
204
205         putenv( psz_env );
206     }
207     if( psz_dvdcss_env ) free( psz_dvdcss_env );
208
209     /* Open dvdread */
210     if( !(p_dvdread = DVDOpen( psz_name )) )
211     {
212         msg_Err( p_demux, "DVDRead cannot open source: %s", psz_name );
213         free( psz_name );
214         return VLC_EGENERIC;
215     }
216     free( psz_name );
217
218     /* Ifo allocation & initialisation */
219     if( !( p_vmg_file = ifoOpen( p_dvdread, 0 ) ) )
220     {
221         msg_Warn( p_demux, "cannot open VMG info" );
222         return VLC_EGENERIC;
223     }
224     msg_Dbg( p_demux, "VMG opened" );
225
226     /* Fill p_demux field */
227     p_demux->pf_demux = Demux;
228     p_demux->pf_control = Control;
229     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
230     memset( p_sys, 0, sizeof( demux_sys_t ) );
231
232     ps_track_init( p_sys->tk );
233     p_sys->i_aspect = -1;
234     p_sys->i_mux_rate = 0;
235
236     p_sys->p_dvdread = p_dvdread;
237     p_sys->p_vmg_file = p_vmg_file;
238     p_sys->p_title = NULL;
239     p_sys->p_vts_file = NULL;
240
241     p_sys->i_title = p_sys->i_chapter = -1;
242     p_sys->i_angle = i_angle;
243
244     DemuxTitles( p_demux, &i_title, &i_chapter, &i_angle );
245
246     DvdReadSetArea( p_demux, i_title, i_chapter, i_angle );
247
248     /* Update default_pts to a suitable value for dvdread access */
249     var_Create( p_demux, "dvdread-caching",
250                 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
251
252     return VLC_SUCCESS;
253 }
254
255 /*****************************************************************************
256  * Close:
257  *****************************************************************************/
258 static void Close( vlc_object_t *p_this )
259 {
260     demux_t     *p_demux = (demux_t*)p_this;
261     demux_sys_t *p_sys = p_demux->p_sys;
262     int i;
263
264     for( i = 0; i < PS_TK_COUNT; i++ )
265     {
266         ps_track_t *tk = &p_sys->tk[i];
267         if( tk->b_seen )
268         {
269             es_format_Clean( &tk->fmt );
270             if( tk->es ) es_out_Del( p_demux->out, tk->es );
271         }
272     }
273
274     /* Close libdvdread */
275     if( p_sys->p_title ) DVDCloseFile( p_sys->p_title );
276     if( p_sys->p_vts_file ) ifoClose( p_sys->p_vts_file );
277     if( p_sys->p_vmg_file ) ifoClose( p_sys->p_vmg_file );
278     DVDClose( p_sys->p_dvdread );
279
280     free( p_sys );
281 }
282
283 /*****************************************************************************
284  * Control:
285  *****************************************************************************/
286 static int Control( demux_t *p_demux, int i_query, va_list args )
287 {
288     demux_sys_t *p_sys = p_demux->p_sys;
289     double f, *pf;
290     vlc_bool_t *pb;
291     int64_t *pi64;
292     input_title_t ***ppp_title;
293     int *pi_int;
294     int i;
295
296     switch( i_query )
297     {
298         case DEMUX_GET_POSITION:
299         {
300             pf = (double*) va_arg( args, double* );
301
302             if( p_sys->i_title_blocks > 0 )
303                 *pf = (double)p_sys->i_title_offset / p_sys->i_title_blocks;
304             else
305                 *pf = 0.0;
306
307             return VLC_SUCCESS;
308         }
309         case DEMUX_SET_POSITION:
310         {
311             f = (double)va_arg( args, double );
312
313             DvdReadSeek( p_demux, f * p_sys->i_title_blocks );
314
315             return VLC_SUCCESS;
316         }
317         case DEMUX_GET_TIME:
318             pi64 = (int64_t*)va_arg( args, int64_t * );
319             if( p_sys->i_mux_rate > 0 )
320             {
321                 *pi64 = (int64_t)1000000 * DVD_VIDEO_LB_LEN *
322                         p_sys->i_title_offset / 50 / p_sys->i_mux_rate;
323                 return VLC_SUCCESS;
324             }
325             *pi64 = 0;
326             return VLC_EGENERIC;
327
328         case DEMUX_GET_LENGTH:
329             pi64 = (int64_t*)va_arg( args, int64_t * );
330             if( p_sys->i_mux_rate > 0 )
331             {
332                 *pi64 = (int64_t)1000000 * DVD_VIDEO_LB_LEN *
333                         p_sys->i_title_blocks / 50 / p_sys->i_mux_rate;
334                 return VLC_SUCCESS;
335             }
336             *pi64 = 0;
337             return VLC_EGENERIC;
338
339         /* Special for access_demux */
340         case DEMUX_CAN_PAUSE:
341         case DEMUX_CAN_CONTROL_PACE:
342             /* TODO */
343             pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
344             *pb = VLC_TRUE;
345             return VLC_SUCCESS;
346
347         case DEMUX_SET_PAUSE_STATE:
348             return VLC_SUCCESS;
349
350         case DEMUX_GET_TITLE_INFO:
351             ppp_title = (input_title_t***)va_arg( args, input_title_t*** );
352             pi_int    = (int*)va_arg( args, int* );
353
354             /* Duplicate title infos */
355             *pi_int = p_sys->i_titles;
356             *ppp_title = malloc( sizeof(input_title_t **) * p_sys->i_titles );
357             for( i = 0; i < p_sys->i_titles; i++ )
358             {
359                 (*ppp_title)[i] = vlc_input_title_Duplicate(p_sys->titles[i]);
360             }
361             return VLC_SUCCESS;
362
363         case DEMUX_SET_TITLE:
364             i = (int)va_arg( args, int );
365             if( DvdReadSetArea( p_demux, i, 0, -1 ) != VLC_SUCCESS )
366             {
367                 msg_Warn( p_demux, "cannot set title/chapter" );
368                 return VLC_EGENERIC;
369             }
370             p_demux->info.i_update |=
371                 INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
372             p_demux->info.i_title = i;
373             p_demux->info.i_seekpoint = 0;
374             return VLC_SUCCESS;
375
376         case DEMUX_SET_SEEKPOINT:
377             i = (int)va_arg( args, int );
378             if( DvdReadSetArea( p_demux, -1, i, -1 ) != VLC_SUCCESS )
379             {
380                 msg_Warn( p_demux, "cannot set title/chapter" );
381                 return VLC_EGENERIC;
382             }
383             p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
384             p_demux->info.i_seekpoint = i;
385             return VLC_SUCCESS;
386
387         case DEMUX_GET_PTS_DELAY:
388             pi64 = (int64_t*)va_arg( args, int64_t * );
389             *pi64 = (int64_t)var_GetInteger( p_demux, "dvdread-caching" )*1000;
390             return VLC_SUCCESS;
391
392         /* TODO implement others */
393         default:
394             return VLC_EGENERIC;
395     }
396 }
397
398 /*****************************************************************************
399  * Demux:
400  *****************************************************************************/
401 static int Demux( demux_t *p_demux )
402 {
403     demux_sys_t *p_sys = p_demux->p_sys;
404
405     uint8_t p_buffer[DVD_VIDEO_LB_LEN * DVD_BLOCK_READ_ONCE];
406     int i_blocks_once, i_read;
407     int i;
408
409     /*
410      * Playback by cell in this pgc, starting at the cell for our chapter.
411      */
412
413     /*
414      * Check end of pack, and select the following one
415      */
416     if( !p_sys->i_pack_len )
417     {
418         /* Read NAV packet */
419         if( DVDReadBlocks( p_sys->p_title, p_sys->i_next_vobu,
420                            1, p_buffer ) != 1 )
421         {
422             msg_Err( p_demux, "read failed for block %d", p_sys->i_next_vobu );
423             return -1;
424         }
425
426         /* Basic check to be sure we don't have a empty title
427          * go to next title if so */
428         //assert( p_buffer[41] == 0xbf && p_buffer[1027] == 0xbf );
429
430         /* Parse the contained dsi packet */
431         DvdReadHandleDSI( p_demux, p_buffer );
432
433         /* End of title */
434         if( p_sys->i_next_vobu > p_sys->i_title_end_block )
435         {
436             if( p_sys->i_title + 1 >= p_sys->i_titles ) return 0; /* EOF */
437
438             DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
439         }
440
441         if( p_sys->i_pack_len >= 1024 )
442         {
443             msg_Err( p_demux, "i_pack_len >= 1024. This shouldn't happen!" );
444             return 0; /* EOF */
445         }
446
447         /* FIXME: Ugly kludge: we send the pack block to the input for it
448          * sometimes has a zero scr and restart the sync */
449         p_sys->i_cur_block++;
450         p_sys->i_title_offset++;
451
452         DemuxBlock( p_demux, p_buffer, DVD_VIDEO_LB_LEN );
453     }
454
455     if( p_sys->i_cur_block > p_sys->i_title_end_block )
456     {
457         if( p_sys->i_title + 1 >= p_sys->i_titles ) return 0; /* EOF */
458
459         DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
460     }
461
462     /*
463      * Read actual data
464      */
465     i_blocks_once = __MIN( p_sys->i_pack_len, DVD_BLOCK_READ_ONCE );
466     p_sys->i_pack_len -= i_blocks_once;
467
468     /* Reads from DVD */
469     i_read = DVDReadBlocks( p_sys->p_title, p_sys->i_cur_block,
470                             i_blocks_once, p_buffer );
471     if( i_read != i_blocks_once )
472     {
473         msg_Err( p_demux, "read failed for %d/%d blocks at 0x%02x",
474                  i_read, i_blocks_once, p_sys->i_cur_block );
475         return -1;
476     }
477
478     p_sys->i_cur_block += i_read;
479     p_sys->i_title_offset += i_read;
480
481 #if 0
482     msg_Dbg( p_demux, "i_blocks: %d len: %d current: 0x%02x",
483              i_read, p_sys->i_pack_len, p_sys->i_cur_block );
484 #endif
485
486     for( i = 0; i < i_read; i++ )
487     {
488         DemuxBlock( p_demux, p_buffer + i * DVD_VIDEO_LB_LEN,
489                     DVD_VIDEO_LB_LEN );
490     }
491
492 #undef p_pgc
493
494     return 1;
495 }
496
497 /*****************************************************************************
498  * DemuxBlock: demux a given block
499  *****************************************************************************/
500 static int DemuxBlock( demux_t *p_demux, uint8_t *pkt, int i_pkt )
501 {
502     demux_sys_t *p_sys = p_demux->p_sys;
503     uint8_t     *p = pkt;
504
505     while( p < &pkt[i_pkt] )
506     {
507         int i_size = ps_pkt_size( p, &pkt[i_pkt] - p );
508         block_t *p_pkt;
509         if( i_size <= 0 )
510         {
511             break;
512         }
513
514         /* Create a block */
515         p_pkt = block_New( p_demux, i_size );
516         memcpy( p_pkt->p_buffer, p, i_size);
517
518         /* Parse it and send it */
519         switch( 0x100 | p[3] )
520         {
521         case 0x1b9:
522         case 0x1bb:
523         case 0x1bc:
524
525 #ifdef DVDREAD_DEBUG
526             if( p[3] == 0xbc )
527             {
528                 msg_Warn( p_demux, "received a PSM packet" );
529             }
530             else if( p[3] == 0xbb )
531             {
532                 msg_Warn( p_demux, "received a SYSTEM packet" );
533             }
534 #endif
535             block_Release( p_pkt );
536             break;
537
538         case 0x1ba:
539         {
540             int64_t i_scr;
541             int i_mux_rate;
542             if( !ps_pkt_parse_pack( p_pkt, &i_scr, &i_mux_rate ) )
543             {
544                 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_scr );
545                 if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
546             }
547             block_Release( p_pkt );
548             break;
549         }
550         default:
551         {
552             int i_id = ps_pkt_id( p_pkt );
553             if( i_id >= 0xc0 )
554             {
555                 ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
556
557                 if( !tk->b_seen )
558                 {
559                     ESNew( p_demux, i_id, 0 );
560                 }
561                 if( tk->b_seen && tk->es &&
562                     !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
563                 {
564                     es_out_Send( p_demux->out, tk->es, p_pkt );
565                 }
566                 else
567                 {
568                     block_Release( p_pkt );
569                 }
570             }
571             else
572             {
573                 block_Release( p_pkt );
574             }
575             break;
576         }
577         }
578
579         p += i_size;
580     }
581
582     return VLC_SUCCESS;
583 }
584
585 /*****************************************************************************
586  * ESNew: register a new elementary stream
587  *****************************************************************************/
588 static void ESNew( demux_t *p_demux, int i_id, int i_lang )
589 {
590     demux_sys_t *p_sys = p_demux->p_sys;
591     ps_track_t  *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
592     char psz_language[3];
593
594     if( tk->b_seen ) return;
595
596     if( ps_track_fill( tk, i_id ) )
597     {
598         msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
599         return;
600     }
601
602     psz_language[0] = psz_language[1] = psz_language[2] = 0;
603     if( i_lang && i_lang != 0xffff )
604     {
605         psz_language[0] = (i_lang >> 8)&0xff;
606         psz_language[1] = (i_lang     )&0xff;
607     }
608
609     /* Add a new ES */
610     if( tk->fmt.i_cat == VIDEO_ES )
611     {
612         if( p_sys->i_aspect >= 0 )
613         {
614             tk->fmt.video.i_aspect = p_sys->i_aspect;
615         }
616     }
617     else if( tk->fmt.i_cat == AUDIO_ES )
618     {
619         int i_audio = -1;
620         /* find the audio number PLEASE find another way */
621         if( (i_id&0xbdf8) == 0xbd88 )       /* dts */
622         {
623             i_audio = i_id&0x07;
624         }
625         else if( (i_id&0xbdf0) == 0xbd80 )  /* a52 */
626         {
627             i_audio = i_id&0xf;
628         }
629         else if( (i_id&0xbdf0) == 0xbda0 )  /* lpcm */
630         {
631             i_audio = i_id&0x1f;
632         }
633         else if( ( i_id&0xe0 ) == 0xc0 )    /* mpga */
634         {
635             i_audio = i_id&0x1f;
636         }
637
638         if( psz_language[0] ) tk->fmt.psz_language = strdup( psz_language );
639     }
640     else if( tk->fmt.i_cat == SPU_ES )
641     {
642         /* Palette */
643         tk->fmt.subs.spu.palette[0] = 0xBeef;
644         memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
645                 16 * sizeof( uint32_t ) );
646
647         if( psz_language[0] ) tk->fmt.psz_language = strdup( psz_language );
648     }
649
650     tk->es = es_out_Add( p_demux->out, &tk->fmt );
651     tk->b_seen = VLC_TRUE;
652 }
653
654 /*****************************************************************************
655  * DvdReadSetArea: initialize input data for title x, chapter y.
656  * It should be called for each user navigation request.
657  *****************************************************************************
658  * Take care that i_title and i_chapter start from 0.
659  *****************************************************************************/
660 static int DvdReadSetArea( demux_t *p_demux, int i_title, int i_chapter,
661                            int i_angle )
662 {
663     demux_sys_t *p_sys = p_demux->p_sys;
664     int pgc_id = 0, pgn = 0;
665     int i;
666
667 #define p_pgc p_sys->p_cur_pgc
668 #define p_vmg p_sys->p_vmg_file
669 #define p_vts p_sys->p_vts_file
670
671     if( i_title >= 0 && i_title < p_sys->i_titles &&
672         i_title != p_sys->i_title )
673     {
674         int i_start_cell, i_end_cell;
675
676         if( p_sys->p_title != NULL ) DVDCloseFile( p_sys->p_title );
677         if( p_vts != NULL ) ifoClose( p_vts );
678         p_sys->i_title = i_title;
679
680         /*
681          *  We have to load all title information
682          */
683         msg_Dbg( p_demux, "open VTS %d, for title %d",
684                  p_vmg->tt_srpt->title[i_title].title_set_nr, i_title + 1 );
685
686         /* Ifo vts */
687         if( !( p_vts = ifoOpen( p_sys->p_dvdread,
688                p_vmg->tt_srpt->title[i_title].title_set_nr ) ) )
689         {
690             msg_Err( p_demux, "fatal error in vts ifo" );
691             return VLC_EGENERIC;
692         }
693
694         /* Title position inside the selected vts */
695         p_sys->i_ttn = p_vmg->tt_srpt->title[i_title].vts_ttn;
696
697         /* Find title start/end */
698         pgc_id = p_vts->vts_ptt_srpt->title[p_sys->i_ttn - 1].ptt[0].pgcn;
699         pgn = p_vts->vts_ptt_srpt->title[p_sys->i_ttn - 1].ptt[0].pgn;
700         p_pgc = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
701
702         p_sys->i_title_start_cell =
703             i_start_cell = p_pgc->program_map[pgn - 1] - 1;
704         p_sys->i_title_start_block =
705             p_pgc->cell_playback[i_start_cell].first_sector;
706
707         p_sys->i_title_end_cell =
708             i_end_cell = p_pgc->nr_of_cells - 1;
709         p_sys->i_title_end_block =
710             p_pgc->cell_playback[i_end_cell].last_sector;
711
712         p_sys->i_title_offset = 0;
713
714         p_sys->i_title_blocks = 0;
715         for( i = i_start_cell; i <= i_end_cell; i++ )
716         {
717             p_sys->i_title_blocks += p_pgc->cell_playback[i].last_sector -
718                 p_pgc->cell_playback[i].first_sector + 1;
719         }
720
721         msg_Dbg( p_demux, "title %d vts_title %d pgc %d pgn %d "
722                  "start %d end %d blocks: %d",
723                  i_title + 1, p_sys->i_ttn, pgc_id, pgn,
724                  p_sys->i_title_start_block, p_sys->i_title_end_block,
725                  p_sys->i_title_blocks );
726
727         /*
728          * Set properties for current chapter
729          */
730         p_sys->i_chapter = 0;
731         p_sys->i_chapters =
732             p_vts->vts_ptt_srpt->title[p_sys->i_ttn - 1].nr_of_ptts;
733
734         pgc_id = p_vts->vts_ptt_srpt->title[
735                     p_sys->i_ttn - 1].ptt[p_sys->i_chapter].pgcn;
736         pgn = p_vts->vts_ptt_srpt->title[
737                     p_sys->i_ttn - 1].ptt[p_sys->i_chapter].pgn;
738
739         p_pgc = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
740         p_sys->i_pack_len = 0;
741         p_sys->i_next_cell =
742             p_sys->i_cur_cell = p_pgc->program_map[pgn - 1] - 1;
743         DvdReadFindCell( p_demux );
744
745         p_sys->i_next_vobu = p_sys->i_cur_block =
746             p_pgc->cell_playback[p_sys->i_cur_cell].first_sector;
747
748         /*
749          * Angle management
750          */
751         p_sys->i_angles = p_vmg->tt_srpt->title[i_title].nr_of_angles;
752         if( p_sys->i_angle > p_sys->i_angles ) p_sys->i_angle = 1;
753
754         /*
755          * We've got enough info, time to open the title set data.
756          */
757         if( !( p_sys->p_title = DVDOpenFile( p_sys->p_dvdread,
758             p_vmg->tt_srpt->title[i_title].title_set_nr,
759             DVD_READ_TITLE_VOBS ) ) )
760         {
761             msg_Err( p_demux, "cannot open title (VTS_%02d_1.VOB)",
762                      p_vmg->tt_srpt->title[i_title].title_set_nr );
763             return VLC_EGENERIC;
764         }
765
766         //IfoPrintTitle( p_demux );
767
768         /*
769          * Destroy obsolete ES by reinitializing program 0
770          * and find all ES in title with ifo data
771          */
772         es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
773
774         for( i = 0; i < PS_TK_COUNT; i++ )
775         {
776             ps_track_t *tk = &p_sys->tk[i];
777             if( tk->b_seen )
778             {
779                 es_format_Clean( &tk->fmt );
780                 if( tk->es ) es_out_Del( p_demux->out, tk->es );
781             }
782             tk->b_seen = VLC_FALSE;
783         }
784
785         if( p_demux->info.i_title != i_title )
786         {
787             p_demux->info.i_update |=
788                 INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
789             p_demux->info.i_title = i_title;
790             p_demux->info.i_seekpoint = 0;
791         }
792
793         /* TODO: re-add angles */
794
795
796         ESNew( p_demux, 0xe0, 0 ); /* Video, FIXME ? */
797         p_sys->i_aspect = p_vts->vtsi_mat->vts_video_attr.display_aspect_ratio;
798
799 #define audio_control \
800     p_sys->p_vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc->audio_control[i-1]
801
802         /* Audio ES, in the order they appear in the .ifo */
803         for( i = 1; i <= p_vts->vtsi_mat->nr_of_vts_audio_streams; i++ )
804         {
805             int i_position = 0;
806             uint16_t i_id;
807
808             //IfoPrintAudio( p_demux, i );
809
810             /* Audio channel is active if first byte is 0x80 */
811             if( audio_control & 0x8000 )
812             {
813                 i_position = ( audio_control & 0x7F00 ) >> 8;
814
815                 msg_Dbg( p_demux, "audio position  %d", i_position );
816                 switch( p_vts->vtsi_mat->vts_audio_attr[i - 1].audio_format )
817                 {
818                 case 0x00: /* A52 */
819                     i_id = (0x80 + i_position) | 0xbd00;
820                     break;
821                 case 0x02:
822                 case 0x03: /* MPEG audio */
823                     i_id = 0xc000 + i_position;
824                     break;
825                 case 0x04: /* LPCM */
826                     i_id = (0xa0 + i_position) | 0xbd00;
827                     break;
828                 case 0x06: /* DTS */
829                     i_id = (0x88 + i_position) | 0xbd00;
830                     break;
831                 default:
832                     i_id = 0;
833                     msg_Err( p_demux, "unknown audio type %.2x",
834                         p_vts->vtsi_mat->vts_audio_attr[i - 1].audio_format );
835                 }
836
837                 ESNew( p_demux, i_id, p_sys->p_vts_file->vtsi_mat->
838                        vts_audio_attr[i - 1].lang_code );
839             }
840         }
841 #undef audio_control
842
843 #define spu_palette \
844     p_sys->p_vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc->palette
845
846         memcpy( p_sys->clut, spu_palette, 16 * sizeof( uint32_t ) );
847
848 #define spu_control \
849     p_sys->p_vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc->subp_control[i-1]
850
851         /* Sub Picture ES */
852         for( i = 1; i <= p_vts->vtsi_mat->nr_of_vts_subp_streams; i++ )
853         {
854             int i_position = 0;
855             uint16_t i_id;
856
857             //IfoPrintSpu( p_sys, i );
858             msg_Dbg( p_demux, "spu %d 0x%02x", i, spu_control );
859
860             if( spu_control & 0x80000000 )
861             {
862                 /*  there are several streams for one spu */
863                 if( p_vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
864                 {
865                     /* 16:9 */
866                     switch( p_vts->vtsi_mat->vts_video_attr.permitted_df )
867                     {
868                     case 1: /* letterbox */
869                         i_position = spu_control & 0xff;
870                         break;
871                     case 2: /* pan&scan */
872                         i_position = ( spu_control >> 8 ) & 0xff;
873                         break;
874                     default: /* widescreen */
875                         i_position = ( spu_control >> 16 ) & 0xff;
876                         break;
877                     }
878                 }
879                 else
880                 {
881                     /* 4:3 */
882                     i_position = ( spu_control >> 24 ) & 0x7F;
883                 }
884
885                 i_id = (0x20 + i_position) | 0xbd00;
886
887                 ESNew( p_demux, i_id, p_sys->p_vts_file->vtsi_mat->
888                        vts_subp_attr[i - 1].lang_code );
889             }
890         }
891 #undef spu_control
892
893     }
894     else if( i_title != -1 && i_title != p_sys->i_title )
895
896     {
897         return VLC_EGENERIC; /* Couldn't set title */
898     }
899
900     /*
901      * Chapter selection
902      */
903
904     if( i_chapter >= 0 && i_chapter <= p_sys->i_chapters )
905     {
906         pgc_id = p_vts->vts_ptt_srpt->title[
907                      p_sys->i_ttn - 1].ptt[i_chapter].pgcn;
908         pgn = p_vts->vts_ptt_srpt->title[
909                   p_sys->i_ttn - 1].ptt[i_chapter].pgn;
910
911         p_pgc = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
912
913         p_sys->i_cur_cell = p_pgc->program_map[pgn - 1] - 1;
914         p_sys->i_chapter = i_chapter;
915         DvdReadFindCell( p_demux );
916
917         p_sys->i_title_offset = 0;
918         for( i = p_sys->i_title_start_cell; i < p_sys->i_cur_cell; i++ )
919         {
920             p_sys->i_title_offset += p_pgc->cell_playback[i].last_sector -
921                 p_pgc->cell_playback[i].first_sector + 1;
922         }
923
924         p_sys->i_pack_len = 0;
925         p_sys->i_next_vobu = p_sys->i_cur_block =
926             p_pgc->cell_playback[p_sys->i_cur_cell].first_sector;
927
928         if( p_demux->info.i_seekpoint != i_chapter )
929         {
930             p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
931             p_demux->info.i_seekpoint = i_chapter;
932         }
933     }
934     else if( i_chapter != -1 )
935
936     {
937         return VLC_EGENERIC; /* Couldn't set chapter */
938     }
939
940 #undef p_pgc
941 #undef p_vts
942 #undef p_vmg
943
944     return VLC_SUCCESS;
945 }
946
947 /*****************************************************************************
948  * DvdReadSeek : Goes to a given position on the stream.
949  *****************************************************************************
950  * This one is used by the input and translate chronological position from
951  * input to logical position on the device.
952  *****************************************************************************/
953 static void DvdReadSeek( demux_t *p_demux, int i_block_offset )
954 {
955     demux_sys_t *p_sys = p_demux->p_sys;
956     int i_chapter = 0;
957     int i_cell = 0;
958     int i_vobu = 0;
959     int i_sub_cell = 0;
960     int i_block;
961
962 #define p_pgc p_sys->p_cur_pgc
963 #define p_vts p_sys->p_vts_file
964
965     /* Find cell */
966     i_block = i_block_offset;
967     for( i_cell = p_sys->i_title_start_cell;
968          i_cell <= p_sys->i_title_end_cell; i_cell++ )
969     {
970         if( i_block < (int)p_pgc->cell_playback[i_cell].last_sector -
971             (int)p_pgc->cell_playback[i_cell].first_sector + 1 ) break;
972
973         i_block -= (p_pgc->cell_playback[i_cell].last_sector -
974             p_pgc->cell_playback[i_cell].first_sector + 1);
975     }
976     if( i_cell > p_sys->i_title_end_cell )
977     {
978         msg_Err( p_demux, "couldn't find cell for block %i", i_block_offset );
979         return;
980     }
981     i_block += p_pgc->cell_playback[i_cell].first_sector;
982     p_sys->i_title_offset = i_block_offset;
983
984     /* Find chapter */
985     for( i_chapter = 0; i_chapter < p_sys->i_chapters; i_chapter++ )
986     {
987         int pgc_id, pgn, i_tmp;
988
989         pgc_id = p_vts->vts_ptt_srpt->title[
990                     p_sys->i_ttn - 1].ptt[i_chapter].pgcn;
991         pgn = p_vts->vts_ptt_srpt->title[
992                     p_sys->i_ttn - 1].ptt[i_chapter].pgn;
993
994         i_tmp = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc->program_map[pgn-1];
995
996         if( i_tmp > i_cell ) break;
997     }
998
999     if( i_chapter < p_sys->i_chapters &&
1000         p_demux->info.i_seekpoint != i_chapter )
1001     {
1002         p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
1003         p_demux->info.i_seekpoint = i_chapter;
1004     }
1005
1006     /* Find vobu */
1007     while( (int)p_vts->vts_vobu_admap->vobu_start_sectors[i_vobu] <= i_block )
1008     {
1009         i_vobu++;
1010     }
1011
1012     /* Find sub_cell */
1013     while( p_vts->vts_c_adt->cell_adr_table[i_sub_cell].start_sector <
1014            p_vts->vts_vobu_admap->vobu_start_sectors[i_vobu-1] )
1015     {
1016         i_sub_cell++;
1017     }
1018
1019 #if 1
1020     msg_Dbg( p_demux, "cell %d i_sub_cell %d chapter %d vobu %d "
1021              "cell_sector %d vobu_sector %d sub_cell_sector %d",
1022              i_cell, i_sub_cell, i_chapter, i_vobu,
1023              p_sys->p_cur_pgc->cell_playback[i_cell].first_sector,
1024              p_vts->vts_vobu_admap->vobu_start_sectors[i_vobu],
1025              p_vts->vts_c_adt->cell_adr_table[i_sub_cell - 1].start_sector);
1026 #endif
1027
1028     p_sys->i_cur_block = i_block;
1029     p_sys->i_next_vobu = p_vts->vts_vobu_admap->vobu_start_sectors[i_vobu];
1030     p_sys->i_pack_len = p_sys->i_next_vobu - i_block;
1031     p_sys->i_cur_cell = i_cell;
1032     p_sys->i_chapter = i_chapter;
1033     DvdReadFindCell( p_demux );
1034
1035 #undef p_vts
1036 #undef p_pgc
1037
1038     return;
1039 }
1040
1041 /*****************************************************************************
1042  * DvdReadHandleDSI
1043  *****************************************************************************/
1044 static void DvdReadHandleDSI( demux_t *p_demux, uint8_t *p_data )
1045 {
1046     demux_sys_t *p_sys = p_demux->p_sys;
1047
1048     navRead_DSI( &p_sys->dsi_pack, &p_data[DSI_START_BYTE] );
1049
1050     /*
1051      * Determine where we go next.  These values are the ones we mostly
1052      * care about.
1053      */
1054     p_sys->i_cur_block = p_sys->dsi_pack.dsi_gi.nv_pck_lbn;
1055
1056     /*
1057      * If we're not at the end of this cell, we can determine the next
1058      * VOBU to display using the VOBU_SRI information section of the
1059      * DSI.  Using this value correctly follows the current angle,
1060      * avoiding the doubled scenes in The Matrix, and makes our life
1061      * really happy.
1062      */
1063     if( p_sys->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL )
1064     {
1065         switch( ( p_sys->dsi_pack.sml_pbi.category & 0xf000 ) >> 12 )
1066         {
1067         case 0x4:
1068             /* Interleaved unit with no angle */
1069             if( p_sys->dsi_pack.sml_pbi.ilvu_sa != 0 )
1070             {
1071                 p_sys->i_next_vobu = p_sys->i_cur_block +
1072                     p_sys->dsi_pack.sml_pbi.ilvu_sa;
1073                 p_sys->i_pack_len = p_sys->dsi_pack.sml_pbi.ilvu_ea;
1074             }
1075             else
1076             {
1077                 p_sys->i_next_vobu = p_sys->i_cur_block +
1078                     p_sys->dsi_pack.dsi_gi.vobu_ea + 1;
1079                 p_sys->i_pack_len = p_sys->dsi_pack.dsi_gi.vobu_ea;
1080             }
1081             break;
1082         case 0x5:
1083             /* vobu is end of ilvu */
1084             if( p_sys->dsi_pack.sml_agli.data[p_sys->i_angle-1].address )
1085             {
1086                 p_sys->i_next_vobu = p_sys->i_cur_block +
1087                     p_sys->dsi_pack.sml_agli.data[p_sys->i_angle-1].address;
1088                 p_sys->i_pack_len = p_sys->dsi_pack.sml_pbi.ilvu_ea;
1089
1090                 break;
1091             }
1092         case 0x6:
1093             /* vobu is beginning of ilvu */
1094         case 0x9:
1095             /* next scr is 0 */
1096         case 0xa:
1097             /* entering interleaved section */
1098         case 0x8:
1099             /* non interleaved cells in interleaved section */
1100         default:
1101             p_sys->i_next_vobu = p_sys->i_cur_block +
1102                 ( p_sys->dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
1103             p_sys->i_pack_len = p_sys->dsi_pack.dsi_gi.vobu_ea;
1104             break;
1105         }
1106     }
1107     else
1108     {
1109         p_sys->i_cur_cell = p_sys->i_next_cell;
1110         DvdReadFindCell( p_demux );
1111
1112         p_sys->i_pack_len = p_sys->dsi_pack.dsi_gi.vobu_ea;
1113         p_sys->i_next_vobu =
1114             p_sys->p_cur_pgc->cell_playback[p_sys->i_cur_cell].first_sector;
1115     }
1116
1117 #if 0
1118     msg_Dbg( p_demux, 12, "scr %d lbn 0x%02x vobu_ea %d vob_id %d c_id %d",
1119              p_sys->dsi_pack.dsi_gi.nv_pck_scr,
1120              p_sys->dsi_pack.dsi_gi.nv_pck_lbn,
1121              p_sys->dsi_pack.dsi_gi.vobu_ea,
1122              p_sys->dsi_pack.dsi_gi.vobu_vob_idn,
1123              p_sys->dsi_pack.dsi_gi.vobu_c_idn );
1124
1125     msg_Dbg( p_demux, 12, "cat 0x%02x ilvu_ea %d ilvu_sa %d size %d",
1126              p_sys->dsi_pack.sml_pbi.category,
1127              p_sys->dsi_pack.sml_pbi.ilvu_ea,
1128              p_sys->dsi_pack.sml_pbi.ilvu_sa,
1129              p_sys->dsi_pack.sml_pbi.size );
1130
1131     msg_Dbg( p_demux, 12, "next_vobu %d next_ilvu1 %d next_ilvu2 %d",
1132              p_sys->dsi_pack.vobu_sri.next_vobu & 0x7fffffff,
1133              p_sys->dsi_pack.sml_agli.data[ p_sys->i_angle - 1 ].address,
1134              p_sys->dsi_pack.sml_agli.data[ p_sys->i_angle ].address);
1135 #endif
1136 }
1137
1138 /*****************************************************************************
1139  * DvdReadFindCell
1140  *****************************************************************************/
1141 static void DvdReadFindCell( demux_t *p_demux )
1142 {
1143     demux_sys_t *p_sys = p_demux->p_sys;
1144
1145     pgc_t *p_pgc;
1146     int   pgc_id, pgn;
1147     int   i = 0;
1148
1149 #define cell p_sys->p_cur_pgc->cell_playback
1150
1151     if( cell[p_sys->i_cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK )
1152     {
1153         p_sys->i_cur_cell += p_sys->i_angle - 1;
1154
1155         while( cell[p_sys->i_cur_cell+i].block_mode != BLOCK_MODE_LAST_CELL )
1156         {
1157             i++;
1158         }
1159         p_sys->i_next_cell = p_sys->i_cur_cell + i + 1;
1160     }
1161     else
1162     {
1163         p_sys->i_next_cell = p_sys->i_cur_cell + 1;
1164     }
1165
1166 #undef cell
1167
1168     pgc_id = p_sys->p_vts_file->vts_ptt_srpt->title[
1169                 p_sys->i_ttn - 1].ptt[p_sys->i_chapter].pgcn;
1170     pgn = p_sys->p_vts_file->vts_ptt_srpt->title[
1171               p_sys->i_ttn - 1].ptt[p_sys->i_chapter].pgn;
1172     p_pgc = p_sys->p_vts_file->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
1173
1174     if( p_pgc->program_map[pgn - 1] <= p_sys->i_cur_cell )
1175     {
1176         p_sys->i_chapter++;
1177
1178         if( p_sys->i_chapter < p_sys->i_chapters &&
1179             p_demux->info.i_seekpoint != p_sys->i_chapter )
1180         {
1181             p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
1182             p_demux->info.i_seekpoint = p_sys->i_chapter;
1183         }
1184     }
1185 }
1186
1187 /*****************************************************************************
1188  * DemuxTitles: get the titles/chapters structure
1189  *****************************************************************************/
1190 static void DemuxTitles( demux_t *p_demux,
1191                          int *pi_title, int *pi_chapter, int *pi_angle )
1192 {
1193     demux_sys_t *p_sys = p_demux->p_sys;
1194     input_title_t *t;
1195     seekpoint_t *s;
1196     int32_t i_titles;
1197     int i;
1198
1199     /* Find out number of titles/chapters */
1200 #define tt_srpt p_sys->p_vmg_file->tt_srpt
1201
1202     i_titles = tt_srpt->nr_of_srpts;
1203     msg_Dbg( p_demux, "number of titles: %d", i_titles );
1204
1205     for( i = 0; i < i_titles; i++ )
1206     {
1207         int32_t i_chapters = 0;
1208         int j;
1209
1210         i_chapters = tt_srpt->title[i].nr_of_ptts;
1211         msg_Dbg( p_demux, "title %d has %d chapters", i, i_chapters );
1212
1213         t = vlc_input_title_New();
1214         t->psz_name = malloc( strlen( _("Title %i") ) + 20 );
1215         sprintf( t->psz_name, _("Title %i"), i + 1 );
1216
1217         for( j = 0; j < __MAX( i_chapters, 1 ); j++ )
1218         {
1219             s = vlc_seekpoint_New();
1220             s->psz_name = malloc( strlen( _("Chapter %i") ) + 20 );
1221             sprintf( s->psz_name, _("Chapter %i"), j + 1 );
1222             TAB_APPEND( t->i_seekpoint, t->seekpoint, s );
1223         }
1224
1225         TAB_APPEND( p_sys->i_titles, p_sys->titles, t );
1226     }
1227
1228     /* Set forced title/chapter/angle */
1229     *pi_title = (*pi_title >= 0 && *pi_title < i_titles) ? *pi_title : 0;
1230     *pi_chapter = (*pi_chapter >= 0 && *pi_chapter <
1231         tt_srpt->title[*pi_title].nr_of_ptts) ? *pi_chapter : 0;
1232
1233 #undef tt_srpt
1234 }
1235
1236 /*****************************************************************************
1237  * ParseCL: parse command line. Titles, chapters and angles start from 1.
1238  *****************************************************************************/
1239 static char *ParseCL( vlc_object_t *p_this, char *psz_name, vlc_bool_t b_force,
1240                       int *i_title, int *i_chapter, int *i_angle )
1241 {
1242     char *psz_parser, *psz_source, *psz_next;
1243
1244     psz_source = strdup( psz_name );
1245     if( psz_source == NULL ) return NULL;
1246
1247     *i_title = 1;
1248     *i_chapter = 1;
1249     *i_angle = 1;
1250
1251     /* Start with the end, because you could have :
1252      * dvdnav:/Volumes/my@toto/VIDEO_TS@1,1
1253      * (yes, this is kludgy). */
1254     for( psz_parser = psz_source + strlen(psz_source) - 1;
1255          psz_parser >= psz_source && *psz_parser != '@';
1256          psz_parser-- );
1257
1258     if( psz_parser >= psz_source && *psz_parser == '@' )
1259     {
1260         /* Found options */
1261         *psz_parser = '\0';
1262         ++psz_parser;
1263
1264         *i_title = (int)strtol( psz_parser, &psz_next, 10 );
1265         if( *psz_next )
1266         {
1267             psz_parser = psz_next + 1;
1268             *i_chapter = (int)strtol( psz_parser, &psz_next, 10 );
1269             if( *psz_next )
1270             {
1271                 *i_angle = (int)strtol( psz_next + 1, NULL, 10 );
1272             }
1273         }
1274     }
1275
1276     *i_title   = *i_title > 0 ? *i_title : 1;
1277     *i_chapter = *i_chapter > 0 ? *i_chapter : 1;
1278     *i_angle   = *i_angle > 0 ? *i_angle : 1;
1279
1280     if( !*psz_source )
1281     {
1282         free( psz_source );
1283         if( !b_force )
1284         {
1285             return NULL;
1286         }
1287         psz_source = config_GetPsz( p_this, "dvd" );
1288         if( !psz_source ) return NULL;
1289     }
1290
1291 #ifdef WIN32
1292     if( psz_source[0] && psz_source[1] == ':' &&
1293         psz_source[2] == '\\' && psz_source[3] == '\0' )
1294     {
1295         psz_source[2] = '\0';
1296     }
1297 #endif
1298
1299     msg_Dbg( p_this, "dvdroot=%s title=%d chapter=%d angle=%d",
1300              psz_source, *i_title, *i_chapter, *i_angle );
1301
1302     /* Get back to a 0-based offset */
1303     (*i_title)--;
1304     (*i_chapter)--;
1305
1306     return psz_source;
1307 }