]> git.sesse.net Git - vlc/blobdiff - plugins/dvdread/input_dvdread.c
* ./extras/MacOSX_dvdioctl: removed outdated files.
[vlc] / plugins / dvdread / input_dvdread.c
index 2a537a52cd3524fc82d1f76747e4fd9c9ed8bc4a..883cdce64c5724fd887bd7b8651f2468e370edf0 100644 (file)
@@ -6,7 +6,7 @@
  * It depends on: libdvdread for ifo files and block reading.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_dvdread.c,v 1.26 2002/03/04 22:18:25 gbazin Exp $
+ * $Id: input_dvdread.c,v 1.34 2002/03/18 19:14:52 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -131,7 +131,7 @@ void _M( demux_getfunctions )( function_list_t * p_function_list )
  *****************************************************************************/
 static int DvdReadInit( input_thread_t * p_input )
 {
-    if( strncmp( p_input->p_access_module->psz_name, "dvdread", 7 ) )
+    if( p_input->stream.i_method != INPUT_METHOD_DVD )
     {
         return -1;
     }
@@ -284,7 +284,12 @@ static int DvdReadOpen( struct input_thread_s *p_input )
 
     if( !*psz_source )
     {
-        psz_source = config_GetPszVariable( INPUT_DVD_DEVICE_VAR );
+        if( !p_input->psz_access )
+        {
+            free( psz_orig );
+            return -1;
+        }
+        psz_source = config_GetPszVariable( "dvd_device" );
     }
 
     if( stat( psz_source, &stat_info ) == -1 )
@@ -310,7 +315,7 @@ static int DvdReadOpen( struct input_thread_s *p_input )
 
     /* free allocated strings */
     if( psz_source != psz_orig )
-        free( psz_device );
+        free( psz_source );
     free( psz_orig );
 
     if( ! p_dvdread )
@@ -333,9 +338,6 @@ static int DvdReadOpen( struct input_thread_s *p_input )
     p_dvd->p_title = NULL;
     p_dvd->p_vts_file = NULL;
 
-    p_dvd->i_title = i_title;
-    p_dvd->i_chapter = i_chapter;
-    p_dvd->i_angle = i_angle;
 
     p_input->p_access_data = (void *)p_dvd;
 
@@ -389,18 +391,20 @@ static int DvdReadOpen( struct input_thread_s *p_input )
         area[i]->i_part_nb = tt_srpt->title[i-1].nr_of_ptts;
         area[i]->i_part = 1;
 
-        /* Number of angles */
-        area[i]->i_angle_nb = 0;
-        area[i]->i_angle = 1;
-
         area[i]->i_plugin_data = tt_srpt->title[i-1].title_set_nr;
     }
 #undef area
+
+    p_dvd->i_title = i_title <= tt_srpt->nr_of_srpts ? i_title : 1;
 #undef tt_srpt
 
-    p_input->stream.pp_areas[i_title]->i_part = i_chapter;
+    p_area = p_input->stream.pp_areas[p_dvd->i_title];
+    p_dvd->i_chapter = i_chapter;
 
-    p_area = p_input->stream.pp_areas[i_title];
+    p_dvd->i_chapter = i_chapter < p_area->i_part_nb ? i_chapter : 1;
+    p_area->i_part = p_dvd->i_chapter;
+    
+    p_dvd->i_angle = i_angle;
 
     /* set title, chapter, audio and subpic */
     if( DvdReadSetArea( p_input, p_area ) )
@@ -411,6 +415,8 @@ static int DvdReadOpen( struct input_thread_s *p_input )
 
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
+    p_input->psz_demux = "dvdread";
+
     return 0;
 }
 
@@ -440,6 +446,21 @@ static void DvdReadClose( struct input_thread_s *p_input )
 static int DvdReadSetProgram( input_thread_t * p_input,
                               pgrm_descriptor_t * p_program )
 {
+    if( p_input->stream.p_selected_program != p_program )
+    {
+        thread_dvd_data_t *  p_dvd;
+    
+        p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
+        p_dvd->i_angle = p_program->i_number;
+
+        memcpy( p_program, p_input->stream.p_selected_program,
+                sizeof(pgrm_descriptor_t) );
+        p_program->i_number = p_dvd->i_angle;
+        p_input->stream.p_selected_program = p_program;
+
+        intf_WarnMsg( 3, "dvd info: angle %d selected", p_dvd->i_angle );
+    }
+
     return 0;
 }
 
@@ -559,14 +580,11 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
          */
         p_dvd->i_angle_nb = p_vmg->tt_srpt->title[p_area->i_id-1].nr_of_angles;
 
-        if( p_dvd->i_angle > p_area->i_angle_nb )
+        if( p_dvd->i_angle > p_dvd->i_angle_nb )
         {
             p_dvd->i_angle = 1;
         }
 
-        p_area->i_angle = p_dvd->i_angle;
-        p_area->i_angle_nb = p_dvd->i_angle_nb;
-
         /*
          * We've got enough info, time to open the title set data.
          */
@@ -593,21 +611,35 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
             /* We don't use input_EndStream here since
              * we keep area structures */
 
-            for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
+            while( p_input->stream.i_es_number )
             {
-                input_UnselectES( p_input, p_input->stream.pp_selected_es[i] );
+                input_DelES( p_input, p_input->stream.pp_es[0] );
             }
 
-            free( p_input->stream.pp_selected_es );
-            input_DelProgram( p_input, p_input->stream.p_selected_program );
+            while( p_input->stream.i_pgrm_number )
+            {
+                input_DelProgram( p_input, p_input->stream.pp_programs[0] );
+            }
 
