/*****************************************************************************
* 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>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/**
* 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 <vlc_charset.h>
static picture_t *ImageRead( image_handler_t *, block_t *,
video_format_t *, video_format_t * );
if( p_image->p_filter ) DeleteFilter( p_image->p_filter );
free( p_image );
+ p_image = NULL;
}
/**
{
block_t *p_block;
picture_t *p_pic;
- FILE *file;
+ stream_t *p_stream = NULL;
int i_size;
- file = fopen( psz_url, "rb" );
- if( !file )
+ p_stream = stream_UrlNew( p_image->p_parent, psz_url );
+
+ if( !p_stream )
{
- msg_Dbg( p_image->p_parent, "could not open file %s for reading",
+ msg_Dbg( p_image->p_parent, "could not open %s for reading",
psz_url );
return NULL;
}
- fseek( file, 0, SEEK_END );
- i_size = ftell( file );
- fseek( file, 0, SEEK_SET );
+ i_size = stream_Size( p_stream );
p_block = block_New( p_image->p_parent, i_size );
- fread( p_block->p_buffer, sizeof(char), i_size, file );
- fclose( file );
+
+ stream_Read( p_stream, p_block->p_buffer, i_size );
+ stream_Delete( p_stream );
if( !p_fmt_in->i_chroma )
{
*
*/
-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,
p_image->p_enc->fmt_in.video.i_width != p_fmt_in->i_width ||
p_image->p_enc->fmt_in.video.i_height != p_fmt_in->i_height )
{
- picture_t *p_pif;
+ picture_t *p_tmp_pic;
if( p_image->p_filter )
if( p_image->p_filter->fmt_in.video.i_chroma != p_fmt_in->i_chroma ||
pf_release = p_pic->pf_release;
p_pic->pf_release = PicRelease; /* Small hack */
- p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
+ p_tmp_pic =
+ p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
p_pic->pf_release = pf_release;
- p_pic = p_pif;
- }
- p_block = p_image->p_enc->pf_encode_video( p_image->p_enc, p_pic );
+ p_block = p_image->p_enc->pf_encode_video( p_image->p_enc, p_tmp_pic );
+
+ p_image->p_filter->pf_vout_buffer_del( p_image->p_filter, p_tmp_pic );
+ }
+ else
+ {
+ p_block = p_image->p_enc->pf_encode_video( p_image->p_enc, p_pic );
+ }
if( !p_block )
{
p_fmt_out->i_chroma = Ext2Fourcc( psz_url );
}
- file = fopen( psz_url, "wb" );
+ 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;
- return p_block ? VLC_SUCCESS : VLC_EGENERIC;
+ if( err )
+ {
+ errno = err;
+ msg_Err( p_image->p_parent, "%s: %m", psz_url );
+ }
+
+ return err ? VLC_EGENERIC : VLC_SUCCESS;
}
/**
{
/* 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 */
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 );
}
static struct
{
vlc_fourcc_t i_codec;
- char *psz_ext;
+ const char *psz_ext;
} ext_table[] =
{
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 )
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 )
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,
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,
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 )
{
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;
}