mirror of https://code.videolan.org/videolan/vlc
misc: image: refactor and fix ImageWrite
Refactor code to always call the encoder at the end and separate the filtering case. Fix a crash (double-free) when the image handler needs to resize the picture before encoding it. ==150429==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000002bb8 at pc 0x7f4ce1a8a092 bp 0x7fff205294c0 sp 0x7fff205294b0 WRITE of size 8 at 0x614000002bb8 thread T0 #0 0x7f4ce1a8a091 in vlc_atomic_rc_dec ../../include/vlc_atomic.h:66 #1 0x7f4ce1a8a091 in picture_Release ../../include/vlc_picture.h:372 #2 0x7f4ce1a8a091 in ImageWrite ../../src/misc/image.c:454 #3 0x564f4f6a00f7 in OpenIntf ../../test/src/misc/image.c:52 #4 0x7f4ce177bfee in generic_start ../../src/modules/modules.c:275 #5 0x7f4ce177db75 in vlc_module_load ../../src/modules/modules.c:243 #6 0x7f4ce177df33 in module_need ../../src/modules/modules.c:286 #7 0x7f4ce179cbdd in intf_Create ../../src/interface/interface.c:172 #8 0x7f4ce179d86a in libvlc_InternalAddIntf ../../src/interface/interface.c:267 #9 0x7f4ce2350b22 in libvlc_add_intf ../../lib/playlist.c:41 #10 0x564f4f69f53c in main ../../test/src/misc/image.c:122
This commit is contained in:
parent
c91fac9b59
commit
2ea2c7eb19
|
@ -378,8 +378,6 @@ static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
|
|||
const video_format_t *p_fmt_in,
|
||||
const video_format_t *p_fmt_out )
|
||||
{
|
||||
block_t *p_block;
|
||||
|
||||
/* Check if we can reuse the current encoder */
|
||||
if( p_image->p_enc &&
|
||||
( p_image->p_enc->fmt_out.i_codec != p_fmt_out->i_chroma ||
|
||||
|
@ -404,7 +402,6 @@ static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
|
|||
p_image->p_enc->fmt_in.video.i_height != p_fmt_in->i_height ||
|
||||
!BitMapFormatIsSimilar( &p_image->p_enc->fmt_in.video, p_fmt_in ) )
|
||||
{
|
||||
picture_t *p_tmp_pic;
|
||||
|
||||
if( p_image->p_converter &&
|
||||
( p_image->p_converter->fmt_in.video.i_chroma != p_fmt_in->i_chroma ||
|
||||
|
@ -442,25 +439,18 @@ static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
|
|||
es_format_Copy( &p_image->p_converter->fmt_out, &p_image->p_enc->fmt_in );
|
||||
}
|
||||
|
||||
picture_Hold( p_pic );
|
||||
p_pic = p_image->p_converter->ops->filter_video( p_image->p_converter, p_pic );
|
||||
|
||||
p_tmp_pic =
|
||||
p_image->p_converter->ops->filter_video( p_image->p_converter, p_pic );
|
||||
|
||||
if( likely(p_tmp_pic != NULL) )
|
||||
if( likely(p_pic != NULL) )
|
||||
{
|
||||
assert(!picture_HasChainedPics(p_tmp_pic)); // no chaining
|
||||
p_block = vlc_encoder_EncodeVideo(p_image->p_enc, p_tmp_pic );
|
||||
picture_Release( p_tmp_pic );
|
||||
assert(!picture_HasChainedPics(p_pic)); // no chaining
|
||||
}
|
||||
else
|
||||
p_block = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_block = vlc_encoder_EncodeVideo( p_image->p_enc, p_pic );
|
||||
}
|
||||
|
||||
block_t *p_block = NULL;
|
||||
if (p_pic != NULL)
|
||||
p_block = vlc_encoder_EncodeVideo(p_image->p_enc, p_pic);
|
||||
|
||||
if( !p_block )
|
||||
{
|
||||
msg_Dbg( p_image->p_parent, "no image encoded" );
|
||||
|
|
Loading…
Reference in New Issue