Commit eb1e0679 authored by Rafaël Carré's avatar Rafaël Carré

Use pictures reference counting

parent bb5087cf
...@@ -241,14 +241,11 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url, ...@@ -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, static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
video_format_t *p_fmt_in, video_format_t *p_fmt_in,
video_format_t *p_fmt_out ) video_format_t *p_fmt_out )
{ {
block_t *p_block; block_t *p_block;
void (*pf_release)( picture_t * );
/* Check if we can reuse the current encoder */ /* Check if we can reuse the current encoder */
if( p_image->p_enc && if( p_image->p_enc &&
...@@ -310,11 +307,9 @@ static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic, ...@@ -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; p_image->p_filter->fmt_out.video = p_image->p_enc->fmt_in.video;
} }
pf_release = p_pic->pf_release; p_pic->i_refcount++;
p_pic->pf_release = PicRelease; /* Small hack */
p_tmp_pic = p_tmp_pic =
p_image->p_filter->pf_video_filter( p_image->p_filter, p_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 ); 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, ...@@ -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_in,
video_format_t *p_fmt_out ) video_format_t *p_fmt_out )
{ {
void (*pf_release)( picture_t * );
picture_t *p_pif; picture_t *p_pif;
if( !p_fmt_out->i_width && !p_fmt_out->i_height && 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, ...@@ -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; p_image->p_filter->fmt_out.video = *p_fmt_out;
} }
pf_release = p_pic->pf_release; p_pic->i_refcount++; //pf_video_filter() will decrease the refcount
p_pic->pf_release = PicRelease; /* Small hack */
p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic ); 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 && if( p_fmt_in->i_chroma == p_fmt_out->i_chroma &&
p_fmt_in->i_width == p_fmt_out->i_width && 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, ...@@ -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, static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic,
video_format_t *p_fmt, const char *psz_module ) video_format_t *p_fmt, const char *psz_module )
{ {
void (*pf_release)( picture_t * );
picture_t *p_pif;
/* Start a filter */ /* Start a filter */
if( !p_image->p_filter ) if( !p_image->p_filter )
{ {
...@@ -484,12 +473,8 @@ static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic, ...@@ -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; p_image->p_filter->fmt_out.video = *p_fmt;
} }
pf_release = p_pic->pf_release; p_pic->i_refcount++;
p_pic->pf_release = PicRelease; /* Small hack */ return p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
p_pic->pf_release = pf_release;
return p_pif;
} }
/** /**
...@@ -562,9 +547,12 @@ static const char *Fourcc2Ext( vlc_fourcc_t i_codec ) ...@@ -562,9 +547,12 @@ static const char *Fourcc2Ext( vlc_fourcc_t i_codec )
static void video_release_buffer( picture_t *p_pic ) 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->i_refcount > 0 )
if( p_pic && p_pic->p_sys ) free( p_pic->p_sys ); return;
if( p_pic ) free( 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 picture_t *video_new_buffer( decoder_t *p_dec )
...@@ -587,23 +575,26 @@ 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->pf_release = video_release_buffer;
p_pic->i_status = RESERVED_PICTURE; p_pic->i_status = RESERVED_PICTURE;
p_pic->p_sys = NULL; p_pic->p_sys = NULL;
p_pic->i_refcount = 1;
return p_pic; return p_pic;
} }
static void video_del_buffer( decoder_t *p_dec, picture_t *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 ); free( p_pic->p_data_orig );
if( p_pic && p_pic->p_sys ) free( p_pic->p_sys ); free( p_pic->p_sys );
if( p_pic ) free( p_pic ); free( p_pic );
} }
static void video_link_picture( decoder_t *p_dec, picture_t *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 ) 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 ) static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment