]> git.sesse.net Git - vlc/blobdiff - modules/access/dvd/access.c
* Coding style cleanup: removed tabs and trailing spaces.
[vlc] / modules / access / dvd / access.c
index 79cd9345e87db5d1b02d497347d6d09bdad0dfa3..69e93d6ee199cb0c217f0cbd488a4ef622afffb3 100644 (file)
@@ -8,7 +8,7 @@
  *  -udf.* to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: access.c,v 1.5 2002/11/13 20:23:21 fenrir Exp $
+ * $Id: access.c,v 1.15 2003/12/22 14:32:55 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -16,7 +16,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -104,7 +104,7 @@ int E_(DVDOpen) ( vlc_object_t *p_this )
         return -1;
     }
     p_input->p_access_data = (void *)p_dvd;
-    
+
     p_input->pf_read = DVDRead;
     p_input->pf_seek = DVDSeek;
     p_input->pf_set_area = DVDSetArea;
@@ -116,15 +116,15 @@ int E_(DVDOpen) ( vlc_object_t *p_this )
         free( p_dvd );
         return -1;
     }
-    
-    /* 
+
+    /*
      * set up input
-     */ 
+     */
     p_input->i_mtu = 0;
 
     /* override environment variable DVDCSS_METHOD with config option
      * (FIXME: this creates a small memory leak) */
-    psz_dvdcss_env = config_GetPsz( p_input, "dvd-css-method" );
+    psz_dvdcss_env = config_GetPsz( p_input, "dvdcss-method" );
     if( psz_dvdcss_env && *psz_dvdcss_env )
     {
         char *psz_env;
@@ -146,9 +146,9 @@ int E_(DVDOpen) ( vlc_object_t *p_this )
 
     /*
      *  get plugin ready
-     */ 
+     */
     p_dvd->dvdhandle = dvdcss_open( psz_device );
-    
+
     /* free allocated string */
     free( psz_device );
 
@@ -205,41 +205,38 @@ int E_(DVDOpen) ( vlc_object_t *p_this )
      * is reserved for video_ts.vob */
     for( i = 1 ; i <= title_inf.i_title_nb ; i++ )
     {
-        input_AddArea( p_input );
-
         /* Titles are Program Chains */
-        area[i]->i_id = i;
+        input_AddArea( p_input, i, title_inf.p_attr[i-1].i_chapter_nb );
 
-        /* Absolute start offset and size 
+        /* Absolute start offset and size
          * We can only set that with vts ifo, so we do it during the
          * first call to DVDSetArea */
         area[i]->i_start = 0;
         area[i]->i_size = 0;
 
-        /* Number of chapters */
-        area[i]->i_part_nb = title_inf.p_attr[i-1].i_chapter_nb;
+        /* Default Chapter */
         area[i]->i_part = 1;
 
         /* Offset to vts_i_0.ifo */
         area[i]->i_plugin_data = p_dvd->p_ifo->i_start +
                        title_inf.p_attr[i-1].i_start_sector;
-    }   
+    }
 #undef area
-    
+
     p_dvd->i_title = p_dvd->i_title <= title_inf.i_title_nb ?
                      p_dvd->i_title : 1;
 #undef title_inf
 
     p_area = p_input->stream.pp_areas[p_dvd->i_title];
-    
+
     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_spu_nb = 0;
