]> git.sesse.net Git - vlc/blobdiff - src/misc/image.c
Remove useless test before freeing something.
[vlc] / src / misc / image.c
index f788a4d052338e0302e11d51ddbf5f7d0a499975..3ea118a6982ec961622171a44634e3e77498ed9c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * image.c : wrapper for image reading/writing facilities
  *****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004-2007 the VideoLAN team
  * $Id$
  *
  * Author: Gildas Bazin <gbazin@videolan.org>
  * Preamble
  *****************************************************************************/
 #include <ctype.h>
+#include <errno.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
+#include <vlc_codec.h>
 #include <vlc_filter.h>
+#include <vlc_es.h>
 #include <vlc_image.h>
 #include <vlc_stream.h>
-#include <charset.h>
+#include <vlc_charset.h>
 
 static picture_t *ImageRead( image_handler_t *, block_t *,
                              video_format_t *, video_format_t * );
@@ -97,6 +103,7 @@ void image_HandlerDelete( image_handler_t *p_image )
     if( p_image->p_filter ) DeleteFilter( p_image->p_filter );
 
     free( p_image );
+    p_image = NULL;
 }
 
 /**
@@ -209,6 +216,7 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
     int i_size;
 
     p_stream = stream_UrlNew( p_image->p_parent, psz_url );
+
     if( !p_stream )
     {
         msg_Dbg( p_image->p_parent, "could not open %s for reading",
@@ -239,7 +247,7 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
  *
  */
 
-void PicRelease( picture_t *p_pic ){};
+static void PicRelease( picture_t *p_pic ) { (void)p_pic; }
 
 static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
                             video_format_t *p_fmt_in,
@@ -348,22 +356,30 @@ static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic,
     file = utf8_fopen( psz_url, "wb" );
     if( !file )
     {
-        msg_Dbg( p_image->p_parent, "could not open file %s for writing",
-                 psz_url );
+        msg_Err( p_image->p_parent, "%s: %m", psz_url );
         return VLC_EGENERIC;
     }
 
     p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out );
 
+    int err = 0;
     if( p_block )
     {
-        fwrite( p_block->p_buffer, sizeof(char), p_block->i_buffer, file );
+        if( fwrite( p_block->p_buffer, p_block->i_buffer, 1, file ) != 1 )
+            err = errno;
         block_Release( p_block );
     }
 
-    fclose( file );
+    if( fclose( file ) && !err )
+        err = errno;
+
+    if( err )
+    {
+       errno = err;
+       msg_Err( p_image->p_parent, "%s: %m", psz_url );
+    }
 
-    return p_block ? VLC_SUCCESS : VLC_EGENERIC;
+    return err ? VLC_EGENERIC : VLC_SUCCESS;
 }
 
 /**
@@ -407,7 +423,7 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
     {
         /* We need to restart a new filter */
         DeleteFilter( p_image->p_filter );
-        p_image->p_filter = 0;
+        p_image->p_filter = NULL;
     }
 
     /* Start a filter */
@@ -442,6 +458,7 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
         p_fmt_in->i_height == p_fmt_out->i_height )
     {
         /* Duplicate image */
+        p_pif->pf_release( p_pif ); /* XXX: Better fix must be possible */
         p_pif = p_image->p_filter->pf_vout_buffer_new( p_image->p_filter );
         if( p_pif ) vout_CopyPicture( p_image->p_parent, p_pif, p_pic );
     }
@@ -497,7 +514,7 @@ static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic,
 static struct
 {
     vlc_fourcc_t i_codec;
-    char *psz_ext;
+    const char *psz_ext;
 
 } ext_table[] =
 {
@@ -560,9 +577,12 @@ static const char *Fourcc2Ext( vlc_fourcc_t i_codec )
 
 static void video_release_buffer( picture_t *p_pic )
 {
-    if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
-    if( p_pic && p_pic->p_sys ) free( p_pic->p_sys );
-    if( p_pic ) free( p_pic );
+    if( p_pic )
+    {
+        free( p_pic->p_data_orig );
+        free( p_pic->p_sys );
+        free( p_pic );
+    }
 }
 
 static picture_t *video_new_buffer( decoder_t *p_dec )
@@ -591,17 +611,23 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
 
 static void video_del_buffer( decoder_t *p_dec, picture_t *p_pic )
 {
-    if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
-    if( p_pic && p_pic->p_sys ) free( p_pic->p_sys );
-    if( p_pic ) free( p_pic );
+    (void)p_dec;
+    if( p_pic )
+    {
+        free( p_pic->p_data_orig );
+        free( p_pic->p_sys );
+        free( p_pic );
+    }
 }
 
 static void video_link_picture( decoder_t *p_dec, picture_t *p_pic )
 {
+    (void)p_dec; (void)p_pic;
 }
 
 static void video_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
 {
+    (void)p_dec; (void)p_pic;
 }
 
 static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt )
@@ -652,7 +678,8 @@ static void DeleteDecoder( decoder_t * p_dec )
     es_format_Clean( &p_dec->fmt_in );
     es_format_Clean( &p_dec->fmt_out );
 
-    vlc_object_destroy( p_dec );
+    vlc_object_release( p_dec );
+    p_dec = NULL;
 }
 
 static encoder_t *CreateEncoder( vlc_object_t *p_this, video_format_t *fmt_in,
@@ -734,7 +761,8 @@ static void DeleteEncoder( encoder_t * p_enc )
     es_format_Clean( &p_enc->fmt_in );
     es_format_Clean( &p_enc->fmt_out );
 
-    vlc_object_destroy( p_enc );
+    vlc_object_release( p_enc );
+    p_enc = NULL;
 }
 
 static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in,
@@ -755,8 +783,8 @@ static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in,
     p_filter->fmt_out = *p_fmt_in;
     p_filter->fmt_out.i_codec = p_fmt_out->i_chroma;
     p_filter->fmt_out.video = *p_fmt_out;
-    p_filter->p_module = module_Need( p_filter, "video filter2", psz_module,
-                                      0 );
+    p_filter->p_module = module_Need( p_filter, "video filter2",
+                                      psz_module, 0 );
 
     if( !p_filter->p_module )
     {
@@ -777,5 +805,6 @@ static void DeleteFilter( filter_t * p_filter )
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
 
-    vlc_object_destroy( p_filter );
+    vlc_object_release( p_filter );
+    p_filter = NULL;
 }