Commit 547de22d authored by Laurent Aimar's avatar Laurent Aimar

Do not segfault on non video stream (close #1821)

Do not segfault if no video filters.
parent df771177
...@@ -214,9 +214,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -214,9 +214,7 @@ static int Open( vlc_object_t *p_this )
p_sys = malloc( sizeof( sout_stream_sys_t ) ); p_sys = malloc( sizeof( sout_stream_sys_t ) );
if( !p_sys ) if( !p_sys )
{
return VLC_ENOMEM; return VLC_ENOMEM;
}
p_stream->p_sys = p_sys; p_stream->p_sys = p_sys;
p_sys->b_inited = false; p_sys->b_inited = false;
...@@ -225,8 +223,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -225,8 +223,7 @@ static int Open( vlc_object_t *p_this )
var_Get( p_libvlc, "mosaic-lock", &val ); var_Get( p_libvlc, "mosaic-lock", &val );
p_sys->p_lock = val.p_address; p_sys->p_lock = val.p_address;
var_Get( p_stream, CFG_PREFIX "id", &val ); p_sys->psz_id = var_CreateGetString( p_stream, CFG_PREFIX "id" );
p_sys->psz_id = val.psz_string;
p_sys->i_height = p_sys->i_height =
var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" ); var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
...@@ -237,7 +234,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -237,7 +234,7 @@ static int Open( vlc_object_t *p_this )
var_AddCallback( p_stream, CFG_PREFIX "width", WidthCallback, p_stream ); var_AddCallback( p_stream, CFG_PREFIX "width", WidthCallback, p_stream );
var_Get( p_stream, CFG_PREFIX "sar", &val ); var_Get( p_stream, CFG_PREFIX "sar", &val );
if ( val.psz_string ) if( val.psz_string )
{ {
char *psz_parser = strchr( val.psz_string, ':' ); char *psz_parser = strchr( val.psz_string, ':' );
...@@ -270,14 +267,16 @@ static int Open( vlc_object_t *p_this ) ...@@ -270,14 +267,16 @@ static int Open( vlc_object_t *p_this )
msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma ); msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
} }
#define INT_COMMAND( a ) \ #define INT_COMMAND( a ) do { \
var_Create( p_stream, CFG_PREFIX #a, \ var_Create( p_stream, CFG_PREFIX #a, \
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); \ VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); \
var_AddCallback( p_stream, CFG_PREFIX #a, a ## Callback, \ var_AddCallback( p_stream, CFG_PREFIX #a, a ## Callback, \
p_stream ); p_stream ); } while(0)
INT_COMMAND( alpha ) INT_COMMAND( alpha );
INT_COMMAND( x ) INT_COMMAND( x );
INT_COMMAND( y ) INT_COMMAND( y );
#undef INT_COMMAND
p_stream->pf_add = Add; p_stream->pf_add = Add;
p_stream->pf_del = Del; p_stream->pf_del = Del;
...@@ -319,10 +318,8 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -319,10 +318,8 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
char *psz_chain; char *psz_chain;
int i; int i;
if ( p_sys->b_inited ) if( p_sys->b_inited || p_fmt->i_cat != VIDEO_ES )
{
return NULL; return NULL;
}
/* Create decoder object */ /* Create decoder object */
p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER ); p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
...@@ -356,9 +353,18 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -356,9 +353,18 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
p_sys->p_decoder->p_module = p_sys->p_decoder->p_module =
module_Need( p_sys->p_decoder, "decoder", "$codec", 0 ); module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
if( !p_sys->p_decoder->p_module ) if( !p_sys->p_decoder->p_module || !p_sys->p_decoder->pf_decode_video )
{
if( p_sys->p_decoder->p_module )
{
msg_Err( p_stream, "instanciated a non video decoder" );
module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
}
else
{ {
msg_Err( p_stream, "cannot find decoder" ); msg_Err( p_stream, "cannot find decoder" );
}
free( p_sys->p_decoder->p_owner );
vlc_object_detach( p_sys->p_decoder ); vlc_object_detach( p_sys->p_decoder );
vlc_object_release( p_sys->p_decoder ); vlc_object_release( p_sys->p_decoder );
return NULL; return NULL;
...@@ -456,12 +462,10 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) ...@@ -456,12 +462,10 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
bool b_last_es = true; bool b_last_es = true;
int i; int i;
if ( !p_sys->b_inited ) if( !p_sys->b_inited )
{
return VLC_SUCCESS; return VLC_SUCCESS;
}
if ( p_sys->p_decoder != NULL ) if( p_sys->p_decoder != NULL )
{ {
decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner; decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner;
...@@ -484,6 +488,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) ...@@ -484,6 +488,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
} }
/* Destroy user specified video filters */ /* Destroy user specified video filters */
if( p_sys->p_vf2 )
filter_chain_Delete( p_sys->p_vf2 ); filter_chain_Delete( p_sys->p_vf2 );
vlc_mutex_lock( p_sys->p_lock ); vlc_mutex_lock( p_sys->p_lock );
...@@ -605,7 +610,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, ...@@ -605,7 +610,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
if ( p_new_pic == NULL ) if ( p_new_pic == NULL )
{ {
msg_Err( p_stream, "image conversion failed" ); msg_Err( p_stream, "image conversion failed" );
p_pic->pf_release( p_pic ); picture_Release( p_pic );
continue; continue;
} }
} }
...@@ -626,7 +631,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, ...@@ -626,7 +631,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
p_sys->p_decoder->fmt_out.video.i_aspect ) p_sys->p_decoder->fmt_out.video.i_aspect )
!= VLC_SUCCESS ) != VLC_SUCCESS )
{ {
p_pic->pf_release( p_pic ); picture_Release( p_pic );
free( p_new_pic ); free( p_new_pic );
msg_Err( p_stream, "image allocation failed" ); msg_Err( p_stream, "image allocation failed" );
continue; continue;
...@@ -641,7 +646,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, ...@@ -641,7 +646,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release; p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
p_new_pic->pf_release = ReleasePicture; p_new_pic->pf_release = ReleasePicture;
p_new_pic->date = p_pic->date; p_new_pic->date = p_pic->date;
p_pic->pf_release( p_pic ); picture_Release( p_pic );
if( p_sys->p_vf2 ) if( p_sys->p_vf2 )
p_new_pic = filter_chain_VideoFilter( p_sys->p_vf2, p_new_pic ); p_new_pic = filter_chain_VideoFilter( p_sys->p_vf2, p_new_pic );
......
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