dialog: use new API
[vlc.git] / modules / access / dvdread.c
index c806117..5f1f070 100644 (file)
 
 #include <vlc_iso_lang.h>
 
-#include "../demux/ps.h"
-
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
+#include "../demux/mpeg/pes.h"
+#include "../demux/mpeg/ps.h"
 
 #include <sys/types.h>
+#include <unistd.h>
 
 #include <dvdread/dvd_reader.h>
 #include <dvdread/ifo_types.h>
@@ -179,7 +177,7 @@ static int Open( vlc_object_t *p_this )
     else
         psz_file = strdup( p_demux->psz_file );
 
-#if defined( WIN32 ) || defined( __OS2__ )
+#if defined( _WIN32 ) || defined( __OS2__ )
     if( psz_file != NULL )
     {
         size_t flen = strlen( psz_file );
@@ -200,7 +198,7 @@ static int Open( vlc_object_t *p_this )
     if( p_dvdread == NULL )
     {
         msg_Err( p_demux, "DVDRead cannot open source: %s", psz_file );
-        dialog_Fatal( p_demux, _("Playback failure"),
+        vlc_dialog_display_error( p_demux, _("Playback failure"),
                       _("DVDRead could not open the disc \"%s\"."), psz_file );
         free( psz_file );
         return VLC_EGENERIC;
@@ -394,7 +392,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
             /* Duplicate title infos */
             *pi_int = p_sys->i_titles;
-            *ppp_title = malloc( sizeof(input_title_t **) * p_sys->i_titles );
+            *ppp_title = malloc( p_sys->i_titles * sizeof(input_title_t *) );
             for( i = 0; i < p_sys->i_titles; i++ )
             {
                 (*ppp_title)[i] = vlc_input_title_Duplicate(p_sys->titles[i]);
@@ -462,7 +460,7 @@ static int Demux( demux_t *p_demux )
                            1, p_buffer ) != 1 )
         {
             msg_Err( p_demux, "read failed for block %d", p_sys->i_next_vobu );
-            dialog_Fatal( p_demux, _("Playback failure"),
+            vlc_dialog_display_error( p_demux, _("Playback failure"),
                           _("DVDRead could not read block %d."),
                           p_sys->i_next_vobu );
             return -1;
@@ -478,12 +476,15 @@ static int Demux( demux_t *p_demux )
         /* End of title */
         if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells )
         {
-            if( p_sys->i_title + 1 >= p_sys->i_titles )
+            int k = p_sys->i_title;
+
+            /* Looking for a not broken title */
+            while( k < p_sys->i_titles && DvdReadSetArea( p_demux, ++k, 0, -1 ) != VLC_SUCCESS )
             {
-                return 0; /* EOF */
+                msg_Err(p_demux, "Failed next title, trying another: %i", k );
+                if( k >= p_sys->i_titles )
+                    return 0; // EOF
             }
-
-            DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
         }
 
         if( p_sys->i_pack_len >= 1024 )
@@ -503,12 +504,15 @@ static int Demux( demux_t *p_demux )
 
     if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells )
     {
-        if( p_sys->i_title + 1 >= p_sys->i_titles )
+        int k = p_sys->i_title;
+
+        /* Looking for a not broken title */
+        while( k < p_sys->i_titles && DvdReadSetArea( p_demux, ++k, 0, -1 ) != VLC_SUCCESS )
         {
-            return 0; /* EOF */
+            msg_Err(p_demux, "Failed next title, trying another: %i", k );
+            if( k >= p_sys->i_titles )
+                return 0; // EOF
         }
-
-        DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
     }
 
     /*
@@ -524,7 +528,7 @@ static int Demux( demux_t *p_demux )
     {
         msg_Err( p_demux, "read failed for %d/%d blocks at 0x%02x",
                  i_read, i_blocks_once, p_sys->i_cur_block );
-        dialog_Fatal( p_demux, _("Playback failure"),
+        vlc_dialog_display_error( p_demux, _("Playback failure"),
                         _("DVDRead could not read %d/%d blocks at 0x%02x."),
                         i_read, i_blocks_once, p_sys->i_cur_block );
         return -1;
@@ -565,7 +569,7 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len )
         }
 
         /* Create a block */
-        block_t *p_pkt = block_New( p_demux, i_size );
+        block_t *p_pkt = block_Alloc( i_size );
         memcpy( p_pkt->p_buffer, p, i_size);
 
         /* Parse it and send it */
@@ -612,7 +616,7 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *p, int len )
                     ESNew( p_demux, i_id, 0 );
                 }
                 if( tk->b_seen && tk->es &&
-                    !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
+                    !ps_pkt_parse_pes( VLC_OBJECT(p_demux), p_pkt, tk->i_skip ) )
                 {
                     es_out_Send( p_demux->out, tk->es, p_pkt );
                 }
@@ -647,7 +651,7 @@ static void ESNew( demux_t *p_demux, int i_id, int i_lang )
 
     if( tk->b_seen ) return;
 
-    if( ps_track_fill( tk, 0, i_id ) )
+    if( ps_track_fill( tk, 0, i_id, NULL ) )
     {
         msg_Warn( p_demux, "unknown codec for id=0x%x", i_id );
         return;
@@ -729,7 +733,11 @@ static int DvdReadSetArea( demux_t *p_demux, int i_title, int i_chapter,
     {
         int i_start_cell, i_end_cell;
 
-        if( p_sys->p_title != NULL ) DVDCloseFile( p_sys->p_title );
+        if( p_sys->p_title != NULL )
+        {
+            DVDCloseFile( p_sys->p_title );
+            p_sys->p_title = NULL;
+        }
         if( p_vts != NULL ) ifoClose( p_vts );
         p_sys->i_title = i_title;
 
@@ -755,6 +763,12 @@ static int DvdReadSetArea( demux_t *p_demux, int i_title, int i_chapter,
         pgn = p_vts->vts_ptt_srpt->title[p_sys->i_ttn - 1].ptt[0].pgn;
         p_pgc = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
 
+        if( p_pgc->cell_playback == NULL )
+        {
+            msg_Err( p_demux, "Invalid PGC (cell_playback_offset)" );
+            return VLC_EGENERIC;
+        }
+
         p_sys->i_title_start_cell =
             i_start_cell = p_pgc->program_map[pgn - 1] - 1;
         p_sys->i_title_start_block =
@@ -999,6 +1013,8 @@ static int DvdReadSetArea( demux_t *p_demux, int i_title, int i_chapter,
                   p_sys->i_ttn - 1].ptt[i_chapter].pgn;
 
         p_pgc = p_vts->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
+        if( p_pgc->cell_playback == NULL )
+            return VLC_EGENERIC; /* Couldn't set chapter */
 
         p_sys->i_cur_cell = p_pgc->program_map[pgn - 1] - 1;
         p_sys->i_chapter = i_chapter;
@@ -1147,7 +1163,7 @@ static void DvdReadHandleDSI( demux_t *p_demux, uint8_t *p_data )
     /*
      * Store the timecodes so we can get the current time
      */
-    p_sys->i_title_cur_time = (mtime_t) (p_sys->dsi_pack.dsi_gi.nv_pck_scr / 90 * 1000);
+    p_sys->i_title_cur_time = (mtime_t) p_sys->dsi_pack.dsi_gi.nv_pck_scr / 90 * 1000;
     p_sys->i_cell_cur_time = (mtime_t) dvdtime_to_time( &p_sys->dsi_pack.dsi_gi.c_eltm, 0 );
 
     /*