]> git.sesse.net Git - vlc/blobdiff - modules/codec/fake.c
macosx: Fix a memleak.
[vlc] / modules / codec / fake.c
index d3f37d69e4e50e5ff0b605c2f26b2a28db52f580..bd4c1cddc8a9575299cd985dd4c3a6ae4dc0d68e 100644 (file)
@@ -5,6 +5,7 @@
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
+ *          Jean-Paul Saman <jpsaman at m2x dot nl>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_codec.h>
 
 #include <vlc_image.h>
@@ -47,6 +53,9 @@ static int FakeCallback( vlc_object_t *, char const *,
 #define FILE_TEXT N_("Image file")
 #define FILE_LONGTEXT N_( \
     "Path of the image file for fake input." )
+#define RELOAD_TEXT N_("Reload image file")
+#define RELOAD_LONGTEXT N_( \
+    "Reload image file every n seconds." )
 #define WIDTH_TEXT N_("Video width")
 #define WIDTH_LONGTEXT N_( \
     "Output video width." )
@@ -69,7 +78,7 @@ static int FakeCallback( vlc_object_t *, char const *,
 #define CHROMA_LONGTEXT N_( \
     "Force use of a specific chroma for output. Default is I420." )
 
-static const char *ppsz_deinterlace_type[] =
+static const char *const ppsz_deinterlace_type[] =
 {
     "deinterlace", "ffmpeg-deinterlace"
 };
@@ -77,36 +86,42 @@ static const char *ppsz_deinterlace_type[] =
 vlc_module_begin();
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_shortname( _("Fake") );
-    set_description( _("Fake video decoder") );
+    set_shortname( N_("Fake") );
+    set_description( N_("Fake video decoder") );
     set_capability( "decoder", 1000 );
     set_callbacks( OpenDecoder, CloseDecoder );
     add_shortcut( "fake" );
 
     add_file( "fake-file", "", NULL, FILE_TEXT,
-                FILE_LONGTEXT, VLC_FALSE );
+                FILE_LONGTEXT, false );
+    add_integer( "fake-file-reload", 0, NULL, RELOAD_TEXT,
+                RELOAD_LONGTEXT, false );
     add_integer( "fake-width", 0, NULL, WIDTH_TEXT,
-                 WIDTH_LONGTEXT, VLC_TRUE );
+                 WIDTH_LONGTEXT, true );
     add_integer( "fake-height", 0, NULL, HEIGHT_TEXT,
-                 HEIGHT_LONGTEXT, VLC_TRUE );
+                 HEIGHT_LONGTEXT, true );
     add_bool( "fake-keep-ar", 0, NULL, KEEP_AR_TEXT, KEEP_AR_LONGTEXT,
-              VLC_TRUE );
+              true );
     add_string( "fake-aspect-ratio", "", NULL,
-                ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, VLC_TRUE );
+                ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true );
     add_bool( "fake-deinterlace", 0, NULL, DEINTERLACE_TEXT,
-              DEINTERLACE_LONGTEXT, VLC_FALSE );
+              DEINTERLACE_LONGTEXT, false );
     add_string( "fake-deinterlace-module", "deinterlace", NULL,
                 DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,
-                VLC_FALSE );
+                false );
         change_string_list( ppsz_deinterlace_type, 0, 0 );
     add_string( "fake-chroma", "I420", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                VLC_TRUE );
