]> git.sesse.net Git - vlc/blobdiff - modules/video_output/snapshot.c
threads: Make sure we don't re-create a thread if the object has already one.
[vlc] / modules / video_output / snapshot.c
index ee91f3fc124581f1b8dc67f30eabc69df81fd0de..fb0b9cf7ce124ac4c7a73e687e5502b619bc54c2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * snapshot.c : snapshot plugin for vlc
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002 the VideoLAN team
  * $Id$
  *
  * Authors: Olivier Aubert <oaubert@lisi.univ-lyon1.fr>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * This module is a pseudo video output that offers the possibility to
+ * keep a cache of low-res snapshots.
+ * The snapshot structure is defined in include/snapshot.h
+ * In order to access the current snapshot cache, object variables are used:
+ *   snapshot-list-pointer : the pointer on the first element in the list
+ *   snapshot-datasize     : size of a snapshot
+ *                           (also available in snapshot_t->i_datasize)
+ *   snapshot-cache-size   : size of the cache list
+ *
+ * It is used for the moment by the CORBA module and a specialized
+ * python-vlc binding.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
 
-#include <vlc/vlc.h>
-#include <vlc/vout.h>
-#include <vlc/intf.h>
-#include <snapshot.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_vout.h>
+#include <vlc_interface.h>
+#include <vlc_input.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -38,32 +56,38 @@ static int  Create    ( vlc_object_t * );
 static void Destroy   ( vlc_object_t * );
 
 static int  Init      ( vout_thread_t * );
+static void End       ( vout_thread_t * );
 static void Display   ( vout_thread_t *, picture_t * );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define WIDTH_TEXT N_( "snapshot width" )
-#define WIDTH_LONGTEXT N_( "Set the width of the snapshot image." )
+#define WIDTH_TEXT N_( "Snapshot width" )
+#define WIDTH_LONGTEXT N_( "Width of the snapshot image." )
 
-#define HEIGHT_TEXT N_( "snapshot height" )
-#define HEIGHT_LONGTEXT N_( "Set the height of the snapshot image." )
+#define HEIGHT_TEXT N_( "Snapshot height" )
+#define HEIGHT_LONGTEXT N_( "Height of the snapshot image." )
 
-#define CHROMA_TEXT N_( "chroma" )
-#define CHROMA_LONGTEXT N_( "Set the desired chroma for the snapshot image (a 4 character string)." )
+#define CHROMA_TEXT N_( "Chroma" )
+#define CHROMA_LONGTEXT N_( "Output chroma for the snapshot image " \
+                            "(a 4 character string, like \"RV32\")." )
 
-#define CACHE_TEXT N_( "cache size (number of images)" )
-#define CACHE_LONGTEXT N_( "Set the cache size (number of images to keep)." )
+#define CACHE_TEXT N_( "Cache size (number of images)" )
+#define CACHE_LONGTEXT N_( "Snapshot cache size (number of images to keep)." )
 
 
 vlc_module_begin( );
-    set_description( _( "snapshot module" ) );
-    set_capability( "video output", 0 );
+    set_description( N_( "Snapshot module" ) );
+    set_shortname( N_("Snapshot") );
+
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_VOUT );
+    set_capability( "video output", 1 );
 
