* -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>
*
#ifdef GOD_DAMN_DMCA
# include "dummy_dvdcss.h"
#else
-# include <videolan/dvdcss.h>
+# include <dvdcss/dvdcss.h>
#endif
#include "stream_control.h"
#include "dvd_summary.h"
#include "iso_lang.h"
-#include "debug.h"
-
/*****************************************************************************
* Local prototypes
*****************************************************************************/
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 * );
* 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
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;
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
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;
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 );
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 */
* 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;
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;
/* 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 ) );
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 )
{
}
else
{
- psz_raw = NULL;
+ psz_raw = "";
}
if( *psz_parser && !strtol( psz_parser, NULL, 10 ) )
{
/* we have only a partial list of options, no device */
psz_parser = psz_raw;
- psz_raw = NULL;
+ psz_raw = "";
b_options = 1;
break;
}
else
{
/* found beginning of options ; no raw device specified */
- psz_raw = NULL;
+ psz_raw = "";
b_options = 1;
}
p_dvd->i_angle = i_angle ? i_angle : 1;
}
- if( psz_raw )
+ if( *psz_raw )
{
if( *psz_raw )
{
psz_raw, strerror(errno));
/* put back '@' */
*(psz_raw - 1) = '@';
- psz_raw = NULL;
+ psz_raw = "";
}
else
{
" not a valid char device", psz_raw );
/* put back '@' */
*(psz_raw - 1) = '@';
- psz_raw = NULL;
+ psz_raw = "";
}
else
#endif
}
else
{
- psz_raw = NULL;
+ psz_raw = "";
}
}
/* 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