[vlc-devel] commit: Use pictures reference counting ( Rafaël Carré )
git version control
git at videolan.org
Tue May 20 15:21:46 CEST 2008
vlc | branch: 0.8.6-bugfix | Rafaël Carré <funman at videolan.org> | Tue May 20 15:11:17 2008 +0200| [eb1e0679d39bc693025a45bd4a408c764d72d397]
Use pictures reference counting
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eb1e0679d39bc693025a45bd4a408c764d72d397
---
src/misc/image.c | 41 ++++++++++++++++-------------------------
1 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/src/misc/image.c b/src/misc/image.c
index bdb9b4e..f5a4efb 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -241,14 +241,11 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
*
*/
-void PicRelease( picture_t *p_pic ){};
-
static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
video_format_t *p_fmt_in,
video_format_t *p_fmt_out )
{
block_t *p_block;
- void (*pf_release)( picture_t * );
/* Check if we can reuse the current encoder */
if( p_image->p_enc &&
@@ -310,11 +307,9 @@ static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
p_image->p_filter->fmt_out.video = p_image->p_enc->fmt_in.video;
}
- pf_release = p_pic->pf_release;
- p_pic->pf_release = PicRelease; /* Small hack */
+ p_pic->i_refcount++;
p_tmp_pic =
p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
- p_pic->pf_release = pf_release;
p_block = p_image->p_enc->pf_encode_video( p_image->p_enc, p_tmp_pic );
@@ -377,7 +372,6 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
video_format_t *p_fmt_in,
video_format_t *p_fmt_out )
{
- void (*pf_release)( picture_t * );
picture_t *p_pif;
if( !p_fmt_out->i_width && !p_fmt_out->i_height &&
@@ -434,10 +428,8 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
p_image->p_filter->fmt_out.video = *p_fmt_out;
}
- pf_release = p_pic->pf_release;
- p_pic->pf_release = PicRelease; /* Small hack */
+ p_pic->i_refcount++; //pf_video_filter() will decrease the refcount
p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
- p_pic->pf_release = pf_release;
if( p_fmt_in->i_chroma == p_fmt_out->i_chroma &&
p_fmt_in->i_width == p_fmt_out->i_width &&
@@ -459,9 +451,6 @@ static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic,
video_format_t *p_fmt, const char *psz_module )
{
- void (*pf_release)( picture_t * );
- picture_t *p_pif;
-
/* Start a filter */
if( !p_image->p_filter )
{
@@ -484,12 +473,8 @@ static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic,
p_image->p_filter->fmt_out.video = *p_fmt;
}
- 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_pic->pf_release = pf_release;
-
- return p_pif;
+ p_pic->i_refcount++;
+ return p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
}
/**
@@ -562,9 +547,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->i_refcount > 0 )
+ return;
+
+ free( p_pic->p_data_orig );
+ free( p_pic->p_sys );
+ free( p_pic );
}
static picture_t *video_new_buffer( decoder_t *p_dec )
@@ -587,23 +575,26 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
p_pic->pf_release = video_release_buffer;
p_pic->i_status = RESERVED_PICTURE;
p_pic->p_sys = NULL;
+ p_pic->i_refcount = 1;
return p_pic;
}
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 );
+ 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 )
{
+ p_pic->i_refcount++;
}
static void video_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
{
+ video_release_buffer( p_pic );
}
static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt )
More information about the vlc-devel
mailing list