-    
+
     /* set title, chapter, audio and subpic */
     if( DVDSetArea( p_input, p_area ) < 0 )
     {
@@ -268,6 +265,13 @@ void E_(DVDClose) ( vlc_object_t *p_this )
     input_thread_t * p_input = (input_thread_t *)p_this;
     thread_dvd_data_t *p_dvd = (thread_dvd_data_t*)p_input->p_access_data;
 
+    /* This is a very nasty side-effect in the DVD plug-in : language
+     * selection here influences language selection of other streams. So
+     * unset those variables (may not be what the user wants).
+     * FIXME FIXME FIXME FIXME FIXME FIXME FIXME --Meuuh */
+    config_PutInt( p_input, "audio-channel", -1 );
+    config_PutInt( p_input, "spu-channel", -1 );
+
     IfoDestroy( p_dvd->p_ifo );
     dvdcss_close( p_dvd->dvdhandle );
     free( p_dvd );
@@ -277,13 +281,14 @@ void E_(DVDClose) ( vlc_object_t *p_this )
  * DVDSetProgram: used to change angle
  *****************************************************************************/
 static int DVDSetProgram( input_thread_t    * p_input,
-                          pgrm_descriptor_t * p_program ) 
+                          pgrm_descriptor_t * p_program )
 {
     if( p_input->stream.p_selected_program != p_program )
     {
         thread_dvd_data_t *  p_dvd;
         int                  i_angle;
-    
+        vlc_value_t          val;
+
         p_dvd   = (thread_dvd_data_t*)(p_input->p_access_data);
         i_angle = p_program->i_number;
 
@@ -317,6 +322,10 @@ static int DVDSetProgram( input_thread_t    * p_input,
         }
 #undef title
         msg_Dbg( p_input, "angle %d selected", p_dvd->i_angle );
+
+        /* Update the navigation variables without triggering a callback */
+        val.i_int = p_program->i_number;
+        var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
     }
 
     return 0;
@@ -342,7 +351,7 @@ static void DVDFlushStream( input_thread_t * p_input )
         {
             input_DelES( p_input, p_input->stream.pp_es[0] );
         }
-        
+
         while( p_input->stream.i_pgrm_number )
         {
             input_DelProgram( p_input, p_input->stream.pp_programs[0] );
@@ -367,7 +376,7 @@ static int DVDReadAngle( input_thread_t * p_input )
 
     p_dvd      = (thread_dvd_data_t*)(p_input->p_access_data);
     i_angle_nb = vmg.title_inf.p_attr[p_dvd->i_title-1].i_angle_nb;
-    
+
     input_AddProgram( p_input, 1, sizeof( stream_ps_data_t ) );
     p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
 
@@ -382,6 +391,7 @@ static int DVDReadAngle( input_thread_t * p_input )
 static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 {
     thread_dvd_data_t *  p_dvd;
+    vlc_value_t          val;
 
     p_dvd = (thread_dvd_data_t*)(p_input->p_access_data);
 
@@ -390,9 +400,10 @@ 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_first;
-        u32     i_last;
+        int i_vts_title;
+        uint32_t i_first;
+        uint32_t i_last;
+        unsigned int i;
 
         /* Reset the Chapter position of the old title */
         p_input->stream.p_selected_area->i_part = 1;
@@ -459,16 +470,16 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 
         /* Destroy obsolete ES by reinitializing programs */
         DVDFlushStream( p_input );
-        
+
         /* Angle management: angles are handled through programs */
         p_dvd->i_angle_nb = DVDReadAngle( p_input );
         if( ( p_dvd->i_angle <= 0 ) || p_dvd->i_angle > p_dvd->i_angle_nb )
         {
             p_dvd->i_angle = 1;
         }
-       
+
         DVDSetProgram( p_input,
-                       p_input->stream.pp_programs[p_dvd->i_angle-1] ); 
+                       p_input->stream.pp_programs[p_dvd->i_angle-1] );
 
         msg_Dbg( p_input, "title first %i, last %i, size %i",
                           i_first, i_last, i_last + 1 - p_dvd->i_vts_lb );
@@ -481,12 +492,22 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
         DVDReadVideo( p_input );
         DVDReadAudio( p_input );
         DVDReadSPU  ( p_input );
-   
+
         if( p_input->p_demux )
         {
             DVDLaunchDecoders( p_input );
         }
 
+        /* Update the navigation variables without triggering a callback */
+        val.i_int = p_area->i_id;
+        var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
+        var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
+        for( i = 1; i <= p_area->i_part_nb; i++ )
+        {
+            val.i_int = i;
+            var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, NULL );
+        }
+
     } /* i_title >= 0 */
     else
     {
@@ -495,13 +516,17 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 
     /* Chapter selection */
     p_dvd->i_chapter = DVDSetChapter( p_dvd, p_area->i_part );
-    
+
     p_input->stream.p_selected_area->i_tell = DVDTell;
 
     /* warn interface that something has changed */
     p_input->stream.b_seekable = 1;
     p_input->stream.b_changed  = 1;
 
+    /* Update the navigation variables without triggering a callback */
+    val.i_int = p_area->i_part;
+    var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
+
     return 0;
 }
 #undef vts
