]> git.sesse.net Git - vlc/blobdiff - modules/access/vcd/vcd.c
* modules/access/*: strings review + coding style fixes.
[vlc] / modules / access / vcd / vcd.c
index 8e4b7af7dd5538c4f21254e422795101d9f73f62..124ec647e4e24059d09696cccf2553fd58651741 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * vcd.c : VCD input module for vlc
  *****************************************************************************
- * Copyright (C) 2000 VideoLAN
- * $Id: vcd.c,v 1.15 2003/02/12 17:13:33 jobi Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id: vcd.c,v 1.25 2004/01/25 17:31:22 gbazin Exp $
  *
  * Author: Johan Bilien <jobi@via.ecp.fr>
  *
@@ -38,7 +38,7 @@
 
 #include <string.h>
 
-#include "vcd.h"
+#include "cdrom.h"
 
 /* how many blocks VCDRead will read in each loop */
 #define VCD_BLOCKS_ONCE 20
@@ -76,7 +76,7 @@ static int  VCDEntryPoints  ( input_thread_t * );
  * Module descriptior
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("VCD input module") );
+    set_description( _("VCD input") );
     set_capability( "access", 80 );
     set_callbacks( VCDOpen, VCDClose );
     add_shortcut( "svcd" );
@@ -101,17 +101,7 @@ static int VCDOpen( vlc_object_t *p_this )
     input_area_t *          p_area;
     int                     i_title = 1;
     int                     i_chapter = 1;
-
-    p_input->pf_read = VCDRead;
-    p_input->pf_seek = VCDSeek;
-    p_input->pf_set_area = VCDSetArea;
-    p_input->pf_set_program = VCDSetProgram;
-
-#ifdef WIN32
-    /* On Win32 we want the VCD access plugin to be explicitly requested,
-     * we end up with lots of problems otherwise */
-    if( !p_input->psz_access || !*p_input->psz_access ) return( -1 );
-#endif
+    vcddev_t                *vcddev;
 
     /* parse the options passed in command line : */
     psz_orig = psz_parser = psz_source = strdup( p_input->psz_name );
@@ -139,8 +129,8 @@ static int VCDOpen( vlc_object_t *p_this )
             i_chapter = (int)strtol( psz_parser, &psz_next, 10 );
         }
 
-        i_title = i_title ? i_title : 1;
-        i_chapter = i_chapter ? i_chapter : 1;
+        i_title = i_title > 0 ? i_title : 1;
+        i_chapter = i_chapter > 0 ? i_chapter : 1;
     }
 
     if( !*psz_source )
@@ -154,41 +144,38 @@ static int VCDOpen( vlc_object_t *p_this )
         if( !psz_source ) return -1;
     }
 
-    p_vcd = malloc( sizeof(thread_vcd_data_t) );
+    /* Open VCD */
+    if( !(vcddev = ioctl_Open( p_this, psz_source )) )
+    {
+        msg_Warn( p_input, "could not open %s", psz_source );
+        free( psz_source );
+        return -1;
+    }
 
+    p_vcd = malloc( sizeof(thread_vcd_data_t) );
     if( p_vcd == NULL )
     {
         msg_Err( p_input, "out of memory" );
         free( psz_source );
         return -1;
     }
+    free( psz_source );
 
+    p_vcd->vcddev = vcddev;
     p_input->p_access_data = (void *)p_vcd;
 
     p_input->i_mtu = VCD_DATA_ONCE;
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
-
     p_input->stream.b_pace_control = 1;
     p_input->stream.b_seekable = 1;
-    p_input->stream.b_connected = 1;
     p_input->stream.p_selected_area->i_size = 0;
     p_input->stream.p_selected_area->i_tell = 0;
-
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    if( !(p_vcd->vcddev = ioctl_Open( p_this, psz_source )) )
-    {
-        msg_Warn( p_input, "could not open %s", psz_source );
-        free( psz_source );
-        free( p_vcd );
-        return -1;
-    }
-
     /* We read the Table Of Content information */
     p_vcd->i_nb_tracks = ioctl_GetTracksMap( VLC_OBJECT(p_input),
                                            p_vcd->vcddev, &p_vcd->p_sectors );
-    free( psz_source );
     if( p_vcd->i_nb_tracks < 0 )
         msg_Err( p_input, "unable to count tracks" );
     else if( p_vcd->i_nb_tracks <= 1 )
@@ -222,20 +209,17 @@ static int VCDOpen( vlc_object_t *p_this )
     p_input->stream.i_area_nb = 1;
 
 #define area p_input->stream.pp_areas
-    for( i = 1 ; i <= p_vcd->i_nb_tracks - 1 ; i++ )
+    for( i = 1 ; i < p_vcd->i_nb_tracks; i++ )
     {
-        input_AddArea( p_input );
-
         /* Titles are Program Chains */
-        area[i]->i_id = i;
+        input_AddArea( p_input, i, 1 );
 
         /* Absolute start offset and size */
         area[i]->i_start = (off_t)p_vcd->p_sectors[i] * (off_t)VCD_DATA_SIZE;
         area[i]->i_size = (off_t)(p_vcd->p_sectors[i+1] - p_vcd->p_sectors[i])
                            * (off_t)VCD_DATA_SIZE;
 
-        /* Number of chapters */
-        area[i]->i_part_nb = 1;   /* will be the entry points */
+        /* Default Chapter */
         area[i]->i_part = 1;
 
         /* i_plugin_data is used to store which entry point is the first
@@ -244,7 +228,7 @@ static int VCDOpen( vlc_object_t *p_this )
     }
 #undef area
 
-    p_area = p_input->stream.pp_areas[i_title];
+    p_area = p_input->stream.pp_areas[__MIN(i_title,p_vcd->i_nb_tracks -1)];
 
     p_vcd->b_valid_ep = 1;
     if( VCDEntryPoints( p_input ) < 0 )
@@ -262,6 +246,11 @@ static int VCDOpen( vlc_object_t *p_this )
         p_input->psz_demux = "ps";
     }
 
+    p_input->pf_read = VCDRead;
+    p_input->pf_seek = VCDSeek;
+    p_input->pf_set_area = VCDSetArea;
+    p_input->pf_set_program = VCDSetProgram;
+
     return 0;
 }
 
@@ -302,8 +291,9 @@ static int VCDRead( input_thread_t * p_input, byte_t * p_buffer,
 
     for ( i_index = 0 ; i_index < i_blocks ; i_index++ )
     {
-        if ( ioctl_ReadSector( VLC_OBJECT(p_input), p_vcd->vcddev,
-                    p_vcd->i_sector, p_buffer + i_index * VCD_DATA_SIZE ) < 0 )
+        if ( ioctl_ReadSectors( VLC_OBJECT(p_input), p_vcd->vcddev,
+             p_vcd->i_sector, p_buffer + i_index * VCD_DATA_SIZE, 1,
+             VCD_TYPE ) < 0 )
         {
             msg_Err( p_input, "could not read sector %d", p_vcd->i_sector );
             return -1;
@@ -344,8 +334,15 @@ static int VCDRead( input_thread_t * p_input, byte_t * p_buffer,
             if( i_entry + 1 < p_vcd->i_entries_nb &&
                     p_vcd->i_sector >= p_vcd->p_entries[i_entry + 1] )
             {
+                vlc_value_t val;
+
                 msg_Dbg( p_input, "new chapter" );
                 p_input->stream.p_selected_area->i_part ++;
+
+                /* Update the navigation variables without triggering
+                 * a callback */
+                val.i_int = p_input->stream.p_selected_area->i_part;
+                var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
             }
             vlc_mutex_unlock( &p_input->stream.stream_lock );
         }
