static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, video_format_t *p_fmt_in, video_format_t *p_fmt_out ) { block_t *p_block; picture_t *p_pic; stream_t *p_stream = NULL; uint64_t i_size; p_stream = vlc_stream_NewMRL( p_image->p_parent, psz_url ); if( !p_stream ) { msg_Dbg( p_image->p_parent, "could not open %s for reading", psz_url ); return NULL; } if( vlc_stream_GetSize( p_stream, &i_size ) || i_size > SSIZE_MAX ) { msg_Dbg( p_image->p_parent, "could not read %s", psz_url ); goto error; } p_block = vlc_stream_Block( p_stream, i_size ); if( p_block == NULL ) goto error; if( !p_fmt_in->i_chroma ) { char *psz_mime = stream_ContentType( p_stream ); if( psz_mime != NULL ) { p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime ); free( psz_mime ); } } vlc_stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { /* Try to guess format from file name */ p_fmt_in->i_chroma = image_Ext2Fourcc( psz_url ); } p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out ); return p_pic; error: vlc_stream_Delete( p_stream ); return NULL; }
static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, video_format_t *p_fmt_in, video_format_t *p_fmt_out ) { block_t *p_block; picture_t *p_pic; stream_t *p_stream = NULL; 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", psz_url ); return NULL; } i_size = stream_Size( p_stream ); p_block = block_New( p_image->p_parent, i_size ); stream_Read( p_stream, p_block->p_buffer, i_size ); if( !p_fmt_in->i_chroma ) { char *psz_mime = NULL; stream_Control( p_stream, STREAM_GET_CONTENT_TYPE, &psz_mime ); if( psz_mime ) p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime ); free( psz_mime ); } stream_Delete( p_stream ); if( !p_fmt_in->i_chroma ) { /* Try to guess format from file name */ p_fmt_in->i_chroma = image_Ext2Fourcc( psz_url ); } p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out ); return p_pic; }
static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic, video_format_t *p_fmt_in, video_format_t *p_fmt_out, const char *psz_url ) { block_t *p_block; FILE *file; if( !p_fmt_out->i_chroma ) { /* Try to guess format from file name */ p_fmt_out->i_chroma = image_Ext2Fourcc( psz_url ); } file = vlc_fopen( psz_url, "wb" ); if( !file ) { msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); return VLC_EGENERIC; } p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out ); int err = 0; if( p_block ) { if( fwrite( p_block->p_buffer, p_block->i_buffer, 1, file ) != 1 ) err = errno; block_Release( p_block ); } if( fclose( file ) && !err ) err = errno; if( err ) { errno = err; msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); } return err ? VLC_EGENERIC : VLC_SUCCESS; }