]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/input_dvd.c
* Win2000 DVD input by Jon Lech Johansen <jon-vl@nanocrew.net>.
[vlc] / plugins / dvd / input_dvd.c
index ae5656113dc7335544e7d18c1e5db762b9a2ffcf..3060d131596227e1461cadd721f168118e94452c 100644 (file)
@@ -10,7 +10,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.58 2001/05/15 01:01:44 stef Exp $
+ * $Id: input_dvd.c,v 1.64 2001/05/31 03:12:49 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
 #include "defs.h"
 
 #ifdef HAVE_CSS
-#define MODULE_NAME dvd
+#   define MODULE_NAME dvd
 #else /* HAVE_CSS */
-#define MODULE_NAME dvdnocss
+#   define MODULE_NAME dvdnocss
 #endif /* HAVE_CSS */
+
 #include "modules_inner.h"
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <netinet/in.h>
+
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
+
+#if !defined( WIN32 )
+#   include <netinet/in.h>
+#endif
 
 #include <fcntl.h>
 #include <sys/types.h>
-#include <sys/uio.h>
-
 #include <string.h>
+#include <errno.h>
+
 #ifdef STRNCASECMP_IN_STRINGS_H
 #   include <strings.h>
 #endif
-#include <errno.h>
+
+#if defined( WIN32 )
+#   include <io.h>
+#   include "iovec.h"
+#else
+#   include <sys/uio.h>                                      /* struct iovec */
+#endif
 
 #include "config.h"
 #include "common.h"
@@ -75,6 +88,7 @@
 #include "dvd_netlist.h"
 #include "dvd_ifo.h"
 #include "dvd_css.h"
+#include "dvd_summary.h"
 #include "input_dvd.h"
 #include "mpeg_system.h"
 
 
 #include "modules.h"
 