@@ -509,7 +534,7 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
 
 #define title \
     p_dvd->p_ifo->vts.title_unit.p_title[p_dvd->i_title_id-1].title
-    
+
 /*****************************************************************************
  * DVDRead: reads data packets.
  *****************************************************************************
@@ -596,7 +621,7 @@ static ssize_t DVDRead( input_thread_t * p_input,
 static void DVDSeek( input_thread_t * p_input, off_t i_off )
 {
     thread_dvd_data_t *     p_dvd;
-    
+
     p_dvd = ( thread_dvd_data_t * )(p_input->p_access_data);
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
@@ -606,7 +631,7 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
 
     p_dvd->i_prg_cell = Lb2CellPrg( p_dvd );
     p_dvd->i_map_cell = Lb2CellMap( p_dvd );
-    
+
     if( CellIsInterleaved( p_dvd ) )
     {
         /* if we're inside a multi-angle zone, we have to choose i_sector
@@ -614,7 +639,7 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
          * can be very wide out of such zones */
         p_dvd->i_vts_lb = CellFirstSector( p_dvd );
     }
-    
+
     p_dvd->i_last_lb  = CellLastSector( p_dvd );
     p_dvd->i_chapter  = CellPrg2Chapter( p_dvd );
 
@@ -694,7 +719,7 @@ static char * DVDParse( input_thread_t * p_input )
         {
             psz_parser++;
         }
-        
+
         if( *psz_parser == '@' )
         {
             /* found end of raw device, and beginning of options */
@@ -766,8 +791,8 @@ static char * DVDParse( input_thread_t * p_input )
             else
             {
                 char * psz_env;
-                
-#ifndef WIN32    
+
+#ifndef WIN32
                 if( !S_ISCHR(stat_info.st_mode) )
                 {
                     msg_Warn( p_input, "raw device %s is"
@@ -791,11 +816,11 @@ static char * DVDParse( input_thread_t * p_input )
             psz_raw = "";
         }
     }
-    
+
     if( !*psz_device )
     {
         free( psz_device );
-        
+
         if( !p_input->psz_access )
         {
             /* no device and no access specified: we probably don't want DVD */
@@ -804,16 +829,16 @@ static char * DVDParse( input_thread_t * p_input )
         psz_device = config_GetPsz( p_input, "dvd" );
     }
 
-#ifndef WIN32    
+#ifndef WIN32
     /* check block device */
     if( stat( psz_device, &stat_info ) == -1 )
     {
-        msg_Err( p_input, "cannot stat() device `%s' (%s)",
-                          psz_device, strerror(errno));
+        msg_Warn( p_input, "cannot stat() device `%s' (%s)",
+                  psz_device, strerror(errno));
         free( psz_device );
-        return NULL;                    
+        return NULL;
     }
-    
+
     if( !S_ISBLK(stat_info.st_mode) && !S_ISCHR(stat_info.st_mode) )
     {
         msg_Warn( p_input,
@@ -822,10 +847,10 @@ static char * DVDParse( input_thread_t * p_input )
         return NULL;
     }
 #endif
-    
+
     msg_Dbg( p_input, "dvd=%s raw=%s title=%d chapter=%d angle=%d",
                       psz_device, psz_raw, p_dvd->i_title,
                       p_dvd->i_chapter, p_dvd->i_angle );
 
     return psz_device;
-} 
+}