]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/dvd_access.c
* ./plugins/qnx/vout_qnx.c: QNX compilation fix.
[vlc] / plugins / dvd / dvd_access.c
index db250de87af1db5104c743571a7be32197fcd3ad..6cbad86f89c89aeda386dd48986a469b189dc78a 100644 (file)
@@ -8,7 +8,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: dvd_access.c,v 1.6 2002/03/11 07:23:09 gbazin Exp $
+ * $Id: dvd_access.c,v 1.19 2002/05/21 13:34:31 gbazin Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -53,7 +53,7 @@
 #ifdef GOD_DAMN_DMCA
 #   include "dummy_dvdcss.h"
 #else
-#   include <videolan/dvdcss.h>
+#   include <dvdcss/dvdcss.h>
 #endif
 
 #include "stream_control.h"
@@ -68,8 +68,6 @@
 #include "dvd_summary.h"
 #include "iso_lang.h"
 
-#include "debug.h"
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -79,7 +77,7 @@ static int  DVDOpen         ( struct input_thread_s * );
 static void DVDClose        ( struct input_thread_s * );
 static int  DVDSetArea      ( struct input_thread_s *, struct input_area_s * );
 static int  DVDSetProgram   ( struct input_thread_s *, pgrm_descriptor_t * );
-static int  DVDRead         ( struct input_thread_s *, byte_t *, size_t );
+static ssize_t DVDRead      ( struct input_thread_s *, byte_t *, size_t );
 static void DVDSeek         ( struct input_thread_s *, off_t );
 
 static char * DVDParse( input_thread_t * );
@@ -104,7 +102,6 @@ void _M( access_getfunctions)( function_list_t * p_function_list )
  * Data access functions
  */
 
-#define DVDLB     p_dvd->i_vts_start + p_dvd->i_vts_lb
 #define DVDTell   LB2OFF( p_dvd->i_vts_start + p_dvd->i_vts_lb ) \
                   - p_input->stream.p_selected_area->i_start
 
@@ -226,9 +223,9 @@ static int DVDOpen( struct input_thread_s *p_input )
 
     p_area = p_input->stream.pp_areas[p_dvd->i_title];
     
-    p_dvd->i_chapter = p_dvd->i_chapter <= p_area->i_part_nb ?
-                       p_dvd->i_chapter : 1;
-    p_area->i_part = p_dvd->i_chapter;
+    p_area->i_part = p_dvd->i_chapter <= p_area->i_part_nb ?
+                     p_dvd->i_chapter : 1;
+    p_dvd->i_chapter = 1;
     
     p_dvd->b_new_chapter = 0;
     p_dvd->i_audio_nb = 0;
@@ -297,8 +294,8 @@ static int DVDSetProgram( input_thread_t    * p_input,
             p_dvd->i_prg_cell += ( p_program->i_number - p_dvd->i_angle );
             p_dvd->i_map_cell =  CellPrg2Map( p_dvd );
             p_dvd->i_map_cell += p_dvd->i_angle_cell;
-            p_dvd->i_vts_lb   =  CellStartSector( p_dvd );
-            p_dvd->i_end_lb   =  CellEndSector( p_dvd );
+            p_dvd->i_vts_lb   =  CellFirstSector( p_dvd );
+            p_dvd->i_last_lb  =  CellLastSector( p_dvd );
             p_dvd->i_angle    =  p_program->i_number;
         }
         else
@@ -381,8 +378,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
     if( p_area != p_input->stream.p_selected_area )
     {
         int     i_vts_title;
-        u32     i_start;
-        u32     i_size;
+        u32     i_first;
+        u32     i_last;
 
         /* Reset the Chapter position of the old title */
         p_input->stream.p_selected_area->i_part = 1;
@@ -420,31 +417,32 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
             vts.title_unit.p_title[p_dvd->i_title_id-1].title.i_cell_nb;
         p_dvd->i_map_cell = 0;
         p_dvd->i_map_cell = CellPrg2Map( p_dvd );
-        i_size            = CellEndSector( p_dvd );
+        i_last            = CellLastSector( p_dvd );
 
         /* first cell */
         p_dvd->i_prg_cell   = 0;
         p_dvd->i_map_cell   = 0;
         p_dvd->i_angle_cell = 0;
         p_dvd->i_map_cell   = CellPrg2Map    ( p_dvd );
-        p_dvd->i_vts_lb     = CellStartSector( p_dvd );
-        p_dvd->i_end_lb     = CellEndSector  ( p_dvd );
+        p_dvd->i_vts_lb     = CellFirstSector( p_dvd );
+        p_dvd->i_last_lb    = CellLastSector ( p_dvd );
 
         /* Force libdvdcss to check its title key.
          * It is only useful for title cracking method. Methods using the
          * decrypted disc key are fast enough to check the key at each seek */
-        if( ( i_start = dvdcss_seek( p_dvd->dvdhandle, DVDLB,
-                                     DVDCSS_SEEK_KEY ) ) < 0 )
+        i_first = dvdcss_seek( p_dvd->dvdhandle,
+                               p_dvd->i_vts_start + p_dvd->i_vts_lb,
+                               DVDCSS_SEEK_KEY );
+        if( i_first < 0 )
         {
             intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) );
             return -1;
         }
 
-        i_size -= p_dvd->i_vts_lb + 1;
-
         /* Area definition */
-        p_input->stream.p_selected_area->i_start = LB2OFF( i_start );
-        p_input->stream.p_selected_area->i_size  = LB2OFF( i_size );
+        p_input->stream.p_selected_area->i_start = LB2OFF( i_first );
+        p_input->stream.p_selected_area->i_size  =
+                                        LB2OFF( i_last + 1 - p_dvd->i_vts_lb );
 
         /* Destroy obsolete ES by reinitializing programs */
         DVDFlushStream( p_input );