-/*****************************************************************************
- * Local tables
- *****************************************************************************/
-static struct
-{
-    char    p_code[3];
-    char    p_lang_long[20];
-}
-
-lang_tbl[] =
-{
-    /* The ISO 639 language codes.
-     * Language names with * prefix are not spelled in their own language 
-     */
-    { "  ", "Not Specified" },
-    { "aa", "*Afar" },
-    { "ab", "*Abkhazian" },
-    { "af", "*Afrikaans" },
-    { "am", "*Amharic" },
-    { "ar", "*Arabic" },
-    { "as", "*Assamese" },
-    { "ay", "*Aymara" },
-    { "az", "*Azerbaijani" },
-    { "ba", "*Bashkir" },
-    { "be", "*Byelorussian" },
-    { "bg", "*Bulgarian" },
-    { "bh", "*Bihari" },
-    { "bi", "*Bislama" },
-    { "bn", "*Bengali; Bangla" },
-    { "bo", "*Tibetan" },
-    { "br", "*Breton" },
-    { "ca", "*Catalan" },
-    { "co", "*Corsican" },
-    { "cs", "*Czech(Ceske)" },
-    { "cy", "*Welsh" },
-    { "da", "Dansk" },
-    { "de", "Deutsch" },
-    { "dz", "*Bhutani" },
-    { "el", "*Greek" },
-    { "en", "English" },
-    { "eo", "*Esperanto" },
-    { "es", "Espanol" },
-    { "et", "*Estonian" },
-    { "eu", "*Basque" },
-    { "fa", "*Persian" },
-    { "fi", "Suomi" },
-    { "fj", "*Fiji" },
-    { "fo", "*Faroese" },
-    { "fr", "Francais" },
-    { "fy", "*Frisian" },
-    { "ga", "*Irish" },
-    { "gd", "*Scots Gaelic" },
-    { "gl", "*Galician" },
-    { "gn", "*Guarani" },
-    { "gu", "*Gujarati" },
-    { "ha", "*Hausa" },
-    { "he", "*Hebrew" },                                      /* formerly iw */
-    { "hi", "*Hindi" },
-    { "hr", "Hrvatski" },                                        /* Croatian */
-    { "hu", "Magyar" },
-    { "hy", "*Armenian" },
-    { "ia", "*Interlingua" },
-    { "id", "*Indonesian" },                                  /* formerly in */
-    { "ie", "*Interlingue" },
-    { "ik", "*Inupiak" },
-    { "in", "*Indonesian" },                               /* replaced by id */
-    { "is", "Islenska" },
-    { "it", "Italiano" },
-    { "iu", "*Inuktitut" },
-    { "iw", "*Hebrew" },                                   /* replaced by he */
-    { "ja", "*Japanese" },
-    { "ji", "*Yiddish" },                                  /* replaced by yi */
-    { "jw", "*Javanese" },
-    { "ka", "*Georgian" },
-    { "kk", "*Kazakh" },
-    { "kl", "*Greenlandic" },
-    { "km", "*Cambodian" },
-    { "kn", "*Kannada" },
-    { "ko", "*Korean" },
-    { "ks", "*Kashmiri" },
-    { "ku", "*Kurdish" },
-    { "ky", "*Kirghiz" },
-    { "la", "*Latin" },
-    { "ln", "*Lingala" },
-    { "lo", "*Laothian" },
-    { "lt", "*Lithuanian" },
-    { "lv", "*Latvian, Lettish" },
-    { "mg", "*Malagasy" },
-    { "mi", "*Maori" },
-    { "mk", "*Macedonian" },
-    { "ml", "*Malayalam" },
-    { "mn", "*Mongolian" },
-    { "mo", "*Moldavian" },
-    { "mr", "*Marathi" },
-    { "ms", "*Malay" },
-    { "mt", "*Maltese" },
-    { "my", "*Burmese" },
-    { "na", "*Nauru" },
-    { "ne", "*Nepali" },
-    { "nl", "Nederlands" },
-    { "no", "Norsk" },
-    { "oc", "*Occitan" },
-    { "om", "*(Afan) Oromo" },
-    { "or", "*Oriya" },
-    { "pa", "*Punjabi" },
-    { "pl", "*Polish" },
-    { "ps", "*Pashto, Pushto" },
-    { "pt", "Portugues" },
-    { "qu", "*Quechua" },
-    { "rm", "*Rhaeto-Romance" },
-    { "rn", "*Kirundi" },
-    { "ro", "*Romanian"  },
-    { "ru", "*Russian" },
-    { "rw", "*Kinyarwanda" },
-    { "sa", "*Sanskrit" },
-    { "sd", "*Sindhi" },
-    { "sg", "*Sangho" },
-    { "sh", "*Serbo-Croatian" },
-    { "si", "*Sinhalese" },
-    { "sk", "*Slovak" },
-    { "sl", "*Slovenian" },
-    { "sm", "*Samoan" },
-    { "sn", "*Shona"  },
-    { "so", "*Somali" },
-    { "sq", "*Albanian" },
-    { "sr", "*Serbian" },
-    { "ss", "*Siswati" },
-    { "st", "*Sesotho" },
-    { "su", "*Sundanese" },
-    { "sv", "Svenska" },
-    { "sw", "*Swahili" },
-    { "ta", "*Tamil" },
-    { "te", "*Telugu" },
-    { "tg", "*Tajik" },
-    { "th", "*Thai" },
-    { "ti", "*Tigrinya" },
-    { "tk", "*Turkmen" },
-    { "tl", "*Tagalog" },
-    { "tn", "*Setswana" },
-    { "to", "*Tonga" },
-    { "tr", "*Turkish" },
-    { "ts", "*Tsonga" },
-    { "tt", "*Tatar" },
-    { "tw", "*Twi" },
-    { "ug", "*Uighur" },
-    { "uk", "*Ukrainian" },
-    { "ur", "*Urdu" },
-    { "uz", "*Uzbek" },
-    { "vi", "*Vietnamese" },
-    { "vo", "*Volapuk" },
-    { "wo", "*Wolof" },
-    { "xh", "*Xhosa" },
-    { "yi", "*Yiddish" },                                     /* formerly ji */
-    { "yo", "*Yoruba" },
-    { "za", "*Zhuang" },
-    { "zh", "*Chinese" },
-    { "zu", "*Zulu" },
-    { "\0", "" }
-};
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -255,7 +109,6 @@ static void DVDSeek     ( struct input_thread_s *, off_t );
 static int  DVDRewind   ( struct input_thread_s * );
 
 /* called only inside */
-static char * Language( u16 );
 static int  DVDChooseAngle( thread_dvd_data_t * );
 static int  DVDFindCell( thread_dvd_data_t * );
 static int  DVDFindSector( thread_dvd_data_t * );
