]> git.sesse.net Git - vlc/blobdiff - modules/access/cdda/access.c
Another time "Remove useless test before a free".
[vlc] / modules / access / cdda / access.c
index f876d37db878ddea086296afccba839c7c960128..087647b5a4839d804a8fa9c95948e5a19651735f 100644 (file)
 #include "callback.h"      /* FIXME - reorganize callback.h, cdda.h better */
 #include "cdda.h"          /* private structures. Also #includes vlc things */
 #include "info.h"          /* headers for meta info retrieval */
+#include "access.h"
 #include <vlc_playlist.h>  /* Has to come *after* cdda.h */
 #include "vlc_keys.h"
+#include <vlc_interface.h>
 
 #include <cdio/cdio.h>
 #include <cdio/logging.h>
 #include <cdio/cd_types.h>
 
-#include <stdio.h>
 
 /* #ifdef variables below are defined via config.h via #include vlc above. */
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
@@ -61,7 +55,7 @@ access_t *p_cdda_input = NULL;
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int      CDDARead( access_t *, uint8_t *, int );
+static ssize_t  CDDARead( access_t *, uint8_t *, size_t );
 static block_t *CDDAReadBlocks( access_t * p_access );
 static int      CDDASeek( access_t * p_access, int64_t i_pos );
 static int      CDDAControl( access_t *p_access, int i_query,
@@ -74,7 +68,7 @@ static int      CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
  * Private functions
  ****************************************************************************/
 
-/* process messages that originate from libcdio. 
+/* process messages that originate from libcdio.
    called by CDDAOpen
 */
 static void
@@ -90,17 +84,17 @@ cdio_log_handler( cdio_log_level_t level, const char message[] )
         case CDIO_LOG_DEBUG:
         case CDIO_LOG_INFO:
             if (p_cdda->i_debug & INPUT_DBG_CDIO)
-            msg_Dbg( p_cdda_input, message);
+            msg_Dbg( p_cdda_input, "%s", message);
             break;
         case CDIO_LOG_WARN:
-            msg_Warn( p_cdda_input, message);
+            msg_Warn( p_cdda_input, "%s", message);
             break;
         case CDIO_LOG_ERROR:
         case CDIO_LOG_ASSERT:
-            msg_Err( p_cdda_input, message);
+            msg_Err( p_cdda_input, "%s", message);
             break;
         default:
-            msg_Warn( p_cdda_input, message,
+            msg_Warn( p_cdda_input, "%s\n%s %d", message,
                     "the above message had unknown cdio log level",
                     level);
             break;
@@ -166,7 +160,7 @@ uninit_log_handler( cdio_log_level_t level, const char message[] )
     /* gl_default_cdio_log_handler (level, message); */
 }
 
-/* Only used in audio control mode. Gets the current LSN from the 
+/* Only used in audio control mode. Gets the current LSN from the
    CD-ROM drive. */
 static int64_t get_audio_position ( access_t *p_access )
 {
@@ -202,10 +196,10 @@ static int64_t get_audio_position ( access_t *p_access )
     else
     {
         i_offset = p_cdda->i_lsn;
+    }
 #else
         i_offset = p_cdda->i_lsn;
 #endif
-    }
     return i_offset;
 }
 
@@ -221,7 +215,7 @@ static block_t * CDDAReadBlocks( access_t * p_access )
     cdda_data_t *p_cdda   = (cdda_data_t *) p_access->p_sys;
     int          i_blocks = p_cdda->i_blocks_per_read;
 
-    dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN), 
+    dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
                 "called i_lsn: %d i_pos: %lld, size: %lld",
                 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
 
@@ -289,6 +283,9 @@ static block_t * CDDAReadBlocks( access_t * p_access )
     {
         msg_Err( p_access, "cannot get a new block of size: %i",
                 i_blocks * CDIO_CD_FRAMESIZE_RAW );
+        intf_UserFatal( p_access, VLC_FALSE, _("CD reading failed"),
+                        _("VLC could not get a new block of size: %i."),
+                        i_blocks * CDIO_CD_FRAMESIZE_RAW );
         return NULL;
     }
 
@@ -309,8 +306,8 @@ static block_t * CDDAReadBlocks( access_t * p_access )
                     msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
                              psz_err ? psz_err: "" );
 