-            p_input->stream.pp_selected_es = NULL;
+            if( p_input->stream.pp_selected_es )
+            {
+                free( p_input->stream.pp_selected_es );
+                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 ) );
+        input_AddProgram( p_input, 1, sizeof( stream_ps_data_t ) );
         p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
 
+        for( i = 1 ; i < p_dvd->i_angle_nb ; i++ )
+        {
+            input_AddProgram( p_input, i+1, 0 );
+        }
+        
+        DvdReadSetProgram( p_input,
+                           p_input->stream.pp_programs[p_dvd->i_angle-1] ); 
+
         /* No PSM to read in DVD mode, we already have all information */
         p_input->stream.p_selected_program->b_is_ok = 1;
 
@@ -616,7 +648,7 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
         /* ES 0 -> video MPEG2 */
 //        IfoPrintVideo( p_dvd );
 
-        p_es = input_AddES( p_input, p_input->stream.p_selected_program, 0xe0, 0 );
+        p_es = input_AddES( p_input, NULL, 0xe0, 0 );
         p_es->i_stream_id = 0xe0;
         p_es->i_type = MPEG2_VIDEO_ES;
         p_es->i_cat = VIDEO_ES;
@@ -642,8 +674,7 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
                 {
                 case 0x00:              /* AC3 */
                     i_id = ( ( 0x80 + i_position ) << 8 ) | 0xbd;
-                    p_es = input_AddES( p_input,
-                               p_input->stream.p_selected_program, i_id, 0 );
+                    p_es = input_AddES( p_input, NULL, i_id, 0 );
                     p_es->i_stream_id = 0xbd;
                     p_es->i_type = AC3_AUDIO_ES;
                     p_es->b_audio = 1;
@@ -656,8 +687,7 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
                 case 0x02:
                 case 0x03:              /* MPEG audio */
                     i_id = 0xc0 + i_position;
-                    p_es = input_AddES( p_input,
-                                    p_input->stream.p_selected_program, i_id, 0 );
+                    p_es = input_AddES( p_input, NULL, i_id, 0 );
                     p_es->i_stream_id = i_id;
                     p_es->i_type = MPEG2_AUDIO_ES;
                     p_es->b_audio = 1;
@@ -670,8 +700,7 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
                 case 0x04:              /* LPCM */
 
                     i_id = ( ( 0xa0 + i_position ) << 8 ) | 0xbd;
-                    p_es = input_AddES( p_input,
-                                    p_input->stream.p_selected_program, i_id, 0 );
+                    p_es = input_AddES( p_input, NULL, i_id, 0 );
                     p_es->i_stream_id = i_id;
                     p_es->i_type = LPCM_AUDIO_ES;
                     p_es->b_audio = 1;
@@ -735,8 +764,7 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
                 }
 
                 i_id = ( ( 0x20 + i_position ) << 8 ) | 0xbd;
-                p_es = input_AddES( p_input,
-                                    p_input->stream.p_selected_program, i_id, 0 );
+                p_es = input_AddES( p_input, NULL, i_id, 0 );
                 p_es->i_stream_id = 0xbd;
                 p_es->i_type = DVD_SPU_ES;
                 p_es->i_cat = SPU_ES;
@@ -792,12 +820,6 @@ static int DvdReadSetArea( input_thread_t * p_input, input_area_t * p_area )
 #undef p_vts
 #undef p_vmg
 
-    if( p_area->i_angle != p_dvd->i_angle )
-    {
-        p_dvd->i_angle = p_area->i_angle;
-
-        intf_WarnMsg( 3, "dvd info: angle %d selected", p_area->i_angle );
-    }
     /* warn interface that something has changed */
     p_area->i_tell = LB2OFF( p_dvd->i_next_vobu ) - p_area->i_start;
     p_input->stream.b_seekable = 1;
@@ -1191,17 +1213,15 @@ static void DvdReadLauchDecoders( input_thread_t * p_input )
     if( p_main->b_audio )
     {
         /* For audio: first one if none or a not existing one specified */
-        int i_audio = config_GetIntVariable( INPUT_CHANNEL_VAR );
+        int i_audio = config_GetIntVariable( "input_channel" );
         if( i_audio < 0 /*|| i_audio > i_audio_nb*/ )
         {
-            config_PutIntVariable( INPUT_CHANNEL_VAR, 1 );
+            config_PutIntVariable( "input_channel", 1 );
             i_audio = 1;
         }
         if( i_audio > 0/* && i_audio_nb > 0*/ )
         {
-            if( config_GetIntVariable( AOUT_SPDIF_VAR ) ||
-                ( config_GetIntVariable( INPUT_AUDIO_VAR ) ==
-                  REQUESTED_AC3 ) )
+            if( config_GetIntVariable( "input_audio" ) == REQUESTED_AC3 )
             {
                 int     i_ac3 = i_audio;
                 while( ( p_input->stream.pp_es[i_ac3]->i_type !=
@@ -1227,10 +1247,10 @@ static void DvdReadLauchDecoders( input_thread_t * p_input )
     if( p_main->b_video )
     {
         /* for spu, default is none */
-        int i_spu = config_GetIntVariable( INPUT_SUBTITLE_VAR );
+        int i_spu = config_GetIntVariable( "input_subtitle" );
         if( i_spu < 0 /*|| i_spu > i_spu_nb*/ )
         {
-            config_PutIntVariable( INPUT_SUBTITLE_VAR, 0 );
+            config_PutIntVariable( "input_subtitle", 0 );
             i_spu = 0;
         }
         if( i_spu > 0 /*&& i_spu_nb > 0*/ )