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

PaulK gci at paulk.fr
Tue Nov 29 18:16:12 CET 2011


Here is a new version. Notes:
- I figured out that I didn't take care of width and height so I have to
call var_SetInteger twice. What's the clean way to handle this? mutexes?
- I added stdlib.h to libvlc_media_player.h. Apparently including
headers for return types is OK as libvlc_structures.h uses stdint.h and
libvlc_media_player.h is already using stdbool

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..e08706f 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,57 @@ 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)
+        return -1;
+
+    var_SetInteger( p_vout, "snapshot-width", i_width);
+    var_SetInteger( p_vout, "snapshot-height", i_height );
+
+    if( vout_GetSnapshot( p_vout, &block_buffer, NULL, &fmt, "png",
500*1000 ) )
+    {
+        ret_len = -1;
+        goto exit;
+    }
+
+
+    buffer_len = block_buffer->i_buffer;
+    if( buffer_len <= 0 )
+    {
+        ret_len = -1;
+        goto exit;
+    }
+
+    buffer = malloc( buffer_len );
+    if( buffer == NULL )
+    {
+        ret_len = -1;
+        goto exit;
+    }
+
+    psz_addr[0] = buffer;
+    memcpy( buffer, block_buffer->p_buffer, buffer_len );
+
+    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
)
 {




More information about the vlc-devel mailing list