-                if( psz_err ) free( psz_err );
-                if( psz_mes ) free( psz_mes );
+                free( psz_err );
+                free( psz_mes );
                 if( !p_readbuf )
                 {
                     msg_Err( p_access, "paranoia read error on frame %i\n",
@@ -357,8 +354,8 @@ static block_t * CDDAReadBlocks( access_t * p_access )
 /*****************************************************************************
  * CDDARead: Handler for audio control reads the CD-DA.
  *****************************************************************************/
-static int
-CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
+static ssize_t
+CDDARead( access_t * p_access, uint8_t *p_buffer, size_t i_len )
 {
     cdda_data_t *p_cdda   = (cdda_data_t *) p_access->p_sys;
 
@@ -403,7 +400,7 @@ CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
         {
             char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
             input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
-            free(psz_title);
+            free( psz_title );
         }
         else
         {
@@ -508,6 +505,7 @@ static int CDDASeek( access_t * p_access, int64_t i_pos )
     }
 
     p_access->info.i_pos = i_pos;
+    p_access->info.b_eof = VLC_FALSE;
     return VLC_SUCCESS;
 }
 
@@ -531,7 +529,7 @@ static bool cdda_play_track( access_t *p_access, track_t i_track )
     p_cdda->i_track = i_track;
 
     /* set up the frame boundaries for this particular track */
-    p_cdda->first_frame = p_cdda->i_lsn = 
+    p_cdda->first_frame = p_cdda->i_lsn =
     cdio_get_track_lsn( p_cdda->p_cdio, i_track );
 
     p_cdda->last_frame  = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
@@ -630,8 +628,7 @@ int CDDAOpen( vlc_object_t *p_this )
     if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
     {
         msg_Warn( p_access, "could not open %s", psz_source );
-        if ( psz_source )
-            free( psz_source );
+        free( psz_source );
         return VLC_EGENERIC;
     }
 
@@ -738,13 +735,13 @@ int CDDAOpen( vlc_object_t *p_this )
         char *psz_paranoia = config_GetPsz( p_access,
                                 MODULE_STRING "-paranoia" );
 
-        p_cdda->e_paranoia = paranoia_none;
+        p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
         if( psz_paranoia && *psz_paranoia )
         {
             if( !strncmp( psz_paranoia, "full", strlen("full") ) )
-                p_cdda->e_paranoia = paranoia_full;
+                p_cdda->e_paranoia = PARANOIA_MODE_FULL;
             else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
-                p_cdda->e_paranoia = paranoia_overlap;
+                p_cdda->e_paranoia = PARANOIA_MODE_OVERLAP;
 
             /* Use CD Paranoia? */
             if( p_cdda->e_paranoia )
@@ -759,7 +756,7 @@ int CDDAOpen( vlc_object_t *p_this )
                 {
                     msg_Warn( p_cdda_input, "unable to get paranoia support - "
                                 "continuing without it." );
-                    p_cdda->e_paranoia = paranoia_none;
+                    p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
                 }
                 else
                 {
@@ -770,7 +767,7 @@ int CDDAOpen( vlc_object_t *p_this )
                     /* Set reading mode for full or overlap paranoia,
                      * but allow skipping sectors. */
                     cdio_paranoia_modeset( p_cdda->paranoia,
-                        paranoia_full == p_cdda->e_paranoia ?
+                            PARANOIA_MODE_FULL == p_cdda->e_paranoia ?
                             PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
                             PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
                 }
@@ -811,7 +808,7 @@ int CDDAOpen( vlc_object_t *p_this )
 
  error:
     cdio_destroy( p_cdda->p_cdio );
-    if( psz_source) free( psz_source );
+    free( psz_source );
     if( p_cdda )
     {
         if ( p_cdda->p_input )
@@ -859,8 +856,8 @@ void CDDAClose (vlc_object_t *p_this )
         cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
 #endif
 
-    if( p_cdda->psz_mcn )    free( p_cdda->psz_mcn );
-    if( p_cdda->psz_source ) free( p_cdda->psz_source );
+    free( p_cdda->psz_mcn );
+    free( p_cdda->psz_source );
 
 #if LIBCDDB_VERSION_NUM >= 1
     libcddb_shutdown();
@@ -891,8 +888,8 @@ static int CDDAControl( access_t *p_access, int i_query, va_list args )
          */
         case ACCESS_GET_META:
         {
-            vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
 #if 0
+            vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
             if( p_cdda->p_meta )
             {
                 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
@@ -1008,7 +1005,7 @@ static int CDDAControl( access_t *p_access, int i_query, va_list args )
                     char *psz_title = CDDAFormatTitle( p_access, i_track );
                     input_Control( p_cdda->p_input, INPUT_SET_NAME,
                                    psz_title );
-                    free(psz_title);
+                    free( psz_title );
                     p_cdda->i_track = i_track;
                     i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
                                                 CDIO_CDROM_LEADOUT_TRACK );
@@ -1096,7 +1093,7 @@ static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
     return VLC_SUCCESS;
 }
 
-/* 
+/*
  * Local variables:
  *  mode: C
  *  style: gnu