X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=plugins%2Fdvd%2Finput_dvd.c;h=773852b60c8366b8975c2804f70832dddd6701c4;hb=003c2ab30097c1406da51290eccab8863dfe5101;hp=44946fab322bece6fe971048fa99f3611d7b5125;hpb=6ea68caa3d291b5ca003246eefe04d0bc728dbc3;p=vlc diff --git a/plugins/dvd/input_dvd.c b/plugins/dvd/input_dvd.c index 44946fab32..773852b60c 100644 --- a/plugins/dvd/input_dvd.c +++ b/plugins/dvd/input_dvd.c @@ -10,7 +10,7 @@ * -dvd_udf to find files ***************************************************************************** * Copyright (C) 1998-2001 VideoLAN - * $Id: input_dvd.c,v 1.90 2001/10/15 13:33:00 stef Exp $ + * $Id: input_dvd.c,v 1.106 2001/12/10 04:53:10 sam Exp $ * * Author: Stéphane Borel * @@ -39,6 +39,7 @@ #include #include +#include #ifdef HAVE_UNISTD_H # include @@ -65,27 +66,23 @@ # include #endif -#include "config.h" #include "common.h" +#include "intf_msg.h" #include "threads.h" #include "mtime.h" +#include "iso_lang.h" #include "tests.h" #if defined( WIN32 ) # include "input_iovec.h" #endif -#include "intf_msg.h" - -#include "main.h" - #include "stream_control.h" #include "input_ext-intf.h" #include "input_ext-dec.h" #include "input_ext-plugins.h" #include "input_dvd.h" -#include "dvd_netlist.h" #include "dvd_ifo.h" #include "dvd_summary.h" @@ -105,15 +102,16 @@ * Local prototypes *****************************************************************************/ /* called from outside */ -static int DVDProbe ( probedata_t *p_data ); -static void DVDInit ( struct input_thread_s * ); -static void DVDEnd ( struct input_thread_s * ); -static void 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 DVDRead ( struct input_thread_s *, data_packet_t ** ); -static void DVDSeek ( struct input_thread_s *, off_t ); -static int DVDRewind ( struct input_thread_s * ); +static int DVDProbe ( probedata_t *p_data ); +static void DVDInit ( struct input_thread_s * ); +static void DVDEnd ( struct input_thread_s * ); +static void 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 *, data_packet_t ** ); +static void DVDSeek ( struct input_thread_s *, off_t ); +static int DVDRewind ( struct input_thread_s * ); /* called only inside */ static int DVDChooseAngle( thread_dvd_data_t * ); @@ -136,11 +134,12 @@ void _M( input_getfunctions )( function_list_t * p_function_list ) input.pf_init_bit_stream = InitBitstream; input.pf_read = DVDRead; input.pf_set_area = DVDSetArea; + input.pf_set_program = DVDSetProgram; input.pf_demux = input_DemuxPS; - input.pf_new_packet = DVDNewPacket; - input.pf_new_pes = DVDNewPES; - input.pf_delete_packet = DVDDeletePacket; - input.pf_delete_pes = DVDDeletePES; + input.pf_new_packet = input_NetlistNewPacket; + input.pf_new_pes = input_NetlistNewPES; + input.pf_delete_packet = input_NetlistDeletePacket; + input.pf_delete_pes = input_NetlistDeletePES; input.pf_rewind = DVDRewind; input.pf_seek = DVDSeek; #undef input @@ -197,9 +196,14 @@ static void DVDInit( input_thread_t * p_input ) p_input->p_plugin_data = (void *)p_dvd; p_input->p_method_data = NULL; - p_dvd->dvdhandle = (dvdcss_handle) p_input->i_handle; + p_dvd->dvdhandle = (dvdcss_handle) p_input->p_handle; - dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS ); + if( dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS ) < 0 ) + { + intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + p_input->b_error = 1; + return; + } /* We read DVD_BLOCK_READ_ONCE in each loop, so the input will receive * DVD_DATA_READ_ONCE at most */ @@ -208,9 +212,8 @@ static void DVDInit( input_thread_t * p_input ) p_input->i_read_once = DVD_DATA_READ_ONCE; /* Reading structures initialisation */ - p_input->p_method_data = - DVDNetlistInit( DVD_NETLIST_SIZE, 2 * DVD_NETLIST_SIZE, - DVD_NETLIST_SIZE, DVD_LB_SIZE, p_dvd->i_block_once ); + input_NetlistInit( p_input, DVD_NETLIST_SIZE, 2 * DVD_NETLIST_SIZE, + DVD_NETLIST_SIZE, DVD_LB_SIZE, p_dvd->i_block_once ); intf_WarnMsg( 2, "dvd info: netlist initialized" ); /* Ifo allocation & initialisation */ @@ -306,6 +309,8 @@ static void DVDInit( input_thread_t * p_input ) static void DVDOpen( struct input_thread_s *p_input ) { dvdcss_handle dvdhandle; + char * psz_parser; + char * psz_device; vlc_mutex_lock( &p_input->stream.stream_lock ); @@ -319,26 +324,43 @@ static void DVDOpen( struct input_thread_s *p_input ) vlc_mutex_unlock( &p_input->stream.stream_lock ); - /* XXX: put this shit in an access plugin */ + /* Parse input string : dvd:device[:rawdevice] */ if( strlen( p_input->p_source ) > 4 && !strncasecmp( p_input->p_source, "dvd:", 4 ) ) { - dvdhandle = dvdcss_open( p_input->p_source + 4, - DVDCSS_INIT_QUIET ); + psz_parser = psz_device = p_input->p_source + 4; } else { - dvdhandle = dvdcss_open( p_input->p_source, - DVDCSS_INIT_QUIET ); + psz_parser = psz_device = p_input->p_source; + } + + while( *psz_parser && *psz_parser != '@' ) + { + psz_parser++; } + if( *psz_parser == '@' ) + { + /* Found raw device */ + *psz_parser = '\0'; + psz_parser++; + + main_PutPszVariable( "DVDCSS_RAW_DEVICE", psz_parser ); + } + + intf_WarnMsg( 2, "input: dvd=%s raw=%s", psz_device, psz_parser ); + + dvdhandle = dvdcss_open( psz_device ); + if( dvdhandle == NULL ) { + intf_ErrMsg( "dvd error: dvdcss can't open device" ); p_input->b_error = 1; return; } - p_input->i_handle = (int) dvdhandle; + p_input->p_handle = (void *) dvdhandle; } /***************************************************************************** @@ -347,7 +369,7 @@ static void DVDOpen( struct input_thread_s *p_input ) static void DVDClose( struct input_thread_s *p_input ) { /* Clean up libdvdcss */ - dvdcss_close( (dvdcss_handle) p_input->i_handle ); + dvdcss_close( (dvdcss_handle) p_input->p_handle ); } /***************************************************************************** @@ -356,16 +378,23 @@ static void DVDClose( struct input_thread_s *p_input ) static void DVDEnd( input_thread_t * p_input ) { thread_dvd_data_t * p_dvd; - dvd_netlist_t * p_netlist; p_dvd = (thread_dvd_data_t*)p_input->p_plugin_data; - p_netlist = (dvd_netlist_t *)p_input->p_method_data; IfoDestroy( p_dvd->p_ifo ); free( p_dvd ); - DVDNetlistEnd( p_netlist ); + input_NetlistEnd( p_input ); +} + +/***************************************************************************** + * DVDSetProgram: Does nothing, a DVD is mono-program + *****************************************************************************/ +static int DVDSetProgram( input_thread_t * p_input, + pgrm_descriptor_t * p_program ) +{ + return 0; } /***************************************************************************** @@ -478,12 +507,16 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) return -1; } - /* - * 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 - */ - dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_start, DVDCSS_SEEK_INI ); + /* 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( dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_start, + DVDCSS_SEEK_KEY ) < 0 ) + { + intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + return -1; + } p_dvd->i_size -= p_dvd->i_sector + 1; @@ -518,23 +551,25 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) } free( p_input->stream.pp_selected_es ); - input_DelProgram( p_input, p_input->stream.pp_programs[0] ); + input_DelProgram( p_input, p_input->stream.p_selected_program ); p_input->stream.pp_selected_es = NULL; p_input->stream.i_selected_es_number = 0; } input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) ); + p_input->stream.p_selected_program = p_input->stream.pp_programs[0]; /* No PSM to read in DVD mode, we already have all information */ - p_input->stream.pp_programs[0]->b_is_ok = 1; + p_input->stream.p_selected_program->b_is_ok = 1; 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 = input_AddES( p_input, p_input->stream.p_selected_program, + 0xe0, 0 ); p_es->i_stream_id = 0xe0; p_es->i_type = MPEG2_VIDEO_ES; p_es->i_cat = VIDEO_ES; @@ -560,12 +595,12 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) 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_input->stream.p_selected_program, 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( + strcpy( p_es->psz_desc, DecodeLanguage( hton16( vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); strcat( p_es->psz_desc, " (ac3)" ); @@ -574,12 +609,13 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) 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_input->stream.p_selected_program, 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, IfoLanguage( hton16( + strcpy( p_es->psz_desc, DecodeLanguage( hton16( vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); strcat( p_es->psz_desc, " (mpeg)" ); @@ -588,12 +624,13 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) 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_input->stream.p_selected_program, + i_id, 0 ); + p_es->i_stream_id = 0xbd; 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( + strcpy( p_es->psz_desc, DecodeLanguage( hton16( vts.manager_inf.p_audio_attr[i-1].i_lang_code ) ) ); strcat( p_es->psz_desc, " (lpcm)" ); @@ -651,11 +688,12 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area ) | 0xbd; } p_es = input_AddES( p_input, - p_input->stream.pp_programs[0], i_id, 0 ); + p_input->stream.p_selected_program, + 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, IfoLanguage( hton16( + strcpy( p_es->psz_desc, DecodeLanguage( hton16( vts.manager_inf.p_spu_attr[i-1].i_lang_code ) ) ); } } @@ -791,7 +829,7 @@ static int DVDRead( input_thread_t * p_input, data_packet_t ** pp_packets ) { thread_dvd_data_t * p_dvd; - dvd_netlist_t * p_netlist; + netlist_t * p_netlist; struct iovec * p_vec; struct data_packet_s * pp_data[DVD_DATA_READ_ONCE]; u8 * pi_cur; @@ -807,7 +845,7 @@ static int DVDRead( input_thread_t * p_input, boolean_t b_eoc; p_dvd = (thread_dvd_data_t *)p_input->p_plugin_data; - p_netlist = (dvd_netlist_t *)p_input->p_method_data; + p_netlist = (netlist_t *)p_input->p_method_data; b_eoc = 0; i_sector = p_dvd->i_title_start + p_dvd->i_sector; @@ -831,9 +869,13 @@ static int DVDRead( input_thread_t * p_input, } /* Position the fd pointer on the right address */ - i_sector = dvdcss_seek( p_dvd->dvdhandle, - p_dvd->i_title_start + p_dvd->i_sector, - DVDCSS_SEEK_MPEG ); + if( ( i_sector = dvdcss_seek( p_dvd->dvdhandle, + p_dvd->i_title_start + p_dvd->i_sector, + DVDCSS_SEEK_MPEG ) ) < 0 ) + { + intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + return -1; + } /* update chapter : it will be easier when we have navigation * ES support */ @@ -870,7 +912,7 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o p_netlist->i_read_once = i_block_once; /* Get an iovec pointer */ - if( ( p_vec = DVDGetiovec( p_netlist ) ) == NULL ) + if( ( p_vec = input_NetlistGetiovec( p_netlist ) ) == NULL ) { intf_ErrMsg( "dvd error: can't get iovec" ); return -1; @@ -882,7 +924,7 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o /* Update netlist indexes: we don't do it in DVDGetiovec since we * need know the real number of blocks read */ - DVDMviovec( p_netlist, i_read_blocks, pp_data ); + input_NetlistMviovec( p_netlist, i_read_blocks, pp_data ); /* Update global position */ p_dvd->i_sector += i_read_blocks; @@ -903,31 +945,25 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o { /* That's the case for all packets, except pack header. */ i_packet_size = U16_AT( pi_cur + 4 ); - pp_packets[i_packet] = DVDNewPtr( p_netlist ); + pp_packets[i_packet] = input_NetlistNewPtr( p_netlist ); + (*pp_data[i_iovec]->pi_refcount)++; + pp_packets[i_packet]->pi_refcount = + pp_data[i_iovec]->pi_refcount; + pp_packets[i_packet]->p_buffer = pp_data[i_iovec]->p_buffer; } else { /* MPEG-2 Pack header. */ i_packet_size = 8; pp_packets[i_packet] = pp_data[i_iovec]; - } - (*pp_data[i_iovec]->pi_refcount)++; - - pp_packets[i_packet]->pi_refcount = pp_data[i_iovec]->pi_refcount; - - pp_packets[i_packet]->p_buffer = pp_data[i_iovec]->p_buffer; - pp_packets[i_packet]->p_payload_start = pp_packets[i_packet]->p_buffer + i_pos; pp_packets[i_packet]->p_payload_end = pp_packets[i_packet]->p_payload_start + i_packet_size + 6; - pp_packets[i_packet]->p_next = NULL; - pp_packets[i_packet]->b_discard_payload = 0; - i_packet++; i_pos += i_packet_size + 6; } @@ -994,6 +1030,7 @@ static int DVDRewind( input_thread_t * p_input ) static void DVDSeek( input_thread_t * p_input, off_t i_off ) { thread_dvd_data_t * p_dvd; + int i_block; int i_prg_cell; int i_cell; int i_chapter; @@ -1084,11 +1121,17 @@ 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( ( i_block = dvdcss_seek( p_dvd->dvdhandle, + p_dvd->i_title_start + p_dvd->i_sector, + DVDCSS_SEEK_MPEG ) ) < 0 ) + { + intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + p_input->b_error = 1; + return; + } + p_input->stream.p_selected_area->i_tell = - LB2OFF ( dvdcss_seek( p_dvd->dvdhandle, - p_dvd->i_title_start + p_dvd->i_sector, - DVDCSS_SEEK_MPEG ) ) - - p_input->stream.p_selected_area->i_start; + LB2OFF ( i_block ) - p_input->stream.p_selected_area->i_start; intf_WarnMsg( 7, "Program Cell: %d Cell: %d Chapter: %d", p_dvd->i_prg_cell, p_dvd->i_cell, p_dvd->i_chapter ); @@ -1125,7 +1168,7 @@ static int DVDFindCell( thread_dvd_data_t * p_dvd ) } /* -intf_WarnMsg( 7, "FindCell: i_cell %d i_index %d found %d nb %d", +intf_WarnMsg( 12, "FindCell: i_cell %d i_index %d found %d nb %d", p_dvd->i_cell, p_dvd->i_prg_cell, i_cell, @@ -1161,7 +1204,7 @@ static int DVDFindSector( thread_dvd_data_t * p_dvd ) intf_ErrMsg( "dvd error: can't find sector" ); return -1; } - + /* Find start and end sectors of new cell */ #if 1 p_dvd->i_sector = MAX( @@ -1176,7 +1219,7 @@ static int DVDFindSector( thread_dvd_data_t * p_dvd ) #endif /* - intf_WarnMsg( 7, "cell: %d sector1: 0x%x end1: 0x%x\n" + intf_WarnMsg( 12, "cell: %d sector1: 0x%x end1: 0x%x\n" "index: %d sector2: 0x%x end2: 0x%x\n" "category: 0x%x ilvu end: 0x%x vobu start 0x%x", p_dvd->i_cell, @@ -1218,9 +1261,13 @@ static int DVDChapterSelect( thread_dvd_data_t * p_dvd, int i_chapter ) p_dvd->i_start = p_dvd->i_title_start + p_dvd->i_sector; /* Position the fd pointer on the right address */ - p_dvd->i_start = dvdcss_seek( p_dvd->dvdhandle, - p_dvd->i_start, - DVDCSS_SEEK_MPEG ); + if( ( p_dvd->i_start = dvdcss_seek( p_dvd->dvdhandle, + p_dvd->i_start, + DVDCSS_SEEK_MPEG ) ) < 0 ) + { + intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) ); + return -1; + } p_dvd->i_chapter = i_chapter; return 0;