-    add_integer( "snapshot-width", 320, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_FALSE );
-    add_integer( "snapshot-height", 200, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_FALSE );
-    add_string( "snapshot-chroma", "RV32", NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
-    add_integer( "snapshot-cache-size", 50, NULL, CACHE_TEXT, CACHE_LONGTEXT, VLC_TRUE );
+    add_integer( "snapshot-width", 320, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, false );
+    add_integer( "snapshot-height", 200, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, false );
+    add_string( "snapshot-chroma", "RV32", NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true );
+    add_integer( "snapshot-cache-size", 50, NULL, CACHE_TEXT, CACHE_LONGTEXT, true );
 
     set_callbacks( Create, Destroy );
 vlc_module_end();
@@ -94,14 +118,14 @@ static int Create( vlc_object_t *p_this )
     if( ! p_vout->p_sys )
         return VLC_ENOMEM;
 
-    var_Create( p_this, "snapshot-width", VLC_VAR_INTEGER );
-    var_Create( p_this, "snapshot-height", VLC_VAR_INTEGER );
-    var_Create( p_this, "snapshot-datasize", VLC_VAR_INTEGER );
-    var_Create( p_this, "snapshot-cache-size", VLC_VAR_INTEGER );
-    var_Create( p_this, "snapshot-list-pointer", VLC_VAR_ADDRESS );
+    var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER );
+    var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER );
+    var_Create( p_vout, "snapshot-datasize", VLC_VAR_INTEGER );
+    var_Create( p_vout, "snapshot-cache-size", VLC_VAR_INTEGER );
+    var_Create( p_vout, "snapshot-list-pointer", VLC_VAR_ADDRESS );
 
     p_vout->pf_init = Init;
-    p_vout->pf_end = NULL;
+    p_vout->pf_end = End;
     p_vout->pf_manage = NULL;
     p_vout->pf_render = NULL;
     p_vout->pf_display = Display;
@@ -131,7 +155,7 @@ static int Init( vout_thread_t *p_vout )
     {
         if( strlen( psz_chroma ) < 4 )
         {
-            msg_Err( p_vout, "snapshot-chroma should be 4 characters long." );
+            msg_Err( p_vout, "snapshot-chroma should be 4 characters long" );
             return VLC_EGENERIC;
         }
         i_chroma = VLC_FOURCC( psz_chroma[0], psz_chroma[1],
@@ -295,6 +319,14 @@ static int Init( vout_thread_t *p_vout )
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * End: terminate video thread output method
+ *****************************************************************************/
+static void End( vout_thread_t *p_vout )
+{
+    (void)p_vout;
+}
+
 /*****************************************************************************
  * Destroy: destroy video thread
  *****************************************************************************
@@ -303,23 +335,15 @@ static int Init( vout_thread_t *p_vout )
 static void Destroy( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = ( vout_thread_t * )p_this;
-    vlc_object_t *p_vlc;
     int i_index;
 
+    var_Destroy( p_vout->p_sys->p_input, "snapshot-id" );
+
     vlc_object_release( p_vout->p_sys->p_input );
     var_Destroy( p_this, "snapshot-width" );
     var_Destroy( p_this, "snapshot-height" );
     var_Destroy( p_this, "snapshot-datasize" );
 
-    p_vlc = vlc_object_find( p_this, VLC_OBJECT_ROOT, FIND_PARENT );
-    if( p_vlc )
-    {
-        /* UnRegister the snapshot vout module at the root level */
-        /* var_Destroy (p_vlc, "snapshot-id"); */
-        var_Destroy( p_this->p_libvlc, "snapshot-id" );
-        vlc_object_release( p_vlc );
-    }
-
     for( i_index = 0 ; i_index < p_vout->p_sys->i_size ; i_index++ )
     {
         free( p_vout->p_sys->p_list[ i_index ]->p_data );
@@ -342,7 +366,7 @@ static mtime_t snapshot_GetMovietime( vout_thread_t *p_vout )
 
     var_Get( p_input, "time", &val );
 
-    i_result = val.i_time;
+    i_result = val.i_time - p_input->i_pts_delay;
 
     return( i_result / 1000 );
 }
@@ -359,9 +383,8 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
 
     i_index = p_vout->p_sys->i_index;
 
-    p_vout->p_vlc->pf_memcpy( p_vout->p_sys->p_list[i_index]->p_data,
-                              p_pic->p->p_pixels,
-                              p_vout->p_sys->i_datasize );
+    vlc_memcpy( p_vout->p_sys->p_list[i_index]->p_data, p_pic->p->p_pixels,
+                p_vout->p_sys->i_datasize );
 
     i_date = snapshot_GetMovietime( p_vout );