@@ -459,8 +457,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         DVDSetProgram( p_input,
                        p_input->stream.pp_programs[p_dvd->i_angle-1] ); 
 
-        intf_WarnMsg( 3, "dvd info: title start: %d size: %d",
-                         i_start, i_size );
+        intf_WarnMsg( 3, "dvd info: title first %i, last %i, size %i",
+                         i_first, i_last, i_last + 1 - p_dvd->i_vts_lb );
         IfoPrintTitle( p_dvd );
 
         /* No PSM to read in DVD mode, we already have all information */
@@ -505,8 +503,8 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
  * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
  * bytes.
  *****************************************************************************/
-static int DVDRead( input_thread_t * p_input,
-                    byte_t * p_buffer, size_t i_count )
+static ssize_t DVDRead( input_thread_t * p_input,
+                        byte_t * p_buffer, size_t i_count )
 {
     thread_dvd_data_t *     p_dvd;
     int                     i_read;
@@ -520,7 +518,12 @@ static int DVDRead( input_thread_t * p_input,
 
     while( i_blocks )
     {
-        if( ( i_block_once = __MIN( LbMaxOnce( p_dvd ), i_blocks ) ) <= 0 )
+        i_block_once = LbMaxOnce( p_dvd );
+        if( i_block_once > i_blocks )
+        {
+            i_block_once = i_blocks;
+        }
+        else if( i_block_once <= 0 )
         {
             /* EOT */
             break;
@@ -597,13 +600,13 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
         /* if we're inside a multi-angle zone, we have to choose i_sector
          * in the current angle ; we can't do it all the time since cells
          * can be very wide out of such zones */
-        p_dvd->i_vts_lb = CellStartSector( p_dvd );
+        p_dvd->i_vts_lb = CellFirstSector( p_dvd );
     }
     
-    p_dvd->i_end_lb   = CellEndSector  ( p_dvd );
+    p_dvd->i_last_lb  = CellLastSector( p_dvd );
     p_dvd->i_chapter  = CellPrg2Chapter( p_dvd );
 
-    if( dvdcss_seek( p_dvd->dvdhandle, DVDLB,
+    if( dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_vts_start + p_dvd->i_vts_lb,
                      DVDCSS_SEEK_MPEG ) < 0 )
     {
         intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) );
@@ -638,9 +641,15 @@ static char * DVDParse( input_thread_t * p_input )
     int                  i_chapter = 1;
     int                  i_angle = 1;
     int                  i;
-    
+
     p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
 
+#ifdef WIN32
+    /* On Win32 we want the DVD access plugin to be explicitly requested,
+     * we end up with lots of problems otherwise */
+    if( !p_input->psz_access || !*p_input->psz_access ) return NULL;
+#endif
+
     psz_parser = psz_device = strdup( p_input->psz_name );
     if( !psz_parser )
     {
@@ -662,7 +671,7 @@ static char * DVDParse( input_thread_t * p_input )
     }
     else
     {
-        psz_raw = NULL;
+        psz_raw = "";
     }
 
     if( *psz_parser && !strtol( psz_parser, NULL, 10 ) )
@@ -695,7 +704,7 @@ static char * DVDParse( input_thread_t * p_input )
                 {
                     /* we have only a partial list of options, no device */
                     psz_parser = psz_raw;
-                    psz_raw = NULL;
+                    psz_raw = "";
                     b_options = 1;
                     break;
                 }
@@ -706,7 +715,7 @@ static char * DVDParse( input_thread_t * p_input )
     else
     {
         /* found beginning of options ; no raw device specified */
-        psz_raw = NULL;
+        psz_raw = "";
         b_options = 1;
     }
 
@@ -729,7 +738,7 @@ static char * DVDParse( input_thread_t * p_input )
         p_dvd->i_angle = i_angle ? i_angle : 1;
     }
 
-    if( psz_raw )
+    if( *psz_raw )
     {
         if( *psz_raw )
         {
@@ -741,7 +750,7 @@ static char * DVDParse( input_thread_t * p_input )
                              psz_raw, strerror(errno));
                 /* put back '@' */
                 *(psz_raw - 1) = '@';
-                psz_raw = NULL;
+                psz_raw = "";
             }
             else
             {
@@ -754,7 +763,7 @@ static char * DVDParse( input_thread_t * p_input )
                                      " not a valid char device", psz_raw );
                     /* put back '@' */
                     *(psz_raw - 1) = '@';
-                    psz_raw = NULL;
+                    psz_raw = "";
                 }
                 else
 #endif
@@ -768,7 +777,7 @@ static char * DVDParse( input_thread_t * p_input )
         }
         else
         {
-            psz_raw = NULL;
+            psz_raw = "";
         }
     }
     
@@ -781,22 +790,24 @@ static char * DVDParse( input_thread_t * p_input )
             /* no device and no access specified: we probably don't want DVD */
             return NULL;
         }
-        psz_device = config_GetPszVariable( "dvd_device" );
+        psz_device = config_GetPszVariable( "dvd" );
     }
 
+#ifndef WIN32    
     /* check block device */
     if( stat( psz_device, &stat_info ) == -1 )
     {
-        intf_ErrMsg( "input error: cannot stat() device `%s' (%s)",
+        intf_ErrMsg( "dvd error: cannot stat() device `%s' (%s)",
                      psz_device, strerror(errno));
+        free( psz_device );
         return NULL;                    
     }
     
-#ifndef WIN32    
     if( !S_ISBLK(stat_info.st_mode) && !S_ISCHR(stat_info.st_mode) )
     {
         intf_WarnMsg( 3, "input: DVD plugin discarded"
                          " (not a valid block device)" );
+        free( psz_device );
         return NULL;
     }
 #endif