+                true );
 vlc_module_end();
 
 struct decoder_sys_t
 {
     picture_t *p_image;
     vlc_mutex_t lock;
+
+    bool  b_reload;
+    mtime_t     i_reload;
+    mtime_t     i_next;
 };
 
 /*****************************************************************************
@@ -120,7 +135,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     video_format_t fmt_in, fmt_out;
     picture_t *p_image;
     char *psz_file, *psz_chroma;
-    vlc_bool_t b_keep_ar;
+    bool b_keep_ar;
     int i_aspect = 0;
 
     if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') )
@@ -133,11 +148,13 @@ static int OpenDecoder( vlc_object_t *p_this )
     {
         return VLC_ENOMEM;
     }
+    memset( p_dec->p_sys, 0, sizeof( decoder_sys_t ) );
 
     psz_file = var_CreateGetNonEmptyStringCommand( p_dec, "fake-file" );
     if( !psz_file )
     {
         msg_Err( p_dec, "specify a file with --fake-file=..." );
+        free( p_dec->p_sys );
         return VLC_EGENERIC;
     }
     var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec );
@@ -145,6 +162,14 @@ static int OpenDecoder( vlc_object_t *p_this )
     memset( &fmt_in, 0, sizeof(fmt_in) );
     memset( &fmt_out, 0, sizeof(fmt_out) );
 
+    val.i_int = var_CreateGetIntegerCommand( p_dec, "fake-file-reload" );
+    if( val.i_int > 0)
+    {
+        p_dec->p_sys->b_reload = true;
+        p_dec->p_sys->i_reload = (mtime_t)(val.i_int * 1000000);
+        p_dec->p_sys->i_next   = (mtime_t)(p_dec->p_sys->i_reload + mdate());
+    }
+
     psz_chroma = var_CreateGetString( p_dec, "fake-chroma" );
     if( strlen( psz_chroma ) != 4 )
     {
@@ -198,11 +223,13 @@ static int OpenDecoder( vlc_object_t *p_this )
     if ( p_image == NULL )
     {
         msg_Err( p_dec, "unable to read image file %s", psz_file );
+        free( psz_file );
+        free( p_dec->p_sys );
         return VLC_EGENERIC;
     }
     msg_Dbg( p_dec, "file %s loaded successfully", psz_file );
 
-    if ( psz_file ) free( psz_file );
+    free( psz_file );
 
     if ( b_keep_ar )
     {
@@ -253,7 +280,7 @@ static int OpenDecoder( vlc_object_t *p_this )
             }
             else
             {
-                p_old->pf_release( p_old );
+                picture_Release( p_old );
             }
         }
     }
@@ -281,7 +308,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         p_handler = image_HandlerCreate( p_dec );
         p_image = image_Filter( p_handler, p_old, &fmt_out, val.psz_string );
         image_HandlerDelete( p_handler );
-        if ( val.psz_string != NULL ) free( val.psz_string );
+        free( val.psz_string );
 
         if ( p_image == NULL )
         {
@@ -290,7 +317,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         }
         else
         {
-            p_old->pf_release( p_old );
+            picture_Release( p_old );
         }
     }
 
@@ -303,7 +330,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->pf_decode_video = DecodeBlock;
 
     p_dec->p_sys->p_image = p_image;
-    vlc_mutex_init( p_dec, &p_dec->p_sys->lock );
+    vlc_mutex_init( &p_dec->p_sys->lock );
 
     return VLC_SUCCESS;
 }
@@ -313,6 +340,7 @@ static int OpenDecoder( vlc_object_t *p_this )
  ****************************************************************************/
 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
+    decoder_sys_t *p_sys = (decoder_sys_t*) p_dec->p_sys;
     picture_t *p_pic;
 
     if( pp_block == NULL || !*pp_block ) return NULL;
@@ -323,6 +351,12 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         goto error;
     }
 
+    if( p_sys->b_reload && (mdate() >= p_sys->i_next) )
+    {
+        var_TriggerCallback( p_dec, "fake-file" );
+        /* next period */
+        p_sys->i_next = (mtime_t)(p_sys->i_reload + mdate());
+    }
     vlc_mutex_lock( &p_dec->p_sys->lock );
     vout_CopyPicture( p_dec, p_pic, p_dec->p_sys->p_image );
     vlc_mutex_unlock( &p_dec->p_sys->lock );
@@ -345,7 +379,7 @@ static void CloseDecoder( vlc_object_t *p_this )
     picture_t *p_image = p_dec->p_sys->p_image;
 
     if( p_image != NULL )
-        p_image->pf_release( p_image );
+        picture_Release( p_image );
 
     vlc_mutex_destroy( &p_dec->p_sys->lock );
     free( p_dec->p_sys );
@@ -358,6 +392,7 @@ static int FakeCallback( vlc_object_t *p_this, char const *psz_var,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
 {
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
     decoder_t *p_dec = (decoder_t *)p_data;
 
     if( !strcmp( psz_var, "fake-file" ) )
@@ -393,9 +428,22 @@ static int FakeCallback( vlc_object_t *p_this, char const *psz_var,
         }
 
         p_dec->p_sys->p_image = p_new_image;
-        p_image->pf_release( p_image );
+        picture_Release( p_image );
         vlc_mutex_unlock( &p_dec->p_sys->lock );
     }
+    else if( !strcmp( psz_var, "fake-file-reload" ) )
+    {
+        if( newval.i_int > 0)
+        {
+            p_dec->p_sys->b_reload = true;
+            p_dec->p_sys->i_reload = (mtime_t)(newval.i_int * 1000000);
+            p_dec->p_sys->i_next   = (mtime_t)(p_dec->p_sys->i_reload + mdate());
+        }
+        else
+        {
+            p_dec->p_sys->b_reload = false;
+        }
+    }
 
     return VLC_SUCCESS;
 }