[vlc-devel] [PATCH] Added libvlc_video_take_snapshot_addr to libvlc and related functions to libvlccore

PaulK gci at paulk.fr
Sun Dec 4 19:04:42 CET 2011


Le jeudi 01 décembre 2011 à 08:07 +0100, Rémi Denis-Courmont a écrit :
> On Wed, 30 Nov 2011 22:43:34 +0100, PaulK <gci at paulk.fr> wrote:
> > diff --git a/include/vlc/libvlc_media_player.h
> > b/include/vlc/libvlc_media_player.h
> > index a2b5748..b2a5c54 100644
> > --- a/include/vlc/libvlc_media_player.h
> > +++ b/include/vlc/libvlc_media_player.h
> > @@ -35,6 +35,7 @@
> >  extern "C" {
> >  # else
> >  #  include <stdbool.h>
> > +#  include <stdlib.h>
> >  # endif
> >  
> > 
> /*****************************************************************************
> > @@ -1151,6 +1152,25 @@ int
> > libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
> >                                  unsigned int i_height );
> >  
> >  /**
> > + * Take a snapshot of the current video window and return the snapshot
> > address.
> > + *
> > + * If i_width AND i_height is 0, original size is used.
> > + * If i_width XOR i_height is 0, original aspect-ratio is preserved.
> > + *
> > + * \param p_mi media player instance
> > + * \param num number of video output (typically 0 for the first/only
> > one)
> > + * \param psz_addr place to return the snapshot address (you MUST free
> > it after use)
> > + * \param i_width the snapshot's width
> > + * \param i_height the snapshot's height
> > + * \return the snapshot memory area size on success, -1 if there was a
> > problem
> > + */
> > +LIBVLC_API
> > +ssize_t
> > +libvlc_video_snapshot_get_data( libvlc_media_player_t *p_mi, unsigned
> > num,
> > +                                 void **psz_addr, unsigned int
> > i_width, 
> > +                                 unsigned int i_height );
> > +
> > +/**
> >   * Enable or disable deinterlace filter
> >   *
> >   * \param p_mi libvlc media player
> > diff --git a/lib/libvlc.sym b/lib/libvlc.sym
> > index 6582a96..099cbb8 100644
> > --- a/lib/libvlc.sym
> > +++ b/lib/libvlc.sym
> > @@ -215,6 +215,7 @@ libvlc_video_set_spu
> >  libvlc_video_set_subtitle_file
> >  libvlc_video_set_teletext
> >  libvlc_video_set_track
> > +libvlc_video_snapshot_get_data
> >  libvlc_video_take_snapshot
> >  libvlc_vlm_add_broadcast
> >  libvlc_vlm_add_vod
> > diff --git a/lib/video.c b/lib/video.c
> > index 6e1ea06..3071646 100644
> > --- a/lib/video.c
> > +++ b/lib/video.c
> > @@ -34,6 +34,7 @@
> >  #include <vlc/libvlc_media_player.h>
> >  
> >  #include <vlc_common.h>
> > +#include <vlc_block.h>
> >  #include <vlc_input.h>
> >  #include <vlc_vout.h>
> >  
> > @@ -158,6 +159,63 @@ libvlc_video_take_snapshot( libvlc_media_player_t
> > *p_mi, unsigned num,
> >      return 0;
> >  }
> >  
> > +ssize_t
> > +libvlc_video_snapshot_get_data( libvlc_media_player_t *p_mi, unsigned
> > num,
> > +                                 void **psz_addr, unsigned int
> > i_width, 
> > +                                 unsigned int i_height )
> > +{
> > +    block_t *block_buffer;
> > +    size_t buffer_len = 0;
> > +    char *buffer = NULL;
> > +    ssize_t ret_len;
> > +    video_format_t fmt;
> > +
> > +    vout_thread_t *p_vout = GetVout( p_mi, num );
> > +    if (p_vout == NULL)
> > +    {
> > +        libvlc_printerr ("No usable vout");
> > +        return -1;
> > +    }
> > +
> > +    var_SetInteger( p_vout, "snapshot-width", i_width);
> > +    var_SetInteger( p_vout, "snapshot-height", i_height );
> 
> Not thread-safe.

I know this is not thread safe but this is how it's done in the other
snapshot function "libvlc_video_take_snapshot" (which is actually
worse). How can I fix this? I don't know how we're supposed to handle
this in VLC (mutex?)… 

> > +
> > +    if( vout_GetSnapshot( p_vout, &block_buffer, NULL, &fmt, "png",
> > 500*1000 ) )
> > +    {
> > +        libvlc_printerr ("Can't get the snapshot");
> > +        ret_len = -1;
> > +        goto exit;
> > +    }
> > +
> > +
> > +    buffer_len = block_buffer->i_buffer;
> > +    if( buffer_len <= 0 )
> > +    {
> > +        libvlc_printerr ("Snapshot buffer length is negative or zero");
> > +        ret_len = -1;
> > +        goto exit;
> > +    }
> > +
> > +    buffer = malloc( buffer_len );
> > +    if( buffer == NULL )
> > +    {
> > +        libvlc_printerr ("buffer memory allocation failed");
> > +        ret_len = -1;
> > +        goto exit;
> > +    }
> > +
> > +    psz_addr[0] = buffer;
> > +    memcpy( buffer, block_buffer->p_buffer, buffer_len );
> 
> For the second time, please don't do this. We have buffer management.
> 
> > +
> > +    ret_len = buffer_len;
> > +
> > +exit:
> > +    if( block_buffer != NULL )
> > +        block_Release( block_buffer );
> > +
> > +    return ret_len;
> > +}
> > +
> >  int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
> >                             unsigned *restrict px, unsigned *restrict py
> > )
> >  {
> > 
> > 
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > http://mailman.videolan.org/listinfo/vlc-devel
> 





More information about the vlc-devel mailing list