[vlc-devel] [PATCH] smem: do not crash if the callbacks are not defined

Rémi Denis-Courmont remi at remlab.net
Wed Jul 6 21:46:03 CEST 2016


On Wednesday 06 July 2016 16:05:38 Adrien Maglo wrote:
> ---
>  modules/stream_out/smem.c | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)

Looks OK though I don´t really see the point beating the dead smem horse 
further. IMHO, I´d check for NULL at init and replace with a default callback.

> 
> diff --git a/modules/stream_out/smem.c b/modules/stream_out/smem.c
> index a5fb1ee..ee69f4d 100644
> --- a/modules/stream_out/smem.c
> +++ b/modules/stream_out/smem.c
> @@ -320,6 +320,11 @@ static int SendVideo( sout_stream_t *p_stream,
> sout_stream_id_sys_t *id, uint8_t* p_pixels = NULL;
> 
>      /* Calling the prerender callback to get user buffer */
> +    if (p_sys->pf_video_prerender_callback == NULL)
> +    {
> +        block_ChainRelease( p_buffer );
> +        return VLC_EGENERIC;
> +    }
>      p_sys->pf_video_prerender_callback( id->p_data, &p_pixels, i_size );
> 
>      if (!p_pixels)
> @@ -332,9 +337,10 @@ static int SendVideo( sout_stream_t *p_stream,
> sout_stream_id_sys_t *id, /* Copying data into user buffer */
>      memcpy( p_pixels, p_buffer->p_buffer, i_size );
>      /* Calling the postrender callback to tell the user his buffer is ready
> */ -    p_sys->pf_video_postrender_callback( id->p_data, p_pixels,
> -                                         id->format->video.i_width,
> id->format->video.i_height, -                                        
> id->format->video.i_bits_per_pixel, i_size, p_buffer->i_pts ); +    if
> (p_sys->pf_video_postrender_callback != NULL)
> +        p_sys->pf_video_postrender_callback( id->p_data, p_pixels,
> +                                             id->format->video.i_width,
> id->format->video.i_height, +                                            
> id->format->video.i_bits_per_pixel, i_size, p_buffer->i_pts );
> block_ChainRelease( p_buffer );
>      return VLC_SUCCESS;
>  }
> @@ -356,8 +362,15 @@ static int SendAudio( sout_stream_t *p_stream,
> sout_stream_id_sys_t *id, }
> 
>      i_samples = i_size / ( ( id->format->audio.i_bitspersample / 8 ) *
> id->format->audio.i_channels ); +
>      /* Calling the prerender callback to get user buffer */
> +    if (p_sys->pf_audio_prerender_callback == NULL)
> +    {
> +        block_ChainRelease( p_buffer );
> +        return VLC_EGENERIC;
> +    }
>      p_sys->pf_audio_prerender_callback( id->p_data, &p_pcm_buffer, i_size
> ); +
>      if (!p_pcm_buffer)
>      {
>          msg_Err( p_stream, "No buffer given!" );
> @@ -368,9 +381,10 @@ static int SendAudio( sout_stream_t *p_stream,
> sout_stream_id_sys_t *id, /* Copying data into user buffer */
>      memcpy( p_pcm_buffer, p_buffer->p_buffer, i_size );
>      /* Calling the postrender callback to tell the user his buffer is ready
> */ -    p_sys->pf_audio_postrender_callback( id->p_data, p_pcm_buffer, -   
>                                      id->format->audio.i_channels,
> id->format->audio.i_rate, i_samples, -                                     
>    id->format->audio.i_bitspersample, i_size, p_buffer->i_pts ); +    if
> (p_sys->pf_audio_postrender_callback != NULL)
> +        p_sys->pf_audio_postrender_callback( id->p_data, p_pcm_buffer,
> +                                             id->format->audio.i_channels,
> id->format->audio.i_rate, i_samples, +                                     
>        id->format->audio.i_bitspersample, i_size, p_buffer->i_pts );
> block_ChainRelease( p_buffer );
>      return VLC_SUCCESS;
>  }

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list