Commit 8f3ee352 authored by Jean-Paul Saman's avatar Jean-Paul Saman
Browse files

Specifying --fake-file-reload 5 reloads the image file every 5 seconds. This...

Specifying --fake-file-reload 5 reloads the image file every 5 seconds. This will change the background image in a mosaic solution. The usage scenario is for instance a webcam that uploads an images every x seconds to the same file location.
parent 88f28f63
......@@ -164,6 +164,7 @@ VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, co
*****************************************************************************/
VLC_EXPORT( int, __var_AddCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback_t, void * ) );
VLC_EXPORT( int, __var_TriggerCallback, ( vlc_object_t *, const char * ) );
/**
* __var_AddCallback() with automatic casting
......@@ -175,6 +176,11 @@ VLC_EXPORT( int, __var_DelCallback, ( vlc_object_t *, const char *, vlc_callback
*/
#define var_DelCallback(a,b,c,d) __var_DelCallback( VLC_OBJECT(a), b, c, d )
/**
* __var_TriggerCallback() with automatic casting
*/
#define var_TriggerCallback(a,b) __var_TriggerCallback( VLC_OBJECT(a), b )
/*****************************************************************************
* helpers functions
*****************************************************************************/
......
......@@ -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
......@@ -47,6 +48,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." )
......@@ -85,6 +89,8 @@ vlc_module_begin();
add_file( "fake-file", "", NULL, FILE_TEXT,
FILE_LONGTEXT, VLC_FALSE );
add_integer( "fake-file-reload", 0, NULL, RELOAD_TEXT,
RELOAD_LONGTEXT, VLC_FALSE );
add_integer( "fake-width", 0, NULL, WIDTH_TEXT,
WIDTH_LONGTEXT, VLC_TRUE );
add_integer( "fake-height", 0, NULL, HEIGHT_TEXT,
......@@ -107,6 +113,10 @@ struct decoder_sys_t
{
picture_t *p_image;
vlc_mutex_t lock;
vlc_bool_t b_reload;
mtime_t i_reload;
mtime_t i_next;
};
/*****************************************************************************
......@@ -133,6 +143,7 @@ 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 )
......@@ -145,6 +156,15 @@ static int OpenDecoder( vlc_object_t *p_this )
memset( &fmt_in, 0, sizeof(fmt_in) );
memset( &fmt_out, 0, sizeof(fmt_out) );
var_Create( p_dec, "fake-file-reload", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_dec, "fake-file-reload", &val );
if( val.i_int > 0)
{
p_dec->p_sys->b_reload = VLC_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 )
{
......@@ -313,6 +333,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 +344,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 );
......
......@@ -920,6 +920,68 @@ int __var_DelCallback( vlc_object_t *p_this, const char *psz_name,
return VLC_SUCCESS;
}
/**
* Trigger callback on a variable
*
* \param p_this The object that hold the variable
* \param psz_name The name of the variable
*/
int __var_TriggerCallback( vlc_object_t *p_this, const char *psz_name )
{
int i_var;
variable_t *p_var;
vlc_value_t oldval;
vlc_mutex_lock( &p_this->var_lock );
i_var = GetUnused( p_this, psz_name );
if( i_var < 0 )
{
vlc_mutex_unlock( &p_this->var_lock );
return i_var;
}
p_var = &p_this->p_vars[i_var];
/* Backup needed stuff */
oldval = p_var->val;
/* Deal with callbacks. Tell we're in a callback, release the lock,
* call stored functions, retake the lock. */
if( p_var->i_entries )
{
int i_var;
int i_entries = p_var->i_entries;
callback_entry_t *p_entries = p_var->p_entries;
p_var->b_incallback = VLC_TRUE;
vlc_mutex_unlock( &p_this->var_lock );
/* The real calls */
for( ; i_entries-- ; )
{
p_entries[i_entries].pf_callback( p_this, psz_name, oldval, oldval,
p_entries[i_entries].p_data );
}
vlc_mutex_lock( &p_this->var_lock );
i_var = Lookup( p_this->p_vars, p_this->i_vars, psz_name );
if( i_var < 0 )
{
msg_Err( p_this, "variable %s has disappeared", psz_name );
vlc_mutex_unlock( &p_this->var_lock );
return VLC_ENOVAR;
}
p_var = &p_this->p_vars[i_var];
p_var->b_incallback = VLC_FALSE;
}
vlc_mutex_unlock( &p_this->var_lock );
return VLC_SUCCESS;
}
/** Parse a stringified option
* This function parse a string option and create the associated object
* variable
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment