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

PaulK gci at paulk.fr
Mon Nov 28 21:46:00 CET 2011


Le lundi 28 novembre 2011 à 21:34 +0100, Laurent Aimar a écrit :
> Hi,
> 
> On Mon, Nov 28, 2011 at 08:29:47PM +0100, PaulK wrote:
> > Added libvlc_video_take_snapshot_addr to libvlc and related functions to
> > libvlccore
> > 
> > This should fix https://trac.videolan.org/vlc/ticket/2513
> > and permits to return a pointer to the (png-encoded) snapshot data
> > instead of writing it to a file.
> 
> > This should fix https://trac.videolan.org/vlc/ticket/2513
> > and permits to return a pointer to the (png-encoded) snapshot data instead of
> > writing it to a file.
> > ---
> >  include/vlc/libvlc_media_player.h |   19 ++++++++
> >  lib/libvlc.sym                    |    1 +
> >  lib/video.c                       |   40 ++++++++++++++++++
> >  src/video_output/vout_intf.c      |   83 +++++++++++++++++++++++++++++++++++++
> >  4 files changed, 143 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
> > index a2b5748..30ed0cd 100644
> > --- a/include/vlc/libvlc_media_player.h
> > +++ b/include/vlc/libvlc_media_player.h
> > @@ -1151,6 +1151,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
> > +size_t
> > +libvlc_video_take_snapshot_addr( 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..0a15838 100644
> > --- a/lib/libvlc.sym
> > +++ b/lib/libvlc.sym
> > @@ -216,6 +216,7 @@ libvlc_video_set_subtitle_file
> >  libvlc_video_set_teletext
> >  libvlc_video_set_track
> >  libvlc_video_take_snapshot
> > +libvlc_video_take_snapshot_addr
> >  libvlc_vlm_add_broadcast
> >  libvlc_vlm_add_vod
> >  libvlc_vlm_add_input
> > diff --git a/lib/video.c b/lib/video.c
> > index 6e1ea06..deb45b1 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,45 @@ libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
> >      return 0;
> >  }
> >  
> > +size_t
> > +libvlc_video_take_snapshot_addr( 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;
> > +
> > +    vout_thread_t *p_vout = GetVout( p_mi, num );
> > +    if (p_vout == NULL)
> > +        return -1;
> > +
> > +    var_SetInteger( p_vout, "snapshot-width", i_width);
> > +    var_SetInteger( p_vout, "snapshot-height", i_height );
> > +    var_SetString( p_vout, "snapshot-format", "png" );
> > +
> > +    var_TriggerCallback( p_vout, "video-snapshot-addr" );
> > +
> > +    block_buffer = (block_t *) var_GetAddress( p_vout, "snapshot-addr" );
> > +    if( block_buffer == NULL )
> > +        return -1;
> > +
> > +    buffer_len = block_buffer->i_buffer;
> > +    if( buffer_len <= 0 )
> > +        return -1;
> > +
> > +    buffer = malloc( buffer_len );
> > +    if( buffer == NULL )
> > +        return -1;
> > +
> > +    psz_addr[0] = buffer;
> > +    memcpy( buffer, block_buffer->p_buffer, buffer_len );
> > +
> > +    var_TriggerCallback( p_vout, "video-snapshot-addr-free" );
> > +
> > +    return buffer_len;
> > +}
> I think that you could directly use vout_GetSnapshot() which should
> make the code simpler and avoid some race conditions.

You mean directly from lib/video.c ? I didn't think it could access it… 




More information about the vlc-devel mailing list