/*****************************************************************************
* fake.c: decoder reading from a fake stream, outputting a fixed image
*****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
+ * Copyright (C) 2005-2009 the VideoLAN team
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
#include <vlc_image.h>
#include <vlc_filter.h>
-#include <vlc_charset.h>
/*****************************************************************************
* Local prototypes
#define DEINTERLACE_MODULE_TEXT N_("Deinterlace module")
#define DEINTERLACE_MODULE_LONGTEXT N_( \
"Deinterlace module to use." )
-#define CHROMA_TEXT N_("Chroma used.")
+#define CHROMA_TEXT N_("Chroma used")
#define CHROMA_LONGTEXT N_( \
"Force use of a specific chroma for output. Default is I420." )
"deinterlace", "ffmpeg-deinterlace"
};
-vlc_module_begin();
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_VCODEC );
- set_shortname( N_("Fake") );
- set_description( N_("Fake video decoder") );
- set_capability( "decoder", 1000 );
- set_callbacks( OpenDecoder, CloseDecoder );
- add_shortcut( "fake" );
+vlc_module_begin ()
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_VCODEC )
+ 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, false );
+ FILE_LONGTEXT, false )
add_integer( "fake-file-reload", 0, NULL, RELOAD_TEXT,
- RELOAD_LONGTEXT, false );
+ RELOAD_LONGTEXT, false )
add_integer( "fake-width", 0, NULL, WIDTH_TEXT,
- WIDTH_LONGTEXT, true );
+ WIDTH_LONGTEXT, true )
add_integer( "fake-height", 0, NULL, HEIGHT_TEXT,
- HEIGHT_LONGTEXT, true );
- add_bool( "fake-keep-ar", 0, NULL, KEEP_AR_TEXT, KEEP_AR_LONGTEXT,
- true );
+ HEIGHT_LONGTEXT, true )
+ add_bool( "fake-keep-ar", false, NULL, KEEP_AR_TEXT, KEEP_AR_LONGTEXT,
+ true )
add_string( "fake-aspect-ratio", "", NULL,
- ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true );
- add_bool( "fake-deinterlace", 0, NULL, DEINTERLACE_TEXT,
- DEINTERLACE_LONGTEXT, false );
+ ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true )
+ add_bool( "fake-deinterlace", false, NULL, DEINTERLACE_TEXT,
+ DEINTERLACE_LONGTEXT, false )
add_string( "fake-deinterlace-module", "deinterlace", NULL,
DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,
- false );
- change_string_list( ppsz_deinterlace_type, 0, 0 );
+ false )
+ change_string_list( ppsz_deinterlace_type, 0, 0 )
add_string( "fake-chroma", "I420", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
- true );
-vlc_module_end();
+ true )
+vlc_module_end ()
struct decoder_sys_t
{
static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
- vlc_value_t val;
image_handler_t *p_handler;
video_format_t fmt_in, fmt_out;
picture_t *p_image;
- char *psz_file, *psz_chroma;
+ char *psz_file, *psz_chroma, *psz_string;
bool b_keep_ar;
int i_aspect = 0;
+ int i_int;
if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') )
{
return VLC_EGENERIC;
}
- p_dec->p_sys = (decoder_sys_t *)malloc( sizeof( decoder_sys_t ) );
+ p_dec->p_sys = calloc( 1, sizeof( *p_dec->p_sys ) );
if( !p_dec->p_sys )
- {
return VLC_ENOMEM;
- }
- memset( p_dec->p_sys, 0, sizeof( decoder_sys_t ) );
psz_file = var_CreateGetNonEmptyStringCommand( p_dec, "fake-file" );
if( !psz_file )
free( p_dec->p_sys );
return VLC_EGENERIC;
}
- var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec );
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)
+ i_int = var_CreateGetIntegerCommand( p_dec, "fake-file-reload" );
+ if( 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_reload = (mtime_t)(i_int * 1000000);
p_dec->p_sys->i_next = (mtime_t)(p_dec->p_sys->i_reload + mdate());
}
- var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec );
psz_chroma = var_CreateGetString( p_dec, "fake-chroma" );
- if( strlen( psz_chroma ) != 4 )
+ fmt_out.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma );
+ if( !fmt_out.i_chroma )
{
msg_Warn( p_dec, "Invalid chroma (%s). Using I420.", psz_chroma );
- fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
- }
- else
- {
- fmt_out.i_chroma = VLC_FOURCC( psz_chroma[0],
- psz_chroma[1],
- psz_chroma[2],
- psz_chroma[3] );
+ fmt_out.i_chroma = VLC_CODEC_I420;
}
free( psz_chroma );
- var_Create( p_dec, "fake-keep-ar", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- var_Get( p_dec, "fake-keep-ar", &val );
- b_keep_ar = val.b_bool;
-
var_Create( p_dec, "fake-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_dec, "fake-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
- var_Create( p_dec, "fake-aspect-ratio",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ psz_string = var_CreateGetString( p_dec, "fake-aspect-ratio" );
- var_Get( p_dec, "fake-aspect-ratio", &val );
- if ( val.psz_string )
+ if( psz_string )
{
- char *psz_parser = strchr( val.psz_string, ':' );
+ char *psz_parser = strchr( psz_string, ':' );
if( psz_parser )
{
*psz_parser++ = '\0';
- i_aspect = atoi( val.psz_string )
+ i_aspect = atoi( psz_string )
* VOUT_ASPECT_FACTOR / atoi( psz_parser );
}
- free( val.psz_string );
+ free( psz_string );
}
- if ( !b_keep_ar )
+ b_keep_ar = var_CreateGetBool( p_dec, "fake-keep-ar" );
+
+ if( !b_keep_ar )
{
- var_Get( p_dec, "fake-width", &val );
- fmt_out.i_width = val.i_int;
- var_Get( p_dec, "fake-height", &val );
- fmt_out.i_height = val.i_int;
+ fmt_out.i_width = var_GetInteger( p_dec, "fake-width" );
+ fmt_out.i_height = var_GetInteger( p_dec, "fake-height" );
}
p_handler = image_HandlerCreate( p_dec );
picture_t *p_old = p_image;
int i_width, i_height;
- var_Get( p_dec, "fake-width", &val );
- i_width = val.i_int;
- var_Get( p_dec, "fake-height", &val );
- i_height = val.i_int;
+ i_width = var_GetInteger( p_dec, "fake-width" );
+ i_height = var_GetInteger( p_dec, "fake-height" );
if ( i_width && i_height )
{
if ( i_aspect )
{
- fmt_out.i_aspect = i_aspect;
+ fmt_out.i_sar_num = i_aspect * fmt_out.i_height;
+ fmt_out.i_sar_den = VOUT_ASPECT_FACTOR * fmt_out.i_width;
}
else
{
- fmt_out.i_aspect = fmt_out.i_width
- * VOUT_ASPECT_FACTOR / fmt_out.i_height;
+ fmt_out.i_sar_num = 1;
+ fmt_out.i_sar_den = 1;
}
- var_Create( p_dec, "fake-deinterlace", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- var_Get( p_dec, "fake-deinterlace", &val );
- if ( val.b_bool )
+ if( var_CreateGetBool( p_dec, "fake-deinterlace" ) )
{
picture_t *p_old = p_image;
- var_Create( p_dec, "fake-deinterlace-module",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- var_Get( p_dec, "fake-deinterlace-module", &val );
+ psz_string = var_CreateGetString( p_dec, "fake-deinterlace-module" );
p_handler = image_HandlerCreate( p_dec );
- p_image = image_Filter( p_handler, p_old, &fmt_out, val.psz_string );
+ p_image = image_Filter( p_handler, p_old, &fmt_out, psz_string );
image_HandlerDelete( p_handler );
- free( val.psz_string );
+ free( psz_string );
if ( p_image == NULL )
{
p_dec->p_sys->p_image = p_image;
vlc_mutex_init( &p_dec->p_sys->lock );
+ /* Add the callback when every variables are available */
+ var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec );
+ var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec );
+
return VLC_SUCCESS;
}
decoder_t *p_dec = (decoder_t *)p_this;
picture_t *p_image = p_dec->p_sys->p_image;
+ var_DelCallback( p_dec, "fake-file", FakeCallback, p_dec );
+ var_DelCallback( p_dec, "fake-file-reload", FakeCallback , p_dec );
+
if( p_image != NULL )
picture_Release( p_image );