@@ -270,8 +123,8 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #define input p_function_list->functions.input
     p_function_list->pf_probe = DVDProbe;
     input.pf_init             = DVDInit;
-    input.pf_open             = input_FileOpen;
-    input.pf_close            = input_FileClose;
+    input.pf_open             = NULL; /* Set in DVDInit */
+    input.pf_close            = NULL;
     input.pf_end              = DVDEnd;
     input.pf_read             = DVDRead;
     input.pf_set_area         = DVDSetArea;
@@ -285,26 +138,6 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #undef input
 }
 
-/*
- * Local tools to decode some data in ifo
- */
-
-/*****************************************************************************
- * Language: gives the long language name from the two-letters ISO-639 code
- *****************************************************************************/
-static char * Language( u16 i_code )
-{
-    int     i = 0;
-
-    while( memcmp( lang_tbl[i].p_code, &i_code, 2 ) &&
-           lang_tbl[i].p_lang_long[0] )
-    {
-        i++;
-    }
-
-    return lang_tbl[i].p_lang_long;
-}
-
 /*
  * Data reading functions
  */
@@ -319,6 +152,9 @@ static int DVDProbe( probedata_t *p_data )
     char * psz_name = p_input->p_source;
     int i_handle;
     int i_score = 5;
+#if defined( WIN32 )
+    char buf[7];
+#endif
 
     if( TestMethod( INPUT_METHOD_VAR, "dvd" ) )
     {
@@ -340,12 +176,25 @@ static int DVDProbe( probedata_t *p_data )
         psz_name += 4;
     }
 
+#if !defined( WIN32 )
     i_handle = open( psz_name, 0 );
     if( i_handle == -1 )
     {
         return( 0 );
     }
     close( i_handle );
+#else
+    snprintf( buf, 7, "\\\\.\\%c:", psz_name[0] );
+    (HANDLE) i_handle = CreateFile( i_score < 90 ? psz_name : buf, 
+                        GENERIC_READ | GENERIC_WRITE,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE,
+                        NULL, OPEN_EXISTING, 0, NULL );
+    if( (HANDLE) i_handle == INVALID_HANDLE_VALUE )
+    {
+        return( 0 );
+    }
+    CloseHandle( (HANDLE) i_handle );
+#endif
 
     return( i_score );
 }
@@ -361,9 +210,6 @@ static void DVDInit( input_thread_t * p_input )
     int                  i_chapter;
     int                  i;
 
