]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/input_dvd.c
* Removed unused code (intf_channels.c, keystrokes.h).
[vlc] / plugins / dvd / input_dvd.c
index 3874caff00fa6ecef74c8c91214df8caf86b1a63..773852b60c8366b8975c2804f70832dddd6701c4 100644 (file)
@@ -10,7 +10,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.92 2001/11/07 17:37:16 stef Exp $
+ * $Id: input_dvd.c,v 1.106 2001/12/10 04:53:10 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -39,6 +39,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
@@ -65,8 +66,8 @@
 #   include <videolan/dvdcss.h>
 #endif
 
-#include "config.h"
 #include "common.h"
+#include "intf_msg.h"
 #include "threads.h"
 #include "mtime.h"
 #include "iso_lang.h"
 #   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"
 
  * 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 * );
@@ -137,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
@@ -198,7 +196,7 @@ 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;
 
     if( dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS ) < 0 )
     {
@@ -214,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 */
@@ -312,7 +309,8 @@ static void DVDInit( input_thread_t * p_input )
 static void DVDOpen( struct input_thread_s *p_input )
 {
     dvdcss_handle dvdhandle;
-    int           i_flags;
+    char * psz_parser;
+    char * psz_device;
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
@@ -326,25 +324,35 @@ static void DVDOpen( struct input_thread_s *p_input )
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    /* Error messages from libdvdcss only in verbose mode */
-    i_flags = p_main->i_warning_level ? DVDCSS_NOFLAGS : DVDCSS_INIT_QUIET;
-    
-    /* Debug message from libdvdcss selected from config.h #define */
-#ifdef TRACE_DVDCSS
-    i_flags |= DVDCSS_INIT_DEBUG;
-#endif
-
-    /* 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, i_flags );
+        psz_parser = psz_device = p_input->p_source + 4;
     }
     else
     {
-        dvdhandle = dvdcss_open( p_input->p_source, i_flags );
+        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" );
@@ -352,7 +360,7 @@ static void DVDOpen( struct input_thread_s *p_input )
         return;
     }
 
-    p_input->i_handle = (int) dvdhandle;
+    p_input->p_handle = (void *) dvdhandle;
 }
 
 /*****************************************************************************
@@ -361,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 );
 }
 
 /*****************************************************************************
@@ -370,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;
 }
 
 /*****************************************************************************
@@ -492,12 +507,12 @@ 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
-         */
-        if( dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_start, DVDCSS_SEEK_INI ) < 0 )
+        /* 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;
@@ -536,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;
@@ -578,7 +595,7 @@ 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;
@@ -592,7 +609,8 @@ 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;
@@ -606,8 +624,9 @@ 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;
@@ -669,7 +688,8 @@ 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;
@@ -809,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;
@@ -825,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;
@@ -892,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;
@@ -904,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;
@@ -925,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;
         }