@@ -355,8 +352,8 @@ static int VCDRead( input_thread_t * p_input, byte_t * p_buffer,
 
     if ( i_len % VCD_DATA_SIZE ) /* this should not happen */
     {
-        if ( ioctl_ReadSector( VLC_OBJECT(p_input), p_vcd->vcddev,
-                               p_vcd->i_sector, p_last_sector ) < 0 )
+        if ( ioctl_ReadSectors( VLC_OBJECT(p_input), p_vcd->vcddev,
+             p_vcd->i_sector, p_last_sector, 1, VCD_TYPE ) < 0 )
         {
             msg_Err( p_input, "could not read sector %d", p_vcd->i_sector );
             return -1;
@@ -370,7 +367,6 @@ static int VCDRead( input_thread_t * p_input, byte_t * p_buffer,
     return i_read;
 }
 
-
 /*****************************************************************************
  * VCDSetProgram: Does nothing since a VCD is mono_program
  *****************************************************************************/
@@ -380,7 +376,6 @@ static int VCDSetProgram( input_thread_t * p_input,
     return 0;
 }
 
-
 /*****************************************************************************
  * VCDSetArea: initialize input data for title x, chapter y.
  * It should be called for each user navigation request.
@@ -388,6 +383,7 @@ static int VCDSetProgram( input_thread_t * p_input,
 static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
 {
     thread_vcd_data_t *     p_vcd;
+    vlc_value_t val;
 
     p_vcd = (thread_vcd_data_t*)p_input->p_access_data;
 
@@ -396,6 +392,8 @@ static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
 
     if( p_area != p_input->stream.p_selected_area )
     {
+        unsigned int i;
+
         /* Reset the Chapter position of the current title */
         p_input->stream.p_selected_area->i_part = 1;
         p_input->stream.p_selected_area->i_tell = 0;
@@ -407,6 +405,16 @@ static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
         /* The first track is not a valid one  */
         p_vcd->i_track = p_area->i_id;
         p_vcd->i_sector = p_vcd->p_sectors[p_vcd->i_track];
+
+        /* 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 );
+        }
     }
 
     if( p_vcd->b_valid_ep )
@@ -427,10 +435,13 @@ static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
     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;
 }
 
-
 /****************************************************************************
  * VCDSeek
  ****************************************************************************/
@@ -449,12 +460,19 @@ static void VCDSeek( input_thread_t * p_input, off_t i_off )
     /* Find chapter */
     if( p_vcd->b_valid_ep )
     {
-        for( i_index = 0 ; i_index < p_area->i_part_nb - 1 ; i_index ++ )
+        for( i_index = 2 ; i_index <= p_area->i_part_nb; i_index ++ )
         {
             if( p_vcd->i_sector < p_vcd->p_entries[p_area->i_plugin_data
-                + i_index + 1] )
+                + i_index - 1] )
             {
-                p_area->i_part = i_index;
+                vlc_value_t val;
+
+                p_area->i_part = i_index - 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 );
                 break;
             }
         }
@@ -488,8 +506,8 @@ static int VCDEntryPoints( input_thread_t * p_input )
         return -1;
     }
 
-    if( ioctl_ReadSector( VLC_OBJECT(p_input), p_vcd->vcddev,
-                                VCD_ENTRIES_SECTOR, p_sector ) < 0 )
+    if( ioctl_ReadSectors( VLC_OBJECT(p_input), p_vcd->vcddev,
+        VCD_ENTRIES_SECTOR, p_sector, 1, VCD_TYPE ) < 0 )
     {
         msg_Err( p_input, "could not read entry points sector" );
         free( p_sector );
@@ -523,6 +541,15 @@ static int VCDEntryPoints( input_thread_t * p_input )
     p_vcd->i_entries_nb = 0;
 
 #define i_track BCD_TO_BIN(entries.entry[i].i_track)
+    /* Reset the i_part_nb for each track */
+    for( i = 0 ; i < i_nb ; i++ )
+    {
+        if( i_track <= p_input->stream.i_area_nb )
+        {
+            p_input->stream.pp_areas[i_track-1]->i_part_nb = 0;
+        }
+    }
+
     for( i = 0 ; i < i_nb ; i++ )
     {
         if( i_track <= p_input->stream.i_area_nb )
@@ -540,6 +567,9 @@ static int VCDEntryPoints( input_thread_t * p_input )
                                                             i_entry_index;
                 i_previous_track = i_track;
             }
+            msg_Dbg( p_input, "entry point %i begins at LBA: %i",
+                     i_entry_index, p_vcd->p_entries[i_entry_index] );
+
             i_entry_index ++;
             p_vcd->i_entries_nb ++;
         }