-    /* I don't want DVDs to start playing immediately */
-//    p_input->stream.i_new_status = PAUSE_S;
-
     p_dvd = malloc( sizeof(thread_dvd_data_t) );
     if( p_dvd == NULL )
     {
@@ -380,13 +226,14 @@ static void DVDInit( input_thread_t * p_input )
     /* reading several block once seems to cause lock-up
      * when using input_ToggleES
      * who wrote thez damn buggy piece of shit ??? --stef */
-    p_dvd->i_block_once = 1;//32;
-    p_input->i_read_once = 8;//128;
+    p_dvd->i_block_once = 32;
+    p_input->i_read_once = 128;
 
     i = CSSTest( p_input->i_handle );
 
     if( i < 0 )
     {
+        intf_ErrMsg( "dvd error: error in css" );
         free( p_dvd );
         p_input->b_error = 1;
         return;
@@ -394,7 +241,11 @@ static void DVDInit( input_thread_t * p_input )
 
     p_dvd->b_encrypted = i;
 
+#if !defined( WIN32 )
     lseek( p_input->i_handle, 0, SEEK_SET );
+#else
+    SetFilePointer( (HANDLE) p_input->i_handle, 0, 0, FILE_BEGIN );
+#endif
 
     /* Reading structures initialisation */
     p_input->p_method_data =
@@ -505,11 +356,11 @@ static void DVDInit( input_thread_t * p_input )
 
     p_area = p_input->stream.pp_areas[i_title];
 
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
     /* set title, chapter, audio and subpic */
     DVDSetArea( p_input, p_area );
 
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
     return;
 }
 
@@ -536,32 +387,24 @@ static void DVDEnd( input_thread_t * p_input )
 
 /*****************************************************************************
  * DVDSetArea: initialize input data for title x, chapter y.
- * It should be called for each user navigation request, and to change
- * audio or sub-picture streams.
- * ---
+ * It should be called for each user navigation request.
+ *****************************************************************************
  * Take care that i_title starts from 0 (vmg) and i_chapter start from 1.
- * i_audio, i_spu start from 1 ; 0 means off.
- * A negative value for an argument means it does not change
+ * Note that you have to take the lock before entering here.
  *****************************************************************************/
 static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 {
     thread_dvd_data_t *  p_dvd;
     es_descriptor_t *    p_es;
+    u16                  i_id;
+    int                  i_vts_title;
     int                  i_audio;
     int                  i_spu;
-    u16                  i_id;
-    u8                   i_ac3;
-    u8                   i_mpeg;
-    u8                   i_lpcm;
-    u8                   i_sub_pic;
-    u8                   i;
+    int                  i;
     int                  j;
-    boolean_t            b_last;
 
     p_dvd = (thread_dvd_data_t*)p_input->p_plugin_data;
 
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-
     /* we can't use the interface slider until initilization is complete */
     p_input->stream.b_seekable = 0;
 
@@ -575,6 +418,7 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         p_input->stream.p_selected_area =
                     p_input->stream.pp_areas[p_area->i_id];
 
+        /* release the lock to to let the interface go */
 //        vlc_mutex_unlock( &p_input->stream.stream_lock );
 
         /* title number: it is not vts nb!,
@@ -582,9 +426,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         p_dvd->i_title = p_area->i_id;
         p_dvd->p_ifo->i_title = p_dvd->i_title;
 
-        /* uodate title environnement variable so that we don't
-         * loop on the same title forever */
-//        main_PutIntVariable( INPUT_TITLE_VAR, p_dvd->i_title + 1 );
+        /* set number of chapters of current title */
+        p_dvd->i_chapter_nb = p_area->i_part_nb;
 
         /* ifo vts */
         if( IfoTitleSet( p_dvd->p_ifo ) < 0 )
@@ -598,14 +441,13 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 #define vmg p_dvd->p_ifo->vmg
 #define vts p_dvd->p_ifo->vts
         /* title position inside the selected vts */
-        p_dvd->i_vts_title =
-                    vmg.title_inf.p_attr[p_dvd->i_title-1].i_title_num;
+        i_vts_title = vmg.title_inf.p_attr[p_dvd->i_title-1].i_title_num;
         p_dvd->i_title_id =
-          vts.title_inf.p_title_start[p_dvd->i_vts_title-1].i_title_id;
+            vts.title_inf.p_title_start[i_vts_title-1].i_title_id;
 
         intf_WarnMsg( 3, "dvd: title %d vts_title %d pgc %d",
                         p_dvd->i_title,
-                        p_dvd->i_vts_title,
+                        i_vts_title,
                         p_dvd->i_title_id );
 
         /* css title key for current vts */
@@ -686,12 +528,7 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 
         p_dvd->i_size -= (off_t)( p_dvd->i_sector + 1 ) *DVD_LB_SIZE;
 
-        intf_WarnMsg( 2, "dvd info: title: %d", p_dvd->i_title );
-        intf_WarnMsg( 2, "dvd info: vobstart at: %lld", p_dvd->i_start );
-        intf_WarnMsg( 2, "dvd info: stream size: %lld", p_dvd->i_size );
-        intf_WarnMsg( 2, "dvd info: number of chapters: %d",
-                   vmg.title_inf.p_attr[p_dvd->i_title-1].i_chapter_nb );
-        intf_WarnMsg( 2, "dvd info: number of angles: %d", p_dvd->i_angle_nb );
+        IfoPrintTitle( p_dvd );
 
 //        vlc_mutex_lock( &p_input->stream.stream_lock );
 
@@ -730,6 +567,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         p_es = NULL;
 
         /* ES 0 -> video MPEG2 */
+        IfoPrintVideo( p_dvd );
+
         p_es = input_AddES( p_input, p_input->stream.pp_programs[0], 0xe0, 0 );
         p_es->i_stream_id = 0xe0;
         p_es->i_type = MPEG2_VIDEO_ES;
@@ -739,123 +578,131 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         {
             input_SelectES( p_input, p_es );
         }
+        intf_WarnMsg( 4, "dvd info: video selected" );
 
+#define audio_status \
+    vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_audio_status[i-1]
         /* Audio ES, in the order they appear in .ifo */
-            
-        i_ac3 = 0x7f;
-        i_mpeg = 0xc0;
-        i_lpcm = 0x9f;
-
         for( i = 1 ; i <= vts.manager_inf.i_audio_nb ; i++ )
         {
+            IfoPrintAudio( p_dvd, i );
 
-        intf_WarnMsg( 5, "dvd info: audio %d: %x %x %x %x %x %x %x %x %x %x %x %x", i,
-            vts.manager_inf.p_audio_attr[i-1].i_num_channels,
-            vts.manager_inf.p_audio_attr[i-1].i_coding_mode,
-            vts.manager_inf.p_audio_attr[i-1].i_multichannel_extension,
-            vts.manager_inf.p_audio_attr[i-1].i_type,
-            vts.manager_inf.p_audio_attr[i-1].i_appl_mode,
-            vts.manager_inf.p_audio_attr[i-1].i_foo,
-            vts.manager_inf.p_audio_attr[i-1].i_test,
-            vts.manager_inf.p_audio_attr[i-1].i_bar,
-            vts.manager_inf.p_audio_attr[i-1].i_quantization,
-            vts.manager_inf.p_audio_attr[i-1].i_sample_freq,
-            vts.manager_inf.p_audio_attr[i-1].i_lang_code,
-            vts.manager_inf.p_audio_attr[i-1].i_caption );
-
-            switch( vts.manager_inf.p_audio_attr[i-1].i_coding_mode )
+            /* audio channel is active if first byte is 0x80 */
+            if( audio_status.i_available )
             {
-            case 0x00:              /* AC3 */
-                i_id = ( ( i_ac3 + i ) << 8 ) | 0xbd;
-                p_es = input_AddES( p_input,
-                                    p_input->stream.pp_programs[0], i_id, 0 );
-                p_es->i_stream_id = 0xbd;
-                p_es->i_type = AC3_AUDIO_ES;
-                p_es->b_audio = 1;
-                p_es->i_cat = AUDIO_ES;
-                strcpy( p_es->psz_desc, Language( hton16(
-                    vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
-                strcat( p_es->psz_desc, " (ac3)" );
-
-                intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
-                              i, p_es->psz_desc, i_id );
-
-                break;
-            case 0x02:
-            case 0x03:              /* MPEG audio */
-                i_id = 0xbf + i;
-                p_es = input_AddES( p_input,
+                switch( vts.manager_inf.p_audio_attr[i-1].i_coding_mode )
+                {
+                case 0x00:              /* AC3 */
+                    i_id = ( ( 0x80 + audio_status.i_position ) << 8 ) | 0xbd;
+                    p_es = input_AddES( p_input,
+                               p_input->stream.pp_programs[0], i_id, 0 );
+                    p_es->i_stream_id = 0xbd;
+                    p_es->i_type = AC3_AUDIO_ES;
+                    p_es->b_audio = 1;
+                    p_es->i_cat = AUDIO_ES;
+                    strcpy( p_es->psz_desc, IfoLanguage( hton16(
+                        vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
+                    strcat( p_es->psz_desc, " (ac3)" );
+    
+                    intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
+                                  i, p_es->psz_desc, i_id );
+    
+                    break;
+                case 0x02:
+                case 0x03:              /* MPEG audio */
+                    i_id = 0xc0 + audio_status.i_position;
+                    p_es = input_AddES( p_input,
                                     p_input->stream.pp_programs[0], i_id, 0 );
-                p_es->i_stream_id = i_id;
-                p_es->i_type = MPEG2_AUDIO_ES;
-                p_es->b_audio = 1;
-                p_es->i_cat = AUDIO_ES;
-                strcpy( p_es->psz_desc, Language( hton16(
-                    vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
-                strcat( p_es->psz_desc, " (mpeg)" );
-
-                intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
-                              i, p_es->psz_desc, i_id );
-
-                break;
-            case 0x04:              /* LPCM */
-#if 0
-                i_id = ( ( i_lpcm + i ) << 8 ) | 0xbd;
-                p_es = input_AddES( p_input,
+                    p_es->i_stream_id = i_id;
+                    p_es->i_type = MPEG2_AUDIO_ES;
+                    p_es->b_audio = 1;
+                    p_es->i_cat = AUDIO_ES;
+                    strcpy( p_es->psz_desc, IfoLanguage( hton16(
+                        vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
+                    strcat( p_es->psz_desc, " (mpeg)" );
+    
+                    intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
+                                  i, p_es->psz_desc, i_id );
+    
+                    break;
+                case 0x04:              /* LPCM */
+    
+                    i_id = ( ( 0xa0 + audio_status.i_position ) << 8 ) | 0xbd;
+                    p_es = input_AddES( p_input,
                                     p_input->stream.pp_programs[0], i_id, 0 );
-                p_es->i_stream_id = i_id;
-                p_es->i_type = LPCM_AUDIO_ES;
-                p_es->b_audio = 1;
-                p_es->i_cat = AUDIO_ES;
-                strcpy( p_es->psz_desc, Language( hton16(
-                    vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
-                strcat( p_es->psz_desc, " (lpcm)" );
-
-                intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
-                              i, p_es->psz_desc, i_id );
-#else
-                i_id = 0;
-                intf_ErrMsg( "dvd warning: LPCM audio not handled yet" );
-#endif
-                break;
-            case 0x06:              /* DTS */
-                i_id = 0;
-                i_ac3--;
-                intf_ErrMsg( "dvd warning: DTS audio not handled yet" );
-                break;
-            default:
-                i_id = 0;
-                intf_ErrMsg( "dvd warning: unknown audio type %.2x",
-                         vts.manager_inf.p_audio_attr[i-1].i_coding_mode );
+                    p_es->i_stream_id = i_id;
+                    p_es->i_type = LPCM_AUDIO_ES;
+                    p_es->b_audio = 1;
+                    p_es->i_cat = AUDIO_ES;
+                    strcpy( p_es->psz_desc, IfoLanguage( hton16(
+                        vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); 
+                    strcat( p_es->psz_desc, " (lpcm)" );
+    
+                    intf_WarnMsg( 3, "dvd info: audio stream %d %s\t(0x%x)",
+                                  i, p_es->psz_desc, i_id );
+                    break;
+                case 0x06:              /* DTS */
+                    i_id = ( ( 0x88 + audio_status.i_position ) << 8 ) | 0xbd;
+                    intf_ErrMsg( "dvd warning: DTS audio not handled yet"
+                                 "(0x%x)", i_id );
+                    break;
+                default:
+                    i_id = 0;
+                    intf_ErrMsg( "dvd warning: unknown audio type %.2x",
+                             vts.manager_inf.p_audio_attr[i-1].i_coding_mode );
+                }
             }
-        
         }
-    
+#undef audio_status
+#define spu_status \
+    vts.title_unit.p_title[p_dvd->i_title_id-1].title.pi_spu_status[i-1]
+
         /* Sub Picture ES */
            
-        b_last = 0;
-        i_sub_pic = 0x20;
         for( i = 1 ; i <= vts.manager_inf.i_spu_nb; i++ )
         {
-            if( !b_last )
+            IfoPrintSpu( p_dvd, i );
+
+            if( spu_status.i_available )
             {
-                i_id = ( i_sub_pic++ << 8 ) | 0xbd;
+                /*  there are several streams for one spu */
+                if(  vts.manager_inf.video_attr.i_ratio )
+                {
+                    /* 16:9 */
+                    switch( vts.manager_inf.video_attr.i_perm_displ )
+                    {
+                    case 1:
+                        i_id = ( ( 0x20 + spu_status.i_position_pan ) << 8 )
+                               | 0xbd;
+                        break;
+                    case 2:
+                        i_id = ( ( 0x20 + spu_status.i_position_letter ) << 8 )
+                               | 0xbd;
+                        break;
+                    default:
+                        i_id = ( ( 0x20 + spu_status.i_position_wide ) << 8 )
+                               | 0xbd;
+                        break;
+                    }
+                }
+                else
+                {
+                    /* 4:3 */
+                    i_id = ( ( 0x20 + spu_status.i_position_43 ) << 8 )
+                           | 0xbd;
+                }
                 p_es = input_AddES( p_input,
                                     p_input->stream.pp_programs[0], i_id, 0 );
                 p_es->i_stream_id = 0xbd;
                 p_es->i_type = DVD_SPU_ES;
                 p_es->i_cat = SPU_ES;
-                strcpy( p_es->psz_desc, Language( hton16(
+                strcpy( p_es->psz_desc, IfoLanguage( hton16(
                     vts.manager_inf.p_spu_attr[i-1].i_lang_code ) ) ); 
                 intf_WarnMsg( 3, "dvd info: spu stream %d %s\t(0x%x)",
                               i, p_es->psz_desc, i_id );
-    
-                /* The before the last spu has a 0x0 prefix */
-                b_last =
-                    ( vts.manager_inf.p_spu_attr[i].i_prefix == 0 ); 
             }
         }
-
+#undef spu_status
         if( p_main->b_audio )
         {
             /* For audio: first one if none or a not existing one specified */
@@ -924,9 +771,9 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
             p_dvd->i_chapter = 1;
         }
     }
+
 #define title \
     p_dvd->p_ifo->vts.title_unit.p_title[p_dvd->i_title_id-1].title
-
     if( p_area->i_angle != p_dvd->i_angle )
     {
         if( title.p_cell_play[p_dvd->i_prg_cell].i_category & 0xf000 )
@@ -952,9 +799,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
     /* warn interface that something has changed */
     p_input->stream.b_seekable = 1;
     p_input->stream.b_changed = 1;
-intf_WarnMsg( 3, "Pos: %lld Size: %lld", p_input->stream.p_selected_area->i_tell,p_input->stream.p_selected_area->i_size );
 
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
+    p_input->stream.pp_programs[0]->i_synchro_state = SYNCHRO_REINIT;
 
     return 0;
 }
@@ -971,9 +817,8 @@ static int DVDRead( input_thread_t * p_input,
 {
     thread_dvd_data_t *     p_dvd;
     dvd_netlist_t *         p_netlist;
-    input_area_t *          p_area;
     struct iovec *          p_vec;
-    struct data_packet_s *  pp_data[p_input->i_read_once];
+    struct data_packet_s ** pp_data;
     u8 *                    pi_cur;
     int                     i_block_once;
     int                     i_packet_size;
@@ -986,6 +831,22 @@ static int DVDRead( input_thread_t * p_input,
     boolean_t               b_eof;
     boolean_t               b_eot;
 
+    pp_data = (struct data_packet_s **) malloc( p_input->i_read_once *
+                                        sizeof( struct data_packet_s * ) );
+    if( pp_data == NULL )
+    {
+        intf_ErrMsg( "dvd error: out of memory" );
+        return -1;
+    }
+
+    pp_data = (struct data_packet_s **) malloc( p_input->i_read_once *
+                                        sizeof( struct data_packet_s * ) );
+    if( pp_data == NULL )
+    {
+        intf_ErrMsg( "dvd error: out of memory" );
+        return -1;
+    }
+
     p_dvd = (thread_dvd_data_t *)p_input->p_plugin_data;
     p_netlist = (dvd_netlist_t *)p_input->p_method_data;
 
@@ -993,6 +854,7 @@ static int DVDRead( input_thread_t * p_input,
     if( ( p_vec = DVDGetiovec( p_netlist ) ) == NULL )
     {
         intf_ErrMsg( "dvd error: can't get iovec" );
+        free( pp_data );
         return -1;
     }
 
@@ -1011,6 +873,7 @@ static int DVDRead( input_thread_t * p_input,
         {
             pp_packets[0] = NULL;
             intf_ErrMsg( "dvd error: can't find next cell" );
+            free( pp_data );
             return 1;
         }
 
@@ -1063,7 +926,11 @@ static int DVDRead( input_thread_t * p_input,
     p_netlist->i_read_once = i_block_once;
 
     /* Reads from DVD */
+#if !defined( WIN32 )
     i_read_bytes = readv( p_dvd->i_fd, p_vec, i_block_once );
+#else
+    i_read_bytes = ReadFileV( p_dvd->i_fd, p_vec, i_block_once );
+#endif
     i_read_blocks = ( i_read_bytes + 0x7ff ) >> 11;
 
     /* Update netlist indexes */
@@ -1088,7 +955,7 @@ static int DVDRead( input_thread_t * p_input,
 
         while( i_pos < p_netlist->i_buffer_size )
         {
-            pi_cur = (u8*)(p_vec[i_iovec].iov_base + i_pos);
+            pi_cur = (u8*)p_vec[i_iovec].iov_base + i_pos;
 
             /*default header */
             if( U32_AT( pi_cur ) != 0x1BA )
@@ -1113,6 +980,7 @@ static int DVDRead( input_thread_t * p_input,
                 else
                 {
                     intf_ErrMsg( "Unable to determine stream type" );
+                    free( pp_data );
                     return( -1 );
                 }
 
@@ -1147,10 +1015,13 @@ static int DVDRead( input_thread_t * p_input,
     p_input->stream.p_selected_area->i_tell += i_read_bytes;
     b_eot = !( p_input->stream.p_selected_area->i_tell < p_dvd->i_size );
     b_eof = b_eot && ( ( p_dvd->i_title + 1 ) >= p_input->stream.i_area_nb );
-    p_area = p_input->stream.pp_areas[p_dvd->i_title + 1];
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
+    free( pp_data );
+
+    free( pp_data );
+
     if( b_eof )
     {
         return 1;
@@ -1158,9 +1029,11 @@ static int DVDRead( input_thread_t * p_input,
 
     if( b_eot )
     {
-        intf_WarnMsg( 3, "dvd info: new title" );
+        intf_WarnMsg( 4, "dvd info: new title" );
         p_dvd->i_title++;
-        DVDSetArea( p_input, p_area );
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+        DVDSetArea( p_input, p_input->stream.pp_areas[p_dvd->i_title] );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
         return 0;
     }
 
@@ -1181,10 +1054,10 @@ static int DVDRewind( input_thread_t * p_input )
 }
 
 /*****************************************************************************
- * DVDSeek : Goes to a given position on the stream ; this one is used by the 
- * input and translate chronological position from input to logical postion
- * on the device
- * ---
+ * DVDSeek : Goes to a given position on the stream.
+ *****************************************************************************
+ * This one is used by the input and translate chronological position from
+ * input to logical position on the device.
  * The lock should be taken before calling this function.
  *****************************************************************************/
 static void DVDSeek( input_thread_t * p_input, off_t i_off )
@@ -1277,10 +1150,18 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
     p_dvd->i_chapter = i_chapter;
     p_input->stream.p_selected_area->i_part = p_dvd->i_chapter;
 
+#if !defined( WIN32 )
     p_input->stream.p_selected_area->i_tell =
                 lseek( p_dvd->i_fd, p_dvd->i_title_start +
                        (off_t)( p_dvd->i_sector ) *DVD_LB_SIZE, SEEK_SET ) -
                 p_input->stream.p_selected_area->i_start;
+#else
+    p_input->stream.p_selected_area->i_tell =
+                SetFilePointer( (HANDLE) p_dvd->i_fd, p_dvd->i_title_start +
+                        (off_t)( p_dvd->i_sector ) *DVD_LB_SIZE, NULL, FILE_BEGIN) -
+                         p_input->stream.p_selected_area->i_start;
+
+#endif
 /*
     intf_WarnMsg( 3, "Program Cell: %d Cell: %d Chapter: %d",
                      p_dvd->i_prg_cell, p_dvd->i_cell, p_dvd->i_chapter );
@@ -1411,7 +1292,12 @@ static int DVDChapterSelect( thread_dvd_data_t * p_dvd, int i_chapter )
                          DVD_LB_SIZE * (off_t)( p_dvd->i_sector );
 
     /* Position the fd pointer on the right address */
+#if !defined( WIN32 )
     p_dvd->i_start = lseek( p_dvd->i_fd, p_dvd->i_start, SEEK_SET );
+#else
+    p_dvd->i_start = SetFilePointer( (HANDLE) p_dvd->i_fd,
+                        p_dvd->i_start, NULL, FILE_BEGIN );
+#endif
 
     p_dvd->i_chapter = i_chapter;
     return 0;
@@ -1430,7 +1316,6 @@ static int DVDChooseAngle( thread_dvd_data_t * p_dvd )
         case 0x5:
             p_dvd->i_prg_cell += p_dvd->i_angle - 1;
             p_dvd->i_angle_cell = 0;
-//            intf_WarnMsg( 3, "dvd info: choosing angle %d", p_dvd->i_angle );
             break;
         /* we exit a multi-angle section */
         case 0x9: